Skip to content

Commit 4f5f540

Browse files
author
Andy Hanson
committed
Merge branch 'master' into completionsBracket
2 parents fd9ea5b + e3a20e7 commit 4f5f540

File tree

144 files changed

+5234
-3720
lines changed

Some content is hidden

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

144 files changed

+5234
-3720
lines changed

Diff for: src/compiler/checker.ts

+114-83
Large diffs are not rendered by default.

Diff for: src/compiler/core.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,8 @@ namespace ts {
14191419
return Array.isArray ? Array.isArray(value) : value instanceof Array;
14201420
}
14211421

1422-
export function toArray<T>(value: T | ReadonlyArray<T>): ReadonlyArray<T>;
14231422
export function toArray<T>(value: T | T[]): T[];
1423+
export function toArray<T>(value: T | ReadonlyArray<T>): ReadonlyArray<T>;
14241424
export function toArray<T>(value: T | T[]): T[] {
14251425
return isArray(value) ? value : [value];
14261426
}
@@ -3257,4 +3257,8 @@ namespace ts {
32573257
cachedReadDirectoryResult.clear();
32583258
}
32593259
}
3260+
3261+
export function singleElementArray<T>(t: T | undefined): T[] | undefined {
3262+
return t === undefined ? undefined : [t];
3263+
}
32603264
}

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,10 @@
22762276
"category": "Error",
22772277
"code": 2719
22782278
},
2279+
"Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?": {
2280+
"category": "Error",
2281+
"code": 2720
2282+
},
22792283

