Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ describe('Platform.select', () => {
expect(select('{ios() { return 1; }}')).toContain('function');
});

test('uses the last definition of a duplicate key', () => {
expect(select('{ios: 1, ios: 2}')).toContain('const value=2');
});

test('does not inline computed keys', () => {
expect(select('{[key]: 1, default: 2}')).toContain('Platform.select');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ module.exports = function inlinePlatformPlugin(
key /*: string */,
fallback /*: () => Node */,
) /*: Node */ {
for (const property of objectExpression.properties) {
// Object literal evaluation keeps the last definition of a duplicate key.
for (let i = objectExpression.properties.length - 1; i >= 0; i--) {
const property = objectExpression.properties[i];
if (!t.isObjectProperty(property) && !t.isObjectMethod(property)) {
continue;
}
Expand Down
Loading