Skip to content

fix(compiler-core): ensure mapping is added only if node source is available #13285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented May 6, 2025

close #13261
close vitejs/vite-plugin-vue#368

Summary by CodeRabbit

  • Bug Fixes

    • Improved source map accuracy by ensuring mappings are only created for nodes with explicit source information.
  • Tests

    • Added a test to confirm that generated comment nodes from v-if directives are correctly excluded from source maps.

Copy link

coderabbitai bot commented May 6, 2025

Walkthrough

The changes add a conditional check to only include nodes with valid loc.source in source map mappings within the code generator, preventing mappings for generated nodes without source information. Additionally, a new test verifies that comment nodes produced by v-if do not map to the original template source in the generated source map.

Changes

File(s) Change Summary
packages/compiler-core/src/codegen.ts Added condition to only call addMapping if node.loc.source exists, restricting source map entries.
packages/compiler-sfc/__tests__/compileTemplate.spec.ts Introduced a test to ensure generated comment nodes from v-if do not map to original source code.

Assessment against linked issues

Objective Addressed Explanation
Remove generated code (e.g., v-if comment nodes) from source maps and ensure coverage tools reflect correct lines (#13261, #368)
Add test cases to verify source map mapping for coverage, specifically for v-if branches (#13261)

Poem

In the warren where code lines hop,
Source maps now know where to stop.
No more phantom lines in sight—
v-if’s comments mapped just right.
Coverage tools can now rejoice,
For every branch and every choice!
🐇✨


📜 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 56be3dd and bb76e0f.

📒 Files selected for processing (2)
  • packages/compiler-core/src/codegen.ts (2 hunks)
  • packages/compiler-sfc/__tests__/compileTemplate.spec.ts (1 hunks)
🔇 Additional comments (3)
packages/compiler-core/src/codegen.ts (2)

191-193: Good enhancement by conditionally adding mappings only for nodes with source information.

The addition of the node.loc.source check ensures source mappings are only created for nodes that have valid source locations, preventing incorrect mappings for compiler-generated nodes.


230-232: Consistent condition added for end location mapping.

This change correctly applies the same condition to the end location mapping as was applied to the start location mapping, ensuring complete consistency in the source map generation logic.

packages/compiler-sfc/__tests__/compileTemplate.spec.ts (1)

160-187: Well-designed test that verifies the source mapping enhancement.

This test effectively verifies that comment nodes generated by v-if directives don't map back to the original template source. It properly:

  1. Compiles a template with a v-if directive
  2. Verifies the source map structure
  3. Locates the generated comment node
  4. Confirms all source mapping attributes (line, column, source) are null

This complements the changes in codegen.ts by validating that generated nodes without source information are properly excluded from source maps.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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

github-actions bot commented May 6, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.2 kB 34.4 kB
vue.global.prod.js 159 kB 58.4 kB 51.9 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.6 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.3 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24 kB

Copy link

pkg-pr-new bot commented May 6, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13285

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13285

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13285

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13285

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13285

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13285

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13285

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13285

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13285

vue

npm i https://pkg.pr.new/vue@13285

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13285

commit: bb76e0f

@edison1105
Copy link
Member Author

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented May 6, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
vite-plugin-vue success success
nuxt success success
quasar success success
pinia success success
vant success success
primevue success success
test-utils success success
language-tools success success
vitepress success success
radix-vue success success
vueuse success success
vuetify success success
vue-simple-compiler success success
vue-macros success success
vue-i18n success success
router success success

@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: compiler 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels May 6, 2025
@edison1105 edison1105 marked this pull request as ready for review May 6, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: compiler
Projects
None yet
2 participants