Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit abb780a

Browse files
committed
Add basic support for getter properties
Issue angelozerr#377
1 parent a5b71a3 commit abb780a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/infer.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -930,19 +930,23 @@
930930

931931
for (var i = 0; i < node.properties.length; ++i) {
932932
var prop = node.properties[i], key = prop.key, name;
933-
if (prop.value.name == "✖") {
934-
continue;
935-
} else if (key.type == "Identifier") {
933+
if (prop.value.name == "✖") continue;
934+
935+
if (key.type == "Identifier") {
936936
name = key.name;
937937
} else if (typeof key.value == "string") {
938938
name = key.value;
939-
} else {
939+
}
940+
if (!name || prop.kind == "set") {
940941
infer(prop.value, scope, c, ANull);
941942
continue;
942943
}
943-
var val = obj.defProp(name, key);
944+
945+
var val = obj.defProp(name, key), out = val;
944946
val.initializer = true;
945-
infer(prop.value, scope, c, val, name);
947+
if (prop.kind == "get")
948+
out = new IsCallee(obj, [], null, val);
949+
infer(prop.value, scope, c, out, name);
946950
}
947951
return obj;
948952
}),
@@ -1339,8 +1343,7 @@
13391343
};
13401344

13411345
function findType(node, scope) {
1342-
var found = typeFinder[node.type](node, scope);
1343-
return found;
1346+
return typeFinder[node.type](node, scope);
13441347
}
13451348

13461349
var searchVisitor = exports.searchVisitor = walk.make({

plugin/doc_comment.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
ObjectExpression: function(node) {
4646
for (var i = 0; i < node.properties.length; ++i)
47-
attachComments(node.properties[i].key);
47+
attachComments(node.properties[i]);
4848
},
4949
CallExpression: function(node) {
5050
if (isDefinePropertyCall(node)) attachComments(node);
@@ -82,10 +82,10 @@
8282
},
8383
ObjectExpression: function(node, scope) {
8484
for (var i = 0; i < node.properties.length; ++i) {
85-
var prop = node.properties[i], key = prop.key;
86-
if (key.commentsBefore)
87-
interpretComments(prop, key.commentsBefore, scope,
88-
node.objType.getProp(key.name));
85+
var prop = node.properties[i];
86+
if (prop.commentsBefore)
87+
interpretComments(prop, prop.commentsBefore, scope,
88+
node.objType.getProp(prop.key.name));
8989
}
9090
},
9191
CallExpression: function(node, scope) {

0 commit comments

Comments
 (0)