is-reference
Advanced tools
Comparing version 1.1.1 to 1.1.2
# is-reference changelog | ||
## 1.1.2 | ||
* Ignore labels in break/continue statements ([#4](https://github.com/Rich-Harris/is-reference/pull/4)) | ||
## 1.1.1 | ||
@@ -4,0 +8,0 @@ |
@@ -6,21 +6,17 @@ function isReference(node, parent) { | ||
if (node.type === 'Identifier') { | ||
// the only time we could have an identifier node without a parent is | ||
// if it's the entire body of a function without a block statement – | ||
// i.e. an arrow function expression like `a => a` | ||
if (!parent) | ||
return true; | ||
if (parent.type === 'MemberExpression') | ||
return parent.computed || node === parent.object; | ||
if (parent.type === 'MethodDefinition') | ||
return parent.computed; | ||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` | ||
if (parent.type === 'Property') | ||
return parent.computed || node === parent.value; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) | ||
return false; | ||
// disregard the foo in `foo: bar` | ||
if (parent.type === 'LabeledStatement') | ||
return false; | ||
return true; | ||
switch (parent.type) { | ||
// disregard `bar` in `foo.bar` | ||
case 'MemberExpression': return parent.computed || node === parent.object; | ||
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}` | ||
case 'MethodDefinition': return parent.computed; | ||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` | ||
case 'Property': return parent.computed || node === parent.value; | ||
// disregard the `bar` in `export { foo as bar }` | ||
case 'ExportSpecifier': return node === parent.local; | ||
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}` | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': return false; | ||
default: return true; | ||
} | ||
} | ||
@@ -27,0 +23,0 @@ return false; |
@@ -12,21 +12,17 @@ (function (global, factory) { | ||
if (node.type === 'Identifier') { | ||
// the only time we could have an identifier node without a parent is | ||
// if it's the entire body of a function without a block statement – | ||
// i.e. an arrow function expression like `a => a` | ||
if (!parent) | ||
return true; | ||
if (parent.type === 'MemberExpression') | ||
return parent.computed || node === parent.object; | ||
if (parent.type === 'MethodDefinition') | ||
return parent.computed; | ||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` | ||
if (parent.type === 'Property') | ||
return parent.computed || node === parent.value; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) | ||
return false; | ||
// disregard the foo in `foo: bar` | ||
if (parent.type === 'LabeledStatement') | ||
return false; | ||
return true; | ||
switch (parent.type) { | ||
// disregard `bar` in `foo.bar` | ||
case 'MemberExpression': return parent.computed || node === parent.object; | ||
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}` | ||
case 'MethodDefinition': return parent.computed; | ||
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` | ||
case 'Property': return parent.computed || node === parent.value; | ||
// disregard the `bar` in `export { foo as bar }` | ||
case 'ExportSpecifier': return node === parent.local; | ||
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}` | ||
case 'LabeledStatement': | ||
case 'BreakStatement': | ||
case 'ContinueStatement': return false; | ||
default: return true; | ||
} | ||
} | ||
@@ -33,0 +29,0 @@ return false; |
{ | ||
"name": "is-reference", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Determine whether an AST node is a reference", | ||
@@ -14,5 +14,6 @@ "main": "dist/is-reference.js", | ||
"test": "mocha", | ||
"build": "rollup -c && tsc", | ||
"build": "rollup -c && tsc --emitDeclarationOnly", | ||
"pretest": "npm run build", | ||
"prepublish": "npm test" | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test" | ||
}, | ||
@@ -39,10 +40,10 @@ "repository": { | ||
"devDependencies": { | ||
"acorn": "^6.0.4", | ||
"acorn": "^6.1.1", | ||
"estree-walker": "^0.6.0", | ||
"mocha": "^5.2.0", | ||
"rollup": "^1.0.0", | ||
"rollup-plugin-typescript": "^1.0.0", | ||
"mocha": "^6.0.2", | ||
"rollup": "^1.7.0", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"tslib": "^1.9.3", | ||
"typescript": "^3.2.2" | ||
"typescript": "^3.3.4000" | ||
} | ||
} |
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
5350
56