Skip to content

Commit 1bbe661

Browse files
committed
Merge branch 'master' into esau-squash
2 parents c184ad7 + bb9e059 commit 1bbe661

File tree

118 files changed

+3820
-2687
lines changed

Some content is hidden

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

118 files changed

+3820
-2687
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ tests/services/browser/typescriptServices.js
2323
src/harness/*.js
2424
src/compiler/diagnosticInformationMap.generated.ts
2525
src/compiler/diagnosticMessages.generated.json
26+
src/parser/diagnosticInformationMap.generated.ts
27+
src/parser/diagnosticMessages.generated.json
2628
rwc-report.html
2729
*.swp
2830
build.json

scripts/processDiagnosticMessages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
6060
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string, thisFilePathRel: string): string {
6161
let result =
6262
"// <auto-generated />\r\n" +
63-
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel + "'\r\n" +
63+
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel.replace(/\\/g, '/') + "'\r\n" +
6464
"/* @internal */\r\n" +
6565
"namespace ts {\r\n" +
6666
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}): DiagnosticMessage {\r\n" +
@@ -119,4 +119,4 @@ function convertPropertyName(origName: string): string {
119119
return result;
120120
}
121121

122-
main();
122+
main();

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,11 +2514,12 @@ namespace ts {
25142514
return true;
25152515
}
25162516
const node = symbol.valueDeclaration;
2517-
const init = !node ? undefined :
2517+
let init = !node ? undefined :
25182518
isVariableDeclaration(node) ? node.initializer :
25192519
isBinaryExpression(node) ? node.right :
25202520
isPropertyAccessExpression(node) && isBinaryExpression(node.parent) ? node.parent.right :
25212521
undefined;
2522+
init = init && getRightMostAssignedExpression(init);
25222523
if (init) {
25232524
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
25242525
return !!getJavascriptInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);

src/compiler/checker.ts

Lines changed: 140 additions & 79 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,13 @@ namespace ts {
475475
{
476476
name: "sourceRoot",
477477
type: "string",
478-
isFilePath: true,
479478
paramType: Diagnostics.LOCATION,
480479
category: Diagnostics.Source_Map_Options,
481480
description: Diagnostics.Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
482481
},
483482
{
484483
name: "mapRoot",
485484
type: "string",
486-
isFilePath: true,
487485
paramType: Diagnostics.LOCATION,
488486
category: Diagnostics.Source_Map_Options,
489487
description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,

src/compiler/moduleSpecifiers.ts

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ namespace ts.moduleSpecifiers {
1515
// For each symlink/original for a module, returns a list of ways to import that file.
1616
export function getModuleSpecifiers(
1717
moduleSymbol: Symbol,
18-
program: Program,
18+
compilerOptions: CompilerOptions,
1919
importingSourceFile: SourceFile,
2020
host: ModuleSpecifierResolutionHost,
21+
files: ReadonlyArray<SourceFile>,
2122
preferences: ModuleSpecifierPreferences,
2223
): ReadonlyArray<ReadonlyArray<string>> {
2324
const ambient = tryGetModuleNameFromAmbientModule(moduleSymbol);
2425
if (ambient) return [[ambient]];
2526

26-
const compilerOptions = program.getCompilerOptions();
27-
const info = getInfo(compilerOptions, importingSourceFile, importingSourceFile.fileName, host);
28-
const modulePaths = getAllModulePaths(program, getSourceFileOfNode(moduleSymbol.valueDeclaration));
27+
const info = getInfo(compilerOptions, importingSourceFile, importingSourceFile.path, host);
28+
if (!files) {
29+
return Debug.fail("Files list must be present to resolve symlinks in specifier resolution");
30+
}
31+
const modulePaths = getAllModulePaths(files, getSourceFileOfNode(moduleSymbol.valueDeclaration), info.getCanonicalFileName, host);
2932

3033
const global = mapDefined(modulePaths, moduleFileName => getGlobalModuleSpecifier(moduleFileName, info, host, compilerOptions));
3134
return global.length ? global.map(g => [g]) : modulePaths.map(moduleFileName =>
@@ -130,15 +133,57 @@ namespace ts.moduleSpecifiers {
130133
return firstDefined(imports, ({ text }) => pathIsRelative(text) ? fileExtensionIs(text, Extension.Js) : undefined) || false;
131134
}
132135

136+
function discoverProbableSymlinks(files: ReadonlyArray<SourceFile>) {
137+
const symlinks = mapDefined(files, sf =>
138+
sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res =>
139+
res && res.originalPath && res.resolvedFileName !== res.originalPath ? [res.resolvedFileName, res.originalPath] : undefined));
140+
const result = createMap<string>();
141+
if (symlinks) {
142+
for (const [resolvedPath, originalPath] of symlinks) {
143+
const resolvedParts = getPathComponents(resolvedPath);
144+
const originalParts = getPathComponents(originalPath);
145+
while (resolvedParts[resolvedParts.length - 1] === originalParts[originalParts.length - 1]) {
146+
resolvedParts.pop();
147+
originalParts.pop();
148+
}
149+
result.set(getPathFromPathComponents(originalParts), getPathFromPathComponents(resolvedParts));
150+
}
151+
}
152+
return result;
153+
}
154+
155+
function getAllModulePathsUsingIndirectSymlinks(files: ReadonlyArray<SourceFile>, target: string, getCanonicalFileName: (file: string) => string, host: ModuleSpecifierResolutionHost) {
156+
const links = discoverProbableSymlinks(files);
157+
const paths = arrayFrom(links.keys());
158+
let options: string[] | undefined;
159+
for (const path of paths) {
160+
const resolved = links.get(path)!;
161+
if (startsWith(target, resolved + "/")) {
162+
const relative = getRelativePathFromDirectory(resolved, target, getCanonicalFileName);
163+
const option = resolvePath(path, relative);
164+
if (!host.fileExists || host.fileExists(option)) {
165+
if (!options) options = [];
166+
options.push(option);
167+
}
168+
}
169+
}
170+
const resolvedtarget = host.getCurrentDirectory ? resolvePath(host.getCurrentDirectory(), target) : target;
171+
if (options) {
172+
options.push(resolvedtarget); // Since these are speculative, we also include the original resolved name as a possibility
173+
return options;
174+
}
175+
return [resolvedtarget];
176+
}
177+
133178
/**
134179
* Looks for a existing imports that use symlinks to this module.
135180
* Only if no symlink is available, the real path will be used.
136181
*/
137-
function getAllModulePaths(program: Program, { fileName }: SourceFile): ReadonlyArray<string> {
138-
const symlinks = mapDefined(program.getSourceFiles(), sf =>
182+
function getAllModulePaths(files: ReadonlyArray<SourceFile>, { fileName }: SourceFile, getCanonicalFileName: (file: string) => string, host: ModuleSpecifierResolutionHost): ReadonlyArray<string> {
183+
const symlinks = mapDefined(files, sf =>
139184
sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res =>
140185
res && res.resolvedFileName === fileName ? res.originalPath : undefined));
141-
return symlinks.length === 0 ? [fileName] : symlinks;
186+
return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, fileName, getCanonicalFileName, host) : symlinks;
142187
}
143188

144189
function getRelativePathNParents(relativePath: string): number {

src/compiler/parser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ namespace ts {
491491
case SyntaxKind.JSDocCallbackTag:
492492
return visitNode(cbNode, (node as JSDocCallbackTag).fullName) ||
493493
visitNode(cbNode, (node as JSDocCallbackTag).typeExpression);
494+
case SyntaxKind.JSDocThisTag:
495+
return visitNode(cbNode, (node as JSDocThisTag).typeExpression);
494496
case SyntaxKind.JSDocSignature:
495497
return visitNodes(cbNode, cbNodes, node.decorators) ||
496498
visitNodes(cbNode, cbNodes, node.modifiers) ||
@@ -6497,6 +6499,9 @@ namespace ts {
64976499
case "constructor":
64986500
tag = parseClassTag(atToken, tagName);
64996501
break;
6502+
case "this":
6503+
tag = parseThisTag(atToken, tagName);
6504+
break;
65006505
case "arg":
65016506
case "argument":
65026507
case "param":
@@ -6768,6 +6773,15 @@ namespace ts {
67686773
return finishNode(tag);
67696774
}
67706775

6776+
function parseThisTag(atToken: AtToken, tagName: Identifier): JSDocThisTag {
6777+
const tag = <JSDocThisTag>createNode(SyntaxKind.JSDocThisTag, atToken.pos);
6778+
tag.atToken = atToken;
6779+
tag.tagName = tagName;
6780+
tag.typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true);
6781+
skipWhitespace();
6782+
return finishNode(tag);
6783+
}
6784+
67716785
function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag {
67726786
const typeExpression = tryParseTypeExpression();
67736787
skipWhitespace();

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ namespace ts {
616616
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createMap<SourceFile>() : undefined;
617617

618618
// A parallel array to projectReferences storing the results of reading in the referenced tsconfig files
619-
const resolvedProjectReferences: (ResolvedProjectReference | undefined)[] | undefined = projectReferences ? [] : undefined;
619+
let resolvedProjectReferences: (ResolvedProjectReference | undefined)[] | undefined = projectReferences ? [] : undefined;
620620
const projectReferenceRedirects: Map<string> = createMap();
621621

622622
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
@@ -1190,6 +1190,7 @@ namespace ts {
11901190
fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile.newFile);
11911191
}
11921192
resolvedTypeReferenceDirectives = oldProgram.getResolvedTypeReferenceDirectives();
1193+
resolvedProjectReferences = oldProgram.getProjectReferences();
11931194

11941195
sourceFileToPackageName = oldProgram.sourceFileToPackageName;
11951196
redirectTargetsSet = oldProgram.redirectTargetsSet;

src/compiler/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ namespace ts {
371371
JSDocCallbackTag,
372372
JSDocParameterTag,
373373
JSDocReturnTag,
374+
JSDocThisTag,
374375
JSDocTypeTag,
375376
JSDocTemplateTag,
376377
JSDocTypedefTag,
@@ -2323,6 +2324,11 @@ namespace ts {
23232324
kind: SyntaxKind.JSDocClassTag;
23242325
}
23252326

2327+
export interface JSDocThisTag extends JSDocTag {
2328+
kind: SyntaxKind.JSDocThisTag;
2329+
typeExpression?: JSDocTypeExpression;
2330+
}
2331+
23262332
export interface JSDocTemplateTag extends JSDocTag {
23272333
kind: SyntaxKind.JSDocTemplateTag;
23282334
typeParameters: NodeArray<TypeParameterDeclaration>;
@@ -5255,6 +5261,7 @@ namespace ts {
52555261
useCaseSensitiveFileNames?(): boolean;
52565262
fileExists?(path: string): boolean;
52575263
readFile?(path: string): string | undefined;
5264+
getSourceFiles?(): ReadonlyArray<SourceFile>; // Used for cached resolutions to find symlinks without traversing the fs (again)
52585265
}
52595266

52605267
/** @deprecated See comment on SymbolWriter */

src/compiler/utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,12 @@ namespace ts {
17571757
return node.initializer;
17581758
}
17591759

1760+
/** Get the declaration initializer when it is container-like (See getJavascriptInitializer). */
1761+
export function getDeclaredJavascriptInitializer(node: HasExpressionInitializer) {
1762+
const init = getEffectiveInitializer(node);
1763+
return init && getJavascriptInitializer(init, isPrototypeAccess(node.name));
1764+
}
1765+
17601766
/**
17611767
* Get the assignment 'initializer' -- the righthand side-- when the initializer is container-like (See getJavascriptInitializer).
17621768
* We treat the right hand side of assignments with container-like initalizers as declarations.
@@ -4325,6 +4331,8 @@ namespace ts {
43254331
switch (options.target) {
43264332
case ScriptTarget.ESNext:
43274333
return "lib.esnext.full.d.ts";
4334+
case ScriptTarget.ES2018:
4335+
return "lib.es2018.full.d.ts";
43284336
case ScriptTarget.ES2017:
43294337
return "lib.es2017.full.d.ts";
43304338
case ScriptTarget.ES2016:
@@ -4962,6 +4970,11 @@ namespace ts {
49624970
return getFirstJSDocTag(node, isJSDocClassTag);
49634971
}
49644972

4973+
/** Gets the JSDoc this tag for the node if present */
4974+
export function getJSDocThisTag(node: Node): JSDocThisTag | undefined {
4975+
return getFirstJSDocTag(node, isJSDocThisTag);
4976+
}
4977+
49654978
/** Gets the JSDoc return tag for the node if present */
49664979
export function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined {
49674980
return getFirstJSDocTag(node, isJSDocReturnTag);
@@ -5693,6 +5706,10 @@ namespace ts {
56935706
return node.kind === SyntaxKind.JSDocClassTag;
56945707
}
56955708

5709+
export function isJSDocThisTag(node: Node): node is JSDocThisTag {
5710+
return node.kind === SyntaxKind.JSDocThisTag;
5711+
}
5712+
56965713
export function isJSDocParameterTag(node: Node): node is JSDocParameterTag {
56975714
return node.kind === SyntaxKind.JSDocParameterTag;
56985715
}

0 commit comments

Comments
 (0)