Enable babel translation to enable ES module support.
This commit is contained in:
parent
02370f952a
commit
25873e92f0
@ -8,6 +8,8 @@ external/webL10n/
|
||||
external/cmapscompress/
|
||||
external/builder/fixtures/
|
||||
external/builder/fixtures_esprima/
|
||||
src/shared/cffStandardStrings.js
|
||||
src/shared/fonts_utils.js
|
||||
test/tmp/
|
||||
test/features/
|
||||
test/pdfs/
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 5,
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
|
||||
"env": {
|
||||
@ -78,7 +79,7 @@
|
||||
}],
|
||||
|
||||
// Strict Mode
|
||||
"strict": ["error", "global"],
|
||||
"strict": ["off", "global"],
|
||||
|
||||
// Variables
|
||||
"no-catch-shadow": "error",
|
||||
|
9
extensions/chromium/.eslintrc
Normal file
9
extensions/chromium/.eslintrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": [
|
||||
../../.eslintrc
|
||||
],
|
||||
|
||||
"parserOptions": {
|
||||
"sourceType": "script"
|
||||
},
|
||||
}
|
@ -4,7 +4,8 @@
|
||||
],
|
||||
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "script"
|
||||
},
|
||||
|
||||
"rules": {
|
||||
|
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);
|
||||
}
|
||||
|
13
gulpfile.js
13
gulpfile.js
@ -109,6 +109,12 @@ function createWebpackConfig(defines, output) {
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
plugins: ['transform-es2015-modules-commonjs']
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: path.join(__dirname, 'external/webpack/pdfjsdev-loader.js'),
|
||||
options: {
|
||||
@ -116,7 +122,7 @@ function createWebpackConfig(defines, output) {
|
||||
saveComments: false,
|
||||
defines: bundleDefines
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -928,6 +934,10 @@ gulp.task('jsdoc', function (done) {
|
||||
gulp.task('lib', ['buildnumber'], function () {
|
||||
function preprocess(content) {
|
||||
content = preprocessor2.preprocessPDFJSCode(ctx, content);
|
||||
content = babel.transform(content, {
|
||||
sourceType: 'module',
|
||||
plugins: ['transform-es2015-modules-commonjs'],
|
||||
}).code;
|
||||
var removeCjsSrc =
|
||||
/^(var\s+\w+\s*=\s*require\('.*?)(?:\/src)(\/[^']*'\);)$/gm;
|
||||
content = content.replace(removeCjsSrc, function (all, prefix, suffix) {
|
||||
@ -935,6 +945,7 @@ gulp.task('lib', ['buildnumber'], function () {
|
||||
});
|
||||
return licenseHeader + content;
|
||||
}
|
||||
var babel = require('babel-core');
|
||||
var versionInfo = getVersionJSON();
|
||||
var ctx = {
|
||||
rootPath: __dirname,
|
||||
|
5
make.js
5
make.js
@ -19,9 +19,8 @@
|
||||
try {
|
||||
require('shelljs/make');
|
||||
} catch (e) {
|
||||
console.log('ShellJS is not installed. Run "npm install" to install ' +
|
||||
'all dependencies.');
|
||||
return;
|
||||
throw new Error('ShellJS is not installed. Run "npm install" to install ' +
|
||||
'all dependencies.');
|
||||
}
|
||||
|
||||
var fs = require('fs');
|
||||
|
@ -2,9 +2,12 @@
|
||||
"name": "pdf.js",
|
||||
"version": "0.8.0",
|
||||
"devDependencies": {
|
||||
"acorn": "^4.0.11",
|
||||
"babel-core": "^6.23.1",
|
||||
"babel-loader": "^6.4.0",
|
||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
|
||||
"escodegen": "^1.8.0",
|
||||
"eslint": "^3.11.1",
|
||||
"esprima": "^2.7.2",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-replace": "^0.5.4",
|
||||
@ -22,6 +25,7 @@
|
||||
"shelljs": "~0.4.0",
|
||||
"streamqueue": "^1.1.1",
|
||||
"systemjs": "^0.20.7",
|
||||
"systemjs-plugin-babel": "0.0.21",
|
||||
"typogr": "~0.6.5",
|
||||
"uglify-js": "^2.6.1",
|
||||
"webpack": "^2.2.1",
|
||||
|
@ -29,10 +29,13 @@
|
||||
throw new Error('Cannot configure SystemJS');
|
||||
}
|
||||
|
||||
var PluginBabelPath = 'node_modules/systemjs-plugin-babel/plugin-babel.js';
|
||||
var SystemJSPluginBabelPath =
|
||||
'node_modules/systemjs-plugin-babel/systemjs-babel-browser.js';
|
||||
|
||||
SystemJS.config({
|
||||
packages: {
|
||||
'': {
|
||||
format: 'amd',
|
||||
defaultExtension: 'js',
|
||||
}
|
||||
},
|
||||
@ -40,6 +43,18 @@
|
||||
'pdfjs': new URL('src', baseLocation).href,
|
||||
'pdfjs-web': new URL('web', baseLocation).href,
|
||||
'pdfjs-test': new URL('test', baseLocation).href,
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
'*': {
|
||||
scriptLoad: false,
|
||||
esModule: true
|
||||
}
|
||||
},
|
||||
map: {
|
||||
'plugin-babel': new URL(PluginBabelPath, baseLocation).href,
|
||||
'systemjs-babel-build':
|
||||
new URL(SystemJSPluginBabelPath, baseLocation).href,
|
||||
},
|
||||
transpiler: 'plugin-babel'
|
||||
});
|
||||
})();
|
||||
|
@ -502,7 +502,7 @@ var Stats = (function Stats() {
|
||||
})();
|
||||
|
||||
// Manages all the debugging tools.
|
||||
var PDFBug = (function PDFBugClosure() {
|
||||
window.PDFBug = (function PDFBugClosure() {
|
||||
var panelWidth = 300;
|
||||
var buttons = [];
|
||||
var activePanel = null;
|
||||
|
Loading…
Reference in New Issue
Block a user