Default to "compact: false" in the code generate phase

Reviewed By: davidaurelio

Differential Revision: D5630578

fbshipit-source-id: 5049be735f41f1207b8ca329f4a78fc92f683c23
This commit is contained in:
Alex Dvornikov 2017-08-18 04:56:09 -07:00 committed by Facebook Github Bot
parent 936b8c31e7
commit 5cd43a675b
4 changed files with 20 additions and 6 deletions

View File

@ -162,9 +162,11 @@ describe('transforming JS modules:', () => {
it('creates source maps', done => { it('creates source maps', done => {
transformModule(sourceCode, options(), (error, result) => { transformModule(sourceCode, options(), (error, result) => {
const {code, map} = result.details.transformed.default; const {code, map} = result.details.transformed.default;
const column = code.indexOf('code'); const position = findColumnAndLine(code, 'code');
expect(position).not.toBeNull();
const consumer = new SourceMapConsumer(map); const consumer = new SourceMapConsumer(map);
expect(consumer.originalPositionFor({line: 1, column})).toEqual( expect(consumer.originalPositionFor(position)).toEqual(
expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}), expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}),
); );
done(); done();
@ -273,3 +275,15 @@ function createTestData() {
transformedCode: generate(fileAst).code, transformedCode: generate(fileAst).code,
}; };
} }
function findColumnAndLine(text, string) {
const lines = text.split('\n');
for (let i = 0; i < lines.length; i++) {
const column = lines[i].indexOf(string);
if (column !== -1) {
const line = i + 1;
return {line, column};
}
}
return null;
}

View File

@ -12,10 +12,10 @@
const babelGenerate = require('babel-generator').default; const babelGenerate = require('babel-generator').default;
function generate(ast: Object, filename: string, sourceCode: string) { function generate(ast: Object, filename: string, sourceCode: string, compact: boolean) {
return babelGenerate(ast, { return babelGenerate(ast, {
comments: false, comments: false,
compact: true, compact,
filename, filename,
sourceFileName: filename, sourceFileName: filename,
sourceMaps: true, sourceMaps: true,

View File

@ -73,7 +73,7 @@ function optimize(transformed, file, originalCode, options) {
} }
const inputMap = transformed.map; const inputMap = transformed.map;
const gen = generate(optimized.ast, file, originalCode); const gen = generate(optimized.ast, file, originalCode, true);
const min = minify.withSourceMap( const min = minify.withSourceMap(
gen.code, gen.code,

View File

@ -178,7 +178,7 @@ function makeResult(ast, filename, sourceCode, isPolyfill = false) {
file = JsFileWrapping.wrapModule(ast, dependencyMapName); file = JsFileWrapping.wrapModule(ast, dependencyMapName);
} }
const gen = generate(file, filename, sourceCode); const gen = generate(file, filename, sourceCode, false);
return {code: gen.code, map: gen.map, dependencies, dependencyMapName}; return {code: gen.code, map: gen.map, dependencies, dependencyMapName};
} }