Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/corePublic

feat(compiler-core): consider component import names for resolving setup component references#13624

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alex-snezhko wants to merge1 commit intovuejs:main
base:main
Choose a base branch
Loading
fromalex-snezhko:imported-component-template-name-casing

Conversation

alex-snezhko
Copy link
Contributor

@alex-snezhkoalex-snezhko commentedJul 13, 2025
edited by coderabbitaibot
Loading

close#9303

If the issue above is not considered a bug then this can be considered a breaking change, though a worthwhile one in my opinion.

Verified that the SFC playground example from the issue works as expected:
Screenshot From 2025-07-12 22-45-02

Summary by CodeRabbit

  • New Features

    • Improved component reference resolution in templates, ensuring correct handling of component names with different casing styles.
    • Enhanced support for distinguishing between components and directives during template compilation.
  • Bug Fixes

    • Fixed issues where components with similar names but different casing could be incorrectly referenced in templates.
  • Tests

    • Added a new test to verify correct component referencing with various casing styles in<script setup>.

@coderabbitaicoderabbitai
Copy link

coderabbitaibot commentedJul 13, 2025
edited
Loading

Walkthrough

The changes introduce a new mechanism for tracking "known components" in the Vue compiler's transformation and code generation stages. This includes adding aknownComponents set to transformation contexts, updating component resolution logic to prioritize these known components, and adding a targeted test to verify correct handling of component and function name collisions with different casing.

Changes

File(s)Change Summary
packages/compiler-core/src/codegen.tsExcludedknownComponents from properties inherited byCodegenContext.
packages/compiler-core/src/options.tsAdded optionalknownComponents?: Set<string> toSharedTransformCodegenOptions.
packages/compiler-core/src/transform.tsAddedknownComponents parameter and property tocreateTransformContext.
packages/compiler-core/src/transforms/transformElement.tsModifiedresolveSetupReference to acceptisComponent param; updated logic to prefer known components.
packages/compiler-sfc/tests/compileScript.spec.tsAdded a test verifying correct component/function name disambiguation with different casing.
packages/compiler-sfc/src/compileScript.tsTracked known components during script compilation and passed them to template compilation.

Sequence Diagram(s)

sequenceDiagram    participant SFCCompiler as SFC Compiler    participant ScriptCompile as compileScript    participant Transform as createTransformContext    participant TemplateCompile as compileTemplate    SFCCompiler->>ScriptCompile: Compile <script setup>    ScriptCompile->>ScriptCompile: Identify user imports    ScriptCompile->>ScriptCompile: Add known components to knownComponents set    ScriptCompile->>TemplateCompile: Pass knownComponents in compilerOptions    TemplateCompile->>Transform: createTransformContext(knownComponents)    Transform->>Transform: Provide knownComponents to transform context    TemplateCompile->>TemplateCompile: Use resolveSetupReference with isComponent flag    TemplateCompile->>TemplateCompile: Prefer knownComponents for component tags
Loading

Assessment against linked issues

