Skip to content

Commit e91450c

Browse files
committed
I cant believe its not eval
1 parent 32dfb37 commit e91450c

File tree

10 files changed

+426
-51
lines changed

10 files changed

+426
-51
lines changed

src/compiler/commandLineParser.ts

+138-43
Large diffs are not rendered by default.

src/compiler/core.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
EqualityComparer,
77
MapLike,
88
Queue,
9+
RawTSConfig,
910
SortedArray,
1011
SortedReadonlyArray,
1112
TextSpan,
@@ -2716,3 +2717,8 @@ export function isNodeLikeSystem(): boolean {
27162717
&& !(process as any).browser
27172718
&& typeof require !== "undefined";
27182719
}
2720+
2721+
export function config<const T extends RawTSConfig>(config: T): T {
2722+
Debug.fail("This function does nothing at runtime.");
2723+
return config;
2724+
}

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ export function getLibraryNameFromLibFileName(libFileName: string) {
11471147

11481148
function getLibFileNameFromLibReference(libReference: FileReference) {
11491149
const libName = toFileNameLowerCase(libReference.fileName);
1150-
const libFileName = libMap.get(libName);
1150+
const libFileName = libMap.get(libName as Parameters<(typeof libMap)["get"]>[0]);
11511151
return { libName, libFileName };
11521152
}
11531153

src/compiler/tsbuildPublic.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
closeFileWatcher,
1212
closeFileWatcherOf,
1313
combinePaths,
14+
CommandLineOption,
1415
commonOptionsWithBuild,
1516
CompilerHost,
1617
CompilerOptions,
@@ -324,7 +325,7 @@ export function createSolutionBuilderWithWatchHost<T extends BuilderProgram = Em
324325

325326
function getCompilerOptionsOfBuildOptions(buildOptions: BuildOptions): CompilerOptions {
326327
const result = {} as CompilerOptions;
327-
commonOptionsWithBuild.forEach(option => {
328+
commonOptionsWithBuild.forEach((option: CommandLineOption) => {
328329
if (hasProperty(buildOptions, option.name)) result[option.name] = buildOptions[option.name];
329330
});
330331
return result;

src/compiler/types.ts

+43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ModuleResolutionCache,
1010
MultiMap,
1111
NodeFactoryFlags,
12+
optionDeclarations,
1213
OptionsNameMap,
1314
PackageJsonInfo,
1415
PackageJsonInfoCache,
@@ -9912,6 +9913,48 @@ export interface PragmaMap extends Map<string, PragmaPseudoMap[keyof PragmaPseud
99129913
forEach(action: <TKey extends keyof PragmaPseudoMap>(value: PragmaPseudoMap[TKey] | PragmaPseudoMap[TKey][], key: TKey, map: PragmaMap) => void): void;
99139914
}
99149915

9916+
type IntoCompilerOptionsValue<T extends CommandLineOption> =
9917+
T["type"] extends "string"
9918+
? string
9919+
: T["type"] extends "number"
9920+
? number
9921+
: T["type"] extends "boolean"
9922+
? boolean
9923+
: T["type"] extends "object"
9924+
? Record<string, any>
9925+
: T["type"] extends "list"
9926+
? IntoCompilerOptionsValue<Extract<T, CommandLineOptionOfListType>["element"]>[]
9927+
: T["type"] extends "listOrElement"
9928+
? IntoCompilerOptionsValue<Extract<T, CommandLineOptionOfListType>["element"]>[] | IntoCompilerOptionsValue<Extract<T, CommandLineOptionOfListType>["element"]>
9929+
: T["type"] extends Map<infer InputKeyTypes, infer _EnumType>
9930+
? InputKeyTypes
9931+
: never;
9932+
9933+
type IntoCompilerOptionsNameValuePair<T extends CommandLineOption> = {
9934+
[K in T["name"]]?: IntoCompilerOptionsValue<T>;
9935+
};
9936+
9937+
type IntoCompilerOptionsNameValuePairs<T extends CommandLineOption> = T extends T ? IntoCompilerOptionsNameValuePair<T> : never;
9938+
9939+
type IntoCompilerOptionsDefinitionWorker<T extends CommandLineOption[]> = UnionToIntersection<IntoCompilerOptionsNameValuePairs<T[number]>>;
9940+
9941+
type IntoCompilerOptionsDefinition<T extends CommandLineOption[]> = IntoCompilerOptionsDefinitionWorker<T> extends infer U ? {[K in keyof U]: U[K]} : never;
9942+
9943+
export const _optionsType = [undefined! as IntoCompilerOptionsDefinition<typeof optionDeclarations> | undefined][0];
9944+
9945+
/**
9946+
* An unprocessed TSConfig object, suitable to read as JSON and transform into command line options
9947+
*/
9948+
export interface RawTSConfig {
9949+
extends?: string | string[];
9950+
compilerOptions?: NonNullable<typeof _optionsType>;
9951+
references?: { path: string }[];
9952+
files?: string[];
9953+
include?: string[];
9954+
exclude?: string[];
9955+
compileOnSave?: boolean;
9956+
}
9957+
99159958
/** @internal */
99169959
export interface CommentDirectivesMap {
99179960
getUnusedExpectations(): CommentDirective[];

src/executeCommandLine/executeCommandLine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function getOptionsForHelp(commandLine: ParsedCommandLine) {
169169
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
170170
return !!commandLine.options.all ?
171171
sort(optionDeclarations, (a, b) => compareStringsCaseInsensitive(a.name, b.name)) :
172-
filter(optionDeclarations.slice(), v => !!v.showInSimplifiedHelpView);
172+
filter(optionDeclarations.slice(), (v: CommandLineOption) => !!v.showInSimplifiedHelpView);
173173
}
174174

175175
function printVersion(sys: System) {

src/services/transpile.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
addRange,
33
cloneCompilerOptions,
4+
CommandLineOption,
45
CommandLineOptionOfCustomType,
56
CompilerHost,
67
CompilerOptions,
@@ -169,7 +170,7 @@ let commandLineOptionsStringToEnum: CommandLineOptionOfCustomType[];
169170
export function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]): CompilerOptions {
170171
// Lazily create this value to fix module loading errors.
171172
commandLineOptionsStringToEnum = commandLineOptionsStringToEnum ||
172-
filter(optionDeclarations, o => typeof o.type === "object" && !forEachEntry(o.type, v => typeof v !== "number")) as CommandLineOptionOfCustomType[];
173+
filter(optionDeclarations, (o: CommandLineOption) => typeof o.type === "object" && !forEachEntry(o.type, v => typeof v !== "number")) as CommandLineOptionOfCustomType[];
173174

174175
options = cloneCompilerOptions(options);
175176

src/testRunner/projectsRunner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,13 @@ function createCompilerOptions(testCase: ProjectRunnerTestCase & ts.CompilerOpti
472472
const optionNameMap = ts.arrayToMap(ts.optionDeclarations, option => option.name);
473473
for (const name in testCase) {
474474
if (name !== "mapRoot" && name !== "sourceRoot") {
475-
const option = optionNameMap.get(name);
475+
const option = optionNameMap.get(name as Parameters<(typeof optionNameMap)["get"]>[0]);
476476
if (option) {
477477
const optType = option.type;
478478
let value = testCase[name] as any;
479479
if (!ts.isString(optType)) {
480480
const key = value.toLowerCase();
481-
const optTypeValue = optType.get(key);
481+
const optTypeValue = optType.get(key as never);
482482
if (optTypeValue) {
483483
value = optTypeValue;
484484
}

src/testRunner/unittests/config/commandLineParsing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => {
253253
describe("unittests:: config:: commandLineParsing:: optionDeclarations", () => {
254254
it("should have affectsBuildInfo true for every option with affectsSemanticDiagnostics", () => {
255255
for (const option of ts.optionDeclarations) {
256-
if (option.affectsSemanticDiagnostics) {
256+
if ((option as ts.CommandLineOption).affectsSemanticDiagnostics) {
257257
// semantic diagnostics affect the build info, so ensure they're included
258-
assert(option.affectsBuildInfo ?? false, option.name);
258+
assert((option as ts.CommandLineOption).affectsBuildInfo ?? false, option.name);
259259
}
260260
}
261261
});

0 commit comments

Comments
 (0)