mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
feat: Support types compiler option in compiler APIs (#4155)
Handles `types` in the compiler APIs to make it easier to supply external type libraries.
This commit is contained in:
parent
daf7617f42
commit
1d26da6a47
6 changed files with 91 additions and 7 deletions
|
@ -182,12 +182,20 @@ export function createWriteFile(state: WriteFileState): WriteFileCallback {
|
|||
};
|
||||
}
|
||||
|
||||
export interface ConvertCompilerOptionsResult {
|
||||
files?: string[];
|
||||
options: ts.CompilerOptions;
|
||||
}
|
||||
|
||||
/** Take a runtime set of compiler options as stringified JSON and convert it
|
||||
* to a set of TypeScript compiler options. */
|
||||
export function convertCompilerOptions(str: string): ts.CompilerOptions {
|
||||
export function convertCompilerOptions(
|
||||
str: string
|
||||
): ConvertCompilerOptionsResult {
|
||||
const options: CompilerOptions = JSON.parse(str);
|
||||
const out: Record<string, unknown> = {};
|
||||
const keys = Object.keys(options) as Array<keyof CompilerOptions>;
|
||||
const files: string[] = [];
|
||||
for (const key of keys) {
|
||||
switch (key) {
|
||||
case "jsx":
|
||||
|
@ -261,11 +269,20 @@ export function convertCompilerOptions(str: string): ts.CompilerOptions {
|
|||
default:
|
||||
throw new TypeError("Unexpected emit target.");
|
||||
}
|
||||
break;
|
||||
case "types":
|
||||
const types = options[key];
|
||||
assert(types);
|
||||
files.push(...types);
|
||||
break;
|
||||
default:
|
||||
out[key] = options[key];
|
||||
}
|
||||
}
|
||||
return out as ts.CompilerOptions;
|
||||
return {
|
||||
options: out as ts.CompilerOptions,
|
||||
files: files.length ? files : undefined
|
||||
};
|
||||
}
|
||||
|
||||
/** An array of TypeScript diagnostic types we ignore. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue