Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch built-in libs to use lib refs
  • Loading branch information
rbuckton committed Jun 5, 2017
commit 32dd033ae8f2860af7bb8e8f84563a21a1654a6c
105 changes: 42 additions & 63 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,70 +105,49 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
const isWin = /^win/.test(process.platform);
const mocha = path.join(nodeModulesPathPrefix, "mocha") + (isWin ? ".cmd" : "");

const es2015LibrarySources = [
"es2015.core.d.ts",
"es2015.collection.d.ts",
"es2015.generator.d.ts",
"es2015.iterable.d.ts",
"es2015.promise.d.ts",
"es2015.proxy.d.ts",
"es2015.reflect.d.ts",
"es2015.symbol.d.ts",
"es2015.symbol.wellknown.d.ts"
];

const es2015LibrarySourceMap = es2015LibrarySources.map(function(source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

const es2016LibrarySource = ["es2016.array.include.d.ts"];

const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

const es2017LibrarySource = [
"es2017.object.d.ts",
"es2017.sharedmemory.d.ts",
"es2017.string.d.ts",
"es2017.intl.d.ts",
];

const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

const esnextLibrarySource = [
"esnext.asynciterable.d.ts"
];

const esnextLibrarySourceMap = esnextLibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"];

const librarySourceMap = [
// Host library
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },

// JavaScript library
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
{ target: "lib.esnext.d.ts", sources: ["header.d.ts", "esnext.d.ts"] },

// JavaScript + all host library
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
// Host libraries
"dom.generated=lib.dom.d.ts",
"dom.iterable",
"webworker.generated=lib.webworker.d.ts",
"webworker.importscripts",
"scripthost",

// Javascript libraries
"es5",
"es2015",
"es2015.core",
"es2015.collection",
"es2015.generator",
"es2015.iterable",
"es2015.promise",
"es2015.proxy",
"es2015.reflect",
"es2015.symbol",
"es2015.symbol.wellknown",
"es2016",
"es2016.array.include",
"es2017",
"es2017.object",
"es2017.sharedmemory",
"es2017.string",
"es2017.intl",
"esnext",
"esnext.asynciterable",

// Default libraries
"default.es5=lib.d.ts",
"default.es2015=lib.es6.d.ts",
"default.es2016=lib.es2016.full.d.ts",
"default.es2017=lib.es2017.full.d.ts",
"default.esnext=lib.esnext.full.d.ts",
].map(function (lib) {
var parts = lib.split("=", 2);
return {
sources: ["header.d.ts", parts[0] + ".d.ts"],
target: parts[1] || ("lib." + parts[0] + ".d.ts")
};
});

const libraryTargets = librarySourceMap.map(function(f) {
return path.join(builtLocalDirectory, f.target);
Expand Down
105 changes: 42 additions & 63 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,70 +148,49 @@ var harnessSources = harnessCoreSources.concat([
return path.join(serverDirectory, f);
}));

var es2015LibrarySources = [
"es2015.core.d.ts",
"es2015.collection.d.ts",
"es2015.generator.d.ts",
"es2015.iterable.d.ts",
"es2015.promise.d.ts",
"es2015.proxy.d.ts",
"es2015.reflect.d.ts",
"es2015.symbol.d.ts",
"es2015.symbol.wellknown.d.ts"
];

var es2015LibrarySourceMap = es2015LibrarySources.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

var es2016LibrarySource = ["es2016.array.include.d.ts"];

var es2016LibrarySourceMap = es2016LibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

var es2017LibrarySource = [
"es2017.object.d.ts",
"es2017.sharedmemory.d.ts",
"es2017.string.d.ts",
"es2017.intl.d.ts"
];

var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

var esnextLibrarySource = [
"esnext.asynciterable.d.ts"
];

var esnextLibrarySourceMap = esnextLibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});

var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"];

var librarySourceMap = [
// Host library
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },

