diff --git a/.eslintignore b/.eslintignore index bc3e05a12..d8de39a3e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -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/ diff --git a/.eslintrc b/.eslintrc index 9fecb95ea..9040d7789 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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", diff --git a/extensions/chromium/.eslintrc b/extensions/chromium/.eslintrc new file mode 100644 index 000000000..c3e462548 --- /dev/null +++ b/extensions/chromium/.eslintrc @@ -0,0 +1,9 @@ +{ + "extends": [ + ../../.eslintrc + ], + + "parserOptions": { + "sourceType": "script" + }, +} diff --git a/extensions/firefox/.eslintrc b/extensions/firefox/.eslintrc index 89561cf5f..9f7c5e5f1 100644 --- a/extensions/firefox/.eslintrc +++ b/extensions/firefox/.eslintrc @@ -4,7 +4,8 @@ ], "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": 6, + "sourceType": "script" }, "rules": { diff --git a/external/builder/preprocessor2.js b/external/builder/preprocessor2.js index bf22ac64d..b2142cb65 100644 --- a/external/builder/preprocessor2.js +++ b/external/builder/preprocessor2.js @@ -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); } diff --git a/gulpfile.js b/gulpfile.js index c40378052..fe9fdfe49 100644 --- a/gulpfile.js +++ b/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, diff --git a/make.js b/make.js index 19e7e3c93..5dd9203bc 100644 --- a/make.js +++ b/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'); diff --git a/package.json b/package.json index 262e4788e..190d398e4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/systemjs.config.js b/systemjs.config.js index 83a128ac1..f34a2c146 100644 --- a/systemjs.config.js +++ b/systemjs.config.js @@ -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' }); })(); diff --git a/web/debugger.js b/web/debugger.js index 4aee67fc5..d3b454e5b 100644 --- a/web/debugger.js +++ b/web/debugger.js @@ -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;