fix(compiler): resolve inherited type references against the declaring file#6782
Open
Arul1998 wants to merge 1 commit into
Open
fix(compiler): resolve inherited type references against the declaring file#6782Arul1998 wants to merge 1 commit into
Arul1998 wants to merge 1 commit into
Conversation
…g file Type references on component members are recorded relative to the file declaring them. When members are inherited from a base class in another directory, the references were merged into the component's metadata unchanged, and type generation later resolved them against the component's own file. This produced imports in components.d.ts pointing at nonexistent paths, broke type resolution for library consumers, and emitted duplicate aliased imports for each extending component. This affected both imported types and types declared locally in the base class's file, with any level of inheritance. Re-anchor inherited members' type references when they are merged: relative import specifiers are rewritten to resolve from the component's directory, and base-class-local types become imports of the base class's module. fixes stenciljs#6687
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type references on component members are recorded relative to the file declaring them. When members are inherited from a base class in another directory, the references were merged into the component's metadata unchanged, and type generation later resolved them against the component's own file. This produced imports in
components.d.tspointing at nonexistent paths, broke type resolution for library consumers, and emitted duplicate aliased imports for each extending component. This affected both imported types and types declared locally in the base class's file, with any level of inheritance.Re-anchor inherited members' type references when they are merged: relative import specifiers are rewritten to resolve from the component's directory, and base-class-local types become imports of the base class's module.
fixes #6687
What is the current behavior?
GitHub Issue Number: #6687
When a component inherits decorated members from a base class in a different directory, the generated
components.d.tsresolves the members' type imports against the component's file instead of the base class's file. For the reproduction in #6687, it emitsimport { Validator } from "./components/data-entry/checkbox/input.types"— a path that doesn't exist indist/types— instead of./components/shared/input/input.types. This happens with a single level ofextends(not only chains), also affects types declared locally in the base class's file, and each extending component emits its own broken duplicate import under an incremented alias. A consumer type-checking against the package gets hardTS2307/TS2305errors.What is the new behavior?
When inherited members are merged into a component's metadata (
mergeExtendedClassMeta), their type references are re-anchored to the component's file: relative import specifiers are rewritten relative to the component's directory, and types declared in the base class's file are converted to imports of that file. Since the metadata itself is corrected, every consumer of it (components.d.ts, docs outputs, collections) gets the right paths. Shared types now emit a single correct import instead of per-component broken duplicates. References for same-directory base classes, package imports, globals, and base classes shipped in external collections are left untouched.Documentation
N/A
Does this introduce a breaking change?
Testing
Added unit tests covering: re-anchoring relative import specifiers (including ones pointing outside the base class's tree), converting base-class-local references to imports,
./-prefixing bare specifiers, and the no-op cases (same directory, package imports, globals,node_modulesbase classes, members without references). Manually verified end-to-end with a project matching the issue's structure: pre-fix,tscagainst the generateddist/typesfails with 8 errors; with this fix it passes, andcomponents.d.tscontains single, correct imports for both inherited-imported and inherited-local types, while non-inherited components are byte-identical.Other information
N/A