ast-types
Advanced tools
Comparing version 0.8.14 to 0.8.15
@@ -308,3 +308,11 @@ var types = require("../lib/types"); | ||
.field("property", or(def("Identifier"), def("Expression"))) | ||
.field("computed", Boolean, defaults["false"]); | ||
.field("computed", Boolean, function(){ | ||
var type = this.property.type; | ||
if (type === 'Literal' || | ||
type === 'MemberExpression' || | ||
type === 'BinaryExpression') { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
@@ -311,0 +319,0 @@ def("Pattern").bases("Node"); |
@@ -37,3 +37,4 @@ var types = require("./types"); | ||
parent: { value: parentScope }, | ||
bindings: { value: {} } | ||
bindings: { value: {} }, | ||
types: { value: {} }, | ||
}); | ||
@@ -71,2 +72,7 @@ } | ||
Sp.declaresType = function(name) { | ||
this.scan(); | ||
return hasOwn.call(this.types, name); | ||
}; | ||
Sp.declareTemporary = function(prefix) { | ||
@@ -120,3 +126,3 @@ if (prefix) { | ||
} | ||
scanScope(this.path, this.bindings); | ||
scanScope(this.path, this.bindings, this.types); | ||
this.didScan = true; | ||
@@ -131,3 +137,8 @@ } | ||
function scanScope(path, bindings) { | ||
Sp.getTypes = function () { | ||
this.scan(); | ||
return this.types; | ||
}; | ||
function scanScope(path, bindings, scopeTypes) { | ||
var node = path.value; | ||
@@ -143,7 +154,7 @@ ScopeType.assert(node); | ||
} else { | ||
recursiveScanScope(path, bindings); | ||
recursiveScanScope(path, bindings, scopeTypes); | ||
} | ||
} | ||
function recursiveScanScope(path, bindings) { | ||
function recursiveScanScope(path, bindings, scopeTypes) { | ||
var node = path.value; | ||
@@ -162,3 +173,3 @@ | ||
path.each(function(childPath) { | ||
recursiveScanChild(childPath, bindings); | ||
recursiveScanChild(childPath, bindings, scopeTypes); | ||
}); | ||
@@ -171,7 +182,10 @@ | ||
recursiveScanChild(path.get("body"), bindings); | ||
recursiveScanChild(path.get("body"), bindings, scopeTypes); | ||
} else if (namedTypes.TypeAlias && namedTypes.TypeAlias.check(node)) { | ||
addTypePattern(path.get("id"), scopeTypes); | ||
} else if (namedTypes.VariableDeclarator.check(node)) { | ||
addPattern(path.get("id"), bindings); | ||
recursiveScanChild(path.get("init"), bindings); | ||
recursiveScanChild(path.get("init"), bindings, scopeTypes); | ||
@@ -197,3 +211,3 @@ } else if (node.type === "ImportSpecifier" || | ||
} | ||
recursiveScanChild(childPath, bindings); | ||
recursiveScanChild(childPath, bindings, scopeTypes); | ||
}); | ||
@@ -203,3 +217,3 @@ } | ||
function recursiveScanChild(path, bindings) { | ||
function recursiveScanChild(path, bindings, scopeTypes) { | ||
var node = path.value; | ||
@@ -225,3 +239,3 @@ | ||
// as bindings in the outer scope. | ||
recursiveScanScope(path.get("body"), bindings); | ||
recursiveScanScope(path.get("body"), bindings, scopeTypes); | ||
@@ -238,3 +252,3 @@ // If a new binding matching the catch parameter name was | ||
} else { | ||
recursiveScanScope(path, bindings); | ||
recursiveScanScope(path, bindings, scopeTypes); | ||
} | ||
@@ -292,2 +306,16 @@ } | ||
function addTypePattern(patternPath, types) { | ||
var pattern = patternPath.value; | ||
namedTypes.Pattern.assert(pattern); | ||
if (namedTypes.Identifier.check(pattern)) { | ||
if (hasOwn.call(types, pattern.name)) { | ||
types[pattern.name].push(patternPath); | ||
} else { | ||
types[pattern.name] = [patternPath]; | ||
} | ||
} | ||
} | ||
Sp.lookup = function(name) { | ||
@@ -300,2 +328,9 @@ for (var scope = this; scope; scope = scope.parent) | ||
Sp.lookupType = function(name) { | ||
for (var scope = this; scope; scope = scope.parent) | ||
if (scope.declaresType(name)) | ||
break; | ||
return scope; | ||
}; | ||
Sp.getGlobalScope = function() { | ||
@@ -302,0 +337,0 @@ var scope = this; |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.8.14", | ||
"version": "0.8.15", | ||
"homepage": "http://github.com/benjamn/ast-types", | ||
@@ -24,0 +24,0 @@ "repository": { |
134084
3291