Skip to content

Conversation

@KazariEX
Copy link
Member

@KazariEX KazariEX commented Feb 22, 2025

Nowadays, language tools rely on string search to determine the offset of tags, which is not reliable and may cause some issues, like:

<img v-bind="imgAttrs">
        <!-- ^^^ is recognized as the close tag -->
<div></Div>
  <!-- ^^^ is not recognized as the close tag -->

Summary by CodeRabbit

  • New Features

    • Added an option to record the precise source location of opening and closing tags in parsed elements.
    • Introduced a parser setting to enable or disable recording of tag locations.
  • Tests

    • Enhanced test coverage to verify accurate recording of tag location information in parsed elements.

@github-actions
Copy link

github-actions bot commented Feb 22, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.3 kB 34.5 kB
vue.global.prod.js 159 kB (+114 B) 58.5 kB (+39 B) 52 kB (+41 B)

Usages

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: fb731b8

@KazariEX KazariEX marked this pull request as ready for review February 22, 2025 17:50
@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: compiler language-tools related to vue language-tools labels Feb 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes introduce new options and properties to enable and handle precise source location tracking for opening and closing tags in the parser's AST nodes. Updates include AST type extensions, parser logic to populate these locations when enabled, parser options to control the feature, and corresponding test coverage.

Changes

File(s) Change Summary
packages/compiler-core/src/ast.ts Extended BaseElementNode interface with optional openTagLoc and closeTagLoc properties.
packages/compiler-core/src/options.ts Added optional tagLocations boolean property to ParserOptions interface.
packages/compiler-core/src/parser.ts Updated parser logic and options to support tagLocations, recording tag locations in AST nodes.
packages/compiler-dom/tests/parse.spec.ts Enhanced test to assert presence and correctness of tagLoc in parsed AST for a void <img> element.

Sequence Diagram(s)

sequenceDiagram
    participant SourceCode
    participant Parser
    participant ASTNode

    SourceCode->>Parser: Provide HTML/XML source
    Parser->>Parser: Check if tagLocations option is enabled
    alt tagLocations enabled
        Parser->>ASTNode: Attach openTagLoc during open tag parse
        Parser->>ASTNode: Attach closeTagLoc during close tag parse
    end
    Parser->>ASTNode: Build AST with tag location info (if enabled)
Loading

Poem

🐇
With tags now tracked from open to close,
The parser knows just where it goes.
Locations marked with careful care,
In ASTs, precision’s there!
A hop, a skip, a test that sings—
The code now maps all taggy things!

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

@KazariEX KazariEX changed the title feat(compiler-core): add tagLoc and closeTagLoc to element ast node feat(compiler-core): add openTagLoc and closeTagLoc to element ast node Jun 18, 2025
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: 4

🧹 Nitpick comments (1)
packages/compiler-core/src/options.ts (1)

100-104: Minor doc tweak

The comment says “open tag and close tag of each node” – consider clarifying that it records the tag-name locations, not the whole tag range, to avoid ambiguity.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 604d087 and b4566c2.

📒 Files selected for processing (4)
  • packages/compiler-core/src/ast.ts (1 hunks)
  • packages/compiler-core/src/options.ts (1 hunks)
  • packages/compiler-core/src/parser.ts (3 hunks)
  • packages/compiler-dom/__tests__/parse.spec.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / unit-test-windows
🔇 Additional comments (1)
packages/compiler-core/src/parser.ts (1)

81-82: Performance toggle added – ensure downstream opts in

tagLocations defaults to false, yet the DOM-parser tests rely on it being true.
If parserOptions in packages/compiler-dom/src/parserOptions.ts is not explicitly enabling this flag, the new fields will never be set and tests will still fail even after the naming fix.
Please verify & enable where needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

language-tools related to vue language-tools ready to merge The PR is ready to be merged. scope: compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants