better identification of strict directives - cc @jmm
This commit is contained in:
parent
0fbc714315
commit
beb8061d3f
@ -103,8 +103,8 @@ exports.nodes = {
|
|||||||
* Test if Literal needs whitespace.
|
* Test if Literal needs whitespace.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Literal(node) {
|
Literal(node, parent) {
|
||||||
if (node.value === "use strict") {
|
if (t.isExpressionStatement(parent)) {
|
||||||
return {
|
return {
|
||||||
after: true
|
after: true
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,6 +6,16 @@ export var metadata = {
|
|||||||
|
|
||||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassExpression", "ClassDeclaration"];
|
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassExpression", "ClassDeclaration"];
|
||||||
|
|
||||||
|
function isUseStrict(node) {
|
||||||
|
if (!t.isLiteral(node)) return false;
|
||||||
|
|
||||||
|
if (node.raw && node.rawValue === node.value) {
|
||||||
|
return node.rawValue === "use strict";
|
||||||
|
} else {
|
||||||
|
return node.value === "use strict";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [Please add a description.]
|
* [Please add a description.]
|
||||||
*/
|
*/
|
||||||
@ -21,7 +31,7 @@ export var visitor = {
|
|||||||
var first = program.body[0];
|
var first = program.body[0];
|
||||||
|
|
||||||
var directive;
|
var directive;
|
||||||
if (t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" })) {
|
if (t.isExpressionStatement(first) && isUseStrict(first.expression)) {
|
||||||
directive = first;
|
directive = first;
|
||||||
} else {
|
} else {
|
||||||
directive = t.expressionStatement(t.literal("use strict"));
|
directive = t.expressionStatement(t.literal("use strict"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user