mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Enable babel translation to enable ES module support.
This commit is contained in:
parent
02370f952a
commit
25873e92f0
10 changed files with 65 additions and 18 deletions
19
external/builder/preprocessor2.js
vendored
19
external/builder/preprocessor2.js
vendored
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var esprima = require('esprima');
|
||||
var acorn = require('acorn');
|
||||
var escodegen = require('escodegen');
|
||||
var vm = require('vm');
|
||||
var fs = require('fs');
|
||||
|
@ -49,7 +49,7 @@ function handlePreprocessorAction(ctx, actionName, args, loc) {
|
|||
return {type: 'Literal', value: result, loc: loc};
|
||||
}
|
||||
if (typeof result === 'object') {
|
||||
var parsedObj = esprima.parse('(' + JSON.stringify(result) + ')');
|
||||
var parsedObj = acorn.parse('(' + JSON.stringify(result) + ')');
|
||||
parsedObj.body[0].expression.loc = loc;
|
||||
return parsedObj.body[0].expression;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ function handlePreprocessorAction(ctx, actionName, args, loc) {
|
|||
jsonPath.substring(ROOT_PREFIX.length));
|
||||
}
|
||||
var jsonContent = fs.readFileSync(jsonPath).toString();
|
||||
var parsedJSON = esprima.parse('(' + jsonContent + ')');
|
||||
var parsedJSON = acorn.parse('(' + jsonContent + ')');
|
||||
parsedJSON.body[0].expression.loc = loc;
|
||||
return parsedJSON.body[0].expression;
|
||||
}
|
||||
|
@ -354,16 +354,21 @@ function preprocessPDFJSCode(ctx, code) {
|
|||
adjustMultilineComment: saveComments,
|
||||
}
|
||||
};
|
||||
var comments;
|
||||
var parseComment = {
|
||||
loc: true,
|
||||
attachComment: saveComments
|
||||
locations: true,
|
||||
onComments: saveComments || (comments = []),
|
||||
sourceType: 'module',
|
||||
};
|
||||
var codegenOptions = {
|
||||
format: format,
|
||||
comment: saveComments,
|
||||
parse: esprima.parse
|
||||
parse: acorn.parse,
|
||||
};
|
||||
var syntax = esprima.parse(code, parseComment);
|
||||
var syntax = acorn.parse(code, parseComment);
|
||||
if (saveComments) {
|
||||
escodegen.attachComments(syntax, comments);
|
||||
}
|
||||
traverseTree(ctx, syntax);
|
||||
return escodegen.generate(syntax, codegenOptions);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue