Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flast

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flast - npm Package Compare versions

Comparing version 1.5.2 to 1.6.0

6

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc