Skip to content

Conversation

cernymatej
Copy link
Member

📚 Description

This PR removes the old implementation of the parse utils and migrates to the new ones from oxc-walker.

The dependency wasn't included yet, since this needs to be released first.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

@cernymatej looks like a few tests fail owing to differences in scope tracker - might warrant a look

@cernymatej
Copy link
Member Author

noticed that too… I'll investigate

Locally, some tests related to logging failed too - specifically the ones that require the vite plugin defined in root-level nuxt.config.ts (intoduced in the async data layer rewrite).
How should I run the tests to include it, so that it is easier to see which tests really fail? 🙏
Thanks!

@danielroe
Copy link
Member

you should be able to run pnpm vitest <name of test file> now that we have a single vitest file with environments

@cernymatej
Copy link
Member Author

That's what I've been using, but for example, pnpm vitest test/nuxt/composables.test.ts -t="should warn if incompatible options are used" always fails

image

and if I change the isDev check in asyncData.ts, it passes

const isDev = import.meta.dev /* and in test */ || true

Copy link

pkg-pr-new bot commented Jun 2, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32250

nuxt

npm i https://pkg.pr.new/nuxt@32250

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32250

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32250

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32250

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32250

commit: 692ddbd

Copy link

codspeed-hq bot commented Jun 2, 2025

CodSpeed Performance Report

Merging #32250 will not alter performance

Comparing cernymatej:chore-migrate-to-oxc-walker (692ddbd) with main (8f8db53)

Summary

✅ 10 untouched benchmarks

@cernymatej
Copy link
Member Author

The problem was that this PR didn't include the last-minute changes made in oxc-walker because I had been waiting for the package to be released.
Should be all good now. (apart from the failing tests - at least locally - I mentioned earlier)

@cernymatej cernymatej marked this pull request as ready for review June 2, 2025 15:31
@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 15:31
@cernymatej cernymatej requested a review from danielroe as a code owner June 2, 2025 15:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the Nuxt parse utilities to use the new oxc-walker package and removes the old implementation. Key changes include updating imports and API calls across multiple files, replacing withLocations call usages with direct node references, and renaming options (e.g. keepExitedScopes to preserveExitedScopes).

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/nuxt/src/pages/utils.ts Migrated parse functions to use oxc-walker and updated types.
packages/nuxt/src/pages/route-rules.ts Updated import and direct usage of parseAndWalk.
packages/nuxt/src/pages/plugins/page-meta.ts Replaced withLocations & isNotReferencePosition with new methods.
packages/nuxt/src/head/plugins/unhead-imports.ts Removed withLocations usage and switched to oxc-walker import.
packages/nuxt/src/core/plugins/prehydrate.ts Modified parseAndWalk and removed withLocations from callback.
packages/nuxt/src/core/plugins/plugin-metadata.ts Updated AST node handling and type adjustments.
packages/nuxt/src/core/plugins/composable-keys.ts Replaced keepExitedScopes with preserveExitedScopes.
packages/nuxt/src/components/plugins/tree-shake.ts Revised AST traversal and node removal logic using oxc-walker.
packages/nuxt/src/components/plugins/component-names.ts Simplified import and node location retrieval.
packages/nuxt/package.json Added dependency on oxc-walker.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (3)

packages/nuxt/src/pages/plugins/page-meta.ts:192

  • Replacing 'isNotReferencePosition' with 'isBindingIdentifier' may change the filtering logic; please verify that this new condition preserves the intended behavior when handling identifier nodes.
if (isBindingIdentifier(node, parent) || node.type !== 'Identifier') { return }

packages/nuxt/src/core/plugins/composable-keys.ts:59

  • [nitpick] Confirm that 'preserveExitedScopes' is the correct replacement for 'keepExitedScopes' in the current context, and update any related documentation if necessary.
preserveExitedScopes: true,

packages/nuxt/src/components/plugins/tree-shake.ts:51

  • [nitpick] Verify that destructuring 'program' from the parseAndWalk result aligns with the new API's return structure and does not affect downstream AST processing.
