Skip to content
Merged
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
18 changes: 18 additions & 0 deletions packages/formatjs/__tests__/wasm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ describe("formatjs swc plugin", () => {
expect(output).not.toMatch(/description/);
});

// Regression test for https://github.com/swc-project/plugins/issues/532
it("should handle string concatenation in defaultMessage (issue #532)", async () => {
const input = `
import { defineMessage } from 'react-intl';

const message = defineMessage({
defaultMessage: 'Hello ' + 'world'
});
`;

const output = await transformCode(input);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise AST mode in the regression test

I checked packages/formatjs/transform/src/lib.rs:893-905, and the defaultMessage: [] symptom only comes from the options.ast branch; with the default transformCode(input) call here, the plugin always prints a string literal instead. As written, this test can still pass while issue #532 remains broken for ast: true, so it doesn't actually cover the empty-array regression described in the comment/commit message.

Useful? React with 👍 / 👎.


expect(output).toMatch(/id: "[^"]+"/);
// Should concatenate strings, not produce an empty array
expect(output).toMatch(/defaultMessage: "Hello world"/);
expect(output).not.toMatch(/defaultMessage: \[\]/);
});

it("should handle multiple string concatenations", async () => {
const input = `
import { defineMessage } from 'react-intl';
Expand Down
Loading