Fix use strict as expression statement (#602)
* Add parentheses if node is StringLiteral surrounded by ExpressionStatement :tools:. * Add new test. * Update tests to run against Babylon, plus no regression case. * Split actual test and no regression test in two files. * Disable Flow till facebook/flow#3234 is merged.master
parent
6b74de3716
commit
8c66e44db1
|
@ -497,6 +497,11 @@ FPp.needsParens = function(assumeExpressionContext) {
|
|||
return name === "object" && parent.object === node;
|
||||
}
|
||||
|
||||
case "StringLiteral":
|
||||
if (parent.type === "ExpressionStatement") {
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
if (
|
||||
parent.type === "NewExpression" &&
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
exports[`test no_regression.js 1`] = `
|
||||
"// Ensure no regression.
|
||||
\"use strict\";
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Ensure no regression.
|
||||
\"use strict\";
|
||||
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test use_strict.js 1`] = `
|
||||
"// Parentheses around expression statement should be preserved in this case.
|
||||
(\"use strict\");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Parentheses around expression statement should be preserved in this case.
|
||||
(\"use strict\");
|
||||
"
|
||||
`;
|
|
@ -0,0 +1,2 @@
|
|||
// TODO: Re-enable Flow when the following fix is merged facebook/flow#3234.
|
||||
run_spec(__dirname, {parser: 'babylon'});
|
|
@ -0,0 +1,2 @@
|
|||
// Ensure no regression.
|
||||
"use strict";
|
|
@ -0,0 +1,2 @@
|
|||
// Parentheses around expression statement should be preserved in this case.
|
||||
("use strict");
|
Loading…
Reference in New Issue