mirror of https://github.com/status-im/metro.git
Use the previously upgraded transforms
Summary: public Move all the transforms that had been previously upgraded to be the default now. Reviewed By: vjeux Differential Revision: D2631308 fb-gh-sync-id: a2120a9850c98ce65784b77598baa123121246ab
This commit is contained in:
parent
a88f69e482
commit
7ea13f835c
|
@ -1,63 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/*jslint node: true */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const t = require('babel-types');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms asynchronous module importing into a function call
|
|
||||||
* that includes which bundle needs to be loaded
|
|
||||||
*
|
|
||||||
* Transforms:
|
|
||||||
*
|
|
||||||
* System.import('moduleA')
|
|
||||||
*
|
|
||||||
* to:
|
|
||||||
*
|
|
||||||
* loadBundles('bundleA')
|
|
||||||
*/
|
|
||||||
module.exports = function() {
|
|
||||||
return {
|
|
||||||
visitor: {
|
|
||||||
CallExpression: function (path, state) {
|
|
||||||
if (!isAppropriateSystemImportCall(path.node)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bundlesLayout = state.opts.bundlesLayout;
|
|
||||||
var bundleID = bundlesLayout.getBundleIDForModule(
|
|
||||||
path.node.arguments[0].value
|
|
||||||
);
|
|
||||||
|
|
||||||
var bundles = bundleID.split('.');
|
|
||||||
bundles.splice(0, 1);
|
|
||||||
bundles = bundles.map(function(id) {
|
|
||||||
return t.stringLiteral('bundle.' + id);
|
|
||||||
});
|
|
||||||
|
|
||||||
path.replaceWith(t.callExpression(
|
|
||||||
t.identifier('loadBundles'),
|
|
||||||
[t.arrayExpression(bundles)]
|
|
||||||
));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
function isAppropriateSystemImportCall(node) {
|
|
||||||
return (
|
|
||||||
node.callee.type === 'MemberExpression' &&
|
|
||||||
node.callee.object.name === 'System' &&
|
|
||||||
node.callee.property.name === 'import' &&
|
|
||||||
node.arguments.length === 1 &&
|
|
||||||
node.arguments[0].type === 'StringLiteral'
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@
|
||||||
/*jslint node: true */
|
/*jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var t = require('babel-core').types;
|
const t = require('babel-types');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms asynchronous module importing into a function call
|
* Transforms asynchronous module importing into a function call
|
||||||
|
@ -24,34 +24,32 @@ var t = require('babel-core').types;
|
||||||
*
|
*
|
||||||
* loadBundles('bundleA')
|
* loadBundles('bundleA')
|
||||||
*/
|
*/
|
||||||
module.exports = function systemImportTransform(babel) {
|
module.exports = function() {
|
||||||
return new babel.Transformer('system-import', {
|
return {
|
||||||
CallExpression: function(node, parent, scope, state) {
|
visitor: {
|
||||||
if (!isAppropriateSystemImportCall(node, parent)) {
|
CallExpression: function (path, state) {
|
||||||
return node;
|
if (!isAppropriateSystemImportCall(path.node)) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bundlesLayout = state.opts.extra.bundlesLayout;
|
var bundlesLayout = state.opts.bundlesLayout;
|
||||||
var bundleID = bundlesLayout.getBundleIDForModule(
|
var bundleID = bundlesLayout.getBundleIDForModule(
|
||||||
node.arguments[0].value
|
path.node.arguments[0].value
|
||||||
);
|
);
|
||||||
|
|
||||||
var bundles = bundleID.split('.');
|
var bundles = bundleID.split('.');
|
||||||
bundles.splice(0, 1);
|
bundles.splice(0, 1);
|
||||||
bundles = bundles.map(function(id) {
|
bundles = bundles.map(function(id) {
|
||||||
return t.literal('bundle.' + id);
|
return t.stringLiteral('bundle.' + id);
|
||||||
});
|
});
|
||||||
|
|
||||||
return t.callExpression(
|
path.replaceWith(t.callExpression(
|
||||||
t.identifier('loadBundles'),
|
t.identifier('loadBundles'),
|
||||||
[t.arrayExpression(bundles)]
|
[t.arrayExpression(bundles)]
|
||||||
);
|
));
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
};
|
||||||
metadata: {
|
|
||||||
group: 'fb'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function isAppropriateSystemImportCall(node) {
|
function isAppropriateSystemImportCall(node) {
|
||||||
|
@ -60,6 +58,6 @@ function isAppropriateSystemImportCall(node) {
|
||||||
node.callee.object.name === 'System' &&
|
node.callee.object.name === 'System' &&
|
||||||
node.callee.property.name === 'import' &&
|
node.callee.property.name === 'import' &&
|
||||||
node.arguments.length === 1 &&
|
node.arguments.length === 1 &&
|
||||||
node.arguments[0].type === 'Literal'
|
node.arguments[0].type === 'StringLiteral'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue