Merge pull request #17596 from nicolo-ribaudo/fix-babel-plugin
Fix transform of unary expression in Babel plugin
This commit is contained in:
		
						commit
						56dabe9390
					
				@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -17,3 +17,5 @@ var i = '0';
 | 
			
		||||
var j = {
 | 
			
		||||
  i: 1
 | 
			
		||||
};
 | 
			
		||||
var k = false;
 | 
			
		||||
var l = true;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								external/builder/fixtures_esprima/evals.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								external/builder/fixtures_esprima/evals.js
									
									
									
									
										vendored
									
									
								
							@ -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');
 | 
			
		||||
 | 
			
		||||
@ -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(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user