New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flast

Package Overview
Dependencies
Maintainers
2
Versions
28
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.3.2 to 1.3.3

2

CONTRIBUTING.md

@@ -81,3 +81,3 @@ # Contributing

reported to the community leaders responsible for enforcement at
[ben.baryo@perimeterx.com](mailto:ben.baryo@perimeterx.com).
[ben.baryo@humansecurity.com](mailto:ben.baryo@humansecurity.com).
All complaints will be reviewed and investigated promptly and fairly.

@@ -84,0 +84,0 @@

{
"name": "flast",
"version": "1.3.2",
"version": "1.3.3",
"description": "Flatten JS AST",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -110,10 +110,14 @@ // eslint-disable-next-line no-unused-vars

try {
if (replacementNodeIds.includes(node.nodeId)) {
if (replacementNodeIds.includes(node.nodeId) && node.isMarked) {
if (node.src) {
if (badReplacements.includes(node.src)) return;
const nsrc = that._parseSrcForLog(node.src, true);
if (!replacementLogCache.includes(nsrc)) {
const tsrc = that._parseSrcForLog(generateCode(that.markedForReplacement[node.nodeId]));
that.log(`\t\t[+] Replacing\t${nsrc}\t--with--\t${tsrc}`, 2);
replacementLogCache.push(nsrc);
try {
if (badReplacements.includes(node.src)) return;
const nsrc = that._parseSrcForLog(node.src, true);
if (!replacementLogCache.includes(nsrc)) {
const tsrc = that._parseSrcForLog(generateCode(that.markedForReplacement[node.nodeId]));
that.log(`\t\t[+] Replacing\t${nsrc}\t--with--\t${tsrc}`, 2);
replacementLogCache.push(nsrc);
}
} catch {
that.log(`\t\t[+] Replacing ${that._parseSrcForLog('N/A')}\t--with\t${that._parseSrcForLog('N/A')}`);
}

@@ -123,8 +127,12 @@ }

return that.markedForReplacement[node.nodeId];
} else if (that.markedForDeletion.includes(node.nodeId)) {
} else if (that.markedForDeletion.includes(node.nodeId) && node.isMarked) {
if (node.src) {
const ns = that._parseSrcForLog(node.src);
if (!removalLogCache.includes(ns)) {
that.log(`\t\t[+] Removing\t${ns}`, 2);
removalLogCache.push(ns);
try {
const ns = that._parseSrcForLog(node.src);
if (!removalLogCache.includes(ns)) {
that.log(`\t\t[+] Removing\t${ns}`, 2);
removalLogCache.push(ns);
}
} catch {
that.log(`\t\t[+] Removing\tN/A`, 2);
}

@@ -148,6 +156,12 @@ }

// script will remain the same. If it doesn't break, the changes are valid and the script can be marked as modified.
this.script = generateCode(rootNode);
const ast = generateFlatAST(this.script);
if (ast && ast.length) this.ast = ast;
else throw Error('Script is broken.');
const script = generateCode(rootNode);
const ast = generateFlatAST(script);
if (ast && ast.length) {
this.ast = ast;
this.script = script;
}
else {
this.log(`[-] Modified script is invalid. Reverting ${changesCounter} changes...`);
changesCounter = 0;
}
}

@@ -154,0 +168,0 @@ }

@@ -39,3 +39,3 @@ const {parse} = require('espree');

const generateFlatASTDefaultOptions = {
// If false, include only original node without any further details
// If false, include only original node with nodeId, without any further details
detailed: true,

@@ -95,4 +95,4 @@ // If false, do not include node src. Only available when `detailed` option is true

enter(node, parentNode) {
node.nodeId = nodeId++;
if (opts.detailed) {
node.nodeId = nodeId++;
if (opts.includeSrc) Object.defineProperty(node, 'src', {

@@ -99,0 +99,0 @@ get() { return srcClosure(node.range[0], node.range[1]);},

@@ -0,1 +1,4 @@

// eslint-disable-next-line no-unused-vars
const {Scope} = require('eslint-scope');
/**

@@ -17,2 +20,3 @@ * @typedef ASTNode

* @property {ASTNode} [declNode]
* @property {boolean} [delegate]
* @property {ASTNode[]} [elements]

@@ -50,8 +54,9 @@ * @property {number} [end]

* @property {ASTNode} [right]
* @property {ScopeManager} [scope]
* @property {Scope} [scope]
* @property {string} [scriptHash]
* @property {boolean} [shorthand]
* @property {string} [sourceType]
* @property {boolean} [static]
* @property {number} [start]
* @property {string} [src]
* @property {string|function} [src]
* @property {ASTNode|null} [superClass]

@@ -58,0 +63,0 @@ * @property {boolean} [tail]

@@ -142,2 +142,15 @@ const assert = require('node:assert');

},
{
enabled: true,
name: `Invalid changes are not applied`,
description: `Verify a valid AST array can be used to initialize an arborist instance.`,
run() {
const code = `console.log('test');`;
const arborist = new Arborist(code);
arborist.markNode(arborist.ast.find(n => n.type === 'Literal'), {type: 'EmptyStatement'});
arborist.markNode(arborist.ast.find(n => n.name === 'log'), {type: 'EmptyStatement'});
arborist.applyChanges();
assert.equal(arborist.script, code);
},
},
];

@@ -75,3 +75,3 @@ const assert = require('node:assert');

assert.equal(noDetailsVarDec.parentNode || noDetailsVarDec.childNodes || noDetailsVarDec.references ||
noDetailsVarRef.declNode || noDetailsVarRef.nodeId || noDetailsVarRef.scope || noDetailsVarRef.src, undefined,
noDetailsVarRef.declNode || noDetailsVarRef.scope || noDetailsVarRef.src, undefined,
`Flat AST generated with details despite 'detailed' option set to false.`);

@@ -78,0 +78,0 @@ const detailedAst = generateFlatAST(code, {detailed: true});

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