ObjectiveAddressedExplanation
Disambiguate between component tag names and functions with same/different casing (#9303)
Ensure correct rendering of components when both component and function exist (#9303)
Prevent incorrect invocation of functions due to component tag name collision (#9303)

Poem

A bunny hops with nimble feet,
Through code where components and functions meet.
Casing now clear, collisions no more,
Vue's templates render as never before!
With knownComponents in every set,
This rabbit finds no naming threat.
🐇✨

✨ 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 withCodeRabbit:

  • 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 oursupport 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 togenerate 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 theconfiguration 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 ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

@github-actionsGitHub Actions
Copy link

Size Report

Bundles

FileSizeGzipBrotli
runtime-dom.global.prod.js101 kB38.4 kB34.5 kB
vue.global.prod.js159 kB (+44 B)58.5 kB (+15 B)52 kB (-30 B)

Usages

NameSizeGzipBrotli
createApp (CAPI only)46.5 kB18.2 kB16.7 kB
createApp54.5 kB21.2 kB19.4 kB
createSSRApp58.7 kB22.9 kB20.9 kB
defineCustomElement59.5 kB22.8 kB20.8 kB
overall68.5 kB26.4 kB24 kB

@pkg-pr-newpkg.pr.new
Copy link

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit:5c41ad9

Copy link

@coderabbitaicoderabbitaibot 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: 0

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

334-350:Excellent component prioritization logic with minor optimization opportunity.

The implementation correctly prioritizes known components whenisComponent is true by checking each name variant against theknownComponents set before falling back to the original binding resolution.

Consider using optional chaining for cleaner code:

-    isKnownComponent:-      context.knownComponents && context.knownComponents.has(name),+    isKnownComponent: context.knownComponents?.has(name),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between347ef1d and5c41ad9.

⛔ Files ignored due to path filters (1)
  • packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap is excluded by!**/*.snap
📒 Files selected for processing (6)
  • packages/compiler-core/src/codegen.ts (1 hunks)
  • packages/compiler-core/src/options.ts (1 hunks)
  • packages/compiler-core/src/transform.ts (2 hunks)
  • packages/compiler-core/src/transforms/transformElement.ts (3 hunks)
  • packages/compiler-sfc/__tests__/compileScript.spec.ts (1 hunks)
  • packages/compiler-sfc/src/compileScript.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/compiler-sfc/__tests__/compileScript.spec.ts (1)
packages/compiler-sfc/__tests__/utils.ts (1)
  • assertCode (27-42)
packages/compiler-core/src/codegen.ts (1)
packages/compiler-core/src/options.ts (1)
  • CodegenOptions (311-353)
🪛 Biome (1.9.4)
packages/compiler-core/src/transforms/transformElement.ts

[error] 338-338: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (10)
packages/compiler-core/src/options.ts (1)

202-207:LGTM! Clean interface addition with clear documentation.

The newknownComponents property is well-designed with appropriate typing and clear documentation explaining its purpose for component reference disambiguation.

packages/compiler-core/src/codegen.ts (1)

123-126:LGTM! Consistent exclusion of optional property.

The exclusion ofknownComponents from theRequired<CodegenOptions> type follows the established pattern for other optional properties likebindingMetadata andinline.

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

409-433:LGTM! Comprehensive test case for component casing disambiguation.

This test effectively validates the new feature by:

  • Testing different casing styles (PascalCase, camelCase) for imported components
  • Including conflicting local variables with similar names but different casing
  • Verifying correct component resolution in the generated_createVNode calls
  • Following established testing patterns withassertCode() validation

The test provides good coverage for the component reference disambiguation functionality.

packages/compiler-core/src/transform.ts (2)

146-146:LGTM! Clean parameter addition with backward compatibility.

The addition of theknownComponents parameter with a default emptySet<string>() maintains backward compatibility while enabling the new component disambiguation feature.


175-175:LGTM! Proper propagation to transform context.

TheknownComponents property is correctly propagated to theTransformContext object, following the established pattern for other options.

packages/compiler-sfc/src/compileScript.ts (2)

729-744:LGTM! Well-structured known components tracking.

The logic correctly identifies known Vue components from user imports by checking for namespace imports, default imports from .vue files, and Vue package imports. The binding metadata assignment is also appropriate - known components getSETUP_CONST while potentially reactive imports getSETUP_MAYBE_REF.


888-888:Good integration with template compiler.

Passing theknownComponents set to the template compiler options enables the enhanced component resolution in the template transformation phase.

packages/compiler-core/src/transforms/transformElement.ts (3)

322-326:Function signature enhancement enables component prioritization.

The addition of theisComponent parameter allows the function to differentiate between component and directive resolution contexts, enabling more precise binding resolution.


289-289:Appropriate component resolution context.

Correctly passingtrue forisComponent in component resolution scenarios enables the new prioritization logic for known components.

Also applies to: 295-295


899-899:Correct directive resolution context.

Passingfalse forisComponent in directive resolution maintains the original behavior since directives shouldn't prioritize component bindings.

@edison1105edison1105 added the 🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed. labelJul 16, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Assignees
No one assigned
Labels
🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Incorrectly treating the component tag name as a function with the same name and unexpected calling the function twice
2 participants
@alex-snezhko@edison1105

[8]ページ先頭

©2009-2025 Movatter.jp