Skip to content

Commit ff643f2

Browse files
committed
Merge branch 'master' into release-2.3
2 parents 835b128 + 2e43c86 commit ff643f2

File tree

98 files changed

+1900
-440
lines changed

Some content is hidden

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

98 files changed

+1900
-440
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build Status](https://travis-ci.org/Microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript)
22
[![npm version](https://badge.fury.io/js/typescript.svg)](https://www.npmjs.com/package/typescript)
3-
[![Downloads](https://img.shields.io/npm/dm/TypeScript.svg)](https://www.npmjs.com/package/typescript)
3+
[![Downloads](https://img.shields.io/npm/dm/typescript.svg)](https://www.npmjs.com/package/typescript)
44

55
# TypeScript
66

src/compiler/binder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ namespace ts {
14141414
if (isObjectLiteralOrClassExpressionMethod(node)) {
14151415
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
14161416
}
1417+
// falls through
14171418
case SyntaxKind.Constructor:
14181419
case SyntaxKind.FunctionDeclaration:
14191420
case SyntaxKind.MethodSignature:
@@ -1715,7 +1716,7 @@ namespace ts {
17151716
declareModuleMember(node, symbolFlags, symbolExcludes);
17161717
break;
17171718
}
1718-
// fall through.
1719+
// falls through
17191720
default:
17201721
if (!blockScopeContainer.locals) {
17211722
blockScopeContainer.locals = createMap<Symbol>();
@@ -2009,6 +2010,7 @@ namespace ts {
20092010
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
20102011
break;
20112012
}
2013+
// falls through
20122014
case SyntaxKind.ThisKeyword:
20132015
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
20142016
node.flowNode = currentFlow;
@@ -2184,7 +2186,7 @@ namespace ts {
21842186
if (!isFunctionLike(node.parent)) {
21852187
return;
21862188
}
2187-
// Fall through
2189+
// falls through
21882190
case SyntaxKind.ModuleBlock:
21892191
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
21902192
}
@@ -2401,7 +2403,7 @@ namespace ts {
24012403
}
24022404

24032405
function lookupSymbolForName(name: string) {
2404-
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name);
2406+
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name));
24052407
}
24062408

24072409
function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {

src/compiler/checker.ts

Lines changed: 143 additions & 189 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,25 @@ namespace ts {
224224
}
225225
return undefined;
226226
}
227+
/**
228+
* Iterates through the parent chain of a node and performs the callback on each parent until the callback
229+
* returns a truthy value, then returns that value.
230+
* If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit"
231+
* At that point findAncestor returns undefined.
232+
*/
233+
export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node {
234+
while (node) {
235+
const result = callback(node);
236+
if (result === "quit") {
237+
return undefined;
238+
}
239+
else if (result) {
240+
return node;
241+
}
242+
node = node.parent;
243+
}
244+
return undefined;
245+
}
227246

228247
export function zipWith<T, U>(arrayA: T[], arrayB: U[], callback: (a: T, b: U, index: number) => void): void {
229248
Debug.assert(arrayA.length === arrayB.length);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,10 @@
31973197
"category": "Message",
31983198
"code": 6181
31993199
},
3200+
"Scoped package detected, looking in '{0}'": {
3201+
"category": "Message",
3202+
"code": "6182"
3203+
},
32003204

32013205
"Variable '{0}' implicitly has an '{1}' type.": {
32023206
"category": "Error",

src/compiler/moduleNameResolver.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ namespace ts {
378378
directoryPathMap.set(parent, result);
379379
current = parent;
380380

381-
if (current == commonPrefix) {
381+
if (current === commonPrefix) {
382382
break;
383383
}
384384
}
@@ -954,10 +954,25 @@ namespace ts {
954954
}
955955
nodeModulesAtTypesExists = false;
956956
}
957-
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, moduleName, nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
957+
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, mangleScopedPackage(moduleName, state), nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
958958
}
959959
}
960960

961+
/** For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`. */
962+
function mangleScopedPackage(moduleName: string, state: ModuleResolutionState): string {
963+
if (startsWith(moduleName, "@")) {
964+
const replaceSlash = moduleName.replace(ts.directorySeparator, "__");
965+
if (replaceSlash !== moduleName) {
966+
const mangled = replaceSlash.slice(1); // Take off the "@"
967+
if (state.traceEnabled) {
968+
trace(state.host, Diagnostics.Scoped_package_detected_looking_in_0, mangled);
969+
}
970+
return mangled;
971+
}
972+
}
973+
return moduleName;
974+
}
975+
961976
function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult<Resolved> {
962977
const result = cache && cache.get(containingDirectory);
963978
if (result) {

src/compiler/parser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace ts {
5757
// The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray
5858
// callback parameters, but that causes a closure allocation for each invocation with noticeable effects
5959
// on performance.
60-
const visitNodes: (cb: (node: Node | Node[]) => T, nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode;
60+
const visitNodes: (cb: ((node: Node) => T) | ((node: Node[]) => T), nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode;
6161
const cbNodes = cbNodeArray || cbNode;
6262
switch (node.kind) {
6363
case SyntaxKind.QualifiedName:
@@ -3573,6 +3573,7 @@ namespace ts {
35733573
if (isAwaitExpression()) {
35743574
return parseAwaitExpression();
35753575
}
3576+
// falls through
35763577
default:
35773578
return parseIncrementExpression();
35783579
}
@@ -3606,8 +3607,8 @@ namespace ts {
36063607
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
36073608
return false;
36083609
}
3609-
// We are in JSX context and the token is part of JSXElement.
3610-
// Fall through
3610+
// We are in JSX context and the token is part of JSXElement.
3611+
// falls through
36113612
default:
36123613
return true;
36133614
}
@@ -6571,7 +6572,8 @@ namespace ts {
65716572
indent += scanner.getTokenText().length;
65726573
break;
65736574
}
6574-
// FALLTHROUGH otherwise to record the * as a comment
6575+
// record the * as a comment
6576+
// falls through
65756577
default:
65766578
state = JSDocState.SavingComments; // leading identifiers start recording as well
65776579
pushComment(scanner.getTokenText());
@@ -6797,6 +6799,7 @@ namespace ts {
67976799
break;
67986800
case SyntaxKind.Identifier:
67996801
canParseTag = false;
6802+
break;
68006803
case SyntaxKind.EndOfFileToken:
68016804
break;
68026805
}

src/compiler/program.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ namespace ts {
557557
// combine results of resolutions and predicted results
558558
let j = 0;
559559
for (let i = 0; i < result.length; i++) {
560-
if (result[i] == predictedToResolveToAmbientModuleMarker) {
560+
if (result[i] === predictedToResolveToAmbientModuleMarker) {
561561
result[i] = undefined;
562562
}
563563
else {
@@ -930,20 +930,22 @@ namespace ts {
930930
*/
931931
function shouldReportDiagnostic(diagnostic: Diagnostic) {
932932
const { file, start } = diagnostic;
933-
const lineStarts = getLineStarts(file);
934-
let { line } = computeLineAndCharacterOfPosition(lineStarts, start);
935-
while (line > 0) {
936-
const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]);
937-
const result = ignoreDiagnosticCommentRegEx.exec(previousLineText);
938-
if (!result) {
939-
// non-empty line
940-
return true;
941-
}
942-
if (result[3]) {
943-
// @ts-ignore
944-
return false;
933+
if (file) {
934+
const lineStarts = getLineStarts(file);
935+
let { line } = computeLineAndCharacterOfPosition(lineStarts, start);
936+
while (line > 0) {
937+
const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]);
938+
const result = ignoreDiagnosticCommentRegEx.exec(previousLineText);
939+
if (!result) {
940+
// non-empty line
941+
return true;
942+
}
943+
if (result[3]) {
944+
// @ts-ignore
945+
return false;
946+
}
947+
line--;
945948
}
946-
line--;
947949
}
948950
return true;
949951
}
@@ -967,8 +969,7 @@ namespace ts {
967969
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
968970
return;
969971
}
970-
971-
// Pass through
972+
// falls through
972973
case SyntaxKind.MethodDeclaration:
973974
case SyntaxKind.MethodSignature:
974975
case SyntaxKind.Constructor:
@@ -1048,7 +1049,7 @@ namespace ts {
10481049
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
10491050
return;
10501051
}
1051-
// pass through
1052+
// falls through
10521053
case SyntaxKind.VariableStatement:
10531054
// Check modifiers
10541055
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
@@ -1096,7 +1097,8 @@ namespace ts {
10961097
if (isConstValid) {
10971098
continue;
10981099
}
1099-
// Fallthrough to report error
1100+
// to report error,
1101+
// falls through
11001102
case SyntaxKind.PublicKeyword:
11011103
case SyntaxKind.PrivateKeyword:
11021104
case SyntaxKind.ProtectedKeyword:
@@ -1364,7 +1366,7 @@ namespace ts {
13641366

13651367
// If the file was previously found via a node_modules search, but is now being processed as a root file,
13661368
// then everything it sucks in may also be marked incorrectly, and needs to be checked again.
1367-
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth == 0) {
1369+
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) {
13681370
sourceFilesFoundSearchingNodeModules.set(file.path, false);
13691371
if (!options.noResolve) {
13701372
processReferencedFiles(file, isDefaultLib);

src/compiler/scanner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ namespace ts {
308308
if (text.charCodeAt(pos) === CharacterCodes.lineFeed) {
309309
pos++;
310310
}
311+
// falls through
311312
case CharacterCodes.lineFeed:
312313
result.push(lineStart);
313314
lineStart = pos;
@@ -454,6 +455,7 @@ namespace ts {
454455
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
455456
pos++;
456457
}
458+
// falls through
457459
case CharacterCodes.lineFeed:
458460
pos++;
459461
if (stopAfterLineBreak) {
@@ -625,6 +627,7 @@ namespace ts {
625627
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
626628
pos++;
627629
}
630+
// falls through
628631
case CharacterCodes.lineFeed:
629632
pos++;
630633
if (trailing) {
@@ -1072,7 +1075,7 @@ namespace ts {
10721075
if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) {
10731076
pos++;
10741077
}
1075-
// fall through
1078+
// falls through
10761079
case CharacterCodes.lineFeed:
10771080
case CharacterCodes.lineSeparator:
10781081
case CharacterCodes.paragraphSeparator:
@@ -1459,6 +1462,7 @@ namespace ts {
14591462
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
14601463
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
14611464
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
1465+
// falls through
14621466
case CharacterCodes._1:
14631467
case CharacterCodes._2:
14641468
case CharacterCodes._3:

src/compiler/transformers/module/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ namespace ts {
479479
// module is imported only for side-effects, no emit required
480480
break;
481481
}
482+
// falls through
482483

483-
// fall-through
484484
case SyntaxKind.ImportEqualsDeclaration:
485485
Debug.assert(importVariableName !== undefined);
486486
// save import into the local

0 commit comments

Comments
 (0)