const { program: ast } = parseAndWalk(code, id, (node) => {

Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

This set of changes migrates the codebase from using custom AST parsing, walking, and scope tracking utilities to relying on the external oxc-walker and oxc-parser packages. All references to the custom withLocations helper and local parsing utilities are removed, with direct access to AST node properties (start, end, etc.) now used throughout the code. Type annotations and AST node handling are updated to align with the new parser's types. The internal scope tracking implementation and its associated tests are deleted, and all code transformation logic is refactored to operate with the new parsing and walking APIs. Public API signatures are minimally affected, with some internal type updates and minor function signature changes to accommodate the new AST node types.


📜 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 040cb2a and 692ddbd.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/utils/parse.ts (1 hunks)
🔇 Additional comments (1)
packages/nuxt/src/core/utils/parse.ts (1)

1-7: Migration completed successfully for the transform utility.

The migration from custom AST parsing utilities to oxc-walker has been properly executed in this file. All the custom parsing, walking, and scope tracking code has been removed, leaving only the essential transform function that wraps esbuild with Nuxt-specific options. The imports are clean and the function implementation remains correct.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fe3ef77 and 040cb2a.

⛔ Files ignored due to path filters (2)
  • packages/nuxt/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (11)
  • packages/nuxt/src/components/plugins/component-names.ts (2 hunks)
  • packages/nuxt/src/components/plugins/tree-shake.ts (7 hunks)
  • packages/nuxt/src/core/plugins/composable-keys.ts (2 hunks)
  • packages/nuxt/src/core/plugins/plugin-metadata.ts (4 hunks)
  • packages/nuxt/src/core/plugins/prehydrate.ts (2 hunks)
  • packages/nuxt/src/core/utils/parse.ts (1 hunks)
  • packages/nuxt/src/head/plugins/unhead-imports.ts (2 hunks)
  • packages/nuxt/src/pages/plugins/page-meta.ts (6 hunks)
  • packages/nuxt/src/pages/route-rules.ts (1 hunks)
  • packages/nuxt/src/pages/utils.ts (5 hunks)
  • packages/nuxt/test/parse.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/nuxt/test/parse.test.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/nuxt/src/pages/plugins/page-meta.ts (1)
packages/nuxt/src/pages/utils.ts (1)
  • isSerializable (630-676)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: codeql (javascript-typescript)
🔇 Additional comments (16)
packages/nuxt/src/core/utils/parse.ts (1)

7-9: Good implementation of the transform wrapper.

The transform function correctly wraps esbuild's transform with Nuxt-specific options, maintaining backwards compatibility whilst simplifying the module's responsibilities.

packages/nuxt/src/pages/route-rules.ts (1)

6-6:

❓ Verification inconclusive

Import change looks correct.

The migration from local parseAndWalk to oxc-walker package is consistent with the overall migration strategy. The usage pattern in the file appears compatible with the new API.


🏁 Script executed:

#!/bin/bash
# Description: Verify that parseAndWalk from oxc-walker has compatible API with the usage
# Expected: Confirm that oxc-walker's parseAndWalk supports the same callback pattern

# Check how parseAndWalk is used in this file
rg -A 10 -B 2 "parseAndWalk" packages/nuxt/src/pages/route-rules.ts

# Find other files using parseAndWalk to verify consistent migration
rg -l "parseAndWalk.*oxc-walker" --type ts

Length of output: 1517


Ensure oxc-walker parseAndWalk API compatibility

The import of parseAndWalk from oxc-walker is correct and all usages in this package (including packages/nuxt/src/pages/route-rules.ts and six other files) follow the same signature:

parseAndWalk(code, ext, callback)
• Inside the callback you rely on node.start and node.end

Please verify that the public API of oxc-walker:

  • Exports parseAndWalk(code: string, ext: string, cb: (node: Node) => void)
  • Guarantees that Node objects include start and end properties

Review the oxc-walker documentation or its TypeScript definitions to confirm before merging.

packages/nuxt/src/core/plugins/prehydrate.ts (2)

5-6: Clean migration to oxc-walker with improved simplicity.

The import changes correctly migrate to oxc-walker whilst maintaining the transform import from the local module (which is still available). The removal of withLocations wrapper simplifies the code by using direct node properties.


28-28: Simplified node property access.

Good removal of the withLocations wrapper. Direct access to node.arguments[0] is cleaner and should work consistently with oxc-walker's AST nodes.

packages/nuxt/src/components/plugins/component-names.ts (2)

4-4: Correct migration to oxc-walker.

The import change from local parsing utilities to oxc-walker is consistent with the overall migration strategy.


50-50: Improved code clarity with direct property access.

Excellent simplification! Direct destructuring of start and end from node.declaration is much cleaner than using the withLocations wrapper and improves code readability.

packages/nuxt/src/head/plugins/unhead-imports.ts (1)

7-7: LGTM! Clean migration to oxc-walker.

The removal of withLocations wrapper and direct access to node properties is consistent with the new parser API.

Also applies to: 58-59

packages/nuxt/src/core/plugins/composable-keys.ts (1)

9-9: LGTM! Correct API adjustments for oxc-walker.

The option rename to preserveExitedScopes and the updated return structure handling (parseResult.program) are consistent with the new parser API.

Also applies to: 59-59, 61-62, 67-67

packages/nuxt/src/pages/plugins/page-meta.ts (1)

9-16:

❓ Verification inconclusive

Verify the semantic equivalence of isBindingIdentifier.

The migration looks correct. However, please ensure that isBindingIdentifier from oxc-walker provides the same semantic behaviour as the previous isNotReferencePosition check to avoid any unintended changes in identifier handling logic.

Run the following script to verify that the identifier handling tests pass with the new implementation:

Also applies to: 178-178, 194-194, 216-216, 231-231, 239-239, 245-245, 263-263


🏁 Script executed:

#!/bin/bash
# Description: Check if there are any tests specifically for identifier handling in page-meta that might catch semantic differences

# Search for test files related to page-meta
fd -e test.ts -e spec.ts | xargs rg -l "page-meta|definePageMeta" -A 5

# Search for any tests that might test identifier handling
rg -A 10 "isNotReferencePosition|isBindingIdentifier|identifier.*handling" --type ts

Length of output: 3207


Verify isBindingIdentifier matches previous isNotReferencePosition semantics
No existing tests in page-meta reference isNotReferencePosition or isBindingIdentifier, so we can’t be sure the new check hasn’t altered identifier handling. Please manually confirm (or add tests to cover) that every case covered by the old isNotReferencePosition—for example:

  • variable declarations vs references
  • function parameters and default values
  • object destructuring and property accesses
  • import specifiers

still behaves identically under isBindingIdentifier.

packages/nuxt/src/components/plugins/tree-shake.ts (1)

8-9: LGTM! Comprehensive type migration to oxc-parser.

The migration from ESTree types to oxc-parser types is thorough and consistent. The updated filtering logic properly handles the new BindingPattern and BindingProperty types.

Also applies to: 51-51, 64-65, 67-67, 150-150, 173-173, 176-176, 240-240, 253-253, 259-259, 266-266

packages/nuxt/src/core/plugins/plugin-metadata.ts (3)

1-1: Import changes look good.

The migration correctly adds the necessary imports from oxc-walker and oxc-parser. The Literal type from estree is still needed for the type cast at line 109.

Also applies to: 10-11


87-94: Function updates correctly handle new AST node types.

The changes appropriately handle the migration from estree to oxc-parser AST nodes, with proper type checks for both string keys and IdentifierName objects.


168-170: Direct node property access is implemented correctly.

The removal of the withLocations wrapper and direct access to start and end properties aligns with the oxc-parser node structure.

packages/nuxt/src/pages/utils.ts (3)

13-14: Import migration is correct.

The replacement of estree types with oxc-parser types and the use of parseAndWalk from oxc-walker aligns with the migration objectives.


260-263: Type updates in getRouteMeta are correct.

The property finding logic correctly uses the new ObjectProperty type, and the direct access to property.value aligns with the oxc-parser node structure.


631-676: isSerializable function correctly migrated to new AST types.

All node type checks and property accesses have been properly updated to work with oxc-parser nodes. The direct access to start, end, and value properties is consistent with the removal of the withLocations wrapper.

@danielroe danielroe changed the title chore(nuxt): migrate to oxc-walker refactor(nuxt): migrate to oxc-walker Jun 2, 2025
@danielroe danielroe merged commit 4aa1439 into nuxt:main Jun 2, 2025
48 checks passed
@github-actions github-actions bot mentioned this pull request Jun 2, 2025
@cernymatej cernymatej deleted the chore-migrate-to-oxc-walker branch July 18, 2025 10:58
danielroe added a commit that referenced this pull request Jul 21, 2025
Co-authored-by: Daniel Roe <daniel@roe.dev>
This was referenced Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants