Merge pull request #17596 from nicolo-ribaudo/fix-babel-plugin

Fix transform of unary expression in Babel plugin
This commit is contained in:
Jonas Jenwald 2024-01-29 12:57:42 +01:00 committed by GitHub
commit 56dabe9390
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 12 deletions

View File

@ -92,17 +92,22 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
}
},
},
UnaryExpression(path) {
const { node } = path;
if (node.operator === "typeof" && isPDFJSPreprocessor(node.argument)) {
// typeof PDFJSDev => 'object'
path.replaceWith(t.stringLiteral("object"));
return;
}
if (node.operator === "!" && t.isBooleanLiteral(node.argument)) {
// !true => false, !false => true
path.replaceWith(t.booleanLiteral(!node.argument.value));
}
UnaryExpression: {
exit(path) {
const { node } = path;
if (
node.operator === "typeof" &&
isPDFJSPreprocessor(node.argument)
) {
// typeof PDFJSDev => 'object'
path.replaceWith(t.stringLiteral("object"));
return;
}
if (node.operator === "!" && t.isBooleanLiteral(node.argument)) {
// !true => false, !false => true
path.replaceWith(t.booleanLiteral(!node.argument.value));
}
},
},
LogicalExpression: {
exit(path) {

View File

@ -17,3 +17,5 @@ var i = '0';
var j = {
i: 1
};
var k = false;
var l = true;

View File

@ -8,3 +8,5 @@ var g = PDFJSDev.eval('OBJ');
var h = PDFJSDev.json('$ROOT/external/builder/fixtures_esprima/evals.json');
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
var k = !PDFJSDev.test('TRUE');
var l = !PDFJSDev.test('FALSE');

View File

@ -400,7 +400,7 @@ class ExternalServices extends BaseExternalServices {
}
async getNimbusExperimentData() {
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("GECKOVIEW")) {
if (!PDFJSDev.test("GECKOVIEW")) {
return null;
}
const nimbusData = await FirefoxCom.requestAsync(