🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ast-util

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-util - npm Package Compare versions

Comparing version

to
0.5.2

31

lib/index.js

@@ -406,3 +406,14 @@ /* jshint node:true, undef:true, unused:true */

bodyPath.unshift(
var declarationIndex;
var bodyStatements = bodyPath.node.body;
for (declarationIndex = 0; declarationIndex < bodyStatements.length; declarationIndex++) {
var statement = bodyStatements[declarationIndex];
if (!isDirectivePrologue(statement)) {
break;
}
}
bodyPath.insertAt(
declarationIndex,
b.variableDeclaration(

@@ -427,2 +438,20 @@ 'var',

/**
* Determines whether the given statement is a directive prologue, e.g.
* "use strict".
*
* @param {Statement} statement
* @returns {boolean}
*/
function isDirectivePrologue(statement) {
if (n.ExpressionStatement.check(statement)) {
var expression = statement.expression;
if (n.Literal.check(expression)) {
return typeof expression.value === 'string';
}
}
return false;
}
/**
* Determines whether the given `path` is a value reference. For example, `a`

@@ -429,0 +458,0 @@ * and `b` are references, but `c` is not:

2

package.json
{
"name": "ast-util",
"version": "0.5.1",
"version": "0.5.2",
"description": "Utilities for AST transformers.",

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

@@ -300,3 +300,3 @@ /* jshint node:true, mocha:true, undef:true, unused:true */

sameSource(ast,'var hasOwnProp = Object.prototype.hasOwnProperty; IT;');
sameSource(ast, 'var hasOwnProp = Object.prototype.hasOwnProperty; IT;');
});

@@ -321,2 +321,26 @@

});
it('injects after any global "use strict" pragma', function() {
var ast = processIt('"use strict"; IT;', function() {
util.injectVariable(
this.scope,
b.identifier('a'),
b.literal(1)
)
});
sameSource(ast, '"use strict"; var a = 1; IT;');
});
it('injects after any local "use strict" pragma', function() {
var ast = processIt('function getIt() { "use strict"; return IT; }', function() {
util.injectVariable(
this.scope,
b.identifier('a'),
b.literal(1)
)
});
sameSource(ast, 'function getIt() { "use strict"; var a = 1; return IT; }');
});
});

@@ -323,0 +347,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet