Merge pull request #17647 from Snuffleupagus/babel-rm-empty-nodes

Remove empty, top-level, nodes in the Babel plugin
This commit is contained in:
Jonas Jenwald 2024-02-12 09:25:59 +01:00 committed by GitHub
commit d742daf4b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -84,11 +84,13 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
if (t.isBooleanLiteral(node.test)) { if (t.isBooleanLiteral(node.test)) {
// if (true) stmt1; => stmt1 // if (true) stmt1; => stmt1
// if (false) stmt1; else stmt2; => stmt2 // if (false) stmt1; else stmt2; => stmt2
path.replaceWith( if (node.test.value === true) {
node.test.value === true path.replaceWith(node.consequent);
? node.consequent } else if (node.alternate) {
: node.alternate || t.emptyStatement() path.replaceWith(node.alternate);
); } else {
path.remove(node);
}
} }
}, },
}, },

View File

@ -7,11 +7,12 @@ if ('test') {
{ {
"1"; "1";
} }
;
{ {
"2"; "2";
} }
;
if ('1') { if ('1') {
"1"; "1";
} }
function f1() {
"1";
}

View File

@ -23,3 +23,12 @@ if (true && false) {
if (true && false || '1') { if (true && false || '1') {
"1"; "1";
} }
function f1() {
if (true) {
"1";
}
if (false) {
"2";
}
}