ast-types
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -178,5 +178,3 @@ var assert = require("assert"); | ||
Cp.constructor = Context; | ||
Cp.reset = sharedReset; | ||
Cp.invokeVisitorMethod = sharedInvokeVisitorMethod; | ||
Cp.traverse = sharedTraverse; | ||
extend(Cp, sharedContextProtoMethods); | ||
@@ -186,3 +184,9 @@ return Context; | ||
function sharedReset(path) { | ||
// Every PathVisitor has a different this.Context constructor and | ||
// this.Context.prototype object, but those prototypes can all use the | ||
// same reset, invokeVisitorMethod, and traverse function objects. | ||
var sharedContextProtoMethods = Object.create(null); | ||
sharedContextProtoMethods.reset = | ||
function reset(path) { | ||
assert.ok(this instanceof this.Context); | ||
@@ -195,5 +199,6 @@ assert.ok(path instanceof NodePath); | ||
return this; | ||
} | ||
}; | ||
function sharedInvokeVisitorMethod(methodName) { | ||
sharedContextProtoMethods.invokeVisitorMethod = | ||
function invokeVisitorMethod(methodName) { | ||
assert.ok(this instanceof this.Context); | ||
@@ -226,5 +231,6 @@ assert.ok(this.currentPath instanceof NodePath); | ||
); | ||
} | ||
}; | ||
function sharedTraverse(path, newVisitor) { | ||
sharedContextProtoMethods.traverse = | ||
function traverse(path, newVisitor) { | ||
assert.ok(this instanceof this.Context); | ||
@@ -239,4 +245,4 @@ assert.ok(path instanceof NodePath); | ||
)); | ||
} | ||
}; | ||
module.exports = PathVisitor; |
@@ -237,2 +237,38 @@ var assert = require("assert"); | ||
function repairRelationshipWithParent(path) { | ||
assert.ok(path instanceof Path); | ||
var pp = path.parentPath; | ||
if (!pp) { | ||
// Orphan paths have no relationship to repair. | ||
return path; | ||
} | ||
var parentValue = pp.value; | ||
var parentCache = pp.__childCache; | ||
// Make sure parentCache[path.name] is populated. | ||
if (parentValue[path.name] === path.value) { | ||
parentCache[path.name] = path; | ||
} else if (isArray.check(parentValue)) { | ||
// Something caused path.name to become out of date, so attempt to | ||
// recover by searching for path.value in parentValue. | ||
var i = parentValue.indexOf(path.value); | ||
if (i >= 0) { | ||
parentCache[path.name = i] = path; | ||
} | ||
} else { | ||
// If path.value disagrees with parentValue[path.name], and | ||
// path.name is not an array index, let path.value become the new | ||
// parentValue[path.name] and update parentCache accordingly. | ||
parentValue[path.name] = path.value; | ||
parentCache[path.name] = path; | ||
} | ||
assert.strictEqual(parentValue[path.name], path.value); | ||
assert.strictEqual(path.parentPath.get(path.name), path); | ||
return path; | ||
} | ||
Pp.replace = function replace(replacement) { | ||
@@ -244,16 +280,6 @@ var results = []; | ||
repairRelationshipWithParent(this); | ||
if (isArray.check(parentValue)) { | ||
var originalLength = parentValue.length; | ||
if (parentValue[this.name] !== this.value) { | ||
// Something caused our index (name) to become out of date. | ||
var i = parentValue.indexOf(this.value); | ||
if (i >= 0) { | ||
parentCache[this.name = i] = this; | ||
} | ||
} | ||
assert.strictEqual(parentValue[this.name], this.value); | ||
assert.strictEqual(this.parentPath.get(this.name), this); | ||
var move = getMoves(this.parentPath, count - 1, this.name + 1); | ||
@@ -260,0 +286,0 @@ |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"homepage": "http://github.com/benjamn/ast-types", | ||
@@ -24,0 +24,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91639
2320