Comparing version 1.2.3 to 1.2.4
{ | ||
"name": "flast", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Flatten JS AST", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -188,12 +188,2 @@ # flAST - FLat Abstract Syntax Tree | ||
## Contribution | ||
To contribute to this project see our [contribution guide](CONTRIBUTING.md) | ||
## Changes | ||
### v1.2.1 | ||
- Overhaul scoping to account for declarations with the same name in different scopes. | ||
### v1.1.1 | ||
- Improve getParentKey to include parsing the name of grouped nodes such as 'arguments' or 'body'. | ||
### v1.1.0 | ||
- Added parentKey property. | ||
- Improved ASTNode definition (useful for intellisense). | ||
- Ability to pass options directly to the espree parser. | ||
To contribute to this project see our [contribution guide](CONTRIBUTING.md) |
@@ -98,3 +98,3 @@ // noinspection JSUnusedGlobalSymbols | ||
if (isDeclaration) node.references = node.references || []; | ||
else { | ||
else if (!(node.parentKey === 'id' && node.parentNode.type === 'FunctionDeclaration')) { | ||
// Find declaration by finding the closest declaration of the same name. | ||
@@ -101,0 +101,0 @@ let decls = []; |
@@ -47,2 +47,21 @@ const assert = require('node:assert'); | ||
}, | ||
{ | ||
enabled: true, | ||
name: 'Variable references are not confused with functions of the same name', | ||
description: `Verify a function's identifier isn't treated as a reference.`, | ||
run() { | ||
const code = `function a() { | ||
var a; | ||
}`; | ||
const ast = generateFlatAST(code); | ||
const funcId = ast.find(n => n.name ==='a' && n.parentNode.type === 'FunctionDeclaration'); | ||
const varId = ast.find(n =>n.name ==='a' && n.parentNode.type === 'VariableDeclarator'); | ||
const functionReferencesFound = !!funcId.references?.length; | ||
const variableReferencesFound = !!varId.references?.length; | ||
assert(!functionReferencesFound, | ||
`References to a function were incorrectly found. Got "${functionReferencesFound}" instead of "false"`); | ||
assert(!variableReferencesFound, | ||
`References to a variable were incorrectly found. Got "${variableReferencesFound}" instead of "false"`); | ||
}, | ||
}, | ||
]; |
36548
606
188