Skip to content

Commit a5a26ec

Browse files
authored
Merge pull request #26109 from Microsoft/invalidTsconfig
Handle when property name turns out to be non string literal computed name because of errors in tsconfig file
2 parents 9c9f3e3 + 3c971ed commit a5a26ec

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/compiler/commandLineParser.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,10 @@ namespace ts {
13271327
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, Diagnostics.String_literal_with_double_quotes_expected));
13281328
}
13291329

1330-
const keyText = unescapeLeadingUnderscores(getTextOfPropertyName(element.name));
1331-
const option = knownOptions ? knownOptions.get(keyText) : undefined;
1332-
if (extraKeyDiagnosticMessage && !option) {
1330+
const textOfKey = getTextOfPropertyName(element.name);
1331+
const keyText = textOfKey && unescapeLeadingUnderscores(textOfKey);
1332+
const option = keyText && knownOptions ? knownOptions.get(keyText) : undefined;
1333+
if (keyText && extraKeyDiagnosticMessage && !option) {
13331334
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, extraKeyDiagnosticMessage, keyText));
13341335
}
13351336
const value = convertPropertyValueToJson(element.initializer, option);

src/testRunner/unittests/tsconfigParsing.ts

+13
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,18 @@ namespace ts {
331331
Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code,
332332
/*noLocation*/ true);
333333
});
334+
335+
336+
it("generates errors for when invalid comment type present in tsconfig", () => {
337+
const jsonText = `{
338+
"compilerOptions": {
339+
## this comment does cause issues
340+
"types" : [
341+
]
342+
}
343+
}`;
344+
const parsed = getParsedCommandJsonNode(jsonText, "/apath/tsconfig.json", "tests/cases/unittests", ["/apath/a.ts"]);
345+
assert.isTrue(parsed.errors.length >= 0);
346+
});
334347
});
335348
}

0 commit comments

Comments
 (0)