Skip to content

Commit 459196b

Browse files
committed
Pragmas are case-insensitive
1 parent 6611554 commit 459196b

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/compiler/commandLineParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1444,12 +1444,12 @@ namespace ts {
14441444
export const optionsAllowedAsPragmaOption = optionDeclarations.filter(isAllowedAsPragmaOption);
14451445

14461446
/* @internal */
1447-
type CompilerOptionsIntoPragmaDefinitions<T extends CommandLineOption> = UnionToIntersection<T extends unknown ? {[K in T["name"] & string as `ts-${K}`]: { readonly kind: PragmaKindFlags, readonly args: readonly [{ readonly name: "value", readonly optional: true }] }} : never>;
1447+
type CompilerOptionsIntoPragmaDefinitions<T extends CommandLineOption> = UnionToIntersection<T extends unknown ? {[K in T["name"] & string as `ts-${Lowercase<K>}`]: { readonly kind: PragmaKindFlags, readonly args: readonly [{ readonly name: "value", readonly optional: true }] }} : never>;
14481448

14491449
function convertCompilerOptionsIntoPragmasSpecs<T extends readonly CommandLineOption[]>(options: T): CompilerOptionsIntoPragmaDefinitions<T[number]> {
14501450
const result = {} as CompilerOptionsIntoPragmaDefinitions<T[number]>;
14511451
for (const elem of options) {
1452-
result[`ts-${elem.name}` as keyof typeof result] = {
1452+
result[`ts-${elem.name.toLowerCase()}` as keyof typeof result] = {
14531453
args: [{ name: "value", optional: true }],
14541454
kind: PragmaKindFlags.SingleLine | PragmaKindFlags.MultiLine
14551455
} as any;

src/compiler/parser.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -9642,29 +9642,29 @@ namespace ts {
96429642
break;
96439643
}
96449644
case "ts-strict":
9645-
case "ts-noImplicitAny":
9646-
case "ts-strictNullChecks":
9647-
case "ts-strictFunctionTypes":
9648-
case "ts-strictBindCallApply":
9649-
case "ts-noImplicitThis":
9650-
case "ts-strictPropertyInitialization":
9651-
case "ts-useUnknownInCatchVariables":
9652-
case "ts-alwaysStrict":
9653-
case "ts-noUnusedLocals":
9654-
case "ts-noUnusedParameters":
9655-
case "ts-exactOptionalPropertyTypes":
9656-
case "ts-noPropertyAccessFromIndexSignature":
9657-
case "ts-noImplicitReturns":
9658-
case "ts-noFallthroughCasesInSwitch":
9659-
case "ts-noUncheckedIndexedAccess":
9660-
case "ts-noImplicitOverride": {
9645+
case "ts-noimplicitany":
9646+
case "ts-strictnullchecks":
9647+
case "ts-strictfunctiontypes":
9648+
case "ts-strictbindcallapply":
9649+
case "ts-noimplicitthis":
9650+
case "ts-strictpropertyinitialization":
9651+
case "ts-useunknownincatchvariables":
9652+
case "ts-alwaysstrict":
9653+
case "ts-nounusedlocals":
9654+
case "ts-nounusedparameters":
9655+
case "ts-exactoptionalpropertytypes":
9656+
case "ts-nopropertyaccessfromindexsignature":
9657+
case "ts-noimplicitreturns":
9658+
case "ts-nofallthroughcasesinswitch":
9659+
case "ts-nouncheckedindexedaccess":
9660+
case "ts-noimplicitoverride": {
96619661
const optName = key.slice(3);
9662-
const opt = find(optionsAllowedAsPragmaOption, o => o.name === optName)!;
9662+
const opt = find(optionsAllowedAsPragmaOption, o => o.name.toLowerCase() === optName)!;
96639663
const entry = (isArray(entryOrList) ? last(entryOrList) : entryOrList);
9664-
const unparsedValue = (entry.arguments as PragmaArgumentType<`ts-${FileLocalOptionName}`>).value;
9664+
const unparsedValue = (entry.arguments as PragmaArgumentType<`ts-${Lowercase<FileLocalOptionName>}`>).value;
96659665
const optContainer: OptionsBase = {};
96669666
const errors: Diagnostic[] = []
9667-
const parsedValue = unparsedValue === undefined ? true : (parseOptionValue([unparsedValue], 0, /*diagnostics*/ undefined, opt, optContainer, errors), optContainer[unparsedValue]);
9667+
const parsedValue = unparsedValue === undefined ? true : (parseOptionValue([unparsedValue], 0, /*diagnostics*/ undefined, opt, optContainer, errors), optContainer[opt.name]);
96689668
if (unparsedValue === undefined && opt.type !== "boolean") {
96699669
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, optName));
96709670
}
@@ -9679,7 +9679,7 @@ namespace ts {
96799679
});
96809680
}
96819681
if (!length(errors)) {
9682-
(context.localOptions ??= {})[optName] = parsedValue;
9682+
(context.localOptions ??= {})[opt.name as string] = parsedValue;
96839683
}
96849684
}
96859685
case "jsx":

0 commit comments

Comments
 (0)