Skip to content

Commit f046d82

Browse files
committed
Merge branch 'master' into builderApi
2 parents 1a91256 + 7bb5fc2 commit f046d82

74 files changed

Lines changed: 2215 additions & 1386 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ compileFile(
795795
/*prereqs*/[builtLocalDirectory, tscFile, tsserverLibraryFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
796796
/*prefixes*/[],
797797
/*useBuiltCompiler:*/ true,
798-
/*opts*/ { types: ["node", "mocha", "chai"], lib: "es6" });
798+
/*opts*/ { types: ["node", "mocha"], lib: "es6" });
799799

800800
var internalTests = "internal/";
801801

package-lock.json

Lines changed: 299 additions & 264 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
},
3131
"devDependencies": {
3232
"@types/browserify": "latest",
33-
"@types/chai": "latest",
3433
"@types/colors": "latest",
3534
"@types/convert-source-map": "latest",
3635
"@types/del": "latest",
@@ -53,7 +52,6 @@
5352
"xml2js": "^0.4.19",
5453
"browser-resolve": "^1.11.2",
5554
"browserify": "latest",
56-
"chai": "latest",
5755
"convert-source-map": "latest",
5856
"del": "latest",
5957
"gulp": "3.X",

src/compiler/checker.ts

Lines changed: 152 additions & 59 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,10 @@
28282828
"category": "Message",
28292829
"code": 6030
28302830
},
2831+
"Starting compilation in watch mode...": {
2832+
"category": "Message",
2833+
"code": 6031
2834+
},
28312835
"File change detected. Starting incremental compilation...": {
28322836
"category": "Message",
28332837
"code": 6032

src/compiler/symbolWalker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace ts {
33
export function createGetSymbolWalker(
44
getRestTypeOfSignature: (sig: Signature) => Type,
5+
getTypePredicateOfSignature: (sig: Signature) => TypePredicate | undefined,
56
getReturnTypeOfSignature: (sig: Signature) => Type,
67
getBaseTypes: (type: Type) => Type[],
78
resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType,
@@ -117,8 +118,9 @@ namespace ts {
117118
}
118119

119120
function visitSignature(signature: Signature): void {
120-
if (signature.typePredicate) {
121-
visitType(signature.typePredicate.type);
121+
const typePredicate = getTypePredicateOfSignature(signature);
122+
if (typePredicate) {
123+
visitType(typePredicate.type);
122124
}
123125
forEach(signature.typeParameters, visitType);
124126

src/compiler/types.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,17 @@ namespace ts {
27912791
/* @internal */ createPromiseType(type: Type): Type;
27922792

27932793
/* @internal */ createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): Type;
2794-
/* @internal */ createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisParameter: Symbol | undefined, parameters: Symbol[], resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasLiteralTypes: boolean): Signature;
2794+
/* @internal */ createSignature(
2795+
declaration: SignatureDeclaration,
2796+
typeParameters: TypeParameter[],
2797+
thisParameter: Symbol | undefined,
2798+
parameters: Symbol[],
2799+
resolvedReturnType: Type,
2800+
typePredicate: TypePredicate | undefined,
2801+
minArgumentCount: number,
2802+
hasRestParameter: boolean,
2803+
hasLiteralTypes: boolean,
2804+
): Signature;
27952805
/* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol;
27962806
/* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
27972807
/* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
@@ -3638,7 +3648,13 @@ namespace ts {
36383648
/* @internal */
36393649
thisParameter?: Symbol; // symbol of this-type parameter
36403650
/* @internal */
3641-
resolvedReturnType: Type; // Resolved return type
3651+
// See comment in `instantiateSignature` for why these are set lazily.
3652+
resolvedReturnType: Type | undefined; // Lazily set by `getReturnTypeOfSignature`.
3653+
/* @internal */
3654+
// Lazily set by `getTypePredicateOfSignature`.
3655+
// `undefined` indicates a type predicate that has not yet been computed.
3656+
// Uses a special `noTypePredicate` sentinel value to indicate that there is no type predicate. This looks like a TypePredicate at runtime to avoid polymorphism.
3657+
resolvedTypePredicate: TypePredicate | undefined;
36423658
/* @internal */
36433659
minArgumentCount: number; // Number of non-optional parameters
36443660
/* @internal */
@@ -3658,8 +3674,6 @@ namespace ts {
36583674
/* @internal */
36593675
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
36603676
/* @internal */
3661-
typePredicate?: TypePredicate;
3662-
/* @internal */
36633677
instantiations?: Map<Signature>; // Generic signature instantiation cache
36643678
}
36653679

src/compiler/watch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ namespace ts {
355355
resolutionCache.resolveModuleNames.bind(resolutionCache);
356356
compilerHost.resolveTypeReferenceDirectives = resolutionCache.resolveTypeReferenceDirectives.bind(resolutionCache);
357357

358+
clearHostScreen();
359+
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Starting_compilation_in_watch_mode));
358360
synchronizeProgram();
359361

360362
// Update the wild card directory watch
@@ -557,10 +559,14 @@ namespace ts {
557559
scheduleProgramUpdate();
558560
}
559561

560-
function updateProgram() {
562+
function clearHostScreen() {
561563
if (system.clearScreen) {
562564
system.clearScreen();
563565
}
566+
}
567+
568+
function updateProgram() {
569+
clearHostScreen();
564570

565571
timerToUpdateProgram = undefined;
566572
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation));

src/harness/fourslash.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ namespace FourSlash {
295295
const host = new Utils.MockParseConfigHost(baseDir, /*ignoreCase*/ false, this.inputFiles);
296296

297297
const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles.get(configFileName));
298-
assert.isTrue(configJsonObj.config !== undefined);
298+
assert(configJsonObj.config !== undefined);
299299

300300
const { options, errors } = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir);
301301

@@ -437,7 +437,7 @@ namespace FourSlash {
437437

438438
public goToEachMarker(action: () => void) {
439439
const markers = this.getMarkers();
440-
assert(markers.length);
440+
assert(markers.length !== 0);
441441
for (const marker of markers) {
442442
this.goToMarker(marker);
443443
action();
@@ -446,7 +446,7 @@ namespace FourSlash {
446446

447447
public goToEachRange(action: () => void) {
448448
const ranges = this.getRanges();
449-
assert(ranges.length);
449+
assert(ranges.length !== 0);
450450
for (const range of ranges) {
451451
this.goToRangeStart(range);
452452
action();
@@ -793,7 +793,7 @@ namespace FourSlash {
793793
}
794794

795795
const entries = this.getCompletionListAtCaret().entries;
796-
assert.isTrue(items.length <= entries.length, `Amount of expected items in completion list [ ${items.length} ] is greater than actual number of items in list [ ${entries.length} ]`);
796+
assert(items.length <= entries.length, `Amount of expected items in completion list [ ${items.length} ] is greater than actual number of items in list [ ${entries.length} ]`);
797797
ts.zipWith(entries, items, (entry, item) => {
798798
assert.equal(entry.name, item, `Unexpected item in completion list`);
799799
});
@@ -947,7 +947,7 @@ namespace FourSlash {
947947
public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]) {
948948
const details = this.getCompletionEntryDetails(entryName);
949949

950-
assert(details, "no completion entry available");
950+
assert.isDefined(details, "no completion entry available");
951951

952952
assert.equal(ts.displayPartsToString(details.displayParts), expectedText, this.assertionMessageAtLastKnownMarker("completion entry details text"));
953953

@@ -1082,7 +1082,7 @@ namespace FourSlash {
10821082

10831083
public verifyRangesReferenceEachOther(ranges?: Range[]) {
10841084
ranges = ranges || this.getRanges();
1085-
assert(ranges.length);
1085+
assert(ranges.length !== 0);
10861086
for (const range of ranges) {
10871087
this.verifyReferencesOf(range, ranges);
10881088
}
@@ -1368,7 +1368,6 @@ Actual: ${stringify(fullActual)}`);
13681368

13691369
public verifyCurrentParameterIsVariable(isVariable: boolean) {
13701370
const signature = this.getActiveSignatureHelpItem();
1371-
assert.isOk(signature);
13721371
assert.equal(isVariable, signature.isVariadic);
13731372
}
13741373

@@ -2019,7 +2018,7 @@ Actual: ${stringify(fullActual)}`);
20192018
const implementations = this.languageService.getImplementationAtPosition(this.activeFile.fileName, this.currentCaretPosition);
20202019

20212020
if (negative) {
2022-
assert.isTrue(implementations && implementations.length > 0, "Expected at least one implementation but got 0");
2021+
assert(implementations && implementations.length > 0, "Expected at least one implementation but got 0");
20232022
}
20242023
else {
20252024
assert.isUndefined(implementations, "Expected implementation list to be empty but implementations returned");
@@ -2472,7 +2471,7 @@ Actual: ${stringify(fullActual)}`);
24722471
}
24732472

24742473
private verifyNewContent(options: FourSlashInterface.NewContentOptions) {
2475-
if (options.newFileContent) {
2474+
if (options.newFileContent !== undefined) {
24762475
assert(!options.newRangeContent);
24772476
this.verifyCurrentFileContent(options.newFileContent);
24782477
}
@@ -3110,7 +3109,7 @@ Actual: ${stringify(fullActual)}`);
31103109

31113110
if (spanIndex !== undefined) {
31123111
const span = this.getTextSpanForRangeAtIndex(spanIndex);
3113-
assert.isTrue(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + entryId));
3112+
assert(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + entryId));
31143113
}
31153114

31163115
assert.equal(item.hasAction, hasAction);

src/harness/harness.ts

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,60 @@
2323
/// <reference path="virtualFileSystem.ts" />
2424
/// <reference types="node" />
2525
/// <reference types="mocha" />
26-
/// <reference types="chai" />
27-
2826

2927
// Block scoped definitions work poorly for global variables, temporarily enable var
3028
/* tslint:disable:no-var-keyword */
3129

32-
// this will work in the browser via browserify
33-
var _chai: typeof chai = require("chai");
34-
var assert: typeof _chai.assert = _chai.assert;
35-
// chai's builtin `assert.isFalse` is featureful but slow - we don't use those features,
36-
// so we'll just overwrite it as an alterative to migrating a bunch of code off of chai
37-
assert.isFalse = (expr, msg) => { if (expr as any as boolean !== false) throw new Error(msg); };
30+
function assert(expr: boolean, msg?: string | (() => string)): void {
31+
if (!expr) {
32+
throw new Error(typeof msg === "string" ? msg : msg());
33+
}
34+
}
35+
namespace assert {
36+
export function isFalse(expr: boolean, msg = "Expected value to be false."): void {
37+
assert(!expr, msg);
38+
}
39+
export function equal<T>(a: T, b: T, msg = "Expected values to be equal."): void {
40+
assert(a === b, msg);
41+
}
42+
export function notEqual<T>(a: T, b: T, msg = "Expected values to not be equal."): void {
43+
assert(a !== b, msg);
44+
}
45+
export function isDefined(x: {} | null | undefined, msg = "Expected value to be defined."): void {
46+
assert(x !== undefined && x !== null, msg);
47+
}
48+
export function isUndefined(x: {} | null | undefined, msg = "Expected value to be undefined."): void {
49+
assert(x === undefined, msg);
50+
}
51+
export function deepEqual<T>(a: T, b: T, msg?: string): void {
52+
assert(isDeepEqual(a, b), msg || (() => `Expected values to be deeply equal:\nExpected:\n${JSON.stringify(a, undefined, 4)}\nActual:\n${JSON.stringify(b, undefined, 4)}`));
53+
}
54+
export function lengthOf(a: ReadonlyArray<{}>, length: number, msg = "Expected length to match."): void {
55+
assert(a.length === length, msg);
56+
}
57+
export function throws(cb: () => void, msg = "Expected callback to throw"): void {
58+
let threw = false;
59+
try {
60+
cb();
61+
}
62+
catch {
63+
threw = true;
64+
}
65+
assert(threw, msg);
66+
}
67+
68+
function isDeepEqual<T>(a: T, b: T): boolean {
69+
if (a === b) {
70+
return true;
71+
}
72+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
73+
return false;
74+
}
75+
const aKeys = Object.keys(a).sort();
76+
const bKeys = Object.keys(b).sort();
77+
return aKeys.length === bKeys.length && aKeys.every((key, i) => bKeys[i] === key && isDeepEqual((a as any)[key], (b as any)[key]));
78+
}
79+
}
3880
declare var __dirname: string; // Node-specific
3981
var global: NodeJS.Global = <any>Function("return this").call(undefined);
4082

@@ -347,8 +389,8 @@ namespace Utils {
347389
return;
348390
}
349391

350-
assert(array1, "array1");
351-
assert(array2, "array2");
392+
assert(!!array1, "array1");
393+
assert(!!array2, "array2");
352394

353395
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
354396

@@ -371,8 +413,8 @@ namespace Utils {
371413
return;
372414
}
373415

374-
assert(node1, "node1");
375-
assert(node2, "node2");
416+
assert(!!node1, "node1");
417+
assert(!!node2, "node2");
376418
assert.equal(node1.pos, node2.pos, "node1.pos !== node2.pos");
377419
assert.equal(node1.end, node2.end, "node1.end !== node2.end");
378420
assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind");
@@ -402,8 +444,8 @@ namespace Utils {
402444
return;
403445
}
404446

405-
assert(array1, "array1");
406-
assert(array2, "array2");
447+
assert(!!array1, "array1");
448+
assert(!!array2, "array2");
407449
assert.equal(array1.pos, array2.pos, "array1.pos !== array2.pos");
408450
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
409451
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
@@ -1259,7 +1301,7 @@ namespace Harness {
12591301

12601302
function findResultCodeFile(fileName: string) {
12611303
const sourceFile = result.program.getSourceFile(fileName);
1262-
assert(sourceFile, "Program has no source file with name '" + fileName + "'");
1304+
assert.isDefined(sourceFile, "Program has no source file with name '" + fileName + "'");
12631305
// Is this file going to be emitted separately
12641306
let sourceFileName: string;
12651307
const outFile = options.outFile || options.out;
@@ -1942,7 +1984,7 @@ namespace Harness {
19421984
const data = testUnitData[i];
19431985
if (ts.getBaseFileName(data.name).toLowerCase() === "tsconfig.json") {
19441986
const configJson = ts.parseJsonText(data.name, data.content);
1945-
assert.isTrue(configJson.endOfFileToken !== undefined);
1987+
assert(configJson.endOfFileToken !== undefined);
19461988
let baseDir = ts.normalizePath(ts.getDirectoryPath(data.name));
19471989
if (rootDir) {
19481990
baseDir = ts.getNormalizedAbsolutePath(baseDir, rootDir);

0 commit comments

Comments
 (0)