Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,19 @@ func isVariableDeclarationInitializedWithRequireHelper(node *Node, allowAccessed
IsRequireCall(initializer, true /*requireStringLiteralLikeArgument*/)
}

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]
}
}
Comment on lines +2854 to +2863
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.
return nil
}

func IsModuleExportsAccessExpression(node *Node) bool {
if IsAccessExpression(node) && IsModuleIdentifier(node.Expression()) {
if name := GetElementOrPropertyAccessName(node); name != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14678,8 +14678,8 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
contextSpecifier = location.AsModuleDeclaration().Name()
} else if ast.IsLiteralImportTypeNode(location) {
contextSpecifier = location.AsImportTypeNode().Argument.AsLiteralTypeNode().Literal
} else if ast.IsVariableDeclaration(location) && location.Initializer() != nil && ast.IsRequireCall(location.Initializer(), true /*requireStringLiteralLikeArgument*/) {
contextSpecifier = location.Initializer().Arguments()[0]
} else if ast.IsVariableDeclarationInitializedToBareOrAccessedRequire(location) {
contextSpecifier = ast.GetModuleSpecifierOfBareOrAccessedRequire(location)
} else {
ancestor := ast.FindAncestor(location, ast.IsImportCall)
if ancestor != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ func (p *Program) verifyCompilerOptions() {
createRemovedOptionDiagnostic("allowSyntheticDefaultImports", "false", "")
}

if options.ModuleResolution == core.ModuleResolutionKindNode10 {
createRemovedOptionDiagnostic("moduleResolution", "node10", "")
}
Comment thread
jakebailey marked this conversation as resolved.

if options.StrictPropertyInitialization.IsTrue() && !options.GetStrictOptionValue(options.StrictNullChecks) {
createDiagnosticForOptionName(diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks")
}
Expand Down
1 change: 0 additions & 1 deletion internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,6 @@ func TestTscModuleResolution(t *testing.T) {
"target": "es5",
"module": "esnext",
"lib": ["ES5"],
"moduleResolution": "node",
"outDir": "dist",
},
"include": ["src"],
Expand Down
1 change: 0 additions & 1 deletion internal/execute/tsctests/tscbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2631,7 +2631,6 @@ func TestBuildResolveJsonModule(t *testing.T) {
{
"compilerOptions": {
"composite": %t,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -51,7 +50,7 @@ project/src/hello.json
project/src/index.ts
Part of 'files' list in tsconfig.json

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -51,7 +50,7 @@ project/src/hello.json
project/src/index.ts
Matched by include pattern 'src/**/*' in 'project/tsconfig.json'

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/index.json
Expand All @@ -51,7 +50,7 @@ project/src/index.json
project/src/index.ts
Matched by include pattern 'src/**/*' in 'project/tsconfig.json'

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -51,7 +50,7 @@ project/src/hello.json
project/src/index.ts
Matched by include pattern 'src/**/*' in 'project/tsconfig.json'

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -50,7 +49,7 @@ project/src/hello.json
project/src/index.ts
Matched by include pattern 'src/**/*' in 'project/tsconfig.json'

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/index.js
Expand All @@ -49,7 +48,7 @@ hello.json
project/src/index.ts
Matched by include pattern 'src/**/*' in 'project/tsconfig.json'

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand All @@ -34,10 +33,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -52,7 +51,7 @@ project/src/hello.json
project/src/index.ts
Part of 'files' list in tsconfig.json

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down Expand Up @@ -136,10 +135,10 @@ Output::

[HH:MM:SS AM] Building project 'project/tsconfig.json'...

project/tsconfig.json:9:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
project/tsconfig.json:8:9 - error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.

9 "outDir": "dist",
8 "outDir": "dist",
   ~~~~~~~~

TSFILE: /home/src/workspaces/solution/project/dist/src/hello.json
Expand All @@ -154,7 +153,7 @@ project/src/hello.json
project/src/index.ts
Part of 'files' list in tsconfig.json

Found 1 error in project/tsconfig.json:9
Found 1 error in project/tsconfig.json:8

//// [/home/src/workspaces/solution/project/dist/src/hello.json] *rewrite with same content*
//// [/home/src/workspaces/solution/project/dist/src/index.js] *rewrite with same content*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": false,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default hello.hello
{
"compilerOptions": {
"composite": true,
"moduleResolution": "node",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down
Loading
Loading