diff --git a/external/builder/babel-plugin-pdfjs-preprocessor.mjs b/external/builder/babel-plugin-pdfjs-preprocessor.mjs index 8c5254e73..8f8be7a72 100644 --- a/external/builder/babel-plugin-pdfjs-preprocessor.mjs +++ b/external/builder/babel-plugin-pdfjs-preprocessor.mjs @@ -184,7 +184,7 @@ function babelPluginPDFJSPreprocessor(babel, ctx) { path.replaceWith(t.importExpression(source)); } }, - BlockStatement: { + "BlockStatement|StaticBlock": { // Visit node in post-order so that recursive flattening // of blocks works correctly. exit(path) { @@ -215,6 +215,10 @@ function babelPluginPDFJSPreprocessor(babel, ctx) { } subExpressionIndex++; } + + if (node.type === "StaticBlock" && node.body.length === 0) { + path.remove(); + } }, }, Function: { diff --git a/external/builder/fixtures_babel/staticblock-expected.js b/external/builder/fixtures_babel/staticblock-expected.js new file mode 100644 index 000000000..7edf5a8d9 --- /dev/null +++ b/external/builder/fixtures_babel/staticblock-expected.js @@ -0,0 +1,8 @@ +class A { + static { + foo(); + } + static { + var a = 0; + } +} diff --git a/external/builder/fixtures_babel/staticblock.js b/external/builder/fixtures_babel/staticblock.js new file mode 100644 index 000000000..161a5d705 --- /dev/null +++ b/external/builder/fixtures_babel/staticblock.js @@ -0,0 +1,20 @@ +class A { + static {} + static { + { foo() } + } + static { + {;} + } + static { + if (PDFJSDev.test('TRUE')) { + var a = 0; + } + } + + static { + if (PDFJSDev.test('FALSE')) { + var a = 1; + } + } +}