Skip to content

Commit 4cb5a36

Browse files
committed
Merge branch 'master' into tsconfigMixedContentSupport
2 parents d528943 + a2fb5f9 commit 4cb5a36

File tree

206 files changed

+2110
-1451
lines changed

Some content is hidden

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

206 files changed

+2110
-1451
lines changed

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ var harnessSources = harnessCoreSources.concat([
250250
"convertToBase64.ts",
251251
"transpile.ts",
252252
"reuseProgramStructure.ts",
253+
"textStorage.ts",
253254
"cachingInServerLSHost.ts",
254255
"moduleResolution.ts",
255256
"tsconfigParsing.ts",

src/compiler/checker.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13475,13 +13475,14 @@ namespace ts {
1347513475
const containingClass = getContainingClass(node);
1347613476
if (containingClass) {
1347713477
const containingType = getTypeOfNode(containingClass);
13478-
const baseTypes = getBaseTypes(<InterfaceType>containingType);
13479-
if (baseTypes.length) {
13478+
let baseTypes = getBaseTypes(containingType as InterfaceType);
13479+
while (baseTypes.length) {
1348013480
const baseType = baseTypes[0];
1348113481
if (modifiers & ModifierFlags.Protected &&
1348213482
baseType.symbol === declaration.parent.symbol) {
1348313483
return true;
1348413484
}
13485+
baseTypes = getBaseTypes(baseType as InterfaceType);
1348513486
}
1348613487
}
1348713488
if (modifiers & ModifierFlags.Private) {
@@ -16207,7 +16208,7 @@ namespace ts {
1620716208
return undefined;
1620816209
}
1620916210

16210-
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefined);
16211+
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefinedOrNull);
1621116212
if (isTypeAny(onfulfilledParameterType)) {
1621216213
return undefined;
1621316214
}
@@ -16701,6 +16702,14 @@ namespace ts {
1670116702
}
1670216703
}
1670316704

16705+
function isRemovedPropertyFromObjectSpread(node: Node) {
16706+
if (isBindingElement(node) && isObjectBindingPattern(node.parent)) {
16707+
const lastElement = lastOrUndefined(node.parent.elements);
16708+
return lastElement !== node && !!lastElement.dotDotDotToken;
16709+
}
16710+
return false;
16711+
}
16712+
1670416713
function errorUnusedLocal(node: Node, name: string) {
1670516714
if (isIdentifierThatStartsWithUnderScore(node)) {
1670616715
const declaration = getRootDeclaration(node.parent);
@@ -16710,7 +16719,10 @@ namespace ts {
1671016719
return;
1671116720
}
1671216721
}
16713-
error(node, Diagnostics._0_is_declared_but_never_used, name);
16722+
16723+
if (!isRemovedPropertyFromObjectSpread(node.kind === SyntaxKind.Identifier ? node.parent : node)) {
16724+
error(node, Diagnostics._0_is_declared_but_never_used, name);
16725+
}
1671416726
}
1671516727

1671616728
function parameterNameStartsWithUnderscore(parameterName: DeclarationName) {

src/compiler/core.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -863,24 +863,6 @@ namespace ts {
863863
return result;
864864
}
865865

866-
/**
867-
* Reduce the properties defined on a map-like (but not from its prototype chain).
868-
*
869-
* NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
870-
* reduceProperties instead as it offers better performance.
871-
*
872-
* @param map The map-like to reduce
873-
* @param callback An aggregation function that is called for each entry in the map
874-
* @param initial The initial value for the reduction.
875-
*/
876-
export function reduceOwnProperties<T, U>(map: MapLike<T>, callback: (aggregate: U, value: T, key: string) => U, initial: U): U {
877-
let result = initial;
878-
for (const key in map) if (hasOwnProperty.call(map, key)) {
879-
result = callback(result, map[key], String(key));
880-
}
881-
return result;
882-
}
883-
884866
/**
885867
* Performs a shallow equality comparison of the contents of two map-likes.
886868
*

src/compiler/sourcemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ namespace ts {
427427

428428
encodeLastRecordedSourceMapSpan();
429429

430-
return stringify({
430+
return JSON.stringify({
431431
version: 3,
432432
file: sourceMapData.sourceMapFile,
433433
sourceRoot: sourceMapData.sourceMapSourceRoot,

src/compiler/transformers/ts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,11 +1223,12 @@ namespace ts {
12231223
}
12241224

12251225
const { firstAccessor, secondAccessor, setAccessor } = getAllAccessorDeclarations(node.members, accessor);
1226-
if (accessor !== firstAccessor) {
1226+
const firstAccessorWithDecorators = firstAccessor.decorators ? firstAccessor : secondAccessor && secondAccessor.decorators ? secondAccessor : undefined;
1227+
if (!firstAccessorWithDecorators || accessor !== firstAccessorWithDecorators) {
12271228
return undefined;
12281229
}
12291230

1230-
const decorators = firstAccessor.decorators || (secondAccessor && secondAccessor.decorators);
1231+
const decorators = firstAccessorWithDecorators.decorators;
12311232
const parameters = getDecoratorsOfParameters(setAccessor);
12321233
if (!decorators && !parameters) {
12331234
return undefined;

src/compiler/utilities.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,55 +3189,6 @@ namespace ts {
31893189
return output;
31903190
}
31913191

3192-
/**
3193-
* Serialize an object graph into a JSON string. This is intended only for use on an acyclic graph
3194-
* as the fallback implementation does not check for circular references by default.
3195-
*/
3196-
export const stringify: (value: any) => string = typeof JSON !== "undefined" && JSON.stringify
3197-
? JSON.stringify
3198-
: stringifyFallback;
3199-
3200-
/**
3201-
* Serialize an object graph into a JSON string.
3202-
*/
3203-
function stringifyFallback(value: any): string {
3204-
// JSON.stringify returns `undefined` here, instead of the string "undefined".
3205-
return value === undefined ? undefined : stringifyValue(value);
3206-
}
3207-
3208-
function stringifyValue(value: any): string {
3209-
return typeof value === "string" ? `"${escapeString(value)}"`
3210-
: typeof value === "number" ? isFinite(value) ? String(value) : "null"
3211-
: typeof value === "boolean" ? value ? "true" : "false"
3212-
: typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value)
3213-
: /*fallback*/ "null";
3214-
}
3215-
3216-
function cycleCheck(cb: (value: any) => string, value: any) {
3217-
Debug.assert(!value.hasOwnProperty("__cycle"), "Converting circular structure to JSON");
3218-
value.__cycle = true;
3219-
const result = cb(value);
3220-
delete value.__cycle;
3221-
return result;
3222-
}
3223-
3224-
function stringifyArray(value: any) {
3225-
return `[${reduceLeft(value, stringifyElement, "")}]`;
3226-
}
3227-
3228-
function stringifyElement(memo: string, value: any) {
3229-
return (memo ? memo + "," : memo) + stringifyValue(value);
3230-
}
3231-
3232-
function stringifyObject(value: any) {
3233-
return `{${reduceOwnProperties(value, stringifyProperty, "")}}`;
3234-
}
3235-
3236-
function stringifyProperty(memo: string, value: any, key: string) {
3237-
return value === undefined || typeof value === "function" || key === "__cycle" ? memo
3238-
: (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`;
3239-
}
3240-
32413192
const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
32423193

32433194
/**

src/harness/fourslash.ts

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,13 @@ namespace FourSlash {
607607
});
608608
}
609609

610-
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
611-
const members = this.getMemberListAtCaret();
612-
if (members) {
613-
this.assertItemInCompletionList(members.entries, symbol, text, documentation, kind);
614-
}
615-
else {
616-
this.raiseError("Expected a member list, but none was provided");
617-
}
618-
}
619-
620-
public verifyMemberListCount(expectedCount: number, negative: boolean) {
610+
public verifyCompletionListCount(expectedCount: number, negative: boolean) {
621611
if (expectedCount === 0 && negative) {
622-
this.verifyMemberListIsEmpty(/*negative*/ false);
612+
this.verifyCompletionListIsEmpty(/*negative*/ false);
623613
return;
624614
}
625615

626-
const members = this.getMemberListAtCaret();
616+
const members = this.getCompletionListAtCaret();
627617

628618
if (members) {
629619
const match = members.entries.length === expectedCount;
@@ -637,13 +627,6 @@ namespace FourSlash {
637627
}
638628
}
639629

640-
public verifyMemberListDoesNotContain(symbol: string) {
641-
const members = this.getMemberListAtCaret();
642-
if (members && members.entries.filter(e => e.name === symbol).length !== 0) {
643-
this.raiseError(`Member list did contain ${symbol}`);
644-
}
645-
}
646-
647630
public verifyCompletionListItemsCountIsGreaterThan(count: number, negative: boolean) {
648631
const completions = this.getCompletionListAtCaret();
649632
const itemsCount = completions.entries.length;
@@ -685,16 +668,6 @@ namespace FourSlash {
685668
}
686669
}
687670

688-
public verifyMemberListIsEmpty(negative: boolean) {
689-
const members = this.getMemberListAtCaret();
690-
if ((!members || members.entries.length === 0) && negative) {
691-
this.raiseError("Member list is empty at Caret");
692-
}
693-
else if ((members && members.entries.length !== 0) && !negative) {
694-
this.raiseError(`Member list is not empty at Caret:\nMember List contains: ${stringify(members.entries.map(e => e.name))}`);
695-
}
696-
}
697-
698671
public verifyCompletionListIsEmpty(negative: boolean) {
699672
const completions = this.getCompletionListAtCaret();
700673
if ((!completions || completions.entries.length === 0) && negative) {
@@ -892,10 +865,6 @@ namespace FourSlash {
892865
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(references)})`);
893866
}
894867

895-
private getMemberListAtCaret() {
896-
return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition);
897-
}
898-
899868
private getCompletionListAtCaret() {
900869
return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition);
901870
}
@@ -1353,11 +1322,6 @@ namespace FourSlash {
13531322
Harness.IO.log(stringify(sigHelp));
13541323
}
13551324