22802284
"Import declaration '{0}' is using private name '{1}'.": {
22812285
"category": "Error",

Diff for: src/compiler/program.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,28 @@ namespace ts {
241241
return errorMessage;
242242
}
243243

244-
const redForegroundEscapeSequence = "\u001b[91m";
245-
const yellowForegroundEscapeSequence = "\u001b[93m";
246-
const blueForegroundEscapeSequence = "\u001b[93m";
244+
/** @internal */
245+
export enum ForegroundColorEscapeSequences {
246+
Grey = "\u001b[90m",
247+
Red = "\u001b[91m",
248+
Yellow = "\u001b[93m",
249+
Blue = "\u001b[94m",
250+
Cyan = "\u001b[96m"
251+
}
247252
const gutterStyleSequence = "\u001b[30;47m";
248253
const gutterSeparator = " ";
249254
const resetEscapeSequence = "\u001b[0m";
250255
const ellipsis = "...";
251256
function getCategoryFormat(category: DiagnosticCategory): string {
252257
switch (category) {
253-
case DiagnosticCategory.Warning: return yellowForegroundEscapeSequence;
254-
case DiagnosticCategory.Error: return redForegroundEscapeSequence;
255-
case DiagnosticCategory.Message: return blueForegroundEscapeSequence;
258+
case DiagnosticCategory.Warning: return ForegroundColorEscapeSequences.Yellow;
259+
case DiagnosticCategory.Error: return ForegroundColorEscapeSequences.Red;
260+
case DiagnosticCategory.Message: return ForegroundColorEscapeSequences.Blue;
256261
}
257262
}
258263

259-
function formatAndReset(text: string, formatStyle: string) {
264+
/** @internal */
265+
export function formatColorAndReset(text: string, formatStyle: string) {
260266
return formatStyle + text + resetEscapeSequence;
261267
}
262268

@@ -289,7 +295,7 @@ namespace ts {
289295
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
290296
// so we'll skip ahead to the second-to-last line.
291297
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
292-
context += formatAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
298+
context += formatColorAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
293299
i = lastLine - 1;
294300
}
295301

@@ -300,12 +306,12 @@ namespace ts {
300306
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
301307

302308
// Output the gutter and the actual contents of the line.
303-
context += formatAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
309+
context += formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
304310
context += lineContent + host.getNewLine();
305311

306312
// Output the gutter and the error span for the line using tildes.
307-
context += formatAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
308-
context += redForegroundEscapeSequence;
313+
context += formatColorAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
314+
context += ForegroundColorEscapeSequences.Red;
309315
if (i === firstLine) {
310316
// If we're on the last line, then limit it to the last character of the last line.
311317
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
@@ -324,13 +330,19 @@ namespace ts {
324330
context += resetEscapeSequence;
325331
}
326332

327-
output += host.getNewLine();
328-
output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `;
333+
output += formatColorAndReset(relativeFileName, ForegroundColorEscapeSequences.Cyan);
334+
output += "(";
335+
output += formatColorAndReset(`${ firstLine + 1 }`, ForegroundColorEscapeSequences.Yellow);
336+
output += ",";
337+
output += formatColorAndReset(`${ firstLineChar + 1 }`, ForegroundColorEscapeSequences.Yellow);
338+
output += "): ";
329339
}
330340

331341
const categoryColor = getCategoryFormat(diagnostic.category);
332342
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
333-
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }`;
343+
output += formatColorAndReset(category, categoryColor);
344+
output += formatColorAndReset(` TS${ diagnostic.code }: `, ForegroundColorEscapeSequences.Grey);
345+
output += flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine());
334346

335347
if (diagnostic.file) {
336348
output += host.getNewLine();
@@ -339,7 +351,7 @@ namespace ts {
339351

340352
output += host.getNewLine();
341353
}
342-
return output;
354+
return output + host.getNewLine();
343355
}
344356

345357
export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string {

Diff for: src/compiler/transformers/esnext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ namespace ts {
968968
name: "typescript:asyncValues",
969969
scoped: false,
970970
text: `
971-
var __asyncValues = (this && this.__asyncIterator) || function (o) {
971+
var __asyncValues = (this && this.__asyncValues) || function (o) {
972972
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
973973
var m = o[Symbol.asyncIterator];
974974
return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator]();

Diff for: src/compiler/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,8 @@ namespace ts {
27852785

27862786
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
27872787
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
2788+
/** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */
2789+
/* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression, type: Type, property: Symbol): boolean;
27882790
/** Follow all aliases to get the original symbol. */
27892791
getAliasedSymbol(symbol: Symbol): Symbol;
27902792
/** Follow a *single* alias to get the immediately aliased symbol. */

Diff for: src/compiler/utilities.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* @internal */
44
namespace ts {
55
export const emptyArray: never[] = [] as never[];
6+
export const resolvingEmptyArray: never[] = [] as never[];
67
export const emptyMap: ReadonlyMap<never> = createMap<never>();
78

89
export const externalHelpersModuleNameText = "tslib";
@@ -5233,6 +5234,18 @@ namespace ts {
52335234
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
52345235
}
52355236

5237+
/* @internal */
5238+
export function isMethodOrAccessor(node: Node): node is MethodDeclaration | AccessorDeclaration {
5239+
switch (node.kind) {
5240+
case SyntaxKind.MethodDeclaration:
5241+
case SyntaxKind.GetAccessor:
5242+
case SyntaxKind.SetAccessor:
5243+
return true;
5244+
default:
5245+
return false;
5246+
}
5247+
}
5248+
52365249
// Type members
52375250

52385251
export function isTypeElement(node: Node): node is TypeElement {

Diff for: src/compiler/watch.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ namespace ts {
4848
};
4949
}
5050

51+
/** @internal */
52+
export function createWatchDiagnosticReporterWithColor(system = sys): DiagnosticReporter {
53+
return diagnostic => {
54+
let output = `[${ formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey) }] `;
55+
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${system.newLine + system.newLine + system.newLine}`;
56+
system.write(output);
57+
};
58+
}
59+
5160
export function reportDiagnostics(diagnostics: Diagnostic[], reportDiagnostic: DiagnosticReporter): void {
5261
for (const diagnostic of diagnostics) {
5362
reportDiagnostic(diagnostic);
@@ -131,7 +140,7 @@ namespace ts {
131140
reportWatchDiagnostic?: DiagnosticReporter
132141
): WatchingSystemHost {
133142
reportDiagnostic = reportDiagnostic || createDiagnosticReporter(system, pretty ? reportDiagnosticWithColorAndContext : reportDiagnosticSimply);
134-
reportWatchDiagnostic = reportWatchDiagnostic || createWatchDiagnosticReporter(system);
143+
reportWatchDiagnostic = reportWatchDiagnostic || pretty ? createWatchDiagnosticReporterWithColor(system) : createWatchDiagnosticReporter(system);
135144
parseConfigFile = parseConfigFile || ts.parseConfigFile;
136145
return {
137146
system,

Diff for: src/harness/externalCompileRunner.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,29 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
4242
const stdio = isWorker ? "pipe" : "inherit";
4343
let types: string[];
4444
if (fs.existsSync(path.join(cwd, "test.json"))) {
45-
const update = cp.spawnSync("git", ["submodule", "update", "--remote"], { cwd, timeout, shell: true, stdio });
46-
if (update.status !== 0) throw new Error(`git submodule update for ${directoryName} failed!`);
45+
const submoduleDir = path.join(cwd, directoryName);
46+
const reset = cp.spawnSync("git", ["reset", "HEAD", "--hard"], { cwd: submoduleDir, timeout, shell: true, stdio });
47+
if (reset.status !== 0) throw new Error(`git reset for ${directoryName} failed: ${reset.stderr.toString()}`);
48+
const clean = cp.spawnSync("git", ["clean", "-f"], { cwd: submoduleDir, timeout, shell: true, stdio });
49+
if (clean.status !== 0) throw new Error(`git clean for ${directoryName} failed: ${clean.stderr.toString()}`);
50+
const update = cp.spawnSync("git", ["submodule", "update", "--remote", "."], { cwd: submoduleDir, timeout, shell: true, stdio });
51+
if (update.status !== 0) throw new Error(`git submodule update for ${directoryName} failed: ${update.stderr.toString()}`);
4752

4853
const config = JSON.parse(fs.readFileSync(path.join(cwd, "test.json"), { encoding: "utf8" })) as UserConfig;
4954
ts.Debug.assert(!!config.types, "Bad format from test.json: Types field must be present.");
5055
types = config.types;
5156

52-
cwd = path.join(cwd, directoryName);
57+
cwd = submoduleDir;
5358
}
5459
if (fs.existsSync(path.join(cwd, "package.json"))) {
5560
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
5661
fs.unlinkSync(path.join(cwd, "package-lock.json"));
5762
}
63+
if (fs.existsSync(path.join(cwd, "node_modules"))) {
64+
require("del").sync(path.join(cwd, "node_modules"));
65+
}
5866
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
59-
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
67+
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed: ${install.stderr.toString()}`);
6068
}
6169
const args = [path.join(__dirname, "tsc.js")];
6270
if (types) {

Diff for: src/harness/fourslash.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,11 @@ namespace FourSlash {
441441
this.goToPosition(marker.position);
442442
}
443443

444-
public goToEachMarker(action: () => void) {
445-
const markers = this.getMarkers();
444+
public goToEachMarker(markers: ReadonlyArray<Marker>, action: (marker: FourSlash.Marker, index: number) => void) {
446445
assert(markers.length);
447-
for (const marker of markers) {
448-
this.goToMarker(marker);
449-
action();
446+
for (let i = 0; i < markers.length; i++) {
447+
this.goToMarker(markers[i]);
448+
action(markers[i], i);
450449
}
451450
}
452451

@@ -3779,8 +3778,11 @@ namespace FourSlashInterface {
37793778
this.state.goToMarker(name);
37803779
}
37813780

3782-
public eachMarker(action: () => void) {
3783-
this.state.goToEachMarker(action);
3781+
public eachMarker(markers: ReadonlyArray<string>, action: (marker: FourSlash.Marker, index: number) => void): void;
3782+
public eachMarker(action: (marker: FourSlash.Marker, index: number) => void): void;
3783+
public eachMarker(a: ReadonlyArray<string> | ((marker: FourSlash.Marker, index: number) => void), b?: (marker: FourSlash.Marker, index: number) => void): void {
3784+
const markers = typeof a === "function" ? this.state.getMarkers() : a.map(m => this.state.getMarkerByName(m));
3785+
this.state.goToEachMarker(markers, typeof a === "function" ? a : b);
37843786
}
37853787

37863788
public rangeStart(range: FourSlash.Range) {

Diff for: src/harness/unittests/tsserverProjectSystem.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,24 @@ namespace ts.projectSystem {
11841184
checkNumberOfInferredProjects(projectService, 0);
11851185
});
11861186

1187+
it("external project for dynamic file", () => {
1188+
const externalProjectName = "^ScriptDocument1 file1.ts";
1189+
const externalFiles = toExternalFiles(["^ScriptDocument1 file1.ts"]);
1190+
const host = createServerHost([]);
1191+
const projectService = createProjectService(host);
1192+
projectService.openExternalProject({
1193+
rootFiles: externalFiles,
1194+
options: {},
1195+
projectFileName: externalProjectName
1196+
});
1197+
1198+
checkNumberOfExternalProjects(projectService, 1);
1199+
checkNumberOfInferredProjects(projectService, 0);
1200+
1201+
externalFiles[0].content = "let x =1;";
1202+
projectService.applyChangesInOpenFiles(externalFiles, [], []);
1203+
});
1204+
11871205
it("external project that included config files", () => {
11881206
const file1 = {
11891207
path: "/a/b/f1.ts",

Diff for: src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl

+11-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
<Str Cat="Text">
155155
<Val><![CDATA[A computed property name in a method overload must refer to an expression whose type is a literal type or a 'unique symbol' type.]]></Val>
156156
<Tgt Cat="Text" Stat="Loc" Orig="New">
157-
<Val><![CDATA[方法重载中的计算属性名称必须引用类型为文本类型或 "unique symbol" 类型的表达式。]]></Val>
157+
<Val><![CDATA[方法重载中的计算属性名称必须引用文本类型或 "unique symbol" 类型的表达式。]]></Val>
158158
</Tgt>
159159
</Str>
160160
<Disp Icon="Str" />
@@ -1384,7 +1384,7 @@
13841384
<Str Cat="Text">
13851385
<Val><![CDATA[Annotate with type from JSDoc]]></Val>
13861386
<Tgt Cat="Text" Stat="Loc" Orig="New">
1387-
<Val><![CDATA[使用 JSDoc 中的类型批注]]></Val>
1387+
<Val><![CDATA[通过 JSDoc 类型批注]]></Val>
13881388
</Tgt>
13891389
</Str>
13901390
<Disp Icon="Str" />
@@ -2070,6 +2070,15 @@
20702070
</Str>
20712071
<Disp Icon="Str" />
20722072
</Item>
2073+
<Item ItemId=";Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720" ItemType="0" PsrId="306" Leaf="true">
2074+
<Str Cat="Text">
2075+
<Val><![CDATA[Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?]]></Val>
2076+
<Tgt Cat="Text" Stat="Loc" Orig="New">
2077+
<Val><![CDATA[类“{0}”错误实现类“{1}”。你是想扩展“{1}”并将其成员作为子类继承吗?]]></Val>
2078+
</Tgt>
2079+
</Str>
2080+
<Disp Icon="Str" />
2081+
</Item>
20732082
<Item ItemId=";Class_0_incorrectly_implements_interface_1_2420" ItemType="0" PsrId="306" Leaf="true">
20742083
<Str Cat="Text">
20752084
<Val><![CDATA[Class '{0}' incorrectly implements interface '{1}'.]]></Val>

Diff for: src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl

+11-2
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,15 @@
20702070
</Str>
20712071
<Disp Icon="Str" />
20722072
</Item>
2073+
<Item ItemId=";Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720" ItemType="0" PsrId="306" Leaf="true">
2074+
<Str Cat="Text">
2075+
<Val><![CDATA[Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?]]></Val>
2076+
<Tgt Cat="Text" Stat="Loc" Orig="New">
2077+
<Val><![CDATA[類別 '{0}' 不當實作類別 '{1}'。您是否要擴充 '{1}',並繼承其成員以成為子類別?]]></Val>
2078+
</Tgt>
2079+
</Str>
2080+
<Disp Icon="Str" />
2081+
</Item>
20732082
<Item ItemId=";Class_0_incorrectly_implements_interface_1_2420" ItemType="0" PsrId="306" Leaf="true">
20742083
<Str Cat="Text">
20752084
<Val><![CDATA[Class '{0}' incorrectly implements interface '{1}'.]]></Val>
@@ -3247,7 +3256,7 @@
32473256
<Str Cat="Text">
32483257
<Val><![CDATA[Expression resolves to variable declaration '_newTarget' that compiler uses to capture 'new.target' meta-property reference.]]></Val>
32493258
<Tgt Cat="Text" Stat="Loc" Orig="New">
3250-
<Val><![CDATA[運算式解析成編譯器用來擷取 'new.target' 中繼屬性參考的變數宣告 '_newTarget']]></Val>
3259+
<Val><![CDATA[運算式將解析成變數宣告 '_newTarget',而供編譯器用來擷取 'new.target' 中繼屬性參考]]></Val>
32513260
</Tgt>
32523261
</Str>
32533262
<Disp Icon="Str" />
@@ -6646,7 +6655,7 @@
66466655
<Str Cat="Text">
66476656
<Val><![CDATA[Stylize errors and messages using color and context (experimental).]]></Val>
66486657
<Tgt Cat="Text" Stat="Loc" Orig="New">
6649-
<Val><![CDATA[使用色彩及內容設計錯誤與訊息的風格 (實驗)。]]></Val>
6658+
<Val><![CDATA[使用色彩及內容來設計錯誤與訊息的風格 (實驗)。]]></Val>
66506659
</Tgt>
66516660
<Prev Cat="Text">
66526661
<Val><![CDATA[Stylize errors and messages using color and context. (experimental)]]></Val>

0 commit comments

Comments
 (0)