mirror of https://github.com/status-im/metro.git
Default to "compact: false" in the code generate phase
Reviewed By: davidaurelio Differential Revision: D5630578 fbshipit-source-id: 5049be735f41f1207b8ca329f4a78fc92f683c23
This commit is contained in:
parent
936b8c31e7
commit
5cd43a675b
|
@ -162,9 +162,11 @@ describe('transforming JS modules:', () => {
|
|||
it('creates source maps', done => {
|
||||
transformModule(sourceCode, options(), (error, result) => {
|
||||
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);
|
||||
expect(consumer.originalPositionFor({line: 1, column})).toEqual(
|
||||
expect(consumer.originalPositionFor(position)).toEqual(
|
||||
expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}),
|
||||
);
|
||||
done();
|
||||
|
@ -273,3 +275,15 @@ function createTestData() {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
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, {
|
||||
comments: false,
|
||||
compact: true,
|
||||
compact,
|
||||
filename,
|
||||
sourceFileName: filename,
|
||||
sourceMaps: true,
|
||||
|
|
|
@ -73,7 +73,7 @@ function optimize(transformed, file, originalCode, options) {
|
|||
}
|
||||
|
||||
const inputMap = transformed.map;
|
||||
const gen = generate(optimized.ast, file, originalCode);
|
||||
const gen = generate(optimized.ast, file, originalCode, true);
|
||||
|
||||
const min = minify.withSourceMap(
|
||||
gen.code,
|
||||
|
|
|
@ -178,7 +178,7 @@ function makeResult(ast, filename, sourceCode, isPolyfill = false) {
|
|||
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};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue