Skip to content

Commit

Permalink
Pragmas are case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Jul 12, 2022
1 parent 6611554 commit 459196b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,12 +1444,12 @@ namespace ts {
export const optionsAllowedAsPragmaOption = optionDeclarations.filter(isAllowedAsPragmaOption);

/* @internal */
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>;
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>;

function convertCompilerOptionsIntoPragmasSpecs<T extends readonly CommandLineOption[]>(options: T): CompilerOptionsIntoPragmaDefinitions<T[number]> {
const result = {} as CompilerOptionsIntoPragmaDefinitions<T[number]>;
for (const elem of options) {
result[`ts-${elem.name}` as keyof typeof result] = {
result[`ts-${elem.name.toLowerCase()}` as keyof typeof result] = {
args: [{ name: "value", optional: true }],
kind: PragmaKindFlags.SingleLine | PragmaKindFlags.MultiLine
} as any;
Expand Down
40 changes: 20 additions & 20 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9642,29 +9642,29 @@ namespace ts {
break;
}
case "ts-strict":
case "ts-noImplicitAny":
case "ts-strictNullChecks":
case "ts-strictFunctionTypes":
case "ts-strictBindCallApply":
case "ts-noImplicitThis":
case "ts-strictPropertyInitialization":
case "ts-useUnknownInCatchVariables":
case "ts-alwaysStrict":
case "ts-noUnusedLocals":
case "ts-noUnusedParameters":
case "ts-exactOptionalPropertyTypes":
case "ts-noPropertyAccessFromIndexSignature":
case "ts-noImplicitReturns":
case "ts-noFallthroughCasesInSwitch":
case "ts-noUncheckedIndexedAccess":
case "ts-noImplicitOverride": {
case "ts-noimplicitany":
case "ts-strictnullchecks":
case "ts-strictfunctiontypes":
case "ts-strictbindcallapply":
case "ts-noimplicitthis":
case "ts-strictpropertyinitialization":
case "ts-useunknownincatchvariables":
case "ts-alwaysstrict":
case "ts-nounusedlocals":
case "ts-nounusedparameters":
case "ts-exactoptionalpropertytypes":
case "ts-nopropertyaccessfromindexsignature":
case "ts-noimplicitreturns":
case "ts-nofallthroughcasesinswitch":
case "ts-nouncheckedindexedaccess":
case "ts-noimplicitoverride": {
const optName = key.slice(3);
const opt = find(optionsAllowedAsPragmaOption, o => o.name === optName)!;
const opt = find(optionsAllowedAsPragmaOption, o => o.name.toLowerCase() === optName)!;
const entry = (isArray(entryOrList) ? last(entryOrList) : entryOrList);
const unparsedValue = (entry.arguments as PragmaArgumentType<`ts-${FileLocalOptionName}`>).value;
const unparsedValue = (entry.arguments as PragmaArgumentType<`ts-${Lowercase<FileLocalOptionName>}`>).value;
const optContainer: OptionsBase = {};
const errors: Diagnostic[] = []
const parsedValue = unparsedValue === undefined ? true : (parseOptionValue([unparsedValue], 0, /*diagnostics*/ undefined, opt, optContainer, errors), optContainer[unparsedValue]);
const parsedValue = unparsedValue === undefined ? true : (parseOptionValue([unparsedValue], 0, /*diagnostics*/ undefined, opt, optContainer, errors), optContainer[opt.name]);
if (unparsedValue === undefined && opt.type !== "boolean") {
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, optName));
}
Expand All @@ -9679,7 +9679,7 @@ namespace ts {
});
}
if (!length(errors)) {
(context.localOptions ??= {})[optName] = parsedValue;
(context.localOptions ??= {})[opt.name as string] = parsedValue;
}
}
case "jsx":
Expand Down

0 comments on commit 459196b

Please sign in to comment.