Fixes T2299: Prevent REPL from printing implicit 'use strict' (#4562)
* Fixes T2299: Prevent REPL from printing implicit 'use strict' * Test for T2299 * make fixes
This commit is contained in:
parent
702259d483
commit
fc2b3cb465
@ -38,7 +38,7 @@ register({
|
||||
|
||||
//
|
||||
|
||||
let replPlugin = () => ({
|
||||
let replPlugin = ({ types: t }) => ({
|
||||
visitor: {
|
||||
ModuleDeclaration(path) {
|
||||
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
|
||||
@ -48,6 +48,14 @@ let replPlugin = () => ({
|
||||
if (path.node.kind !== "var") {
|
||||
throw path.buildCodeFrameError("Only `var` variables are supported in the REPL");
|
||||
}
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
if (path.get("body").some((child) => child.isExpressionStatement())) return;
|
||||
|
||||
// If the executed code doesn't evaluate to a value,
|
||||
// prevent implicit strict mode from printing 'use strict'.
|
||||
path.pushContainer("body", t.expressionStatement(t.identifier("undefined")));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
4
packages/babel-cli/test/fixtures/babel-node/no-strict/options.json
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel-node/no-strict/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["--eval","--print", "var a = 1;"],
|
||||
"stdout": "undefined"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user