Comparing version 0.5.1 to 0.5.2
@@ -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: |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125456
1974