Merge pull request #8368 from yurydelendik/sourcemap
Enables source maps for webpack generated files.
This commit is contained in:
commit
deae2d8cb8
@ -1,28 +1,17 @@
|
|||||||
function f1() {
|
function f1() {
|
||||||
/* head */
|
|
||||||
"1";
|
"1";
|
||||||
/* mid */
|
|
||||||
"2";
|
"2";
|
||||||
}
|
}
|
||||||
/* tail */
|
|
||||||
function f2() {
|
function f2() {
|
||||||
// head
|
|
||||||
"1";
|
"1";
|
||||||
// mid
|
|
||||||
"2";
|
"2";
|
||||||
}
|
}
|
||||||
// tail
|
|
||||||
function f2() {
|
function f2() {
|
||||||
if ("1") {
|
if ("1") {
|
||||||
// begin block
|
|
||||||
"1";
|
"1";
|
||||||
}
|
}
|
||||||
"2";
|
"2";
|
||||||
// trailing
|
if ("3") {
|
||||||
if (/* s */
|
"4";
|
||||||
"3")
|
}
|
||||||
/*e*/
|
|
||||||
{
|
|
||||||
"4";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
15
external/builder/preprocessor2.js
vendored
15
external/builder/preprocessor2.js
vendored
@ -347,28 +347,23 @@ function traverseTree(ctx, node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function preprocessPDFJSCode(ctx, code) {
|
function preprocessPDFJSCode(ctx, code) {
|
||||||
var saveComments = !!ctx.saveComments;
|
|
||||||
var format = ctx.format || {
|
var format = ctx.format || {
|
||||||
indent: {
|
indent: {
|
||||||
style: ' ',
|
style: ' ',
|
||||||
adjustMultilineComment: saveComments,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var comments;
|
var parseOptions = {
|
||||||
var parseComment = {
|
|
||||||
locations: true,
|
locations: true,
|
||||||
onComments: saveComments || (comments = []),
|
sourceFile: ctx.sourceFile,
|
||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
};
|
};
|
||||||
var codegenOptions = {
|
var codegenOptions = {
|
||||||
format: format,
|
format: format,
|
||||||
comment: saveComments,
|
|
||||||
parse: acorn.parse,
|
parse: acorn.parse,
|
||||||
|
sourceMap: ctx.sourceMap,
|
||||||
|
sourceMapWithCode: ctx.sourceMap,
|
||||||
};
|
};
|
||||||
var syntax = acorn.parse(code, parseComment);
|
var syntax = acorn.parse(code, parseOptions);
|
||||||
if (saveComments) {
|
|
||||||
escodegen.attachComments(syntax, comments);
|
|
||||||
}
|
|
||||||
traverseTree(ctx, syntax);
|
traverseTree(ctx, syntax);
|
||||||
return escodegen.generate(syntax, codegenOptions);
|
return escodegen.generate(syntax, codegenOptions);
|
||||||
}
|
}
|
||||||
|
39
external/builder/test-fixtures.js
vendored
39
external/builder/test-fixtures.js
vendored
@ -1,17 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('shelljs/make');
|
|
||||||
|
|
||||||
var builder = require('./builder');
|
var builder = require('./builder');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
var errors = 0;
|
var errors = 0;
|
||||||
|
|
||||||
cd(__dirname);
|
var baseDir = path.join(__dirname, 'fixtures');
|
||||||
cd('fixtures');
|
var files = fs.readdirSync(baseDir).filter(function (name) {
|
||||||
ls('*-expected.*').forEach(function(expectationFilename) {
|
return /-expected\./.test(name);
|
||||||
|
}).map(function (name) {
|
||||||
|
return path.join(baseDir, name);
|
||||||
|
});
|
||||||
|
files.forEach(function(expectationFilename) {
|
||||||
var inFilename = expectationFilename.replace('-expected', '');
|
var inFilename = expectationFilename.replace('-expected', '');
|
||||||
var expectation = cat(expectationFilename).trim()
|
var expectation = fs.readFileSync(expectationFilename).toString().trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replace(/__filename/g, fs.realpathSync(inFilename));
|
||||||
var outLines = [];
|
var outLines = [];
|
||||||
|
|
||||||
@ -32,20 +35,22 @@ ls('*-expected.*').forEach(function(expectationFilename) {
|
|||||||
if (out !== expectation) {
|
if (out !== expectation) {
|
||||||
errors++;
|
errors++;
|
||||||
|
|
||||||
echo('Assertion failed for ' + inFilename);
|
console.log('Assertion failed for ' + inFilename);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo('EXPECTED:');
|
console.log('EXPECTED:');
|
||||||
echo(expectation);
|
console.log(expectation);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo('ACTUAL');
|
console.log('ACTUAL');
|
||||||
echo(out);
|
console.log(out);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo();
|
console.log();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
echo('Found ' + errors + ' expectation failures.');
|
console.error('Found ' + errors + ' expectation failures.');
|
||||||
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
echo('All tests completed without errors.');
|
console.log('All tests completed without errors.');
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
40
external/builder/test-fixtures_esprima.js
vendored
40
external/builder/test-fixtures_esprima.js
vendored
@ -1,17 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('shelljs/make');
|
|
||||||
|
|
||||||
var p2 = require('./preprocessor2.js');
|
var p2 = require('./preprocessor2.js');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
var errors = 0;
|
var errors = 0;
|
||||||
|
|
||||||
cd(__dirname);
|
var baseDir = path.join(__dirname, 'fixtures_esprima');
|
||||||
cd('fixtures_esprima');
|
var files = fs.readdirSync(baseDir).filter(function (name) {
|
||||||
ls('*-expected.*').forEach(function(expectationFilename) {
|
return /-expected\./.test(name);
|
||||||
|
}).map(function (name) {
|
||||||
|
return path.join(baseDir, name);
|
||||||
|
});
|
||||||
|
files.forEach(function(expectationFilename) {
|
||||||
var inFilename = expectationFilename.replace('-expected', '');
|
var inFilename = expectationFilename.replace('-expected', '');
|
||||||
var expectation = cat(expectationFilename).trim()
|
var expectation = fs.readFileSync(expectationFilename).toString().trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replace(/__filename/g, fs.realpathSync(inFilename));
|
||||||
var input = fs.readFileSync(inFilename).toString();
|
var input = fs.readFileSync(inFilename).toString();
|
||||||
|
|
||||||
@ -24,7 +27,6 @@ ls('*-expected.*').forEach(function(expectationFilename) {
|
|||||||
var ctx = {
|
var ctx = {
|
||||||
defines: defines,
|
defines: defines,
|
||||||
rootPath: __dirname + '/../..',
|
rootPath: __dirname + '/../..',
|
||||||
saveComments: true
|
|
||||||
};
|
};
|
||||||
var out;
|
var out;
|
||||||
try {
|
try {
|
||||||
@ -35,20 +37,22 @@ ls('*-expected.*').forEach(function(expectationFilename) {
|
|||||||
if (out !== expectation) {
|
if (out !== expectation) {
|
||||||
errors++;
|
errors++;
|
||||||
|
|
||||||
echo('Assertion failed for ' + inFilename);
|
console.log('Assertion failed for ' + inFilename);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo('EXPECTED:');
|
console.log('EXPECTED:');
|
||||||
echo(expectation);
|
console.log(expectation);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo('ACTUAL');
|
console.log('ACTUAL');
|
||||||
echo(out);
|
console.log(out);
|
||||||
echo('--------------------------------------------------');
|
console.log('--------------------------------------------------');
|
||||||
echo();
|
console.log();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
echo('Found ' + errors + ' expectation failures.');
|
console.error('Found ' + errors + ' expectation failures.');
|
||||||
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
echo('All tests completed without errors.');
|
console.log('All tests completed without errors.');
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
19
external/webpack/pdfjsdev-loader.js
vendored
19
external/webpack/pdfjsdev-loader.js
vendored
@ -17,6 +17,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var preprocessor2 = require('../builder/preprocessor2.js');
|
var preprocessor2 = require('../builder/preprocessor2.js');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
module.exports = function (source) {
|
module.exports = function (source) {
|
||||||
// Options must be specified, ignoring request if not.
|
// Options must be specified, ignoring request if not.
|
||||||
@ -24,7 +25,19 @@ module.exports = function (source) {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
this.cacheable();
|
this.cacheable();
|
||||||
var ctx = this.query;
|
|
||||||
source = preprocessor2.preprocessPDFJSCode(ctx, source);
|
var filePath = this.resourcePath;
|
||||||
return source;
|
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);
|
||||||
};
|
};
|
||||||
|
15
gulpfile.js
15
gulpfile.js
@ -129,6 +129,8 @@ function createWebpackConfig(defines, output) {
|
|||||||
BUNDLE_BUILD: versionInfo.commit
|
BUNDLE_BUILD: versionInfo.commit
|
||||||
});
|
});
|
||||||
var licenseHeader = fs.readFileSync('./src/license_header.js').toString();
|
var licenseHeader = fs.readFileSync('./src/license_header.js').toString();
|
||||||
|
var enableSourceMaps = !bundleDefines.FIREFOX && !bundleDefines.MOZCENTRAL &&
|
||||||
|
!bundleDefines.CHROME;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
output: output,
|
output: output,
|
||||||
@ -142,6 +144,7 @@ function createWebpackConfig(defines, output) {
|
|||||||
'pdfjs-web': path.join(__dirname, 'web'),
|
'pdfjs-web': path.join(__dirname, 'web'),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
devtool: enableSourceMaps ? 'source-map' : undefined,
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
{
|
{
|
||||||
@ -1329,8 +1332,11 @@ gulp.task('dist-repo-prepare', ['dist-pre'], function () {
|
|||||||
.pipe(gulp.dest(DIST_DIR)),
|
.pipe(gulp.dest(DIST_DIR)),
|
||||||
gulp.src([
|
gulp.src([
|
||||||
GENERIC_DIR + 'build/pdf.js',
|
GENERIC_DIR + 'build/pdf.js',
|
||||||
|
GENERIC_DIR + 'build/pdf.js.map',
|
||||||
GENERIC_DIR + 'build/pdf.worker.js',
|
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',
|
||||||
|
SINGLE_FILE_DIR + 'build/pdf.combined.js.map',
|
||||||
SRC_DIR + 'pdf.worker.entry.js',
|
SRC_DIR + 'pdf.worker.entry.js',
|
||||||
]).pipe(gulp.dest(DIST_DIR + 'build/')),
|
]).pipe(gulp.dest(DIST_DIR + 'build/')),
|
||||||
gulp.src(MINIFIED_DIR + 'build/pdf.js')
|
gulp.src(MINIFIED_DIR + 'build/pdf.js')
|
||||||
@ -1424,3 +1430,12 @@ gulp.task('mozcentraldiff', ['mozcentral', 'mozcentralbaseline'],
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('externaltest', function () {
|
||||||
|
gutil.log('Running test-fixtures.js');
|
||||||
|
safeSpawnSync('node', ['external/builder/test-fixtures.js'],
|
||||||
|
{stdio: 'inherit'});
|
||||||
|
gutil.log('Running test-fixtures_esprima.js');
|
||||||
|
safeSpawnSync('node', ['external/builder/test-fixtures_esprima.js'],
|
||||||
|
{stdio: 'inherit'});
|
||||||
|
});
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"yargs": "^3.14.0"
|
"yargs": "^3.14.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "gulp lint unittestcli"
|
"test": "gulp lint unittestcli externaltest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user