-
Notifications
You must be signed in to change notification settings - Fork 720
Fix during porting tsc --composite tests #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
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", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
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{ | ||||||
|
172 changes: 172 additions & 0 deletions
172
testdata/baselines/reference/tsc/composite/converting-to-modules.js
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
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:: |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.