Skip to content

Commit 1a68590

Browse files
Mark more options as affecting errors/resolution (#53403)
Co-authored-by: Sheetal Nandi <[email protected]>
1 parent 6e01b06 commit 1a68590

13 files changed

+420
-32
lines changed

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
647647
{
648648
name: "allowJs",
649649
type: "boolean",
650-
affectsModuleResolution: true,
650+
allowJsFlag: true,
651+
affectsBuildInfo: true,
651652
showInSimplifiedHelpView: true,
652653
category: Diagnostics.JavaScript_Support,
653654
description: Diagnostics.Allow_JavaScript_files_to_be_a_part_of_your_program_Use_the_checkJS_option_to_get_errors_from_these_files,
@@ -657,6 +658,8 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
657658
name: "checkJs",
658659
type: "boolean",
659660
affectsModuleResolution: true,
661+
affectsSemanticDiagnostics: true,
662+
affectsBuildInfo: true,
660663
showInSimplifiedHelpView: true,
661664
category: Diagnostics.JavaScript_Support,
662665
description: Diagnostics.Enable_error_reporting_in_type_checked_JavaScript_files,
@@ -669,6 +672,10 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
669672
affectsEmit: true,
670673
affectsBuildInfo: true,
671674
affectsModuleResolution: true,
675+
// The checker emits an error when it sees JSX but this option is not set in compilerOptions.
676+
// This is effectively a semantic error, so mark this option as affecting semantic diagnostics
677+
// so we know to refresh errors when this option is changed.
678+
affectsSemanticDiagnostics: true,
672679
paramType: Diagnostics.KIND,
673680
showInSimplifiedHelpView: true,
674681
category: Diagnostics.Language_and_Environment,

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7349,6 +7349,7 @@ export interface CommandLineOptionBase {
73497349
showInSimplifiedHelpView?: boolean;
73507350
category?: DiagnosticMessage;
73517351
strictFlag?: true; // true if the option is one of the flag under strict
7352+
allowJsFlag?: true;
73527353
affectsSourceFile?: true; // true if we should recreate SourceFiles after this option changes
73537354
affectsModuleResolution?: true; // currently same effect as `affectsSourceFile`
73547355
affectsBindDiagnostics?: true; // true if this affects binding (currently same effect as `affectsSourceFile`)

src/compiler/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8784,7 +8784,9 @@ export function compilerOptionsAffectDeclarationPath(newOptions: CompilerOptions
87848784

87858785
/** @internal */
87868786
export function getCompilerOptionValue(options: CompilerOptions, option: CommandLineOption): unknown {
8787-
return option.strictFlag ? getStrictOptionValue(options, option.name as StrictOptionName) : options[option.name];
8787+
return option.strictFlag ? getStrictOptionValue(options, option.name as StrictOptionName) :
8788+
option.allowJsFlag ? getAllowJSCompilerOption(options) :
8789+
options[option.name];
87888790
}
87898791

87908792
/** @internal */

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,32 @@ import { x } from "../b";`,
18731873
],
18741874
});
18751875

1876+
verifyTscWatch({
1877+
scenario,
1878+
subScenario: "updates emit on jsx option add",
1879+
commandLineArgs: ["-w"],
1880+
sys: () => {
1881+
const index: File = {
1882+
path: `/user/username/projects/myproject/index.tsx`,
1883+
content: `declare var React: any;\nconst d = <div />;`,
1884+
};
1885+
const configFile: File = {
1886+
path: `/user/username/projects/myproject/tsconfig.json`,
1887+
content: JSON.stringify({
1888+
compilerOptions: {},
1889+
}),
1890+
};
1891+
return createWatchedSystem([index, configFile, libFile], { currentDirectory: "/user/username/projects/myproject" });
1892+
},
1893+
edits: [
1894+
{
1895+
caption: "Update 'jsx' to 'preserve'",
1896+
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, '{ "compilerOptions": { "jsx": "preserve" } }'),
1897+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
1898+
},
1899+
],
1900+
});
1901+
18761902
verifyTscWatch({
18771903
scenario,
18781904
subScenario: "extended source files are watched",
@@ -2138,4 +2164,44 @@ import { x } from "../b";`,
21382164
},
21392165
],
21402166
});
2167+
2168+
verifyTscWatch({
2169+
scenario,
2170+
subScenario: "when changing checkJs of config file",
2171+
commandLineArgs: ["-w", "-p", ".", "--extendedDiagnostics"],
2172+
sys: () => {
2173+
const module1: File = {
2174+
path: `/user/username/projects/myproject/a.js`,
2175+
content: `export const aNumber: number = "string"`,
2176+
};
2177+
const module2: File = {
2178+
path: `/user/username/projects/myproject/b.ts`,
2179+
content: `import { aNumber } from "./a.js";`,
2180+
};
2181+
const config: File = {
2182+
path: `/user/username/projects/myproject/tsconfig.json`,
2183+
content: JSON.stringify({
2184+
compilerOptions: {
2185+
checkJs: false,
2186+
},
2187+
}),
2188+
};
2189+
return createWatchedSystem([module1, module2, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
2190+
},
2191+
edits: [
2192+
{
2193+
caption: "Change checkJs to true",
2194+
edit: sys =>
2195+
sys.writeFile(
2196+
`/user/username/projects/myproject/tsconfig.json`,
2197+
JSON.stringify({
2198+
compilerOptions: {
2199+
checkJs: true,
2200+
},
2201+
}),
2202+
),
2203+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
2204+
},
2205+
],
2206+
});
21412207
});

tests/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module.exports = {};
142142

143143

144144
//// [/lib/common/tsconfig.tsbuildinfo]
145-
{"program":{"fileNames":["../lib.d.ts","../../src/common/nominal.js"],"fileInfos":[{"version":"-32082413277-/// <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; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","affectsGlobalScope":true},{"version":"-9003723607-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};\n","signature":"-13020584488-export type Nominal<T, Name> = T & {\n [Symbol.species]: Name;\n};\n"}],"root":[2],"options":{"composite":true,"declaration":true,"outDir":"..","rootDir":"../../src","skipLibCheck":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./nominal.d.ts"},"version":"FakeTSVersion"}
145+
{"program":{"fileNames":["../lib.d.ts","../../src/common/nominal.js"],"fileInfos":[{"version":"-32082413277-/// <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; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","affectsGlobalScope":true},{"version":"-9003723607-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};\n","signature":"-13020584488-export type Nominal<T, Name> = T & {\n [Symbol.species]: Name;\n};\n"}],"root":[2],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../src","skipLibCheck":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./nominal.d.ts"},"version":"FakeTSVersion"}
146146

147147
//// [/lib/common/tsconfig.tsbuildinfo.readable.baseline.txt]
148148
{
@@ -177,6 +177,8 @@ module.exports = {};
177177
]
178178
],
179179
"options": {
180+
"allowJs": true,
181+
"checkJs": true,
180182
"composite": true,
181183
"declaration": true,
182184
"outDir": "..",
@@ -192,11 +194,11 @@ module.exports = {};
192194
"latestChangedDtsFile": "./nominal.d.ts"
193195
},
194196
"version": "FakeTSVersion",
195-
"size": 1266
197+
"size": 1296
196198
}
197199

198200
//// [/lib/sub-project/tsconfig.tsbuildinfo]
199-
{"program":{"fileNames":["../lib.d.ts","../common/nominal.d.ts","../../src/sub-project/index.js"],"fileInfos":[{"version":"-32082413277-/// <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; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","affectsGlobalScope":true},"-13020584488-export type Nominal<T, Name> = T & {\n [Symbol.species]: Name;\n};\n","-23375763082-import { Nominal } from '../common/nominal';\n\n/**\n * @typedef {Nominal<string, 'MyNominal'>} MyNominal\n */\n"],"root":[3],"options":{"composite":true,"declaration":true,"outDir":"..","rootDir":"../../src","skipLibCheck":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[[3,1]],"semanticDiagnosticsPerFile":[2,1,[3,[{"file":"../../src/sub-project/index.js","start":9,"length":7,"messageText":"'Nominal' is a type and cannot be imported in JavaScript files. Use 'import(\"../common/nominal\").Nominal' in a JSDoc type annotation.","category":1,"code":18042}]]],"affectedFilesPendingEmit":[3],"emitSignatures":[3]},"version":"FakeTSVersion"}
201+
{"program":{"fileNames":["../lib.d.ts","../common/nominal.d.ts","../../src/sub-project/index.js"],"fileInfos":[{"version":"-32082413277-/// <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; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","affectsGlobalScope":true},"-13020584488-export type Nominal<T, Name> = T & {\n [Symbol.species]: Name;\n};\n","-23375763082-import { Nominal } from '../common/nominal';\n\n/**\n * @typedef {Nominal<string, 'MyNominal'>} MyNominal\n */\n"],"root":[3],"options":{"allowJs":true,"checkJs":true,"composite":true,"declaration":true,"outDir":"..","rootDir":"../../src","skipLibCheck":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[[3,1]],"semanticDiagnosticsPerFile":[2,1,[3,[{"file":"../../src/sub-project/index.js","start":9,"length":7,"messageText":"'Nominal' is a type and cannot be imported in JavaScript files. Use 'import(\"../common/nominal\").Nominal' in a JSDoc type annotation.","category":1,"code":18042}]]],"affectedFilesPendingEmit":[3],"emitSignatures":[3]},"version":"FakeTSVersion"}
200202

201203
//// [/lib/sub-project/tsconfig.tsbuildinfo.readable.baseline.txt]
202204
{
@@ -237,6 +239,8 @@ module.exports = {};
237239
]
238240
],
239241
"options": {
242+
"allowJs": true,
243+
"checkJs": true,
240244
"composite": true,
241245
"declaration": true,
242246
"outDir": "..",
@@ -281,6 +285,6 @@ module.exports = {};
281285
]
282286
},
283287
"version": "FakeTSVersion",
284-
"size": 1566
288+
"size": 1596
285289
}
286290

0 commit comments

Comments
 (0)