estraverse
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -46,4 +46,3 @@ /* | ||
VisitorOption, | ||
VisitorKeys, | ||
wrappers; | ||
VisitorKeys; | ||
@@ -150,6 +149,2 @@ Syntax = { | ||
wrappers = { | ||
PropertyWrapper: 'Property' | ||
}; | ||
function Reference(parent, key) { | ||
@@ -181,15 +176,29 @@ this.parent = parent; | ||
// API: | ||
// return property path from root to current node | ||
// return property path array from root to current node | ||
Controller.prototype.path = function path() { | ||
var i, iz, result, element; | ||
var i, iz, j, jz, result, element; | ||
// first node is sentinel | ||
function addToPath(result, path) { | ||
if (isArray(path)) { | ||
for (j = 0, jz = path.length; j < jz; ++j) { | ||
result.push(path[j]); | ||
} | ||
} else { | ||
result.push(path); | ||
} | ||
} | ||
// root node | ||
if (!this.__current.path) { | ||
return null; | ||
} | ||
// first node is sentinel, second node is root element | ||
result = []; | ||
for (i = 1, iz = this.__leavelist.length; i < iz; ++i) { | ||
for (i = 2, iz = this.__leavelist.length; i < iz; ++i) { | ||
element = this.__leavelist[i]; | ||
result.push(element.path); | ||
addToPath(result, element.path); | ||
} | ||
result.push(this.__current.path); | ||
return '$' + result.join('.'); | ||
addToPath(result, this.__current.path); | ||
return result; | ||
}; | ||
@@ -227,2 +236,4 @@ | ||
// API: | ||
// notify control skip / break | ||
Controller.prototype.notify = function notify(flag) { | ||
@@ -232,2 +243,4 @@ this.__state = flag; | ||
// API: | ||
// skip child nodes of current node | ||
Controller.prototype.skip = function () { | ||
@@ -237,2 +250,4 @@ this.notify(VisitorOption.Skip); | ||
// API: | ||
// break traversals | ||
Controller.prototype['break'] = function () { | ||
@@ -265,4 +280,4 @@ this.notify(VisitorOption.Break); | ||
// initialize | ||
worklist.push(new Element(root, '', null, null)); | ||
leavelist.push(new Element(null, '', null, null)); | ||
worklist.push(new Element(root, null, null, null)); | ||
leavelist.push(new Element(null, null, null, null)); | ||
@@ -321,5 +336,5 @@ while (worklist.length) { | ||
if (nodeType === Syntax.ObjectExpression && 'properties' === candidates[current] && null == candidates[current].type) { | ||
element = new Element(candidate[current2], key + '[' + current2 + ']', 'Property', null); | ||
element = new Element(candidate[current2], [key, current2], 'Property', null); | ||
} else { | ||
element = new Element(candidate[current2], key + '[' + current2 + ']', null, null); | ||
element = new Element(candidate[current2], [key, current2], null, null); | ||
} | ||
@@ -360,3 +375,3 @@ worklist.push(element); | ||
}; | ||
element = new Element(root, '', null, new Reference(outer, 'root')); | ||
element = new Element(root, null, null, new Reference(outer, 'root')); | ||
worklist.push(element); | ||
@@ -439,5 +454,5 @@ leavelist.push(element); | ||
if (nodeType === Syntax.ObjectExpression && 'properties' === candidates[current] && null == candidates[current].type) { | ||
element = new Element(candidate[current2], key + '[' + current2 + ']', 'Property', new Reference(candidate, current2)); | ||
element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2)); | ||
} else { | ||
element = new Element(candidate[current2], key + '[' + current2 + ']', null, new Reference(candidate, current2)); | ||
element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2)); | ||
} | ||
@@ -452,3 +467,3 @@ worklist.push(element); | ||
exports.version = '1.0.0'; | ||
exports.version = '1.1.0'; | ||
exports.Syntax = Syntax; | ||
@@ -455,0 +470,0 @@ exports.traverse = traverse; |
@@ -6,3 +6,3 @@ { | ||
"main": "estraverse.js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"engines": { | ||
@@ -9,0 +9,0 @@ "node": ">=0.4.0" |
20756
454