1356-
public printMemberListMembers() {
1357-
const members = this.getMemberListAtCaret();
1358-
this.printMembersOrCompletions(members);
1359-
}
1360-
13611325
public printCompletionListMembers() {
13621326
const completions = this.getCompletionListAtCaret();
13631327
this.printMembersOrCompletions(completions);
@@ -3061,19 +3025,8 @@ namespace FourSlashInterface {
30613025
}
30623026
}
30633027

3064-
// Verifies the member list contains the specified symbol. The
3065-
// member list is brought up if necessary
3066-
public memberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
3067-
if (this.negative) {
3068-
this.state.verifyMemberListDoesNotContain(symbol);
3069-
}
3070-
else {
3071-
this.state.verifyMemberListContains(symbol, text, documentation, kind);
3072-
}
3073-
}
3074-
3075-
public memberListCount(expectedCount: number) {
3076-
this.state.verifyMemberListCount(expectedCount, this.negative);
3028+
public completionListCount(expectedCount: number) {
3029+
this.state.verifyCompletionListCount(expectedCount, this.negative);
30773030
}
30783031

30793032
// Verifies the completion list contains the specified symbol. The
@@ -3109,10 +3062,6 @@ namespace FourSlashInterface {
31093062
this.state.verifyCompletionListAllowsNewIdentifier(this.negative);
31103063
}
31113064

3112-
public memberListIsEmpty() {
3113-
this.state.verifyMemberListIsEmpty(this.negative);
3114-
}
3115-
31163065
public signatureHelpPresent() {
31173066
this.state.verifySignatureHelpPresent(!this.negative);
31183067
}
@@ -3514,10 +3463,6 @@ namespace FourSlashInterface {
35143463
this.state.printCurrentSignatureHelp();
35153464
}
35163465

3517-
public printMemberListMembers() {
3518-
this.state.printMemberListMembers();
3519-
}
3520-
35213466
public printCompletionListMembers() {
35223467
this.state.printCompletionListMembers();
35233468
}

src/harness/unittests/textStorage.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/// <reference path="../harness.ts" />
2+
/// <reference path="../../server/scriptVersionCache.ts"/>
3+
/// <reference path="./tsserverProjectSystem.ts" />
4+
5+
namespace ts.textStorage {
6+
describe("Text storage", () => {
7+
const f = {
8+
path: "/a/app.ts",
9+
content: `
10+
let x = 1;
11+
let y = 2;
12+
function bar(a: number) {
13+
return a + 1;
14+
}`
15+
};
16+
17+
it("text based storage should be have exactly the same as script version cache", () => {
18+
19+
debugger
20+
const host = ts.projectSystem.createServerHost([f]);
21+
22+
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));
23+
const ts2 = new server.TextStorage(host, server.asNormalizedPath(f.path));
24+
25+
ts1.useScriptVersionCache();
26+
ts2.useText();
27+
28+
const lineMap = computeLineStarts(f.content);
29+
30+
for (let line = 0; line < lineMap.length; line++) {
31+
const start = lineMap[line];
32+
const end = line === lineMap.length - 1 ? f.path.length : lineMap[line + 1];
33+
34+
for (let offset = 0; offset < end - start; offset++) {
35+
const pos1 = ts1.lineOffsetToPosition(line + 1, offset + 1);
36+
const pos2 = ts2.lineOffsetToPosition(line + 1, offset + 1);
37+
assert.isTrue(pos1 === pos2, `lineOffsetToPosition ${line + 1}-${offset + 1}: expected ${pos1} to equal ${pos2}`);
38+
}
39+
40+
const {start: start1, length: length1 } = ts1.lineToTextSpan(line);
41+
const {start: start2, length: length2 } = ts2.lineToTextSpan(line);
42+
assert.isTrue(start1 === start2, `lineToTextSpan ${line}::start:: expected ${start1} to equal ${start2}`);
43+
assert.isTrue(length1 === length2, `lineToTextSpan ${line}::length:: expected ${length1} to equal ${length2}`);
44+
}
45+
46+
for (let pos = 0; pos < f.content.length; pos++) {
47+
const { line: line1, offset: offset1 } = ts1.positionToLineOffset(pos);
48+
const { line: line2, offset: offset2 } = ts2.positionToLineOffset(pos);
49+
assert.isTrue(line1 === line2, `positionToLineOffset ${pos}::line:: expected ${line1} to equal ${line2}`);
50+
assert.isTrue(offset1 === offset2, `positionToLineOffset ${pos}::offset:: expected ${offset1} to equal ${offset2}`);
51+
}
52+
});
53+
54+
it("should switch to script version cache if necessary", () => {
55+
const host = ts.projectSystem.createServerHost([f]);
56+
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path));
57+
58+
ts1.getSnapshot();
59+
assert.isTrue(!ts1.hasScriptVersionCache(), "should not have script version cache - 1");
60+
61+
ts1.edit(0, 5, " ");
62+
assert.isTrue(ts1.hasScriptVersionCache(), "have script version cache - 1");
63+
64+
ts1.useText();
65+
assert.isTrue(!ts1.hasScriptVersionCache(), "should not have script version cache - 2");
66+
67+
ts1.getLineInfo(0);
68+
assert.isTrue(ts1.hasScriptVersionCache(), "have script version cache - 2");
69+
})
70+
});
71+
}

0 commit comments

Comments
 (0)