Merge pull request #17647 from Snuffleupagus/babel-rm-empty-nodes
Remove empty, top-level, nodes in the Babel plugin
This commit is contained in:
commit
d742daf4b7
@ -84,11 +84,13 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
|
||||
if (t.isBooleanLiteral(node.test)) {
|
||||
// if (true) stmt1; => stmt1
|
||||
// if (false) stmt1; else stmt2; => stmt2
|
||||
path.replaceWith(
|
||||
node.test.value === true
|
||||
? node.consequent
|
||||
: node.alternate || t.emptyStatement()
|
||||
);
|
||||
if (node.test.value === true) {
|
||||
path.replaceWith(node.consequent);
|
||||
} else if (node.alternate) {
|
||||
path.replaceWith(node.alternate);
|
||||
} else {
|
||||
path.remove(node);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -7,11 +7,12 @@ if ('test') {
|
||||
{
|
||||
"1";
|
||||
}
|
||||
;
|
||||
{
|
||||
"2";
|
||||
}
|
||||
;
|
||||
if ('1') {
|
||||
"1";
|
||||
}
|
||||
function f1() {
|
||||
"1";
|
||||
}
|
||||
|
9
external/builder/fixtures_esprima/ifs.js
vendored
9
external/builder/fixtures_esprima/ifs.js
vendored
@ -23,3 +23,12 @@ if (true && false) {
|
||||
if (true && false || '1') {
|
||||
"1";
|
||||
}
|
||||
|
||||
function f1() {
|
||||
if (true) {
|
||||
"1";
|
||||
}
|
||||
if (false) {
|
||||
"2";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user