mirror of https://github.com/status-im/metro.git
Various cleanups around polyfill transformation
Summary: - Put `isPolyfill` parameter into `options` object - Save information whether a file is a polyfill - Sort properties alphabetically - Rename parameters Reviewed By: cpojer Differential Revision: D4153203 fbshipit-source-id: 67da97546a15c899112b74da6072acdea18d10e8
This commit is contained in:
parent
5dab7599d3
commit
0493002fa3
|
@ -103,10 +103,11 @@ function transformModule(infile, options, outfile, callback) {
|
||||||
const annotations = docblock.parseAsObject(docblock.extract(code));
|
const annotations = docblock.parseAsObject(docblock.extract(code));
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
file: filename,
|
|
||||||
code,
|
code,
|
||||||
transformed,
|
file: filename,
|
||||||
|
isPolyfill: !!options.polyfill,
|
||||||
hasteID: annotations.providesModule || annotations.provide || null,
|
hasteID: annotations.providesModule || annotations.provide || null,
|
||||||
|
transformed,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -122,8 +123,7 @@ function transformModule(infile, options, outfile, callback) {
|
||||||
function optimizeModule(
|
function optimizeModule(
|
||||||
infile,
|
infile,
|
||||||
outfile,
|
outfile,
|
||||||
isPolyfill,
|
optimizationOptions,
|
||||||
inliningOptions,
|
|
||||||
callback,
|
callback,
|
||||||
) {
|
) {
|
||||||
const data = JSON.parse(fs.readFileSync(infile, 'utf8'));
|
const data = JSON.parse(fs.readFileSync(infile, 'utf8'));
|
||||||
|
@ -136,7 +136,7 @@ function optimizeModule(
|
||||||
|
|
||||||
Object.keys(transformed).forEach(key => {
|
Object.keys(transformed).forEach(key => {
|
||||||
result.transformed[key] =
|
result.transformed[key] =
|
||||||
optimize(transformed[key], file, code, isPolyfill, inliningOptions);
|
optimize(transformed[key], file, code, optimizationOptions);
|
||||||
});
|
});
|
||||||
writeResult(outfile, result);
|
writeResult(outfile, result);
|
||||||
|
|
||||||
|
@ -174,11 +174,11 @@ function functionFromProgram(program, parameters) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function optimize(transformed, file, originalCode, isPolyfill, options) {
|
function optimize(transformed, file, originalCode, options) {
|
||||||
const optimized =
|
const optimized =
|
||||||
optimizeCode(transformed.code, transformed.map, file, options);
|
optimizeCode(transformed.code, transformed.map, file, options);
|
||||||
|
|
||||||
const dependencies = isPolyfill
|
const dependencies = options.isPolyfill
|
||||||
? []
|
? []
|
||||||
: collectDependencies.forOptimization(
|
: collectDependencies.forOptimization(
|
||||||
optimized.ast,
|
optimized.ast,
|
||||||
|
@ -196,10 +196,12 @@ function optimize(transformed, file, originalCode, isPolyfill, options) {
|
||||||
return {code: min.code, map: inputMap && min.map, dependencies};
|
return {code: min.code, map: inputMap && min.map, dependencies};
|
||||||
}
|
}
|
||||||
|
|
||||||
function optimizeCode(code, map, filename, options) {
|
function optimizeCode(code, map, filename, inliningOptions) {
|
||||||
const inlineOptions = Object.assign({isWrapped: true}, options);
|
|
||||||
return babel.transform(code, {
|
return babel.transform(code, {
|
||||||
plugins: [[constantFolding], [inline, inlineOptions]],
|
plugins: [
|
||||||
|
[constantFolding],
|
||||||
|
[inline, Object.assign({isWrapped: true}, inliningOptions)],
|
||||||
|
],
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
code: false,
|
code: false,
|
||||||
filename,
|
filename,
|
||||||
|
|
|
@ -24,10 +24,20 @@ declare export function transformModule(
|
||||||
declare export function optimizeModule(
|
declare export function optimizeModule(
|
||||||
infile: string,
|
infile: string,
|
||||||
outfile: string,
|
outfile: string,
|
||||||
isPolyfill?: boolean,
|
optimizationOptions: {
|
||||||
inliningOptions: {
|
|
||||||
dev?: boolean,
|
dev?: boolean,
|
||||||
|
isPolyfill?: boolean,
|
||||||
platform?: string,
|
platform?: string,
|
||||||
},
|
},
|
||||||
callback: (e?: Error) => void,
|
callback: (e?: Error) => void,
|
||||||
): void
|
): void
|
||||||
|
|
||||||
|
declare function optimizeCode(
|
||||||
|
code: string,
|
||||||
|
map: Object,
|
||||||
|
filename: string,
|
||||||
|
inliningOptions: {|
|
||||||
|
dev?: boolean,
|
||||||
|
platform?: string,
|
||||||
|
|},
|
||||||
|
): {code: string, map: Object};
|
||||||
|
|
Loading…
Reference in New Issue