@@ -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
}
@@ -5636,7 +5646,7 @@ namespace ts {
5636
5646
return Ternary.False;
5637
5647
}
5638
5648
let result = Ternary.True;
5639
- for (let i = 0, len = sourceSignatures.length; i < len; ++i ) {
5649
+ for (let i = 0, len = sourceSignatures.length; i < len; i++ ) {
5640
5650
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
5641
5651
if (!related) {
5642
5652
return Ternary.False;
@@ -7312,6 +7322,12 @@ namespace ts {
7312
7322
}
7313
7323
return type;
7314
7324
}
7325
+ else if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) {
7326
+ if (node === binaryExpression.right) {
7327
+ return getContextualType(binaryExpression);
7328
+ }
7329
+ }
7330
+
7315
7331
return undefined;
7316
7332
}
7317
7333
@@ -7424,24 +7440,22 @@ namespace ts {
7424
7440
return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
7425
7441
}
7426
7442
7427
- function getContextualTypeForJsxExpression(expr: JsxExpression | JsxSpreadAttribute): Type {
7428
- // Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions)
7429
- if (expr.parent.kind === SyntaxKind.JsxAttribute) {
7430
- const attrib = <JsxAttribute>expr.parent;
7431
- const attrsType = getJsxElementAttributesType(<JsxOpeningLikeElement>attrib.parent);
7443
+ function getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute) {
7444
+ const kind = attribute.kind;
7445
+ const jsxElement = attribute.parent as JsxOpeningLikeElement;
7446
+ const attrsType = getJsxElementAttributesType(jsxElement);
7447
+
7448
+ if (attribute.kind === SyntaxKind.JsxAttribute) {
7432
7449
if (!attrsType || isTypeAny(attrsType)) {
7433
7450
return undefined;
7434
7451
}
7435
- else {
7436
- return getTypeOfPropertyOfType(attrsType, attrib.name.text);
7437
- }
7452
+ return getTypeOfPropertyOfType(attrsType, (attribute as JsxAttribute).name.text);
7438
7453
}
7439
-
7440
- if (expr.kind === SyntaxKind.JsxSpreadAttribute) {
7441
- return getJsxElementAttributesType(<JsxOpeningLikeElement>expr.parent);
7454
+ else if (attribute.kind === SyntaxKind.JsxSpreadAttribute) {
7455
+ return attrsType;
7442
7456
}
7443
7457
7444
- return undefined ;
7458
+ Debug.fail(`Expected JsxAttribute or JsxSpreadAttribute, got ts.SyntaxKind[${kind}]`) ;
7445
7459
}
7446
7460
7447
7461
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
@@ -7509,8 +7523,10 @@ namespace ts {
7509
7523
case SyntaxKind.ParenthesizedExpression:
7510
7524
return getContextualType(<ParenthesizedExpression>parent);
7511
7525
case SyntaxKind.JsxExpression:
7526
+ return getContextualType(<JsxExpression>parent);
7527
+ case SyntaxKind.JsxAttribute:
7512
7528
case SyntaxKind.JsxSpreadAttribute:
7513
- return getContextualTypeForJsxExpression(<JsxExpression >parent);
7529
+ return getContextualTypeForJsxAttribute(<JsxAttribute | JsxSpreadAttribute >parent);
7514
7530
}
7515
7531
return undefined;
7516
7532
}
@@ -7898,31 +7914,12 @@ namespace ts {
7898
7914
return jsxElementType || anyType;
7899
7915
}
7900
7916
7901
- function tagNamesAreEquivalent(lhs: EntityName, rhs: EntityName): boolean {
7902
- if (lhs.kind !== rhs.kind) {
7903
- return false;
7904
- }
7905
-
7906
- if (lhs.kind === SyntaxKind.Identifier) {
7907
- return (<Identifier>lhs).text === (<Identifier>rhs).text;
7908
- }
7909
-
7910
- return (<QualifiedName>lhs).right.text === (<QualifiedName>rhs).right.text &&
7911
- tagNamesAreEquivalent((<QualifiedName>lhs).left, (<QualifiedName>rhs).left);
7912
- }
7913
-
7914
7917
function checkJsxElement(node: JsxElement) {
7915
7918
// Check attributes
7916
7919
checkJsxOpeningLikeElement(node.openingElement);
7917
7920
7918
- // Check that the closing tag matches
7919
- if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) {
7920
- error(node.closingElement, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNode(node.openingElement.tagName));
7921
- }
7922
- else {
7923
- // Perform resolution on the closing tag so that rename/go to definition/etc work
7924
- getJsxElementTagSymbol(node.closingElement);
7925
- }
7921
+ // Perform resolution on the closing tag so that rename/go to definition/etc work
7922
+ getJsxElementTagSymbol(node.closingElement);
7926
7923
7927
7924
// Check children
7928
7925
for (const child of node.children) {
@@ -8323,14 +8320,13 @@ namespace ts {
8323
8320
checkGrammarJsxElement(node);
8324
8321
checkJsxPreconditions(node);
8325
8322
8326
- // If we're compiling under --jsx react, the symbol 'React' should
8327
- // be marked as 'used' so we don't incorrectly elide its import. And if there
8328
- // is no 'React' symbol in scope, we should issue an error.
8329
- if (compilerOptions.jsx === JsxEmit.React) {
8330
- const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
8331
- if (reactSym) {
8332
- getSymbolLinks(reactSym).referenced = true;
8333
- }
8323
+ // The reactNamespace symbol should be marked as 'used' so we don't incorrectly elide its import. And if there
8324
+ // is no reactNamespace symbol in scope when targeting React emit, we should issue an error.
8325
+ const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
8326
+ const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React";
8327
+ const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
8328
+ if (reactSym) {
8329
+ getSymbolLinks(reactSym).referenced = true;
8334
8330
}
8335
8331
8336
8332
const targetAttributesType = getJsxElementAttributesType(node);
@@ -13801,7 +13797,8 @@ namespace ts {
13801
13797
}
13802
13798
13803
13799
if (autoValue !== undefined) {
13804
- getNodeLinks(member).enumMemberValue = autoValue++;
13800
+ getNodeLinks(member).enumMemberValue = autoValue;
13801
+ autoValue++;
13805
13802
}
13806
13803
}
13807
13804
0 commit comments