// JavaScript library
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
{ target: "lib.esnext.d.ts", sources: ["header.d.ts", "esnext.d.ts"] },

// JavaScript + all host library
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
// Host libraries
"dom.generated=lib.dom.d.ts",
"dom.iterable",
"webworker.generated=lib.webworker.d.ts",
"webworker.importscripts",
"scripthost",

// Javascript libraries
"es5",
"es2015",
"es2015.core",
"es2015.collection",
"es2015.generator",
"es2015.iterable",
"es2015.promise",
"es2015.proxy",
"es2015.reflect",
"es2015.symbol",
"es2015.symbol.wellknown",
"es2016",
"es2016.array.include",
"es2017",
"es2017.object",
"es2017.sharedmemory",
"es2017.string",
"es2017.intl",
"esnext",
"esnext.asynciterable",

// Default libraries
"default.es5=lib.d.ts",
"default.es2015=lib.es6.d.ts",
"default.es2016=lib.es2016.full.d.ts",
"default.es2017=lib.es2017.full.d.ts",
"default.esnext=lib.esnext.full.d.ts",
].map(function (lib) {
var parts = lib.split("=", 2);
return {
sources: ["header.d.ts", parts[0] + ".d.ts"],
target: parts[1] || ("lib." + parts[0] + ".d.ts")
};
});

