Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add es3.d.ts #16077

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ const librarySourceMap = [
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },

// JavaScript library
{ target: "lib.es3.d.ts", sources: ["header.d.ts", "es3.d.ts"] },
{ 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.es3.full.d.ts", sources: ["header.d.ts", "es3.d.ts"].concat(hostsLibrarySources) },
{ 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") },
Expand Down Expand Up @@ -1035,7 +1037,7 @@ gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are:
const fileMatcher = cmdLineOptions["files"];
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
console.log("Linting: " + cmd);
child_process.execSync(cmd, { stdio: [0, 1, 2] });
Expand Down
4 changes: 3 additions & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ var librarySourceMap = [
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },

// JavaScript library
{ target: "lib.es3.d.ts", sources: ["header.d.ts", "es3.d.ts"] },
{ 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.es3.full.d.ts", sources: ["header.d.ts", "es3.d.ts"].concat(hostsLibrarySources) },
{ 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") },
Expand Down Expand Up @@ -1202,7 +1204,7 @@ task("lint", ["build-rules"], () => {
const fileMatcher = process.env.f || process.env.file || process.env.files;
const files = fileMatcher
? `src/**/${fileMatcher}`
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude 'src/lib/*.generated.d.ts'";
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
console.log("Linting: " + cmd);
jake.exec([cmd], { interactive: true }, () => {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace ts {
name: "lib",
type: createMapFromTemplate({
// JavaScript only
"es3": "lib.es3.d.ts",
"es5": "lib.es5.d.ts",
"es6": "lib.es2015.d.ts",
"es2015": "lib.es2015.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4307,9 +4307,11 @@ namespace ts {
case ScriptTarget.ES2016:
return "lib.es2016.full.d.ts";
case ScriptTarget.ES2015:
return "lib.es6.d.ts"; // We don't use lib.es2015.full.d.ts due to breaking change.
default:
return "lib.es6.d.ts"; // We don't use lib.es2015.full.d.ts due to breaking change.
case ScriptTarget.ES5:
return "lib.d.ts";
default:
return "lib.es3.full.d.ts";
}
}

Expand Down
37 changes: 32 additions & 5 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,33 @@ namespace FourSlash {
this.languageServiceAdapterHost.addScript(fileName, file, /*isRootFile*/ true);
}
});

const libs: ts.SourceFile[] = [];
if (compilationOptions.lib) {
for (const lib of compilationOptions.lib) {
const sourceFile = Harness.Compiler.getDefaultLibrarySourceFile(lib);
this.languageServiceAdapterHost.addScript(lib, sourceFile.text, /*isRootFile*/ false);
libs.push(sourceFile);
}
}
else {
const lib = Harness.Compiler.getDefaultLibFileName(compilationOptions);
const sourceFile = Harness.Compiler.getDefaultLibrarySourceFile(lib);
this.languageServiceAdapterHost.addScript(lib, sourceFile.text, /*isRootFile*/ false);
const fullLib = ts.getDefaultLibFileName(compilationOptions);
this.languageServiceAdapterHost.addScript(fullLib, sourceFile.text, /*isRootFile*/ false);
libs.push(sourceFile);
}
for (const lib of libs) {
const resolvedResult = ts.preProcessFile(lib.text, /*readImportFiles*/ false, /*detectJavaScriptImports*/ false);
const referencedFiles: ts.FileReference[] = resolvedResult.referencedFiles;

for (const referenced of referencedFiles) {
this.languageServiceAdapterHost.addScript(referenced.fileName,
Harness.Compiler.getDefaultLibrarySourceFile(referenced.fileName).text, /*isRootFile*/ false);
}
}

this.languageServiceAdapterHost.addScript(Harness.Compiler.defaultLibFileName,
Harness.Compiler.getDefaultLibrarySourceFile().text, /*isRootFile*/ false);
}
Expand Down Expand Up @@ -969,9 +996,9 @@ namespace FourSlash {
}

for (const reference of expectedReferences) {
const {fileName, start, end} = reference;
const { fileName, start, end } = reference;
if (reference.marker && reference.marker.data) {
const {isWriteAccess, isDefinition} = reference.marker.data;
const { isWriteAccess, isDefinition } = reference.marker.data;
this.verifyReferencesWorker(actualReferences, fileName, start, end, isWriteAccess, isDefinition);
}
else {
Expand Down Expand Up @@ -1175,7 +1202,7 @@ namespace FourSlash {
displayParts: ts.SymbolDisplayPart[],
documentation: ts.SymbolDisplayPart[],
tags: ts.JSDocTagInfo[]
) {
) {

const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind"));
Expand Down Expand Up @@ -1898,7 +1925,7 @@ namespace FourSlash {
this.goToPosition(len);
}

public goToRangeStart({fileName, start}: Range) {
public goToRangeStart({ fileName, start }: Range) {
this.openFile(fileName);
this.goToPosition(start);
}
Expand Down Expand Up @@ -2072,7 +2099,7 @@ namespace FourSlash {
return result;
}

private rangeText({fileName, start, end}: Range): string {
private rangeText({ fileName, start, end }: Range): string {
return this.getFileContent(fileName).slice(start, end);
}

Expand Down
8 changes: 5 additions & 3 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,12 @@ namespace Harness {
const carriageReturnLineFeed = "\r\n";
const lineFeed = "\n";

export const defaultLibFileName = "lib.d.ts";
export const defaultLibFileName = "lib.es3.full.d.ts";
export const es2015DefaultLibFileName = "lib.es2015.d.ts";

// Cache of lib files from "built/local"
const libFileNameSourceFileMap = ts.createMapFromTemplate<ts.SourceFile>({
[defaultLibFileName]: createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
[defaultLibFileName]: createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es3.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
});

// Cache of lib files from "tests/lib/"
Expand All @@ -863,9 +863,11 @@ namespace Harness {
return "lib.es2016.d.ts";
case ts.ScriptTarget.ES2015:
return es2015DefaultLibFileName;
case ts.ScriptTarget.ES5:
return "lib.es5.d.ts";

default:
return defaultLibFileName;
return "lib.es3.d.ts";
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace Harness.LanguageService {
return [];
}
getCurrentDirectory(): string { return virtualFileSystemRoot; }
getDefaultLibFileName(): string { return Harness.Compiler.defaultLibFileName; }
getDefaultLibFileName(options: ts.CompilerOptions): string { return Harness.Compiler.getDefaultLibFileName(options); }
getScriptFileNames(): string[] { return this.getFilenames(); }
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
const script = this.getScriptInfo(fileName);
Expand Down Expand Up @@ -302,7 +302,7 @@ namespace Harness.LanguageService {
getCancellationToken(): ts.HostCancellationToken { return this.nativeHost.getCancellationToken(); }
getCurrentDirectory(): string { return this.nativeHost.getCurrentDirectory(); }
getDirectories(path: string): string { return JSON.stringify(this.nativeHost.getDirectories(path)); }
getDefaultLibFileName(): string { return this.nativeHost.getDefaultLibFileName(); }
getDefaultLibFileName(options: string): string { return this.nativeHost.getDefaultLibFileName(JSON.parse(options)); }
getScriptFileNames(): string { return JSON.stringify(this.nativeHost.getScriptFileNames()); }
getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim {
const nativeScriptSnapshot = this.nativeHost.getScriptSnapshot(fileName);
Expand Down
6 changes: 3 additions & 3 deletions src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class ProjectRunner extends RunnerBase {

function getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
let sourceFile: ts.SourceFile = undefined;
if (fileName === Harness.Compiler.defaultLibFileName) {
sourceFile = Harness.Compiler.getDefaultLibrarySourceFile(Harness.Compiler.getDefaultLibFileName(compilerOptions));
if (Harness.isDefaultLibraryFile(fileName)) {
sourceFile = Harness.Compiler.getDefaultLibrarySourceFile(fileName);
}
else {
const text = getSourceFileText(fileName);
Expand All @@ -177,7 +177,7 @@ class ProjectRunner extends RunnerBase {
function createCompilerHost(): ts.CompilerHost {
return {
getSourceFile,
getDefaultLibFileName: () => Harness.Compiler.defaultLibFileName,
getDefaultLibFileName: options => Harness.Compiler.getDefaultLibFileName(options),
writeFile,
getCurrentDirectory,
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
Expand Down
4 changes: 2 additions & 2 deletions src/harness/unittests/cachingInServerLSHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace ts {
{
let fileExistsIsCalled = false;
serverHost.fileExists = (fileName): boolean => {
if (fileName === "lib.d.ts") {
if (Harness.isDefaultLibraryFile(fileName)) {
return false;
}
fileExistsIsCalled = true;
Expand All @@ -142,7 +142,7 @@ namespace ts {
{
let fileExistsCalled = false;
serverHost.fileExists = (fileName): boolean => {
if (fileName === "lib.d.ts") {
if (Harness.isDefaultLibraryFile(fileName)) {
return false;
}
fileExistsCalled = true;
Expand Down
6 changes: 3 additions & 3 deletions src/harness/unittests/commandLineParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace ts {
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es3', 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

Expand Down Expand Up @@ -263,7 +263,7 @@ namespace ts {
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es3', 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

Expand All @@ -283,7 +283,7 @@ namespace ts {
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es3', 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

Expand Down
Loading