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.0 to 1.5.2

10

package.json
{
"name": "flast",
"version": "1.5.0",
"version": "1.5.2",
"description": "Flatten JS AST",

@@ -27,11 +27,11 @@ "main": "src/index.js",

"dependencies": {
"escodegen": "^2.0.0",
"espree": "^9.5.2",
"eslint-scope": "^7.2.0",
"escodegen": "^2.1.0",
"espree": "^9.6.1",
"eslint-scope": "^7.2.2",
"estraverse": "^5.3.0"
},
"devDependencies": {
"eslint": "^8.43.0",
"eslint": "^8.49.0",
"husky": "^8.0.3"
}
}

@@ -36,2 +36,3 @@ const {generateCode, generateFlatAST,} = require(__dirname + '/flast');

)) currentNode = currentNode.parentNode;
if (['consequent', 'alternate'].includes(currentNode.parentKey)) currentNode.isEmpty = true;
return currentNode;

@@ -61,3 +62,4 @@ }

targetNode = this._getCorrectTargetForDeletion(targetNode);
if (!targetNode.isMarked) {
if (targetNode.isEmpty) this.markNode(targetNode, {type: 'EmptyStatement'});
else if (!targetNode.isMarked) {
this.markedForDeletion.push(targetNode.nodeId);

@@ -85,3 +87,7 @@ targetNode.isMarked = true;

this.log(`[+] Applying changes to the root node...`);
const leadingComments = rootNode.leadingComments || [];
const trailingComments = rootNode.trailingComments || [];
rootNode = rootNodeReplacement[1];
if (leadingComments.length) rootNode.leadingComments = (rootNode.leadingComments || []).concat(leadingComments);
if (trailingComments.length) rootNode.trailingComments = (rootNode.trailingComments || []).concat(trailingComments);
} else {

@@ -95,2 +101,4 @@ for (const targetNodeId of this.markedForDeletion) {

parent[targetNode.parentKey] = undefined;
const comments = (targetNode.leadingComments || []).concat(targetNode.trailingComments || []);
if (comments.length) parent.trailingComments = (parent.trailingComments || []).concat(comments);
++changesCounter;

@@ -101,2 +109,7 @@ } else if (Array.isArray(parent[targetNode.parentKey])) {

parent[targetNode.parentKey] = parent[targetNode.parentKey].filter(n => n);
const comments = (targetNode.leadingComments || []).concat(targetNode.trailingComments || []);
if (comments.length) {
const targetParent = idx > 0 ? parent[targetNode.parentKey][idx - 1] : parent[targetNode.parentKey].length > 1 ? parent[targetNode.parentKey][idx + 1] : parent;
targetParent.trailingComments = (targetParent.trailingComments || []).concat(comments);
}
++changesCounter;

@@ -115,2 +128,6 @@ }

parent[targetNode.parentKey] = replacementNode;
const leadingComments = targetNode.leadingComments || [];
const trailingComments = targetNode.trailingComments || [];
if (leadingComments.length) replacementNode.leadingComments = (replacementNode.leadingComments || []).concat(leadingComments);
if (trailingComments.length) replacementNode.trailingComments = (replacementNode.trailingComments || []).concat(trailingComments);
++changesCounter;

@@ -120,2 +137,10 @@ } else if (Array.isArray(parent[targetNode.parentKey])) {

parent[targetNode.parentKey][idx] = replacementNode;
const comments = (targetNode.leadingComments || []).concat(targetNode.trailingComments || []);
if (idx > 0) {
const commentsTarget = parent[targetNode.parentKey][idx - 1];
commentsTarget.trailingComments = (commentsTarget.trailingComments || []).concat(comments);
} else if (parent[targetNode.parentKey].length > 1) {
const commentsTarget = parent[targetNode.parentKey][idx + 1];
commentsTarget.leadingComments = (commentsTarget.leadingComments || []).concat(comments);
} else parent.trailingComments = (parent.trailingComments || []).concat(comments);
++changesCounter;

@@ -122,0 +147,0 @@ }

const {parse} = require('espree');
const {generate} = require('escodegen');
const {generate, attachComments} = require('escodegen');
const estraverse = require('estraverse');

@@ -15,3 +15,5 @@ const {analyze} = require('eslint-scope');

function parseCode(inputCode, opts = {}) {
return parse(inputCode, {ecmaVersion, comment: true, range: true, ...opts});
const rootNode = parse(inputCode, {ecmaVersion, comment: true, range: true, ...opts});
if (rootNode.tokens) attachComments(rootNode, rootNode.comments, rootNode.tokens);
return rootNode;
}

@@ -55,2 +57,4 @@

sourceType,
comment: true,
tokens: true,
},

@@ -57,0 +61,0 @@ };

@@ -14,2 +14,3 @@ const {Scope} = require('eslint-scope');

* @property {ASTNode[]} [childNodes]
* @property {Object[]} [comments]
* @property {boolean} [computed]

@@ -33,13 +34,15 @@ * @property {ASTNode} [consequent]

* @property {ASTNode} [init]
* @property {boolean} [isMarked]
* @property {boolean} [isScopeBlock]
* @property {boolean} [isEmpty] True when the node is set for deletion but should be replced with an Empty Statement instead
* @property {boolean} [isMarked] True when the node has already been marked for replacement or deletion
* @property {boolean} [isScopeBlock] Marks the node as a scope block to allow iterations to quickly find a surrounding block
* @property {ASTNode} [key]
* @property {string} [kind]
* @property {ASTNode} [label]
* @property {Object[]} [leadingComments]
* @property {ASTNode} [left]
* @property {number[]} [lineage]
* @property {number[]} [lineage] The nodeIds of all parent nodes
* @property {ASTNode} [local]
* @property {boolean} [method]
* @property {string} [name]
* @property {number} [nodeId]
* @property {number} [nodeId] A unique id in the AST
* @property {string} [operator]

@@ -49,3 +52,3 @@ * @property {ASTNode} [object]

* @property {ASTNode[]} [params]
* @property {string} [parentKey]
* @property {string} [parentKey] The designation the node has within the parent node
* @property {ASTNode} [parentNode]

@@ -69,6 +72,8 @@ * @property {boolean} [prefix]

* @property {number} [start]
* @property {string|function} [src]
* @property {string|function} [src] The source code for the node
* @property {ASTNode} [superClass]
* @property {boolean} [tail]
* @property {ASTNode} [test]
* @property {ASTNode} [tokens]
* @property {Object[]} [trailingComments]
* @property {ASTNode} [update]

@@ -75,0 +80,0 @@ * @property {ASTNode|string|number|boolean} [value]

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