var libraryTargets = librarySourceMap.map(function (f) {
return path.join(builtLocalDirectory, f.target);
Expand Down
13 changes: 9 additions & 4 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace ts {
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };

/* @internal */
export const libMap = createMapFromTemplate({
const commandLineLibMap = createMapFromTemplate({
// JavaScript only
"es5": "lib.es5.d.ts",
"es6": "lib.es2015.d.ts",
Expand Down Expand Up @@ -42,7 +41,13 @@ namespace ts {
});

/* @internal */
export const libs = arrayFrom(libMap.keys());
// We only support "webworker.importscripts" when used as part of a default lib. It's not available
// on the command line.
export const libMap = cloneMap(commandLineLibMap)
.set("webworker.importscripts", "lib.webworker.importscripts.d.ts");

/* @internal */
export const libs = arrayFrom(commandLineLibMap.keys());

/* @internal */
export const optionDeclarations: CommandLineOption[] = [
Expand Down Expand Up @@ -148,7 +153,7 @@ namespace ts {
type: "list",
element: {
name: "lib",
type: libMap,
type: commandLineLibMap,
},
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
Expand Down
5 changes: 5 additions & 0 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1983,5 +1983,10 @@ namespace Harness {
return { unitName: libFile, content: io.readFile(libFile) };
}

export function getNamedDefaultLibraryFile(io: Harness.IO, libName: string): Harness.Compiler.TestFile {
const libFile = Harness.userSpecifiedRoot + Harness.libFolder + "lib." + libName + ".d.ts";
return { unitName: libFile, content: io.readFile(libFile) };
}

if (Error) (<any>Error).stackTraceLimit = 100;
}
25 changes: 16 additions & 9 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ namespace ts.projectSystem {
path: "/a/lib/lib.d.ts",
content: libFileContent
};
export const libFiles: FileOrFolder[] = [
{ path: "/a/lib/lib.d.ts", content: Harness.getDefaultLibraryFile(Harness.IO).content },
{ path: "/a/lib/lib.es5.d.ts", content: Harness.getNamedDefaultLibraryFile(Harness.IO, "es5").content },
{ path: "/a/lib/lib.dom.d.ts", content: Harness.getNamedDefaultLibraryFile(Harness.IO, "dom").content },
{ path: "/a/lib/lib.webworker.importscripts.d.ts", content: Harness.getNamedDefaultLibraryFile(Harness.IO, "webworker.importscripts").content },
{ path: "/a/lib/lib.scripthost.d.ts", content: Harness.getNamedDefaultLibraryFile(Harness.IO, "scripthost").content }
];

export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller {
protected projectService: server.ProjectService;
Expand Down Expand Up @@ -1285,15 +1292,15 @@ namespace ts.projectSystem {
content: "let x: number;"
};

const host = createServerHost([f1, f2, libFile]);
const host = createServerHost([f1, f2, ...libFiles]);
const service = createProjectService(host);
service.openExternalProject({ projectFileName: "/a/b/project", rootFiles: toExternalFiles([f1.path, f2.path]), options: {} });

service.openClientFile(f1.path);
service.openClientFile(f2.path, "let x: string");

service.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]);
checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, ...libFiles.map(f => f.path)]);

const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2);
// should contain completions for string
Expand Down Expand Up @@ -1895,7 +1902,7 @@ namespace ts.projectSystem {
content: JSON.stringify({ compilerOptions: { allowJs: true } })
};

let host = createServerHost([file1, file2, config1, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
let host = createServerHost([file1, file2, config1, ...libFiles], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
let session = createSession(host);

// Specify .html extension as mixed content in a configure host request
Expand All @@ -1917,7 +1924,7 @@ namespace ts.projectSystem {
content: JSON.stringify({ compilerOptions: { allowJs: false } })
};

host = createServerHost([file1, file2, config2, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
host = createServerHost([file1, file2, config2, ...libFiles], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);

session.executeCommand(configureHostRequest).response;
Expand All @@ -1936,7 +1943,7 @@ namespace ts.projectSystem {
content: JSON.stringify({})
};

host = createServerHost([file1, file2, config3, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
host = createServerHost([file1, file2, config3, ...libFiles], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);

session.executeCommand(configureHostRequest).response;
Expand All @@ -1955,7 +1962,7 @@ namespace ts.projectSystem {
content: JSON.stringify({ compilerOptions: { allowJs: true }, files: [file1.path, file2.path] })
};

host = createServerHost([file1, file2, config4, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
host = createServerHost([file1, file2, config4, ...libFiles], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);

session.executeCommand(configureHostRequest).response;
Expand All @@ -1974,7 +1981,7 @@ namespace ts.projectSystem {
content: JSON.stringify({ compilerOptions: { allowJs: true }, exclude: [file2.path] })
};

host = createServerHost([file1, file2, config5, libFile], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
host = createServerHost([file1, file2, config5, ...libFiles], { executingFilePath: combinePaths(getDirectoryPath(libFile.path), "tsc.js") });
session = createSession(host);

session.executeCommand(configureHostRequest).response;
Expand Down Expand Up @@ -3471,7 +3478,7 @@ namespace ts.projectSystem {
path: "/a/b/f1.js",
content: "function test1() { }"
};
const host = createServerHost([f1, libFile]);
const host = createServerHost([f1, ...libFiles]);
const session = createSession(host);
openFilesForSession([f1], session);

Expand Down Expand Up @@ -3507,7 +3514,7 @@ namespace ts.projectSystem {
path: "/a/b/f1.js",
content: "function test1() { }"
};
const host = createServerHost([f1, libFile]);
const host = createServerHost([f1, ...libFiles]);
const session = createSession(host);
const projectService = session.getProjectService();
const projectFileName = "/a/b/project.csproj";
Expand Down
14 changes: 14 additions & 0 deletions src/lib/default.es2015.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference lib="es5" />
/// <reference lib="es2015.core" />
/// <reference lib="es2015.collection" />
/// <reference lib="es2015.generator" />
/// <reference lib="es2015.iterable" />
/// <reference lib="es2015.promise" />
/// <reference lib="es2015.proxy" />
/// <reference lib="es2015.reflect" />
/// <reference lib="es2015.symbol" />
/// <reference lib="es2015.symbol.wellknown" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
5 changes: 5 additions & 0 deletions src/lib/default.es2016.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference lib="es2016" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
5 changes: 5 additions & 0 deletions src/lib/default.es2017.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference lib="es2017" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
4 changes: 4 additions & 0 deletions src/lib/default.es5.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference lib="es5" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
Loading