mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Revert D119065685: fix(babel-preset): preserve Platform.select initializers
Differential Revision: D119065685 Original commit changeset: ca209fe9b728 Original Phabricator Diff: D119065685 fbshipit-source-id: 1200093b9a798d795a6d4cf4289839dbe11920ee
This commit is contained in:
1 parent
c1ad8ae2ee
commit
679a7b7a96
2 files changed
+5
-27
No files matched your search
-10
@@ -483,16 +483,6 @@ describe('Platform.select', () => {
|
||||
expect(select('{ios: 1, ios: 2}')).toContain('const value=2');
|
||||
});
|
||||
|
||||
test('does not discard impure initializers', () => {
|
||||
expectUnchanged(`
|
||||
const value = require('react-native').Platform.select({
|
||||
ios: first(),
|
||||
android: android(),
|
||||
ios: last(),
|
||||
});
|
||||
`);
|
||||
});
|
||||
|
||||
test('does not inline computed keys', () => {
|
||||
expect(select('{[key]: 1, default: 2}')).toContain('Platform.select');
|
||||
});
|
||||
|
||||
@@ -520,25 +520,13 @@ module.exports = function inlinePlatformPlugin(
|
||||
return;
|
||||
}
|
||||
|
||||
const replacement = findProperty(spec, platform, () =>
|
||||
findProperty(spec, 'native', () =>
|
||||
findProperty(spec, 'default', () => t.identifier('undefined')),
|
||||
path.replaceWith(
|
||||
findProperty(spec, platform, () =>
|
||||
findProperty(spec, 'native', () =>
|
||||
findProperty(spec, 'default', () => t.identifier('undefined')),
|
||||
),
|
||||
),
|
||||
);
|
||||
// Inlining must not drop side effects from discarded property values.
|
||||
// Assess the property itself: an ObjectMethod has no `.value`, so
|
||||
// checking `property.value` would wrongly treat every method as
|
||||
// impure and skip inlining.
|
||||
if (
|
||||
spec.properties.every(
|
||||
property =>
|
||||
(t.isObjectProperty(property) &&
|
||||
property.value === replacement) ||
|
||||
path.scope.isPure(property),
|
||||
)
|
||||
) {
|
||||
path.replaceWith(replacement);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user