Skip to content

Commit 679a7b7

Browse files
generatedunixname89002005232357meta-codesync[bot]
authored andcommitted
Revert D119065685: fix(babel-preset): preserve Platform.select initializers
Differential Revision: D119065685 Original commit changeset: ca209fe9b728 Original Phabricator Diff: D119065685 fbshipit-source-id: 1200093b9a798d795a6d4cf4289839dbe11920ee
1 parent c1ad8ae commit 679a7b7

2 files changed

Lines changed: 5 additions & 27 deletions

File tree

‎packages/react-native-babel-preset/src/__tests__/inline-platform-plugin-test.js‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,6 @@ describe('Platform.select', () => {
483483
expect(select('{ios: 1, ios: 2}')).toContain('const value=2');
484484
});
485485

486-
test('does not discard impure initializers', () => {
487-
expectUnchanged(`
488-
const value = require('react-native').Platform.select({
489-
ios: first(),
490-
android: android(),
491-
ios: last(),
492-
});
493-
`);
494-
});
495-
496486
test('does not inline computed keys', () => {
497487
expect(select('{[key]: 1, default: 2}')).toContain('Platform.select');
498488
});

‎packages/react-native-babel-preset/src/inline-platform-plugin.js‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -520,25 +520,13 @@ module.exports = function inlinePlatformPlugin(
520520
return;
521521
}
522522

523-
const replacement = findProperty(spec, platform, () =>
524-
findProperty(spec, 'native', () =>
525-
findProperty(spec, 'default', () => t.identifier('undefined')),
523+
path.replaceWith(
524+
findProperty(spec, platform, () =>
525+
findProperty(spec, 'native', () =>
526+
findProperty(spec, 'default', () => t.identifier('undefined')),
527+
),
526528
),
527529
);
528-
// Inlining must not drop side effects from discarded property values.
529-
// Assess the property itself: an ObjectMethod has no `.value`, so
530-
// checking `property.value` would wrongly treat every method as
531-
// impure and skip inlining.
532-
if (
533-
spec.properties.every(
534-
property =>
535-
(t.isObjectProperty(property) &&
536-
property.value === replacement) ||
537-
path.scope.isPure(property),
538-
)
539-
) {
540-
path.replaceWith(replacement);
541-
}
542530
},
543531
},
544532
};

0 commit comments

Comments
 (0)