Skip to content

test(pack): add verbatimModuleSyntax test case#2655

Merged
fireairforce merged 1 commit into
nextfrom
add-verbatim-module-syntax-test
Mar 3, 2026
Merged

test(pack): add verbatimModuleSyntax test case#2655
fireairforce merged 1 commit into
nextfrom
add-verbatim-module-syntax-test

Conversation

@fireairforce
Copy link
Copy Markdown
Member

@fireairforce fireairforce commented Mar 3, 2026

Summary

Add a test case for verbatimModuleSyntax under typescript transform:

image

Here it's clear that when verbatimModuleSyntax is set to false, the React import has been removed, causing the classic JSX transform to not find the React dependency.

The opposite test case shows that when the default value is true, React is preserved:

image

Thanks for @hardfist reminds:

web-infra-dev/rspack#9270 (comment)

Test Plan

Just a test case added for pr: #2653

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial test case to validate the interaction between TypeScript's verbatimModuleSyntax compiler option and the classic JSX transform. It ensures that the module syntax setting correctly influences whether React imports are retained or stripped during the build process, preventing potential issues where React dependencies might not be found. The changes also refine an existing JSX test to better reflect real-world TypeScript component structures.

Highlights

  • New Test Case for verbatimModuleSyntax: Added a new snapshot test case to verify the behavior of verbatimModuleSyntax under TypeScript transform, specifically when it's set to false and true, to ensure React imports are correctly preserved or removed based on the setting.
  • Clarified JSX Transform Behavior: The new test case demonstrates how verbatimModuleSyntax: false can lead to React imports being removed, impacting the classic JSX transform, while verbatimModuleSyntax: true correctly preserves them.
  • Updated Existing Snapshot Test: An existing foreign_jsx_transform snapshot test was updated to use .tsx files and include a nested component, making it more robust and aligned with TypeScript usage.
Changelog
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/config.json
    • Updated the entry file extension from .jsx to .tsx.
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/input/comp.tsx
    • Added a new React component file comp.tsx.
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/input/index.tsx
    • Renamed the file from index.jsx to index.tsx.
    • Imported the new Comp component.
    • Integrated the Comp component into the App component's JSX structure.
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/output/_project__basic_foreign_jsx_transform_5da2b40c.js
    • Renamed the output JavaScript file.
    • Updated module paths to reflect the .tsx extension and the new comp.tsx import.
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/output/_project__basic_foreign_jsx_transform_5da2b40c.js.map
    • Renamed the source map file.
    • Updated source content mappings to reflect the .tsx extension and the new comp.tsx file.
  • crates/pack-tests/tests/snapshot/basic/foreign_jsx_transform/output/main.js
    • Updated the otherChunks and runtimeModuleIds to reference the new output file names and .tsx entry point.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/config.json
    • Added a new configuration file for the verbatimModuleSyntax test case, specifying input/index.tsx as the entry and classic React runtime.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/input/index.tsx
    • Added a new index.tsx file containing a simple React component for the verbatimModuleSyntax test.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/node_modules/react/index.js
    • Added a mock react/index.js module for the verbatimModuleSyntax test case.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/output/input_index_tsx_0a80628f.js
    • Added the generated JavaScript output for the verbatimModuleSyntax test case.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/output/input_index_tsx_0a80628f.js.map
    • Added the source map for the generated JavaScript output of the verbatimModuleSyntax test case.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/output/main.js
    • Added the main JavaScript output file for the verbatimModuleSyntax test case.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/output/main.js.map
    • Added the main source map file for the verbatimModuleSyntax test case.
  • crates/pack-tests/tests/snapshot/typescript/verbatim_module_syntax/tsconfig.json
    • Added a tsconfig.json file for the verbatimModuleSyntax test case, explicitly setting verbatimModuleSyntax to false.
Activity
  • A new test case for verbatimModuleSyntax was added under TypeScript transform.
  • The PR description includes screenshots illustrating the impact of verbatimModuleSyntax on React imports.
  • The author acknowledges a reminder from @hardfist regarding this issue, referencing a discussion on web-infra-dev/rspack.
  • The changes are related to a test plan for a pull request in the utooland/utoo repository (PR feat(pack): support pass tsconfig verbatimModuleSyntax to typescript transform #2653).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a test case for verbatimModuleSyntax and updates an existing test to use TypeScript. The changes are logical and contribute to better test coverage. I've found a few minor style issues that could improve code consistency. Specifically, some new files are missing a final newline, and there's an opportunity to use a self-closing tag for a React component.

@fireairforce fireairforce changed the title chore: add verbatimModuleSyntax test case test(pack): add verbatimModuleSyntax test case Mar 3, 2026
@fireairforce
Copy link
Copy Markdown
Member Author

Code Review

This pull request adds a test case for verbatimModuleSyntax and updates an existing test to use TypeScript. The changes are logical and contribute to better test coverage. I've found a few minor style issues that could improve code consistency. Specifically, some new files are missing a final newline, and there's an opportunity to use a self-closing tag for a React component.

test case is no need to review, just keep it

@fireairforce fireairforce enabled auto-merge (squash) March 3, 2026 08:46
@fireairforce fireairforce merged commit 30e53ae into next Mar 3, 2026
49 of 51 checks passed
@fireairforce fireairforce deleted the add-verbatim-module-syntax-test branch March 3, 2026 08:49
bgw pushed a commit to vercel/next.js that referenced this pull request Mar 12, 2026
In utoo case, we need to support react classic jsx transform(To
compitable with react 16 or above project).

We have a case like:

```ts
// index.ts
import React from 'react';

export const App = () => <div></div>;
```

Under the classic jsx transform, the jsx will be transformed as follows:

```ts
export const App = () => React.createElement("div", /***/);
```

But turbopack's jsx transform was behind typescript transform, so in the
stage of typescript transform, the import of react will be deleted by
the default config of swc typescript transform(which set
`verbatimmodulesyntax` as false by default):
https://swc.rs/docs/migrating-from-tsc#verbatimmodulesyntax-true

Then the output of classic jsx transform will get a runtime error like
`React was not found`.

For solve the problem, this pr just support a config
`verbatimModuleSyntax` for turbopack's typescript transform, it will not
remove user's React import under classic jsx transform.

We test the case under utoopack in the following pr:

- utooland/utoo#2653
- utooland/utoo#2655

And Rspack also enable `verbatimModuleSyntax` to true by default under
2.0:
web-infra-dev/rspack#9270 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants