Remove empty, top-level, nodes in the Babel plugin
Looking at the *built* files you'll notice some lines containing nothing more than a semicolon. This is the result of (mostly top-level) `if`-statements, which include `PDFJSDev`-checks, that evalute to `false` during Babel parsing. This has always annoyed me a bit, and looking at Babel plugin it seems that we can fix this simply by *removing* the relevant nodes.
This commit is contained in:
parent
964bfe522b
commit
14ef0b4211
@ -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