Comparing version 1.5.2 to 1.6.0
{ | ||
"name": "flast", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "Flatten JS AST", | ||
@@ -28,4 +28,4 @@ "main": "src/index.js", | ||
"escodegen": "^2.1.0", | ||
"espree": "^9.6.1", | ||
"eslint-scope": "^7.2.2", | ||
"espree": "^10.1.0", | ||
"eslint-scope": "^8.0.1", | ||
"estraverse": "^5.3.0" | ||
@@ -32,0 +32,0 @@ }, |
@@ -143,3 +143,3 @@ const {parse} = require('espree'); | ||
} | ||
if (opts.includeSrc) Object.defineProperty(node, 'src', { | ||
if (opts.includeSrc && !node.src) Object.defineProperty(node, 'src', { | ||
get() { return rootNode.srcClosure(node.range[0], node.range[1]);}, | ||
@@ -229,8 +229,11 @@ }); | ||
optimistic: true, | ||
ecmaVersion, | ||
ecmaVersion: (new Date()).getFullYear(), | ||
sourceType}).acquireAll(rootNode)[0]; | ||
const allScopes = {}; | ||
const stack = [globalScope]; | ||
const seen = []; | ||
while (stack.length) { | ||
let scope = stack.pop(); | ||
if (seen.includes(scope)) continue; | ||
seen.push(scope); | ||
const scopeId = scope.block.nodeId; | ||
@@ -240,4 +243,7 @@ scope.block.isScopeBlock = true; | ||
allScopes[scopeId] = scope; | ||
stack.push(...scope.childScopes); | ||
} | ||
stack.push(...scope.childScopes); | ||
if (scope.type === 'module' && scope.upper?.type === 'global' && scope.variables?.length) { | ||
for (const v of scope.variables) if (!scope.upper.variables.includes(v)) scope.upper.variables.push(v); | ||
} | ||
} | ||
@@ -244,0 +250,0 @@ rootNode.allScopes = allScopes; |
const assert = require('node:assert'); | ||
const {generateFlatAST} = require(__dirname + '/../src/index'); | ||
module.exports = [ | ||
@@ -15,8 +16,9 @@ { | ||
const ast = generateFlatAST(code); | ||
const testedScope = [...new Set(ast.map(n => n.scope))][1]; | ||
const testedScope = ast[0].allScopes[Object.keys(ast[0].allScopes).slice(-1)[0]]; | ||
const expectedParentScopeType = 'function-expression-name'; | ||
const expectedScopeType = 'function'; | ||
assert.equal(testedScope.type, expectedScopeType, | ||
// ast.slice(-1)[0].type is the last identifier in the code and should have the expected scope type | ||
assert.equal(ast.slice(-1)[0].scope.type, expectedScopeType, | ||
`Unexpected scope`); | ||
assert.equal(testedScope.upper.type, expectedParentScopeType, | ||
assert.equal(testedScope.type, expectedParentScopeType, | ||
`Tested scope is not the child of the correct scope`); | ||
@@ -27,3 +29,3 @@ }, | ||
enabled: true, | ||
name: 'Local variable declaration supercedes outer scope declaration', | ||
name: 'Local variable declaration supersedes outer scope declaration', | ||
description: 'Verify declNode references the local declaration correctly.', | ||
@@ -44,5 +46,5 @@ run() { | ||
assert.equal(innerValResult, innerScopeVal, | ||
`Decleration node (inner scope) is incorrectly referenced.`); | ||
`Declaration node (inner scope) is incorrectly referenced.`); | ||
assert.equal(outerValResult, outerScopeVal, | ||
`Decleration node (outer scope) is incorrectly referenced.`); | ||
`Declaration node (outer scope) is incorrectly referenced.`); | ||
}, | ||
@@ -49,0 +51,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
48942
978
+ Addedeslint-scope@8.2.0(transitive)
+ Addedeslint-visitor-keys@4.2.0(transitive)
+ Addedespree@10.3.0(transitive)
- Removedeslint-scope@7.2.2(transitive)
- Removedeslint-visitor-keys@3.4.3(transitive)
- Removedespree@9.6.1(transitive)
Updatedeslint-scope@^8.0.1
Updatedespree@^10.1.0