Repository navigation
Add tests for uncovered module resolution and specifier paths - #65656
YT (magurotuna) wants to merge 1 commit into
Conversation
…lative type reference names These compiler tests cover three code paths that no existing test covered: - getPackageId with a "types" field that points outside the package directory - the nodeModulesPrefix check in tryGetModuleNameAsNodeModule for a file directly in node_modules - a relative type reference name that is resolved from a type root
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for this test-only addition of module-resolution and declaration-specifier regression coverage.
No open issues 🎉
What changed in this PR
This test-only PR adds regression coverage for three module-resolution and declaration-specifier edge cases identified through the tsrs conformance suite. It adds expected baselines without changing compiler code.
Changes:
- Verify that packages whose
typesentry points outside their directory remain distinct. - Cover declaration emit for a type defined directly in
/node_modules/index.d.ts. - Cover relative type-reference resolution from a configured type root, including normalized resolution traces.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/typeReferenceDirectiveRelativeNameFromTypeRoot.ts |
Tests relative type references from a type root. |
tsc/testdata/tests/cases/compiler/duplicatePackage_typesOutsidePackageDirectory.ts |
Tests package identity with an external types target. |
tsc/testdata/tests/cases/compiler/declarationEmitNodeModulesIndexFile.ts |
Tests declaration specifiers for a direct node_modules file. |
tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveRelativeNameFromTypeRoot.types |
Records resolved global and exported types. |
tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveRelativeNameFromTypeRoot.trace.json |
Records normalized primary-lookup resolution. |
tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveRelativeNameFromTypeRoot.symbols |
Records resolved symbol bindings. |
tsc/testdata/baselines/reference/compiler/typeReferenceDirectiveRelativeNameFromTypeRoot.js |
Records JavaScript output. |
tsc/testdata/baselines/reference/compiler/duplicatePackage_typesOutsidePackageDirectory.types |
Records distinct package class types. |
tsc/testdata/baselines/reference/compiler/duplicatePackage_typesOutsidePackageDirectory.symbols |
Records separate class symbol bindings. |
tsc/testdata/baselines/reference/compiler/duplicatePackage_typesOutsidePackageDirectory.js |
Records JavaScript output. |
tsc/testdata/baselines/reference/compiler/duplicatePackage_typesOutsidePackageDirectory.errors.txt |
Records the expected TS2322 assignment error. |
tsc/testdata/baselines/reference/compiler/declarationEmitNodeModulesIndexFile.types |
Records inferred types and import specifiers. |
tsc/testdata/baselines/reference/compiler/declarationEmitNodeModulesIndexFile.symbols |
Records interface and re-export bindings. |
tsc/testdata/baselines/reference/compiler/declarationEmitNodeModulesIndexFile.js |
Records JavaScript and relative declaration output. |
Review effort: Balanced
Krish Khinchi (krishkhinchi)
left a comment
There was a problem hiding this comment.
Good regression test addition, but the three cases should be checked against the actual compiler behavior rather than relying only on the Rust port's findings. In particular, verify that the package ID test catches the missing RelativeTo check, declaration emit correctly handles files directly under node_modules, and relative type reference names are resolved correctly from type roots. Recommendation: Approve once all three tests are confirmed to fail without the corresponding fixes and pass against the current TypeScript implementation.
Fixes #65657
This PR adds compiler tests for three code paths that no existing test covers. It does not change the compiler.
I found them in tsrs, a Rust port of
tsc/that runs these tests as its conformance suite. Each case was a tsrs bug that no test caught:duplicatePackage_typesOutsidePackageDirectory:typespoints outside the package directory. Without theRelativeTocheck ingetPackageId, the two copies of the package merge and the TS2322 error disappears (fix(module): set the package ID sub-module only for files in the package oxc-project/tsrs#1038).declarationEmitNodeModulesIndexFile: a type comes from/node_modules/index.d.ts. Without thenodeModulesPrefixcheck intryGetModuleNameAsNodeModule, declaration emit panics (fix(modulespecifiers): stop a panic for a file named index directly in node_modules oxc-project/tsrs#1037).typeReferenceDirectiveRelativeNameFromTypeRoot: a relative type reference name (../pkg) is resolved from a type root. No existing test uses a relative name (fix(module): normalize type root candidates to stop a panic with project references oxc-project/tsrs#999).