Skip to content
Closed
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14633,7 +14633,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
}

var message *diagnostics.Message
if overrideHost != nil && overrideHost.Kind == ast.KindImportDeclaration && overrideHost.AsImportDeclaration().ImportClause.IsTypeOnly() {
if overrideHost != nil && overrideHost.Kind == ast.KindImportDeclaration && overrideHost.AsImportDeclaration().ImportClause != nil && overrideHost.AsImportDeclaration().ImportClause.IsTypeOnly() {
message = diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute
} else if overrideHost != nil && overrideHost.Kind == ast.KindImportType {
message = diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute
Expand Down
179 changes: 179 additions & 0 deletions internal/execute/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,185 @@ func TestTscCommandline(t *testing.T) {
}
}

func TestTscComposite(t *testing.T) {
t.Parallel()
testCases := []*tscInput{
{
subScenario: "when setting composite false on command line",
files: FileMap{
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"composite": true,
},
"include": [
"src/**/*.ts",
],
}`),
},
commandLineArgs: []string{"--composite", "false"},
},
{
// !!! sheetal null is not reflected in final options
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The comment contains what appears to be a personal name 'sheetal' which seems out of place in a code comment. This should be removed or clarified.

Suggested change
// !!! sheetal null is not reflected in final options
// Setting composite to null on the command line is not reflected in final options

Copilot uses AI. Check for mistakes.

subScenario: "when setting composite null on command line",
files: FileMap{
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"composite": true,
},
"include": [
"src/**/*.ts",
],
}`),
},
commandLineArgs: []string{"--composite", "null"},
},
{
subScenario: "when setting composite false on command line but has tsbuild info in config",
files: FileMap{
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"composite": true,
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
},
"include": [
"src/**/*.ts",
],
}`),
},
commandLineArgs: []string{"--composite", "false"},
},
{
subScenario: "when setting composite false on command line but has tsbuild info in config",
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

This test case has an identical subScenario name to the previous test case (line 173). This will cause confusion and potentially interfere with test identification. Each test case should have a unique subScenario name.

Suggested change
subScenario: "when setting composite false on command line but has tsbuild info in config",
subScenario: "when setting composite false on command line but has tsbuild info in config (variant 2)",

Copilot uses AI. Check for mistakes.

files: FileMap{
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"composite": true,
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
},
"include": [
"src/**/*.ts",
],
}`),
},
commandLineArgs: []string{"--composite", "false"},
},
{
subScenario: "when setting composite false and tsbuildinfo as null on command line but has tsbuild info in config",
files: FileMap{
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"composite": true,
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
},
"include": [
"src/**/*.ts",
],
}`),
},
commandLineArgs: []string{"--composite", "false", "--tsBuildInfoFile", "null"},
},
{
subScenario: "converting to modules",
files: FileMap{
"/home/src/workspaces/project/src/main.ts": "const x = 10;",
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"module": "none",
"composite": true,
},
}`),
},
edits: []*tscEdit{
{
caption: "convert to modules",
edit: func(sys *testSys) {
sys.replaceFileText("/home/src/workspaces/project/tsconfig.json", "none", "es2015")
},
},
},
},
{
subScenario: "synthetic jsx import of ESM module from CJS module no crash no jsx element",
files: FileMap{
"/home/src/projects/project/src/main.ts": "export default 42;",
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"composite": true,
"module": "Node16",
"jsx": "react-jsx",
"jsxImportSource": "solid-js",
},
}`),
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
{
"name": "solid-js",
"type": "module"
}
`),
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
export namespace JSX {
type IntrinsicElements = { div: {}; };
}
`),
},
cwd: "/home/src/projects/project",
},
{
subScenario: "synthetic jsx import of ESM module from CJS module error on jsx element",
files: FileMap{
"/home/src/projects/project/src/main.tsx": "export default <div/>;",
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"composite": true,
"module": "Node16",
"jsx": "react-jsx",
"jsxImportSource": "solid-js",
},
}`),
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
{
"name": "solid-js",
"type": "module"
}
`),
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
export namespace JSX {
type IntrinsicElements = { div: {}; };
}
`),
},
cwd: "/home/src/projects/project",
},
}

for _, testCase := range testCases {
testCase.run(t, "composite")
}
}

func TestNoEmit(t *testing.T) {
t.Parallel()
(&tscInput{
Expand Down
172 changes: 172 additions & 0 deletions testdata/baselines/reference/tsc/composite/converting-to-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
currentDirectory::/home/src/workspaces/project
useCaseSensitiveFileNames::true
Input::
//// [/home/src/workspaces/project/src/main.ts] *new*
const x = 10;
//// [/home/src/workspaces/project/tsconfig.json] *new*
{
"compilerOptions": {
"module": "none",
"composite": true,
},
}

tsgo
ExitStatus:: Success
Output::
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
interface SymbolConstructor {
(desc?: string | number): symbol;
for(name: string): symbol;
readonly toStringTag: symbol;
}
declare var Symbol: SymbolConstructor;
interface Symbol {
readonly [Symbol.toStringTag]: string;
}
declare const console: { log(msg: any): void; };
//// [/home/src/workspaces/project/src/main.d.ts] *new*
declare const x = 10;

//// [/home/src/workspaces/project/src/main.js] *new*
const x = 10;

//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4447ab8c90027f28bdaff9f2056779ce-const x = 10;","signature":"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true},"latestChangedDtsFile":"./src/main.d.ts"}
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"root": [
{
"files": [
"./src/main.ts"
],
"original": 2
}
],
"fileNames": [
"lib.d.ts",
"./src/main.ts"
],
"fileInfos": [
{
"fileName": "lib.d.ts",
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
},
{
"fileName": "./src/main.ts",
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
}
],
"options": {
"composite": true
},
"latestChangedDtsFile": "./src/main.d.ts",
"size": 1113
}

tsconfig.json::
SemanticDiagnostics::
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
*refresh* /home/src/workspaces/project/src/main.ts
Signatures::
(stored at emit) /home/src/workspaces/project/src/main.ts


Edit [0]:: convert to modules
//// [/home/src/workspaces/project/tsconfig.json] *modified*
{
"compilerOptions": {
"module": "es2015",
"composite": true,
},
}

tsgo
ExitStatus:: Success
Output::
//// [/home/src/workspaces/project/src/main.js] *rewrite with same content*
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4447ab8c90027f28bdaff9f2056779ce-const x = 10;","signature":"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true,"module":5},"latestChangedDtsFile":"./src/main.d.ts"}
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
{
"version": "FakeTSVersion",
"root": [
{
"files": [
"./src/main.ts"
],
"original": 2
}
],
"fileNames": [
"lib.d.ts",
"./src/main.ts"
],
"fileInfos": [
{
"fileName": "lib.d.ts",
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
},
{
"fileName": "./src/main.ts",
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
}
],
"options": {
"composite": true,
"module": 5
},
"latestChangedDtsFile": "./src/main.d.ts",
"size": 1124
}

tsconfig.json::
SemanticDiagnostics::
Signatures::
Loading
Loading