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
Pick correct compilerOptions when checking if we can share emitSignatures #50910
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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
126 changes: 126 additions & 0 deletions
126
tests/baselines/reference/tsc/composite/converting-to-modules.js
This file contains 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,126 @@ | ||
Input:: | ||
//// [/lib/lib.d.ts] | ||
/// <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> {} | ||
declare const console: { log(msg: any): void; }; | ||
|
||
//// [/src/project/src/main.ts] | ||
const x = 10; | ||
|
||
//// [/src/project/tsconfig.json] | ||
{"compilerOptions":{"module":"none","composite":true}} | ||
|
||
|
||
|
||
Output:: | ||
/lib/tsc -p /src/project | ||
exitCode:: ExitStatus.Success | ||
|
||
|
||
//// [/src/project/src/main.d.ts] | ||
declare const x = 10; | ||
|
||
|
||
//// [/src/project/src/main.js] | ||
var x = 10; | ||
|
||
|
||
//// [/src/project/tsconfig.tsbuildinfo] | ||
{"program":{"fileNames":["../../lib/lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"5029505981-const x = 10;","signature":"-3198459068-declare const x = 10;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"module":0},"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"} | ||
|
||
//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] | ||
{ | ||
"program": { | ||
"fileNames": [ | ||
"../../lib/lib.d.ts", | ||
"./src/main.ts" | ||
], | ||
"fileInfos": { | ||
"../../lib/lib.d.ts": { | ||
"version": "3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };", | ||
"signature": "3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };", | ||
"affectsGlobalScope": true | ||
}, | ||
"./src/main.ts": { | ||
"version": "5029505981-const x = 10;", | ||
"signature": "-3198459068-declare const x = 10;\r\n", | ||
"affectsGlobalScope": true | ||
} | ||
}, | ||
"options": { | ||
"composite": true, | ||
"module": 0 | ||
}, | ||
"semanticDiagnosticsPerFile": [ | ||
"../../lib/lib.d.ts", | ||
"./src/main.ts" | ||
], | ||
"latestChangedDtsFile": "./src/main.d.ts" | ||
}, | ||
"version": "FakeTSVersion", | ||
"size": 816 | ||
} | ||
|
||
|
||
|
||
Change:: convert to modules | ||
Input:: | ||
//// [/src/project/tsconfig.json] | ||
{"compilerOptions":{"module":"es2015","composite":true}} | ||
|
||
|
||
|
||
Output:: | ||
/lib/tsc -p /src/project | ||
exitCode:: ExitStatus.Success | ||
|
||
|
||
//// [/src/project/src/main.js] file written with same contents | ||
//// [/src/project/tsconfig.tsbuildinfo] | ||
{"program":{"fileNames":["../../lib/lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"5029505981-const x = 10;","signature":"-3198459068-declare const x = 10;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"module":5},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"} | ||
|
||
//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] | ||
{ | ||
"program": { | ||
"fileNames": [ | ||
"../../lib/lib.d.ts", | ||
"./src/main.ts" | ||
], | ||
"fileInfos": { | ||
"../../lib/lib.d.ts": { | ||
"version": "3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };", | ||
"signature": "3858781397-/// <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> {}\ndeclare const console: { log(msg: any): void; };", | ||
"affectsGlobalScope": true | ||
}, | ||
"./src/main.ts": { | ||
"version": "5029505981-const x = 10;", | ||
"signature": "-3198459068-declare const x = 10;\r\n", | ||
"affectsGlobalScope": true | ||
} | ||
}, | ||
"options": { | ||
"composite": true, | ||
"module": 5 | ||
}, | ||
"referencedMap": {}, | ||
"exportedModulesMap": {}, | ||
"semanticDiagnosticsPerFile": [ | ||
"../../lib/lib.d.ts", | ||
"./src/main.ts" | ||
], | ||
"latestChangedDtsFile": "./src/main.d.ts" | ||
}, | ||
"version": "FakeTSVersion", | ||
"size": 859 | ||
} | ||
|
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.
I think a comment would help to explain why this one spot doesn't use
oldCompilerOptions
. (To be honest, I couldn't figure it out from your PR description.) It's especially disconcerting that we might be dotting intooldState
whenuseOldState
is false, so please consider explaining that as well.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.
Please check if its more clear now.
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.
It sounds like maybe
useOldState
should be renamed? Maybe something likeuseOldStateFor...
?I'll attempt to paraphrase - please check my understanding:
We can only reuse emit signatures (i.e. .d.ts signatures) if the .d.ts file is unchanged, which will only be the case if the
declarationDir
andoutDir
options are unchanged.We need to look in
oldState.compilerOptions
, rather thanoldCompilerOptions
(i.e. we need to disregarduseOldState
) becauseoldCompilerOptions
will be undefined if the file references map indicates that the files to be emitted have changed, which isn't relevant for checking signature reuses.Was I close?
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.
Since useOldState is determined by whether we create reference map to check for files to emit or not. So if say module option changes from
Module.None
to some otherModule
kind thenoldCompilerOptions
will beundefined
but that shouldn't be taken into account when considering whether to reuse d.ts emit signatureThere 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.
not ideal since
useOldStateFor
since its everything - like semantic diagnostics, files to emit, changed files and so on except d.ts emit signatureThere 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.
That's much clearer - thanks! For my own edification: every use case other than signature emit should still use
oldCompilerOptions
, correct?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.
Yes