mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Salsa: JS support for discovering and acquiring d.ts files
(Mostly isolating VS host changes from PR#6448)
This commit is contained in:
@@ -537,6 +537,7 @@ namespace ts {
|
||||
return {
|
||||
options,
|
||||
fileNames: getFileNames(),
|
||||
typingOptions: getTypingOptions(),
|
||||
errors
|
||||
};
|
||||
|
||||
@@ -601,6 +602,32 @@ namespace ts {
|
||||
}
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
function getTypingOptions(): TypingOptions {
|
||||
const options: TypingOptions = getBaseFileName(configFileName) === "jsconfig.json"
|
||||
? { enableAutoDiscovery: true, include: [], exclude: [] }
|
||||
: { enableAutoDiscovery: false, include: [], exclude: [] };
|
||||
const jsonTypingOptions = json["typingOptions"];
|
||||
if (jsonTypingOptions) {
|
||||
for (const id in jsonTypingOptions) {
|
||||
if (id === "enableAutoDiscovery") {
|
||||
if (typeof jsonTypingOptions[id] === "boolean") {
|
||||
options.enableAutoDiscovery = jsonTypingOptions[id];
|
||||
}
|
||||
}
|
||||
else if (id === "include") {
|
||||
options.include = isArray(jsonTypingOptions[id]) ? <string[]>jsonTypingOptions[id] : [];
|
||||
}
|
||||
else if (id === "exclude") {
|
||||
options.exclude = isArray(jsonTypingOptions[id]) ? <string[]>jsonTypingOptions[id] : [];
|
||||
}
|
||||
else {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_typing_option_0, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string, configFileName?: string): { options: CompilerOptions, errors: Diagnostic[] } {
|
||||
|
||||
@@ -778,6 +778,32 @@ namespace ts {
|
||||
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
|
||||
}
|
||||
|
||||
export function ensureScriptKind(fileName: string, scriptKind?: ScriptKind): ScriptKind {
|
||||
// Using scriptKind as a condition handles both:
|
||||
// - 'scriptKind' is unspecified and thus it is `undefined`
|
||||
// - 'scriptKind' is set and it is `Unknown` (0)
|
||||
// If the 'scriptKind' is 'undefined' or 'Unknown' then we attempt
|
||||
// to get the ScriptKind from the file name. If it cannot be resolved
|
||||
// from the file name then the default 'TS' script kind is returned.
|
||||
return (scriptKind || getScriptKindFromFileName(fileName)) || ScriptKind.TS;
|
||||
}
|
||||
|
||||
export function getScriptKindFromFileName(fileName: string): ScriptKind {
|
||||
const ext = fileName.substr(fileName.lastIndexOf("."));
|
||||
switch (ext.toLowerCase()) {
|
||||
case ".js":
|
||||
return ScriptKind.JS;
|
||||
case ".jsx":
|
||||
return ScriptKind.JSX;
|
||||
case ".ts":
|
||||
return ScriptKind.TS;
|
||||
case ".tsx":
|
||||
return ScriptKind.TSX;
|
||||
default:
|
||||
return ScriptKind.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List of supported extensions in order of file resolution precedence.
|
||||
*/
|
||||
|
||||
@@ -2800,5 +2800,9 @@
|
||||
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
|
||||
"category": "Error",
|
||||
"code": 17009
|
||||
},
|
||||
"Unknown typing option '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 17010
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,23 +407,6 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function getScriptKindFromFileName(fileName: string): ScriptKind {
|
||||
const ext = fileName.substr(fileName.lastIndexOf("."));
|
||||
switch (ext.toLowerCase()) {
|
||||
case ".js":
|
||||
return ScriptKind.JS;
|
||||
case ".jsx":
|
||||
return ScriptKind.JSX;
|
||||
case ".ts":
|
||||
return ScriptKind.TS;
|
||||
case ".tsx":
|
||||
return ScriptKind.TSX;
|
||||
default:
|
||||
return ScriptKind.TS;
|
||||
}
|
||||
}
|
||||
|
||||
// Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
|
||||
// indicates what changed between the 'text' that this SourceFile has and the 'newText'.
|
||||
// The SourceFile will be created with the compiler attempting to reuse as many nodes from
|
||||
@@ -551,12 +534,7 @@ namespace ts {
|
||||
let parseErrorBeforeNextFinishedNode = false;
|
||||
|
||||
export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile {
|
||||
// Using scriptKind as a condition handles both:
|
||||
// - 'scriptKind' is unspecified and thus it is `undefined`
|
||||
// - 'scriptKind' is set and it is `Unknown` (0)
|
||||
// If the 'scriptKind' is 'undefined' or 'Unknown' then attempt
|
||||
// to get the ScriptKind from the file name.
|
||||
scriptKind = scriptKind ? scriptKind : getScriptKindFromFileName(fileName);
|
||||
scriptKind = ensureScriptKind(fileName, scriptKind);
|
||||
|
||||
initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind);
|
||||
|
||||
|
||||
@@ -2432,6 +2432,13 @@ namespace ts {
|
||||
[option: string]: string | number | boolean | TsConfigOnlyOptions;
|
||||
}
|
||||
|
||||
export interface TypingOptions {
|
||||
enableAutoDiscovery?: boolean;
|
||||
include?: string[];
|
||||
exclude?: string[];
|
||||
[option: string]: any;
|
||||
}
|
||||
|
||||
export enum ModuleKind {
|
||||
None = 0,
|
||||
CommonJS = 1,
|
||||
@@ -2490,6 +2497,7 @@ namespace ts {
|
||||
|
||||
export interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
typingOptions?: TypingOptions;
|
||||
fileNames: string[];
|
||||
errors: Diagnostic[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user