@@ -7,15 +7,19 @@ namespace ts {
7
7
let nextMergeId = 1;
8
8
9
9
export function getNodeId(node: Node): number {
10
- if (!node.id) node.id = nextNodeId++;
10
+ if (!node.id) {
11
+ node.id = nextNodeId;
12
+ nextNodeId++;
13
+ }
11
14
return node.id;
12
15
}
13
16
14
17
export let checkTime = 0;
15
18
16
19
export function getSymbolId(symbol: Symbol): number {
17
20
if (!symbol.id) {
18
- symbol.id = nextSymbolId++;
21
+ symbol.id = nextSymbolId;
22
+ nextSymbolId++;
19
23
}
20
24
21
25
return symbol.id;
@@ -287,7 +291,10 @@ namespace ts {
287
291
}
288
292
289
293
function recordMergedSymbol(target: Symbol, source: Symbol) {
290
- if (!source.mergeId) source.mergeId = nextMergeId++;
294
+ if (!source.mergeId) {
295
+ source.mergeId = nextMergeId;
296
+ nextMergeId++;
297
+ }
291
298
mergedSymbols[source.mergeId] = target;
292
299
}
293
300
@@ -1267,7 +1274,8 @@ namespace ts {
1267
1274
1268
1275
function createType(flags: TypeFlags): Type {
1269
1276
const result = new Type(checker, flags);
1270
- result.id = typeCount++;
1277
+ result.id = typeCount;
1278
+ typeCount++;
1271
1279
return result;
1272
1280
}
1273
1281
@@ -1823,11 +1831,13 @@ namespace ts {
1823
1831
}
1824
1832
if (pos < end) {
1825
1833
writePunctuation(writer, SyntaxKind.LessThanToken);
1826
- writeType(typeArguments[pos++], TypeFormatFlags.None);
1834
+ writeType(typeArguments[pos], TypeFormatFlags.None);
1835
+ pos++;
1827
1836
while (pos < end) {
1828
1837
writePunctuation(writer, SyntaxKind.CommaToken);
1829
1838
writeSpace(writer);
1830
- writeType(typeArguments[pos++], TypeFormatFlags.None);
1839
+ writeType(typeArguments[pos], TypeFormatFlags.None);
1840
+ pos++;
1831
1841
}
1832
1842
writePunctuation(writer, SyntaxKind.GreaterThanToken);
1833
1843
}
@@ -5672,7 +5682,7 @@ namespace ts {
5672
5682
return Ternary.False;
5673
5683
}
5674
5684
let result = Ternary.True;
5675
- for (let i = 0, len = sourceSignatures.length; i < len; ++i ) {
5685
+ for (let i = 0, len = sourceSignatures.length; i < len; i++ ) {
5676
5686
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
5677
5687
if (!related) {
5678
5688
return Ternary.False;
@@ -7348,6 +7358,12 @@ namespace ts {
7348
7358
}
7349
7359
return type;
7350
7360
}
7361
+ else if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) {
7362
+ if (node === binaryExpression.right) {
7363
+ return getContextualType(binaryExpression);
7364
+ }
7365
+ }
7366
+
7351
7367
return undefined;
7352
7368
}
7353
7369
@@ -7460,24 +7476,22 @@ namespace ts {
7460
7476
return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
7461
7477
}
7462
7478
7463
- function getContextualTypeForJsxExpression(expr: JsxExpression | JsxSpreadAttribute): Type {
7464
- // Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions)
7465
- if (expr.parent.kind === SyntaxKind.JsxAttribute) {
7466
- const attrib = <JsxAttribute>expr.parent;
7467
- const attrsType = getJsxElementAttributesType(<JsxOpeningLikeElement>attrib.parent);
7479
+ function getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute) {
7480
+ const kind = attribute.kind;
7481
+ const jsxElement = attribute.parent as JsxOpeningLikeElement;
7482
+ const attrsType = getJsxElementAttributesType(jsxElement);
7483
+
7484
+ if (attribute.kind === SyntaxKind.JsxAttribute) {
7468
7485
if (!attrsType || isTypeAny(attrsType)) {
7469
7486
return undefined;
7470
7487
}
7471
- else {
7472
- return getTypeOfPropertyOfType(attrsType, attrib.name.text);
7473
- }
7488
+ return getTypeOfPropertyOfType(attrsType, (attribute as JsxAttribute).name.text);
7474
7489
}
7475
-
7476
- if (expr.kind === SyntaxKind.JsxSpreadAttribute) {
7477
- return getJsxElementAttributesType(<JsxOpeningLikeElement>expr.parent);
7490
+ else if (attribute.kind === SyntaxKind.JsxSpreadAttribute) {
7491
+ return attrsType;
7478
7492
}
7479
7493
7480
- return undefined ;
7494
+ Debug.fail(`Expected JsxAttribute or JsxSpreadAttribute, got ts.SyntaxKind[${kind}]`) ;
7481
7495
}
7482
7496
7483
7497
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
@@ -7545,8 +7559,10 @@ namespace ts {
7545
7559
case SyntaxKind.ParenthesizedExpression:
7546
7560
return getContextualType(<ParenthesizedExpression>parent);
7547
7561
case SyntaxKind.JsxExpression:
7562
+ return getContextualType(<JsxExpression>parent);
7563
+ case SyntaxKind.JsxAttribute:
7548
7564
case SyntaxKind.JsxSpreadAttribute:
7549
- return getContextualTypeForJsxExpression(<JsxExpression >parent);
7565
+ return getContextualTypeForJsxAttribute(<JsxAttribute | JsxSpreadAttribute >parent);
7550
7566
}
7551
7567
return undefined;
7552
7568
}
@@ -7934,31 +7950,12 @@ namespace ts {
7934
7950
return jsxElementType || anyType;
7935
7951
}
7936
7952
7937
- function tagNamesAreEquivalent(lhs: EntityName, rhs: EntityName): boolean {
7938
- if (lhs.kind !== rhs.kind) {
7939
- return false;
7940
- }
7941
-
7942
- if (lhs.kind === SyntaxKind.Identifier) {
7943
- return (<Identifier>lhs).text === (<Identifier>rhs).text;
7944
- }
7945
-
7946
- return (<QualifiedName>lhs).right.text === (<QualifiedName>rhs).right.text &&
7947
- tagNamesAreEquivalent((<QualifiedName>lhs).left, (<QualifiedName>rhs).left);
7948
- }
7949
-
7950
7953
function checkJsxElement(node: JsxElement) {
7951
7954
// Check attributes
7952
7955
checkJsxOpeningLikeElement(node.openingElement);
7953
7956
7954
- // Check that the closing tag matches
7955
- if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
7956
- error(node.closingElement, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNode(node.openingElement.tagName));
7957
- }
7958
- else {
7959
- // Perform resolution on the closing tag so that rename/go to definition/etc work
7960
- getJsxElementTagSymbol(node.closingElement);
7961
- }
7957
+ // Perform resolution on the closing tag so that rename/go to definition/etc work
7958
+ getJsxElementTagSymbol(node.closingElement);
7962
7959
7963
7960
// Check children
7964
7961
for (const child of node.children) {
@@ -8359,14 +8356,13 @@ namespace ts {
8359
8356
checkGrammarJsxElement(node);
8360
8357
checkJsxPreconditions(node);
8361
8358
8362
- // If we're compiling under --jsx react, the symbol 'React' should
8363
- // be marked as 'used' so we don't incorrectly elide its import. And if there
8364
- // is no 'React' symbol in scope, we should issue an error.
8365
- if (compilerOptions.jsx === JsxEmit.React) {
8366
- const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
8367
- if (reactSym) {
8368
- getSymbolLinks(reactSym).referenced = true;
8369
- }
8359
+ // The reactNamespace symbol should be marked as 'used' so we don't incorrectly elide its import. And if there
8360
+ // is no reactNamespace symbol in scope when targeting React emit, we should issue an error.
8361
+ const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
8362
+ const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React";
8363
+ const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
8364
+ if (reactSym) {
8365
+ getSymbolLinks(reactSym).referenced = true;
8370
8366
}
8371
8367
8372
8368
const targetAttributesType = getJsxElementAttributesType(node);
@@ -13775,7 +13771,8 @@ namespace ts {
13775
13771
}
13776
13772
13777
13773
if (autoValue !== undefined) {
13778
- getNodeLinks(member).enumMemberValue = autoValue++;
13774
+ getNodeLinks(member).enumMemberValue = autoValue;
13775
+ autoValue++;
13779
13776
}
13780
13777
}
13781
13778
0 commit comments