Port TypeScript PR #62338: Deprecate --moduleResolution node10#2817
Port TypeScript PR #62338: Deprecate --moduleResolution node10#2817jakebailey merged 6 commits intomainfrom
Conversation
…ort getModuleSpecifierOfBareOrAccessedRequire, update checker Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
|
|
||
| tsgo --b project --v --explainFiles --listEmittedFiles | ||
| ExitStatus:: Success | ||
| ExitStatus:: DiagnosticsPresent_OutputsGenerated |
There was a problem hiding this comment.
@copilot Change all of these tests to not use node10, but some other resolution mode
There was a problem hiding this comment.
Removed "moduleResolution": "node" from both the resolveJsonModule tsbuild test and the pnpm-style-layout tsc test configs. They now default to bundler instead. Baselines updated accordingly in 3dd2c9c.
…configs instead Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Ports TypeScript PR microsoft/TypeScript#62338 into the Go port, updating option validation and module-specifier extraction to match upstream behavior and adjusting test baselines/configs accordingly.
Changes:
- Treat
--moduleResolution node10as a removed option during compiler-option verification. - Extend require-pattern handling to extract module specifiers from accessed requires (e.g.
require("x").y) and use that inresolveExternalModule. - Update tsc/tsbuild test inputs and reference baselines to stop explicitly setting
"moduleResolution": "node"(so they default tobundler).
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/compiler/program.go | Adds removed-option diagnostic when moduleResolution is Node10. |
| internal/ast/utilities.go | Adds helper to extract module specifier from bare or accessed require(...) initializers. |
| internal/checker/checker.go | Uses new AST helpers in resolveExternalModule to pick the right context specifier for resolution mode. |
| internal/execute/tsctests/tscbuild_test.go | Removes explicit "moduleResolution": "node" from generated tsconfig in resolveJsonModule tsbuild tests. |
| internal/execute/tsctests/tsc_test.go | Removes explicit "moduleResolution": "node" from pnpm-style-layout tsc test fixture. |
| testdata/baselines/reference/tsc/moduleResolution/pnpm-style-layout.js | Updates reference baseline to reflect removed moduleResolution: node in the printed config. |
| testdata/baselines/reference/tsbuild/resolveJsonModule/without-outDir.js | Updates reference baseline to reflect removed moduleResolution: node in the printed config. |
| testdata/baselines/reference/tsbuild/resolveJsonModule/without-outDir-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/sourcemap.js | Same as above (sourcemap variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/sourcemap-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only.js | Same as above (include-only variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-without-outDir.js | Same as above (include-only/without-outDir variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-without-outDir-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-with-json-without-rootDir-but-outside-configDirectory.js | Same as above (json outside config dir variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-with-json-without-rootDir-but-outside-configDirectory-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-with-json-not-in-rootDir.js | Same as above (json not in rootDir variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-with-json-not-in-rootDir-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-only-non-composite.js | Same as above (non-composite include-only variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-of-json-along-with-other-include.js | Same as above (include json + other include variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-of-json-along-with-other-include-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-of-json-along-with-other-include-and-file-name-matches-ts-file.js | Same as above (filename-matches-ts variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-of-json-along-with-other-include-and-file-name-matches-ts-file-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-and-files.js | Same as above (include+files variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/include-and-files-non-composite.js | Same as above (non-composite variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/files-containing-json-file.js | Same as above (files list contains json variant). |
| testdata/baselines/reference/tsbuild/resolveJsonModule/files-containing-json-file-non-composite.js | Same as above (non-composite variant). |
| func GetModuleSpecifierOfBareOrAccessedRequire(node *Node) *Node { | ||
| if isVariableDeclarationInitializedWithRequireHelper(node, false /*allowAccessedRequire*/) { | ||
| return node.Initializer().Arguments()[0] | ||
| } | ||
| if isVariableDeclarationInitializedWithRequireHelper(node, true /*allowAccessedRequire*/) { | ||
| leftmost := GetLeftmostAccessExpression(node.Initializer()) | ||
| if IsRequireCall(leftmost, true /*requireStringLiteralLikeArgument*/) { | ||
| return leftmost.Arguments()[0] | ||
| } | ||
| } |
There was a problem hiding this comment.
This change adds support for extracting module specifiers from accessed-require initializers (e.g. const x = require("pkg").sub). There doesn’t appear to be a compiler test case in testdata/tests/cases/compiler/ that exercises this pattern, so regressions here would be hard to catch. Please add a minimal strict compiler test (likely a JS/TS pair with @allowJs/@checkJs) that fails without this change and passes with it.
Ports microsoft/TypeScript#62338 to the Go codebase.
Fixes #2108
Core changes
internal/compiler/program.go: AddmoduleResolution: node10to the removed options list (TS7+ treats 6.0 deprecations as removed)internal/ast/utilities.go: AddIsVariableDeclarationInitializedToBareOrAccessedRequireandGetModuleSpecifierOfBareOrAccessedRequire— handles accessed require patterns likerequire("foo").barin addition to barerequire("foo")internal/checker/checker.go: Use the new utilities inresolveExternalModuleto correctly resolve module specifiers from accessed require callsTest updates
internal/execute/tsctests/tscbuild_test.go: Removed explicit"moduleResolution": "node"fromresolveJsonModuletsbuild test configs so they default tobundlerinternal/execute/tsctests/tsc_test.go: Removed explicit"moduleResolution": "node"frompnpm-style-layouttsc test config so it defaults tobundlerAlready ported (no changes needed)
moduleResolutionfor--module commonjs→bundler(GetModuleResolutionKindalready maps this)exportsOrImportsLookupreturningboolinstring_completions.godetailsEntryIdcompletions fix not applicable (pattern absent in Go port)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.