diff --git a/external/builder/preprocessor2.js b/external/builder/preprocessor2.js index 9e9b5e3ab..2fc242b22 100644 --- a/external/builder/preprocessor2.js +++ b/external/builder/preprocessor2.js @@ -347,28 +347,23 @@ function traverseTree(ctx, node) { } function preprocessPDFJSCode(ctx, code) { - var saveComments = !!ctx.saveComments; var format = ctx.format || { indent: { style: ' ', - adjustMultilineComment: saveComments, } }; - var comments; - var parseComment = { + var parseOptions = { locations: true, - onComments: saveComments || (comments = []), + sourceFile: ctx.sourceFile, sourceType: 'module', }; var codegenOptions = { format: format, - comment: saveComments, parse: acorn.parse, + sourceMap: ctx.sourceMap, + sourceMapWithCode: ctx.sourceMap, }; - var syntax = acorn.parse(code, parseComment); - if (saveComments) { - escodegen.attachComments(syntax, comments); - } + var syntax = acorn.parse(code, parseOptions); traverseTree(ctx, syntax); return escodegen.generate(syntax, codegenOptions); } diff --git a/external/webpack/pdfjsdev-loader.js b/external/webpack/pdfjsdev-loader.js index beba2a887..ca6cafee2 100644 --- a/external/webpack/pdfjsdev-loader.js +++ b/external/webpack/pdfjsdev-loader.js @@ -17,6 +17,7 @@ 'use strict'; var preprocessor2 = require('../builder/preprocessor2.js'); +var path = require('path'); module.exports = function (source) { // Options must be specified, ignoring request if not. @@ -24,7 +25,19 @@ module.exports = function (source) { return source; } this.cacheable(); - var ctx = this.query; - source = preprocessor2.preprocessPDFJSCode(ctx, source); - return source; + + var filePath = this.resourcePath; + var context = this.options.context; + var sourcePath = path.relative(context, filePath).split(path.sep).join('/'); + + var ctx = Object.create(this.query); + ctx.sourceMap = true; + ctx.sourceFile = sourcePath; + + var callback = this.callback; + var sourceAndMap = preprocessor2.preprocessPDFJSCode(ctx, source); + var map = sourceAndMap.map.toJSON(); + // escodegen does not embed source -- setting map's sourcesContent. + map.sourcesContent = [source]; + callback(null, sourceAndMap.code, map); }; diff --git a/gulpfile.js b/gulpfile.js index 9371002e0..b47fb03bc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -129,6 +129,8 @@ function createWebpackConfig(defines, output) { BUNDLE_BUILD: versionInfo.commit }); var licenseHeader = fs.readFileSync('./src/license_header.js').toString(); + var enableSourceMaps = !bundleDefines.FIREFOX && !bundleDefines.MOZCENTRAL && + !bundleDefines.CHROME; return { output: output, @@ -142,6 +144,7 @@ function createWebpackConfig(defines, output) { 'pdfjs-web': path.join(__dirname, 'web'), } }, + devtool: enableSourceMaps ? 'source-map' : undefined, module: { loaders: [ { @@ -1329,8 +1332,11 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () { .pipe(gulp.dest(DIST_DIR)), gulp.src([ GENERIC_DIR + 'build/pdf.js', + GENERIC_DIR + 'build/pdf.js.map', GENERIC_DIR + 'build/pdf.worker.js', + GENERIC_DIR + 'build/pdf.worker.js.map', SINGLE_FILE_DIR + 'build/pdf.combined.js', + SINGLE_FILE_DIR + 'build/pdf.combined.js.map', SRC_DIR + 'pdf.worker.entry.js', ]).pipe(gulp.dest(DIST_DIR + 'build/')), gulp.src(MINIFIED_DIR + 'build/pdf.js')