Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "flast", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Flatten JS AST", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
// eslint-disable-next-line no-unused-vars | ||
const estraverse = require('estraverse'); | ||
const {generateCode, generateFlatAST, flattenRootNode} = require(__dirname + '/flast'); | ||
const {generateCode, generateFlatAST,} = require(__dirname + '/flast'); | ||
@@ -106,8 +106,10 @@ const Arborist = class { | ||
if (replacementNodeIds.includes(node.nodeId)) { | ||
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); | ||
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); | ||
} | ||
} | ||
@@ -117,6 +119,8 @@ ++changesCounter; | ||
} else if (that.markedForDeletion.includes(node.nodeId)) { | ||
const ns = that._parseSrcForLog(node.src); | ||
if (!removalLogCache.includes(ns)) { | ||
that.log(`\t\t[+] Removing\t${ns}`, 2); | ||
removalLogCache.push(ns); | ||
if (node.src) { | ||
const ns = that._parseSrcForLog(node.src); | ||
if (!removalLogCache.includes(ns)) { | ||
that.log(`\t\t[+] Removing\t${ns}`, 2); | ||
removalLogCache.push(ns); | ||
} | ||
} | ||
@@ -139,3 +143,3 @@ this.remove(); | ||
this.script = generateCode(rootNode); | ||
const ast = flattenRootNode(rootNode); | ||
const ast = generateFlatAST(this.script); | ||
if (ast && ast.length) this.ast = ast; | ||
@@ -142,0 +146,0 @@ else throw Error('Script is broken.'); |
@@ -9,3 +9,2 @@ const {parse} = require('espree'); | ||
/** | ||
@@ -76,12 +75,4 @@ * @param {string} inputCode | ||
} | ||
return flattenRootNode(rootNode, {inputCode, ...opts}); | ||
} | ||
/** | ||
* @param {ASTNode} rootNode | ||
* @param {object} opts | ||
* @returns {ASTNode[]} | ||
*/ | ||
function flattenRootNode(rootNode, opts = {}) { | ||
let scopeManager; | ||
let srcClosure; | ||
try { | ||
@@ -93,2 +84,3 @@ if (opts.detailed) { // noinspection JSCheckFunctionSignatures | ||
sourceType}); | ||
if (opts.includeSrc) srcClosure = createSrcClosure(inputCode); | ||
} | ||
@@ -99,3 +91,2 @@ } catch {} | ||
let scopeId = 0; | ||
const srcClosure = opts.inputCode ? createSrcClosure(opts.inputCode) : () => undefined; | ||
estraverse.traverse(rootNode, { | ||
@@ -189,3 +180,2 @@ /** | ||
estraverse, | ||
flattenRootNode, | ||
generateCode, | ||
@@ -192,0 +182,0 @@ generateFlatAST, |
39904
739