Skip to content

Commit

Permalink
fix(metro-serializer-esbuild): do not lower template literals (#3362)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Sep 17, 2024
1 parent 00247a7 commit 20f6de0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/gentle-eggs-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/metro-serializer-esbuild": patch
---

Do not lower template literals. Template literals are partially supported by
Hermes for most of the use cases we care about (e.g., `styled-components`).
3 changes: 2 additions & 1 deletion packages/metro-serializer-esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,15 @@ export function MetroSerializer(
return undefined;
}

// The following features should be safe to enable if we take into
// `arrow` and `generator` should be safe to enable if we take into
// consideration that Hermes does not support classes. They were
// disabled in esbuild 0.14.49 after the feature compatibility table
// generator was fixed (see
// https://github.com/evanw/esbuild/releases/tag/v0.14.49).
return {
arrow: true,
generator: true,
"template-literal": true, // Used heavily by `styled-components`
};
})(),
write: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log`Hello`;
15 changes: 15 additions & 0 deletions packages/metro-serializer-esbuild/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("metro-serializer-esbuild", () => {
require.resolve("react-native/package.json")
),
dependencies: {},
assets: [],
commands: [],
healthChecks: [],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -308,4 +309,18 @@ describe("metro-serializer-esbuild", () => {
)
);
});

it("preserves template literals", async () => {
const result = await bundle("test/__fixtures__/templateLiterals.ts");
deepEqual(result, [
"(() => {",
" // virtual:metro:__rnx_prelude__",
' var global = new Function("return this;")();',
"",
" // test/__fixtures__/templateLiterals.ts",
" console.log`Hello`;",
"})();",
"",
]);
});
});

0 comments on commit 20f6de0

Please sign in to comment.