Accept new symbol baselines, ensure expected ordering for default libs

This commit is contained in:
Ron Buckton
2018-05-04 17:23:56 -07:00
parent 8d230fc428
commit 68c0e524a6
1516 changed files with 9029 additions and 9006 deletions

View File

@@ -2,43 +2,44 @@ namespace ts {
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
const commandLineLibMap = createMapFromTemplate({
// NOTE: The order here is important to default lib ordering
const commandLineLibMap = createMapFromEntries([
// JavaScript only
"es5": "lib.es5.d.ts",
"es6": "lib.es2015.d.ts",
"es2015": "lib.es2015.d.ts",
"es7": "lib.es2016.d.ts",
"es2016": "lib.es2016.d.ts",
"es2017": "lib.es2017.d.ts",
"es2018": "lib.es2018.d.ts",
"esnext": "lib.esnext.d.ts",
["es5", "lib.es5.d.ts"],
["es6", "lib.es2015.d.ts"],
["es2015", "lib.es2015.d.ts"],
["es7", "lib.es2016.d.ts"],
["es2016", "lib.es2016.d.ts"],
["es2017", "lib.es2017.d.ts"],
["es2018", "lib.es2018.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
"dom": "lib.dom.d.ts",
"dom.iterable": "lib.dom.iterable.d.ts",
"webworker": "lib.webworker.d.ts",
"scripthost": "lib.scripthost.d.ts",
["dom", "lib.dom.d.ts"],
["dom.iterable", "lib.dom.iterable.d.ts"],
["webworker", "lib.webworker.d.ts"],
["scripthost", "lib.scripthost.d.ts"],
// ES2015 Or ESNext By-feature options
"es2015.core": "lib.es2015.core.d.ts",
"es2015.collection": "lib.es2015.collection.d.ts",
"es2015.generator": "lib.es2015.generator.d.ts",
"es2015.iterable": "lib.es2015.iterable.d.ts",
"es2015.promise": "lib.es2015.promise.d.ts",
"es2015.proxy": "lib.es2015.proxy.d.ts",
"es2015.reflect": "lib.es2015.reflect.d.ts",
"es2015.symbol": "lib.es2015.symbol.d.ts",
"es2015.symbol.wellknown": "lib.es2015.symbol.wellknown.d.ts",
"es2016.array.include": "lib.es2016.array.include.d.ts",
"es2017.object": "lib.es2017.object.d.ts",
"es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts",
"es2017.string": "lib.es2017.string.d.ts",
"es2017.intl": "lib.es2017.intl.d.ts",
"es2017.typedarrays": "lib.es2017.typedarrays.d.ts",
"es2018.intl": "lib.es2018.intl.d.ts",
"es2018.promise": "lib.es2018.promise.d.ts",
"es2018.regexp": "lib.es2018.regexp.d.ts",
"esnext.array": "lib.esnext.array.d.ts",
"esnext.asynciterable": "lib.esnext.asynciterable.d.ts",
});
["es2015.core", "lib.es2015.core.d.ts"],
["es2015.collection", "lib.es2015.collection.d.ts"],
["es2015.generator", "lib.es2015.generator.d.ts"],
["es2015.iterable", "lib.es2015.iterable.d.ts"],
["es2015.promise", "lib.es2015.promise.d.ts"],
["es2015.proxy", "lib.es2015.proxy.d.ts"],
["es2015.reflect", "lib.es2015.reflect.d.ts"],
["es2015.symbol", "lib.es2015.symbol.d.ts"],
["es2015.symbol.wellknown", "lib.es2015.symbol.wellknown.d.ts"],
["es2016.array.include", "lib.es2016.array.include.d.ts"],
["es2017.object", "lib.es2017.object.d.ts"],
["es2017.sharedmemory", "lib.es2017.sharedmemory.d.ts"],
["es2017.string", "lib.es2017.string.d.ts"],
["es2017.intl", "lib.es2017.intl.d.ts"],
["es2017.typedarrays", "lib.es2017.typedarrays.d.ts"],
["es2018.intl", "lib.es2018.intl.d.ts"],
["es2018.promise", "lib.es2018.promise.d.ts"],
["es2018.regexp", "lib.es2018.regexp.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.asynciterable", "lib.esnext.asynciterable.d.ts"],
]);
// Internally we add some additional lib references that we only support when used as part of a
// "lib" reference directive. They are not available on the command line or in tsconfig.json.

View File

@@ -59,6 +59,14 @@ namespace ts {
return result;
}
export function createMapFromEntries<T>(entries: [string, T][]): Map<T> {
const map = createMap<T>();
for (const [key, value] of entries) {
map.set(key, value);
}
return map;
}
export function createMapFromTemplate<T>(template?: MapLike<T>): Map<T> {
const map: Map<T> = new MapCtr<T>();

View File

@@ -493,7 +493,9 @@ namespace ts {
*/
export function createProgram(rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): Program {
let program: Program;
let files: SourceFile[] = [];
let processingDefaultLibFiles: SourceFile[] | undefined;
let processingOtherFiles: SourceFile[] | undefined;
let files: SourceFile[] | undefined;
let commonSourceDirectory: string;
let diagnosticsProducingTypeChecker: TypeChecker;
let noDiagnosticsTypeChecker: TypeChecker;
@@ -584,6 +586,8 @@ namespace ts {
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
const structuralIsReused = tryReuseStructureFromOldProgram();
if (structuralIsReused !== StructureIsReused.Completely) {
processingDefaultLibFiles = [];
processingOtherFiles = [];
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false));
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
@@ -618,6 +622,9 @@ namespace ts {
}
missingFilePaths = arrayFrom(filesByName.keys(), p => <Path>p).filter(p => !filesByName.get(p));
files = stableSort(processingDefaultLibFiles, compareDefaultLibFiles).concat(processingOtherFiles);
processingDefaultLibFiles = undefined;
processingOtherFiles = undefined;
}
Debug.assert(!!missingFilePaths);
@@ -677,6 +684,21 @@ namespace ts {
return program;
function compareDefaultLibFiles(a: SourceFile, b: SourceFile) {
return compareValues(getDefaultLibFilePriority(a), getDefaultLibFilePriority(b));
}
function getDefaultLibFilePriority(a: SourceFile) {
if (containsPath(defaultLibraryPath, a.fileName, /*ignoreCase*/ false)) {
const basename = getBaseFileName(a.fileName);
if (basename === "lib.d.ts" || basename === "lib.es6.d.ts") return 0;
const name = removeSuffix(removePrefix(basename, "lib."), ".d.ts");
const index = libs.indexOf(name);
if (index !== -1) return index + 1;
}
return libs.length + 2;
}
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations {
return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache);
}
@@ -1807,10 +1829,11 @@ namespace ts {
sourceFilesFoundSearchingNodeModules.set(file.path, false);
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processLibReferenceDirectives(file);
processTypeReferenceDirectives(file);
}
processLibReferenceDirectives(file);
modulesWithElidedImports.set(file.path, false);
processImportedModules(file);
}
@@ -1846,7 +1869,7 @@ namespace ts {
redirectTargetsSet.set(fileFromPackageId.path, true);
filesByName.set(path, dupFile);
sourceFileToPackageName.set(path, packageId.name);
files.push(dupFile);
processingOtherFiles.push(dupFile);
return dupFile;
}
else if (file) {
@@ -1877,18 +1900,19 @@ namespace ts {
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processLibReferenceDirectives(file);
processTypeReferenceDirectives(file);
}
processLibReferenceDirectives(file);
// always process imported modules to record module name resolutions
processImportedModules(file);
if (isDefaultLib) {
files.unshift(file);
processingDefaultLibFiles.push(file);
}
else {
files.push(file);
processingOtherFiles.push(file);
}
}

2
src/lib/es2015.d.ts vendored
View File

@@ -1,3 +1,4 @@
/// <reference lib="es5" />
/// <reference lib="es2015.core" />
/// <reference lib="es2015.collection" />
/// <reference lib="es2015.generator" />
@@ -7,4 +8,3 @@
/// <reference lib="es2015.reflect" />
/// <reference lib="es2015.symbol" />
/// <reference lib="es2015.symbol.wellknown" />
/// <reference lib="es5" />

View File

@@ -11,4 +11,4 @@
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.iterable" />