Skip to content

Commit 5c9ce9e

Browse files
author
Zhengbo Li
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into fixLargeProjectTry2
# Conflicts: # src/compiler/sys.ts
2 parents 1b76294 + 89350b3 commit 5c9ce9e

13 files changed

Lines changed: 374 additions & 75 deletions

src/compiler/checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,7 +5643,7 @@ namespace ts {
56435643
}
56445644
if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True;
56455645
if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) {
5646-
if (result = enumRelatedTo(source, target)) {
5646+
if (result = enumRelatedTo(source, target, reportErrors)) {
56475647
return result;
56485648
}
56495649
}
@@ -6266,7 +6266,7 @@ namespace ts {
62666266
return Ternary.False;
62676267
}
62686268

6269-
function enumRelatedTo(source: Type, target: Type) {
6269+
function enumRelatedTo(source: Type, target: Type, reportErrors?: boolean) {
62706270
if (source.symbol.name !== target.symbol.name ||
62716271
source.symbol.flags & SymbolFlags.ConstEnum ||
62726272
target.symbol.flags & SymbolFlags.ConstEnum) {
@@ -6277,9 +6277,11 @@ namespace ts {
62776277
if (property.flags & SymbolFlags.EnumMember) {
62786278
const targetProperty = getPropertyOfType(targetEnumType, property.name);
62796279
if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) {
6280-
reportError(Diagnostics.Property_0_is_missing_in_type_1,
6281-
property.name,
6282-
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
6280+
if (reportErrors) {
6281+
reportError(Diagnostics.Property_0_is_missing_in_type_1,
6282+
property.name,
6283+
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
6284+
}
62836285
return Ternary.False;
62846286
}
62856287
}

src/compiler/sys.ts

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// <reference path="core.ts"/>
22

33
namespace ts {
4-
export type FileWatcherCallback = (path: string, removed?: boolean) => void;
5-
export type DirectoryWatcherCallback = (path: string) => void;
4+
export type FileWatcherCallback = (fileName: string, removed?: boolean) => void;
5+
export type DirectoryWatcherCallback = (directoryName: string) => void;
66

77
export interface System {
88
args: string[];
@@ -12,7 +12,7 @@ namespace ts {
1212
readFile(path: string, encoding?: string): string;
1313
getFileSize?(path: string): number;
1414
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
15-
watchFile?(path: Path, callback: FileWatcherCallback): FileWatcher;
15+
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
1616
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
1717
resolvePath(path: string): string;
1818
fileExists(path: string): boolean;
@@ -27,7 +27,7 @@ namespace ts {
2727
}
2828

2929
interface WatchedFile {
30-
filePath: Path;
30+
fileName: string;
3131
callback: FileWatcherCallback;
3232
mtime?: Date;
3333
}
@@ -37,7 +37,7 @@ namespace ts {
3737
}
3838

3939
export interface DirectoryWatcher extends FileWatcher {
40-
directoryPath: Path;
40+
directoryName: string;
4141
referenceCount: number;
4242
}
4343

@@ -246,13 +246,13 @@ namespace ts {
246246
return;
247247
}
248248

249-
_fs.stat(watchedFile.filePath, (err: any, stats: any) => {
249+
_fs.stat(watchedFile.fileName, (err: any, stats: any) => {
250250
if (err) {
251-
watchedFile.callback(watchedFile.filePath);
251+
watchedFile.callback(watchedFile.fileName);
252252
}
253253
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
254-
watchedFile.mtime = getModifiedTime(watchedFile.filePath);
255-
watchedFile.callback(watchedFile.filePath, watchedFile.mtime.getTime() === 0);
254+
watchedFile.mtime = getModifiedTime(watchedFile.fileName);
255+
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
256256
}
257257
});
258258
}
@@ -280,11 +280,11 @@ namespace ts {
280280
}, interval);
281281
}
282282

283-
function addFile(filePath: Path, callback: FileWatcherCallback): WatchedFile {
283+
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
284284
const file: WatchedFile = {
285-
filePath,
285+
fileName,
286286
callback,
287-
mtime: getModifiedTime(filePath)
287+
mtime: getModifiedTime(fileName)
288288
};
289289

290290
watchedFiles.push(file);
@@ -308,26 +308,26 @@ namespace ts {
308308
}
309309

310310
function createWatchedFileSet() {
311-
const dirWatchers = createFileMap<DirectoryWatcher>();
311+
const dirWatchers: Map<DirectoryWatcher> = {};
312312
// One file can have multiple watchers
313-
const fileWatcherCallbacks = createFileMap<FileWatcherCallback[]>();
313+
const fileWatcherCallbacks: Map<FileWatcherCallback[]> = {};
314314
return { addFile, removeFile };
315315

316-
function reduceDirWatcherRefCountForFile(filePath: Path) {
317-
const dirPath = getDirectoryPath(filePath);
318-
if (dirWatchers.contains(dirPath)) {
319-
const watcher = dirWatchers.get(dirPath);
316+
function reduceDirWatcherRefCountForFile(fileName: string) {
317+
const dirName = getDirectoryPath(fileName);
318+
if (hasProperty(dirWatchers, dirName)) {
319+
const watcher = dirWatchers[dirName];
320320
watcher.referenceCount -= 1;
321321
if (watcher.referenceCount <= 0) {
322322
watcher.close();
323-
dirWatchers.remove(dirPath);
323+
delete dirWatchers[dirName];
324324
}
325325
}
326326
}
327327

328-
function addDirWatcher(dirPath: Path): void {
329-
if (dirWatchers.contains(dirPath)) {
330-
const watcher = dirWatchers.get(dirPath);
328+
function addDirWatcher(dirPath: string): void {
329+
if (hasProperty(dirWatchers, dirPath)) {
330+
const watcher = dirWatchers[dirPath];
331331
watcher.referenceCount += 1;
332332
return;
333333
}
@@ -338,52 +338,52 @@ namespace ts {
338338
(eventName: string, relativeFileName: string) => fileEventHandler(eventName, relativeFileName, dirPath)
339339
);
340340
watcher.referenceCount = 1;
341-
dirWatchers.set(dirPath, watcher);
341+
dirWatchers[dirPath] = watcher;
342342
return;
343343
}
344344

345-
function addFileWatcherCallback(filePath: Path, callback: FileWatcherCallback): void {
346-
if (fileWatcherCallbacks.contains(filePath)) {
347-
fileWatcherCallbacks.get(filePath).push(callback);
345+
function addFileWatcherCallback(filePath: string, callback: FileWatcherCallback): void {
346+
if (hasProperty(fileWatcherCallbacks, filePath)) {
347+
fileWatcherCallbacks[filePath].push(callback);
348348
}
349349
else {
350-
fileWatcherCallbacks.set(filePath, [callback]);
350+
fileWatcherCallbacks[filePath] = [callback];
351351
}
352352
}
353353

354-
function addFile(filePath: Path, callback: FileWatcherCallback): WatchedFile {
355-
addFileWatcherCallback(filePath, callback);
356-
addDirWatcher(getDirectoryPath(filePath));
354+
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
355+
addFileWatcherCallback(fileName, callback);
356+
addDirWatcher(getDirectoryPath(fileName));
357357

358-
return { filePath, callback };
358+
return { fileName, callback };
359359
}
360360

361361
function removeFile(watchedFile: WatchedFile) {
362-
removeFileWatcherCallback(watchedFile.filePath, watchedFile.callback);
363-
reduceDirWatcherRefCountForFile(watchedFile.filePath);
362+
removeFileWatcherCallback(watchedFile.fileName, watchedFile.callback);
363+
reduceDirWatcherRefCountForFile(watchedFile.fileName);
364364
}
365365

366-
function removeFileWatcherCallback(filePath: Path, callback: FileWatcherCallback) {
367-
if (fileWatcherCallbacks.contains(filePath)) {
368-
const newCallbacks = copyListRemovingItem(callback, fileWatcherCallbacks.get(filePath));
366+
function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) {
367+
if (hasProperty(fileWatcherCallbacks, filePath)) {
368+
const newCallbacks = copyListRemovingItem(callback, fileWatcherCallbacks[filePath]);
369369
if (newCallbacks.length === 0) {
370-
fileWatcherCallbacks.remove(filePath);
370+
delete fileWatcherCallbacks[filePath];
371371
}
372372
else {
373-
fileWatcherCallbacks.set(filePath, newCallbacks);
373+
fileWatcherCallbacks[filePath] = newCallbacks;
374374
}
375375
}
376376
}
377377

378-
function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: Path) {
378+
function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: string) {
379379
// When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined"
380-
const filePath = typeof relativeFileName !== "string"
380+
const fileName = typeof relativeFileName !== "string"
381381
? undefined
382-
: toPath(relativeFileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
382+
: ts.getNormalizedAbsolutePath(relativeFileName, baseDirPath);
383383
// Some applications save a working file via rename operations
384-
if ((eventName === "change" || eventName === "rename") && fileWatcherCallbacks.contains(filePath)) {
385-
for (const fileCallback of fileWatcherCallbacks.get(filePath)) {
386-
fileCallback(filePath);
384+
if ((eventName === "change" || eventName === "rename") && hasProperty(fileWatcherCallbacks, fileName)) {
385+
for (const fileCallback of fileWatcherCallbacks[fileName]) {
386+
fileCallback(fileName);
387387
}
388388
}
389389
}
@@ -495,6 +495,11 @@ namespace ts {
495495
const files = _fs.readdirSync(path || ".").sort();
496496
const directories: string[] = [];
497497
for (const current of files) {
498+
// This is necessary because on some file system node fails to exclude
499+
// "." and "..". See https://github.com/nodejs/node/issues/4002
500+
if (current === "." || current === "..") {
501+
continue;
502+
}
498503
const name = combinePaths(path, current);
499504
if (!contains(exclude, getCanonicalPath(name))) {
500505
// fs.statSync would throw an exception if the file is a symlink
@@ -553,18 +558,18 @@ namespace ts {
553558
},
554559
readFile,
555560
writeFile,
556-
watchFile: (filePath, callback) => {
561+
watchFile: (fileName, callback) => {
557562
// Node 4.0 stabilized the `fs.watch` function on Windows which avoids polling
558563
// and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649
559564
// and https://github.com/Microsoft/TypeScript/issues/4643), therefore
560565
// if the current node.js version is newer than 4, use `fs.watch` instead.
561566
const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet;
562-
const watchedFile = watchSet.addFile(filePath, callback);
567+
const watchedFile = watchSet.addFile(fileName, callback);
563568
return {
564569
close: () => watchSet.removeFile(watchedFile)
565570
};
566571
},
567-
watchDirectory: (path, callback, recursive) => {
572+
watchDirectory: (directoryName, callback, recursive) => {
568573
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
569574
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
570575
let options: any;
@@ -576,15 +581,15 @@ namespace ts {
576581
}
577582

578583
return _fs.watch(
579-
path,
584+
directoryName,
580585
options,
581586
(eventName: string, relativeFileName: string) => {
582587
// In watchDirectory we only care about adding and removing files (when event name is
583588
// "rename"); changes made within files are handled by corresponding fileWatchers (when
584589
// event name is "change")
585590
if (eventName === "rename") {
586591
// When deleting a file, the passed baseFileName is null
587-
callback(!relativeFileName ? relativeFileName : normalizePath(combinePaths(path, relativeFileName)));
592+
callback(!relativeFileName ? relativeFileName : normalizePath(combinePaths(directoryName, relativeFileName)));
588593
};
589594
}
590595
);

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ namespace FourSlash {
14141414
return;
14151415
}
14161416

1417-
const incrementalSourceFile = this.languageService.getSourceFile(this.activeFile.fileName);
1417+
const incrementalSourceFile = this.languageService.getNonBoundSourceFile(this.activeFile.fileName);
14181418
Utils.assertInvariants(incrementalSourceFile, /*parent:*/ undefined);
14191419

14201420
const incrementalSyntaxDiagnostics = incrementalSourceFile.parseDiagnostics;

src/harness/harnessLanguageService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ namespace Harness.LanguageService {
423423
getProgram(): ts.Program {
424424
throw new Error("Program can not be marshaled across the shim layer.");
425425
}
426-
getSourceFile(fileName: string): ts.SourceFile {
426+
getNonBoundSourceFile(fileName: string): ts.SourceFile {
427427
throw new Error("SourceFile can not be marshaled across the shim layer.");
428428
}
429429
dispose(): void { this.shim.dispose({}); }

src/server/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ namespace ts.server {
613613
throw new Error("SourceFile objects are not serializable through the server protocol.");
614614
}
615615

616-
getSourceFile(fileName: string): SourceFile {
616+
getNonBoundSourceFile(fileName: string): SourceFile {
617617
throw new Error("SourceFile objects are not serializable through the server protocol.");
618618
}
619619

src/server/editorServices.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,7 @@ namespace ts.server {
10821082
info.setFormatOptions(this.getFormatCodeOptions());
10831083
this.filenameToScriptInfo[fileName] = info;
10841084
if (!info.isOpen) {
1085-
info.fileWatcher = this.host.watchFile(
1086-
toPath(fileName, fileName, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
1087-
_ => { this.watchedFileChanged(fileName); });
1085+
info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); });
10881086
}
10891087
}
10901088
}
@@ -1336,9 +1334,7 @@ namespace ts.server {
13361334
}
13371335
}
13381336
project.finishGraph();
1339-
project.projectFileWatcher = this.host.watchFile(
1340-
toPath(configFilename, configFilename, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
1341-
_ => this.watchedProjectConfigFileChanged(project));
1337+
project.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(project));
13421338
this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename));
13431339
project.directoryWatcher = this.host.watchDirectory(
13441340
ts.getDirectoryPath(configFilename),
@@ -1479,7 +1475,7 @@ namespace ts.server {
14791475
}
14801476

14811477
isExternalModule(filename: string): boolean {
1482-
const sourceFile = this.languageService.getSourceFile(filename);
1478+
const sourceFile = this.languageService.getNonBoundSourceFile(filename);
14831479
return ts.isExternalModule(sourceFile);
14841480
}
14851481

0 commit comments

Comments
 (0)