+
Skip to content

Conversation

fireairforce
Copy link
Member

@fireairforce fireairforce commented Jul 27, 2025

Summary

closes: #4934

Support Import phase: https://github.com/tc39/proposal-source-phase-imports

The syntax looks like just as follows:

import source foo from "<specifier>";

Now TypeScript has not supported this syntax(Related issue: microsoft/TypeScript#61216), but babel and swc has supported.

I have not supported dynamic call like import.source("xx"), but i will support in next pr.

Test Plan

I add test case for biome_js_parser and biome_js_formatter, and my test case just refer from babel: https://github.com/babel/babel/tree/main/packages/babel-parser/test/fixtures/experimental/source-phase-imports

Docs

Summary by CodeRabbit

  • New Features

    • Added support for the import source syntax in JavaScript, enabling the use of the stage 3 ECMAScript proposal for importing modules as source.
    • Enhanced parser and formatter to recognize and handle the source keyword in import statements.
  • Bug Fixes

    • Improved error handling and recovery for invalid import source syntax cases.
  • Tests

    • Added new test cases to cover valid and invalid import source import statements, increasing test coverage for this syntax.

@github-actions github-actions bot added A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages labels Jul 27, 2025
Copy link
Contributor

github-actions bot commented Jul 27, 2025

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 50627 50627 0
Passed 49357 49357 0
Failed 1270 1270 0
Panics 0 0 0
Coverage 97.49% 97.49% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6706 6706 0
Passed 2245 2245 0
Failed 4461 4461 0
Panics 0 0 0
Coverage 33.48% 33.48% 0.00%

ts/babel

Test result main count This PR count Difference
Total 822 822 0
Passed 731 731 0
Failed 91 91 0
Panics 0 0 0
Coverage 88.93% 88.93% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18786 18786 0
Passed 14413 14413 0
Failed 4373 4373 0
Panics 0 0 0
Coverage 76.72% 76.72% 0.00%

Copy link

changeset-bot bot commented Jul 27, 2025

🦋 Changeset detected

Latest commit: 3851438

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codspeed-hq bot commented Jul 27, 2025

CodSpeed Performance Report

Merging #7019 will not alter performance

Comparing feat-4934 (3851438) with main (50ca155)1

Summary

✅ 128 untouched benchmarks

Footnotes

  1. No successful run was found on main (2ec91e3) during the generation of this report, so 50ca155 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions github-actions bot added the L-Grit Language: GritQL label Jul 27, 2025
@fireairforce
Copy link
Member Author

now the pr is ready~

Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change set introduces support for the ECMAScript import source proposal in the JavaScript parser, lexer, grammar, and formatter. It updates parsing logic, token recognition, grammar rules, and test suites to handle the new import source x from "<specifier>"; syntax, including error recovery for invalid usages and expanded test coverage.

Changes

Cohort / File(s) Change Summary
Parser: Add import source syntax support
crates/biome_js_parser/src/syntax/module.rs, crates/biome_js_parser/src/lexer/mod.rs, xtask/codegen/js.ungram, xtask/codegen/src/js_kinds_src.rs
Parser logic, lexer, grammar, and keyword list updated to recognize and correctly parse the import source syntax, including error handling for invalid forms.
Formatter: Handle phase token
crates/biome_js_formatter/src/js/module/import_default_clause.rs
Formatter updated to handle the optional phase_token (source) in import default clauses.
Pattern Matching: Import compatibility and transformation
crates/biome_grit_patterns/src/grit_node_patterns.rs
Enhanced compatibility checks and transformation logic for import-related syntax kinds in node pattern matching.
Test Coverage: Import source
crates/biome_js_parser/tests/js_test_suite/ok/import_source.js, crates/biome_js_parser/tests/js_test_suite/error/import_source_err.js, crates/biome_js_parser/tests/spec_test.rs, crates/biome_js_formatter/tests/specs/js/module/import/default_import.js
Added/updated test files to cover valid and invalid import source syntax cases, including new test cases and error scenarios.
Changelog
.changeset/tangy-chicken-start.md
Added a summary of the new feature and its scope.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Parser
    participant Lexer
    participant Formatter

    User->>Parser: Provide JS code with `import source x from "mod"`
    Parser->>Lexer: Tokenize input (recognizes `source` as keyword)
    Parser->>Parser: Parse import statement (handles `source` phase)
    Parser->>Formatter: Pass parsed AST with optional phase token
    Formatter->>User: Output formatted import statement
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Support parsing, lexing, and recognizing import source x from "<specifier>"; syntax (#4934)
Correct error handling and recovery for invalid import source forms (#4934)
Update grammar and keyword lists to include source (#4934)
Add/extend tests for valid and invalid import source statements (#4934)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Enhanced import pattern compatibility and transformation logic (crates/biome_grit_patterns/src/grit_node_patterns.rs) This change refines internal pattern matching for import-related syntax kinds, which is not directly required for supporting the import source proposal. However, it may be indirectly related for broader parser consistency.

Poem

A rabbit hopped through fields of code,
Adding "source" imports to lighten the load.
From parser to lexer, the syntax grew bright,
With tests to ensure all errors took flight.
Now modules import with a sourceful cheer—
Hooray for new syntax, the future is here! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0e36e2 and 3851438.

⛔ Files ignored due to path filters (27)
  • crates/biome_js_factory/src/generated/node_factory.rs is excluded by !**/generated/**
  • crates/biome_js_factory/src/generated/syntax_factory.rs is excluded by !**/generated/**
  • crates/biome_js_formatter/tests/specs/js/module/import/default_import.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/babel-plugins/source-phase-imports.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/dynamic-import/import-phase.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source-attributes-declaration.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source-attributes-expression.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source-binding-from.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source-binding-source.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source-dynamic-import.js.snap is excluded by !**/*.snap
  • crates/biome_js_formatter/tests/specs/prettier/js/source-phase-imports/import-source.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_assertion_err.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_attribute_err.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_decl_not_top_level.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_defer_err.ts.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_err.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/error/import_source_err.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/import_attribute.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/import_default_clause.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/import_source.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/logical_expression_with_jsx.tsx.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/metavar.tsx.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/module.js.snap is excluded by !**/*.snap
  • crates/biome_js_parser/tests/js_test_suite/ok/ts_import_clause_types.ts.snap is excluded by !**/*.snap
  • crates/biome_js_syntax/src/generated/kind.rs is excluded by !**/generated/**
  • crates/biome_js_syntax/src/generated/nodes.rs is excluded by !**/generated/**
  • crates/biome_js_syntax/src/generated/nodes_mut.rs is excluded by !**/generated/**
📒 Files selected for processing (11)
  • .changeset/tangy-chicken-start.md (1 hunks)
  • crates/biome_grit_patterns/src/grit_node_patterns.rs (5 hunks)
  • crates/biome_js_formatter/src/js/module/import_default_clause.rs (2 hunks)
  • crates/biome_js_formatter/tests/specs/js/module/import/default_import.js (1 hunks)
  • crates/biome_js_parser/src/lexer/mod.rs (1 hunks)
  • crates/biome_js_parser/src/syntax/module.rs (3 hunks)
  • crates/biome_js_parser/tests/js_test_suite/error/import_source_err.js (1 hunks)
  • crates/biome_js_parser/tests/js_test_suite/ok/import_source.js (1 hunks)
  • crates/biome_js_parser/tests/spec_test.rs (1 hunks)
  • xtask/codegen/js.ungram (1 hunks)
  • xtask/codegen/src/js_kinds_src.rs (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-4934

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arendjr arendjr merged commit 57c15e6 into main Aug 5, 2025
29 of 30 checks passed
@arendjr arendjr deleted the feat-4934 branch August 5, 2025 14:45
@github-actions github-actions bot mentioned this pull request Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Parser Area: parser A-Tooling Area: internal tools L-Grit Language: GritQL L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Add support for the import source proposal

4 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载