mirror of https://github.com/status-im/metro.git
remove support for `process.platform`
Reviewed By: javache Differential Revision: D3252666 fb-gh-sync-id: af0e4987c34f43ec2472cbdf52fc112b81050513 fbshipit-source-id: af0e4987c34f43ec2472cbdf52fc112b81050513
This commit is contained in:
parent
4695f84448
commit
5f53658fb0
|
@ -165,18 +165,6 @@ describe('inline constants', () => {
|
||||||
normalize(code.replace(/process\.env\.NODE_ENV/, '"development"')));
|
normalize(code.replace(/process\.env\.NODE_ENV/, '"development"')));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('replaces process.platform in the code', () => {
|
|
||||||
const code = `function a() {
|
|
||||||
if (process.platform === 'android') {
|
|
||||||
return require('./android');
|
|
||||||
}
|
|
||||||
return require('./ios');
|
|
||||||
}`;
|
|
||||||
const {ast} = inline('arbitrary.js', {code}, {platform: 'ios'});
|
|
||||||
expect(toString(ast)).toEqual(
|
|
||||||
normalize(code.replace(/process\.platform\b/, '"ios"')));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('accepts an AST as input', function() {
|
it('accepts an AST as input', function() {
|
||||||
const code = 'function ifDev(a,b){return __DEV__?a:b;}';
|
const code = 'function ifDev(a,b){return __DEV__?a:b;}';
|
||||||
const {ast} = inline('arbitrary.hs', {ast: toAst(code)}, {dev: false});
|
const {ast} = inline('arbitrary.hs', {ast: toAst(code)}, {dev: false});
|
||||||
|
|
|
@ -20,7 +20,6 @@ const requirePattern = {name: 'require'};
|
||||||
const env = {name: 'env'};
|
const env = {name: 'env'};
|
||||||
const nodeEnv = {name: 'NODE_ENV'};
|
const nodeEnv = {name: 'NODE_ENV'};
|
||||||
const processId = {name: 'process'};
|
const processId = {name: 'process'};
|
||||||
const platformId = {name: 'platform'};
|
|
||||||
|
|
||||||
const dev = {name: '__DEV__'};
|
const dev = {name: '__DEV__'};
|
||||||
|
|
||||||
|
@ -64,11 +63,6 @@ const isProcessEnvNodeEnv = (node, scope) =>
|
||||||
t.isIdentifier(node.object.object, processId) &&
|
t.isIdentifier(node.object.object, processId) &&
|
||||||
isGlobal(scope.getBinding(processId.name));
|
isGlobal(scope.getBinding(processId.name));
|
||||||
|
|
||||||
const isProcessPlatform = (node, scope) =>
|
|
||||||
t.isIdentifier(node.property, platformId) &&
|
|
||||||
t.isIdentifier(node.object, processId) &&
|
|
||||||
isGlobal(scope.getBinding(processId.name));
|
|
||||||
|
|
||||||
const isDev = (node, parent, scope) =>
|
const isDev = (node, parent, scope) =>
|
||||||
t.isIdentifier(node, dev) &&
|
t.isIdentifier(node, dev) &&
|
||||||
isGlobal(scope.getBinding(dev.name)) &&
|
isGlobal(scope.getBinding(dev.name)) &&
|
||||||
|
@ -90,9 +84,6 @@ const inlinePlugin = {
|
||||||
} else if (isProcessEnvNodeEnv(node, scope)) {
|
} else if (isProcessEnvNodeEnv(node, scope)) {
|
||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
t.stringLiteral(state.opts.dev ? 'development' : 'production'));
|
t.stringLiteral(state.opts.dev ? 'development' : 'production'));
|
||||||
} else if (isProcessPlatform(node, scope)) {
|
|
||||||
path.replaceWith(
|
|
||||||
t.stringLiteral(state.opts.platform));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue