Skip to content

Commit 6b28d21

Browse files
committed
Merge branch 'master' into keyoftypes
# Conflicts: # src/compiler/diagnosticMessages.json
2 parents 8d9356f + 4371889 commit 6b28d21

File tree

629 files changed

+8696
-3904
lines changed

Some content is hidden

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

629 files changed

+8696
-3904
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ matrix:
1515
branches:
1616
only:
1717
- master
18-
- release-2.0
18+
- release-2.1
1919

2020
install:
2121
- npm uninstall typescript

Jakefile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ var compilerSources = [
7070
"visitor.ts",
7171
"transformers/destructuring.ts",
7272
"transformers/ts.ts",
73-
"transformers/module/es2015.ts",
74-
"transformers/module/system.ts",
75-
"transformers/module/module.ts",
7673
"transformers/jsx.ts",
7774
"transformers/es2017.ts",
7875
"transformers/es2016.ts",
7976
"transformers/es2015.ts",
8077
"transformers/generators.ts",
8178
"transformers/es5.ts",
79+
"transformers/module/es2015.ts",
80+
"transformers/module/system.ts",
81+
"transformers/module/module.ts",
8282
"transformer.ts",
8383
"sourcemap.ts",
8484
"comments.ts",
@@ -106,15 +106,15 @@ var servicesSources = [
106106
"visitor.ts",
107107
"transformers/destructuring.ts",
108108
"transformers/ts.ts",
109-
"transformers/module/es2015.ts",
110-
"transformers/module/system.ts",
111-
"transformers/module/module.ts",
112109
"transformers/jsx.ts",
113110
"transformers/es2017.ts",
114111
"transformers/es2016.ts",
115112
"transformers/es2015.ts",
116113
"transformers/generators.ts",
117114
"transformers/es5.ts",
115+
"transformers/module/es2015.ts",
116+
"transformers/module/system.ts",
117+
"transformers/module/module.ts",
118118
"transformer.ts",
119119
"sourcemap.ts",
120120
"comments.ts",

src/compiler/binder.ts

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ namespace ts {
5454
const body = (<ModuleDeclaration>node).body;
5555
return body ? getModuleInstanceState(body) : ModuleInstanceState.Instantiated;
5656
}
57+
// Only jsdoc typedef definition can exist in jsdoc namespace, and it should
58+
// be considered the same as type alias
59+
else if (node.kind === SyntaxKind.Identifier && (<Identifier>node).isInJSDocNamespace) {
60+
return ModuleInstanceState.NonInstantiated;
61+
}
5762
else {
5863
return ModuleInstanceState.Instantiated;
5964
}
@@ -429,7 +434,11 @@ namespace ts {
429434
// during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
430435
// and this case is specially handled. Module augmentations should only be merged with original module definition
431436
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
432-
if (!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) {
437+
const isJSDocTypedefInJSDocNamespace = node.kind === SyntaxKind.JSDocTypedefTag &&
438+
node.name &&
439+
node.name.kind === SyntaxKind.Identifier &&
440+
(<Identifier>node.name).isInJSDocNamespace;
441+
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
433442
const exportKind =
434443
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
435444
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
@@ -490,8 +499,8 @@ namespace ts {
490499
const saveReturnTarget = currentReturnTarget;
491500
const saveActiveLabels = activeLabels;
492501
const saveHasExplicitReturn = hasExplicitReturn;
493-
const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !!getImmediatelyInvokedFunctionExpression(node);
494-
// An IIFE is considered part of the containing control flow. Return statements behave
502+
const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && !!getImmediatelyInvokedFunctionExpression(node);
503+
// A non-async IIFE is considered part of the containing control flow. Return statements behave
495504
// similarly to break statements that exit to a label just past the statement body.
496505
if (isIIFE) {
497506
currentReturnTarget = createBranchLabel();
@@ -883,8 +892,13 @@ namespace ts {
883892

884893
function bindDoStatement(node: DoStatement): void {
885894
const preDoLabel = createLoopLabel();
886-
const preConditionLabel = createBranchLabel();
887-
const postDoLabel = createBranchLabel();
895+
const enclosingLabeledStatement = node.parent.kind === SyntaxKind.LabeledStatement
896+
? lastOrUndefined(activeLabels)
897+
: undefined;
898+
// if do statement is wrapped in labeled statement then target labels for break/continue with or without
899+
// label should be the same
900+
const preConditionLabel = enclosingLabeledStatement ? enclosingLabeledStatement.continueTarget : createBranchLabel();
901+
const postDoLabel = enclosingLabeledStatement ? enclosingLabeledStatement.breakTarget : createBranchLabel();
888902
addAntecedent(preDoLabel, currentFlow);
889903
currentFlow = preDoLabel;
890904
bindIterativeStatement(node.statement, postDoLabel, preConditionLabel);
@@ -1007,7 +1021,7 @@ namespace ts {
10071021
currentFlow = finishFlowLabel(preFinallyLabel);
10081022
bind(node.finallyBlock);
10091023
// if flow after finally is unreachable - keep it
1010-
// otherwise check if flows after try and after catch are unreachable
1024+
// otherwise check if flows after try and after catch are unreachable
10111025
// if yes - convert current flow to unreachable
10121026
// i.e.
10131027
// try { return "1" } finally { console.log(1); }
@@ -1102,8 +1116,11 @@ namespace ts {
11021116
if (!activeLabel.referenced && !options.allowUnusedLabels) {
11031117
file.bindDiagnostics.push(createDiagnosticForNode(node.label, Diagnostics.Unused_label));
11041118
}
1105-
addAntecedent(postStatementLabel, currentFlow);
1106-
currentFlow = finishFlowLabel(postStatementLabel);
1119+
if (!node.statement || node.statement.kind !== SyntaxKind.DoStatement) {
1120+
// do statement sets current flow inside bindDoStatement
1121+
addAntecedent(postStatementLabel, currentFlow);
1122+
currentFlow = finishFlowLabel(postStatementLabel);
1123+
}
11071124
}
11081125

11091126
function bindDestructuringTargetFlow(node: Expression) {
@@ -1828,6 +1845,17 @@ namespace ts {
18281845
switch (node.kind) {
18291846
/* Strict mode checks */
18301847
case SyntaxKind.Identifier:
1848+
// for typedef type names with namespaces, bind the new jsdoc type symbol here
1849+
// because it requires all containing namespaces to be in effect, namely the
1850+
// current "blockScopeContainer" needs to be set to its immediate namespace parent.
1851+
if ((<Identifier>node).isInJSDocNamespace) {
1852+
let parentNode = node.parent;
1853+
while (parentNode && parentNode.kind !== SyntaxKind.JSDocTypedefTag) {
1854+
parentNode = parentNode.parent;
1855+
}
1856+
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
1857+
break;
1858+
}
18311859
case SyntaxKind.ThisKeyword:
18321860
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
18331861
node.flowNode = currentFlow;
@@ -1951,6 +1979,10 @@ namespace ts {
19511979
case SyntaxKind.InterfaceDeclaration:
19521980
return bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes);
19531981
case SyntaxKind.JSDocTypedefTag:
1982+
if (!(<JSDocTypedefTag>node).fullName || (<JSDocTypedefTag>node).fullName.kind === SyntaxKind.Identifier) {
1983+
return bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
1984+
}
1985+
break;
19541986
case SyntaxKind.TypeAliasDeclaration:
19551987
return bindBlockScopedDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
19561988
case SyntaxKind.EnumDeclaration:
@@ -2421,6 +2453,9 @@ namespace ts {
24212453
case SyntaxKind.HeritageClause:
24222454
return computeHeritageClause(<HeritageClause>node, subtreeFlags);
24232455

2456+
case SyntaxKind.CatchClause:
2457+
return computeCatchClause(<CatchClause>node, subtreeFlags);
2458+
24242459
case SyntaxKind.ExpressionWithTypeArguments:
24252460
return computeExpressionWithTypeArguments(<ExpressionWithTypeArguments>node, subtreeFlags);
24262461

@@ -2507,7 +2542,7 @@ namespace ts {
25072542
&& (leftKind === SyntaxKind.ObjectLiteralExpression
25082543
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
25092544
// Destructuring assignments are ES6 syntax.
2510-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.DestructuringAssignment;
2545+
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
25112546
}
25122547
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
25132548
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
@@ -2588,9 +2623,9 @@ namespace ts {
25882623

25892624
// A class with a parameter property assignment, property initializer, or decorator is
25902625
// TypeScript syntax.
2591-
// An exported declaration may be TypeScript syntax.
2626+
// An exported declaration may be TypeScript syntax, but is handled by the visitor
2627+
// for a namespace declaration.
25922628
if ((subtreeFlags & TransformFlags.TypeScriptClassSyntaxMask)
2593-
|| (modifierFlags & ModifierFlags.Export)
25942629
|| node.typeParameters) {
25952630
transformFlags |= TransformFlags.AssertTypeScript;
25962631
}
@@ -2650,6 +2685,17 @@ namespace ts {
26502685
return transformFlags & ~TransformFlags.NodeExcludes;
26512686
}
26522687

2688+
function computeCatchClause(node: CatchClause, subtreeFlags: TransformFlags) {
2689+
let transformFlags = subtreeFlags;
2690+
2691+
if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) {
2692+
transformFlags |= TransformFlags.AssertES2015;
2693+
}
2694+
2695+
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
2696+
return transformFlags & ~TransformFlags.NodeExcludes;
2697+
}
2698+
26532699
function computeExpressionWithTypeArguments(node: ExpressionWithTypeArguments, subtreeFlags: TransformFlags) {
26542700
// An ExpressionWithTypeArguments is ES6 syntax, as it is used in the
26552701
// extends clause of a class.
@@ -2749,11 +2795,6 @@ namespace ts {
27492795
else {
27502796
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;
27512797

2752-
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
2753-
if (modifierFlags & ModifierFlags.Export) {
2754-
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2015;
2755-
}
2756-
27572798
// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
27582799
// syntax.
27592800
if (modifierFlags & ModifierFlags.TypeScriptModifier
@@ -2895,11 +2936,6 @@ namespace ts {
28952936
else {
28962937
transformFlags = subtreeFlags;
28972938

2898-
// If a VariableStatement is exported, then it is either ES6 or TypeScript syntax.
2899-
if (modifierFlags & ModifierFlags.Export) {
2900-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
2901-
}
2902-
29032939
if (declarationListTransformFlags & TransformFlags.ContainsBindingPattern) {
29042940
transformFlags |= TransformFlags.AssertES2015;
29052941
}
@@ -3016,12 +3052,6 @@ namespace ts {
30163052
transformFlags |= TransformFlags.AssertJsx;
30173053
break;
30183054

3019-
case SyntaxKind.ExportKeyword:
3020-
// This node is both ES6 and TypeScript syntax.
3021-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
3022-
break;
3023-
3024-
case SyntaxKind.DefaultKeyword:
30253055
case SyntaxKind.NoSubstitutionTemplateLiteral:
30263056
case SyntaxKind.TemplateHead:
30273057
case SyntaxKind.TemplateMiddle:
@@ -3030,6 +3060,7 @@ namespace ts {
30303060
case SyntaxKind.TaggedTemplateExpression:
30313061
case SyntaxKind.ShorthandPropertyAssignment:
30323062
case SyntaxKind.ForOfStatement:
3063+
case SyntaxKind.StaticKeyword:
30333064
// These nodes are ES6 syntax.
30343065
transformFlags |= TransformFlags.AssertES2015;
30353066
break;

0 commit comments

Comments
 (0)