Skip to content

Commit f6d672e

Browse files
committed
Merge remote-tracking branch 'origin/master' into tsserverVS-WIP-projectsystem
2 parents 9eb01bf + 613e2d3 commit f6d672e

69 files changed

Lines changed: 2678 additions & 148 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.

ThirdPartyNoticeText.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Third Party Code Components
2121
--------------------------------------------
2222

2323
------------------- DefinitelyTyped --------------------
24-
This file is based on or incorporates material from the projects listed below (collectively ?Third Party Code?). Microsoft is not the original author of the Third Party Code. The original copyright notice and the license, under which Microsoft received such Third Party Code, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft, not the third party, licenses the Third Party Code to you under the terms set forth in the EULA for the Microsoft Product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
24+
This file is based on or incorporates material from the projects listed below (collectively "Third Party Code"). Microsoft is not the original author of the Third Party Code. The original copyright notice and the license, under which Microsoft received such Third Party Code, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft, not the third party, licenses the Third Party Code to you under the terms set forth in the EULA for the Microsoft Product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
2525
DefinitelyTyped
2626
This project is licensed under the MIT license.
2727
Copyrights are respective of each contributor listed at the beginning of each definition file.

src/compiler/checker.ts

Lines changed: 172 additions & 93 deletions
Large diffs are not rendered by default.

src/compiler/parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,12 @@ namespace ts {
11561156
if (token === SyntaxKind.ExportKeyword) {
11571157
nextToken();
11581158
if (token === SyntaxKind.DefaultKeyword) {
1159-
return lookAhead(nextTokenIsClassOrFunction);
1159+
return lookAhead(nextTokenIsClassOrFunctionOrAsync);
11601160
}
11611161
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
11621162
}
11631163
if (token === SyntaxKind.DefaultKeyword) {
1164-
return nextTokenIsClassOrFunction();
1164+
return nextTokenIsClassOrFunctionOrAsync();
11651165
}
11661166
if (token === SyntaxKind.StaticKeyword) {
11671167
nextToken();
@@ -1183,9 +1183,9 @@ namespace ts {
11831183
|| isLiteralPropertyName();
11841184
}
11851185

1186-
function nextTokenIsClassOrFunction(): boolean {
1186+
function nextTokenIsClassOrFunctionOrAsync(): boolean {
11871187
nextToken();
1188-
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword;
1188+
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || token === SyntaxKind.AsyncKeyword;
11891189
}
11901190

11911191
// True if positioned at the start of a list element
@@ -5071,7 +5071,7 @@ namespace ts {
50715071
* In such situations, 'permitInvalidConstAsModifier' should be set to true.
50725072
*/
50735073
function parseModifiers(permitInvalidConstAsModifier?: boolean): ModifiersArray {
5074-
let flags = 0;
5074+
let flags: NodeFlags = 0;
50755075
let modifiers: ModifiersArray;
50765076
while (true) {
50775077
const modifierStart = scanner.getStartPos();

src/compiler/program.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,18 @@ namespace ts {
779779
while (true) {
780780
const baseName = getBaseFileName(directory);
781781
if (baseName !== "node_modules") {
782-
const result =
783-
// first: try to load module as-is
784-
loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state) ||
785-
// second: try to load module from the scope '@types'
786-
loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state);
787-
if (result) {
788-
return result;
782+
// Try to load source from the package
783+
const packageResult = loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state);
784+
if (packageResult && hasTypeScriptFileExtension(packageResult)) {
785+
// Always prefer a TypeScript (.ts, .tsx, .d.ts) file shipped with the package
786+
return packageResult;
787+
}
788+
else {
789+
// Else prefer a types package over non-TypeScript results (e.g. JavaScript files)
790+
const typesResult = loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state);
791+
if (typesResult || packageResult) {
792+
return typesResult || packageResult;
793+
}
789794
}
790795
}
791796

@@ -1097,7 +1102,7 @@ namespace ts {
10971102
const modulesWithElidedImports: Map<boolean> = {};
10981103

10991104
// Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled.
1100-
const jsFilesFoundSearchingNodeModules: Map<boolean> = {};
1105+
const sourceFilesFoundSearchingNodeModules: Map<boolean> = {};
11011106

11021107
const start = new Date().getTime();
11031108

@@ -1379,7 +1384,7 @@ namespace ts {
13791384
getSourceFile: program.getSourceFile,
13801385
getSourceFileByPath: program.getSourceFileByPath,
13811386
getSourceFiles: program.getSourceFiles,
1382-
getFilesFromNodeModules: () => jsFilesFoundSearchingNodeModules,
1387+
isSourceFileFromExternalLibrary: (file: SourceFile) => !!lookUp(sourceFilesFoundSearchingNodeModules, file.path),
13831388
writeFile: writeFileCallback || (
13841389
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
13851390
isEmitBlocked,
@@ -2071,15 +2076,17 @@ namespace ts {
20712076
// - noResolve is falsy
20722077
// - module name comes from the list of imports
20732078
// - it's not a top level JavaScript module that exceeded the search max
2074-
const isJsFileUnderNodeModules = resolution && resolution.isExternalLibraryImport &&
2075-
hasJavaScriptFileExtension(resolution.resolvedFileName);
2079+
const isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport;
2080+
const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension(resolution.resolvedFileName);
20762081

2077-
if (isJsFileUnderNodeModules) {
2078-
jsFilesFoundSearchingNodeModules[resolvedPath] = true;
2082+
if (isFromNodeModulesSearch) {
2083+
sourceFilesFoundSearchingNodeModules[resolvedPath] = true;
2084+
}
2085+
if (isJsFileFromNodeModules) {
20792086
currentNodeModulesJsDepth++;
20802087
}
20812088

2082-
const elideImport = isJsFileUnderNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
2089+
const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
20832090
const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport;
20842091

20852092
if (elideImport) {
@@ -2094,7 +2101,7 @@ namespace ts {
20942101
file.imports[i].end);
20952102
}
20962103

2097-
if (isJsFileUnderNodeModules) {
2104+
if (isJsFileFromNodeModules) {
20982105
currentNodeModulesJsDepth--;
20992106
}
21002107
}

src/compiler/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ namespace ts {
469469
}
470470

471471
export interface ModifiersArray extends NodeArray<Modifier> {
472-
flags: number;
472+
flags: NodeFlags;
473473
}
474474

475475
// @kind(SyntaxKind.AbstractKeyword)
@@ -2108,6 +2108,8 @@ namespace ts {
21082108
PropertyOrAccessor = Property | Accessor,
21092109
Export = ExportNamespace | ExportType | ExportValue,
21102110

2111+
ClassMember = Method | Accessor | Property,
2112+
21112113
/* @internal */
21122114
// The set of things we consider semantically classifiable. Used to speed up the LS during
21132115
// classification.
@@ -2129,7 +2131,7 @@ namespace ts {
21292131
/* @internal */ parent?: Symbol; // Parent symbol
21302132
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
21312133
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums
2132-
/* @internal */ hasReference?: boolean; // True if the symbol is referenced elsewhere
2134+
/* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere
21332135
}
21342136

21352137
/* @internal */

src/compiler/utilities.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace ts {
3636
getSourceFiles(): SourceFile[];
3737

3838
/* @internal */
39-
getFilesFromNodeModules(): Map<boolean>;
39+
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
4040

4141
getCommonSourceDirectory(): string;
4242
getCanonicalFileName(fileName: string): string;
@@ -2277,10 +2277,9 @@ namespace ts {
22772277
}
22782278
else {
22792279
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
2280-
const nodeModulesFiles = host.getFilesFromNodeModules();
22812280
for (const sourceFile of sourceFiles) {
22822281
// Don't emit if source file is a declaration file, or was located under node_modules
2283-
if (!isDeclarationFile(sourceFile) && !lookUp(nodeModulesFiles, sourceFile.path)) {
2282+
if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) {
22842283
onSingleFileEmit(host, sourceFile);
22852284
}
22862285
}
@@ -2314,10 +2313,9 @@ namespace ts {
23142313
function onBundledEmit(host: EmitHost) {
23152314
// Can emit only sources that are not declaration file and are either non module code or module with
23162315
// --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
2317-
const nodeModulesFiles = host.getFilesFromNodeModules();
23182316
const bundledSources = filter(host.getSourceFiles(),
23192317
sourceFile => !isDeclarationFile(sourceFile) &&
2320-
!lookUp(nodeModulesFiles, sourceFile.path) &&
2318+
!host.isSourceFileFromExternalLibrary(sourceFile) &&
23212319
(!isExternalModule(sourceFile) ||
23222320
!!getEmitModuleKind(options)));
23232321
if (bundledSources.length) {

src/lib/scripthost.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,8 @@ interface VarDate { }
284284

285285
interface DateConstructor {
286286
new (vd: VarDate): Date;
287+
}
288+
289+
interface Date {
287290
getVarDate: () => VarDate;
288-
}
291+
}

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ namespace ts.formatting {
497497
return childKind !== SyntaxKind.NamedExports;
498498
case SyntaxKind.ImportDeclaration:
499499
return childKind !== SyntaxKind.ImportClause ||
500-
(<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports;
500+
((<ImportClause>child).namedBindings && (<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports);
501501
case SyntaxKind.JsxElement:
502502
return childKind !== SyntaxKind.JsxClosingElement;
503503
}

src/services/navigationBar.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ namespace ts.NavigationBar {
412412
case SyntaxKind.JSDocTypedefTag:
413413
return getJSDocTypedefTagName(<JSDocTypedefTag>node);
414414
default:
415-
Debug.fail();
416-
return "";
415+
return "<unknown>";
417416
}
418417
}
419418

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error TS2318: Cannot find global type 'Promise'.
2+
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS1311: Async functions are only available when targeting ECMAScript 2015 or higher.
3+
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS1057: An async function or method must have a valid awaitable return type.
4+
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS7030: Not all code paths return a value.
5+
tests/cases/compiler/asyncFunctionNoReturnType.ts(2,9): error TS2304: Cannot find name 'window'.
6+
tests/cases/compiler/asyncFunctionNoReturnType.ts(3,9): error TS7030: Not all code paths return a value.
7+
8+
9+
!!! error TS2318: Cannot find global type 'Promise'.
10+
==== tests/cases/compiler/asyncFunctionNoReturnType.ts (5 errors) ====
11+
async () => {
12+
~~~~~
13+
!!! error TS1311: Async functions are only available when targeting ECMAScript 2015 or higher.
14+
~~~~~~~~~~~~~
15+
!!! error TS1057: An async function or method must have a valid awaitable return type.
16+
~~~~~~~~~~~~~
17+
!!! error TS7030: Not all code paths return a value.
18+
if (window)
19+
~~~~~~
20+
!!! error TS2304: Cannot find name 'window'.
21+
return;
22+
~~~~~~~
23+
!!! error TS7030: Not all code paths return a value.
24+
}
25+

0 commit comments

Comments
 (0)