@@ -7,15 +7,19 @@ namespace ts {
77 let nextMergeId = 1;
88
99 export function getNodeId(node: Node): number {
10- if (!node.id) node.id = nextNodeId++;
10+ if (!node.id) {
11+ node.id = nextNodeId;
12+ nextNodeId++;
13+ }
1114 return node.id;
1215 }
1316
1417 export let checkTime = 0;
1518
1619 export function getSymbolId(symbol: Symbol): number {
1720 if (!symbol.id) {
18- symbol.id = nextSymbolId++;
21+ symbol.id = nextSymbolId;
22+ nextSymbolId++;
1923 }
2024
2125 return symbol.id;
@@ -287,7 +291,10 @@ namespace ts {
287291 }
288292
289293 function recordMergedSymbol(target: Symbol, source: Symbol) {
290- if (!source.mergeId) source.mergeId = nextMergeId++;
294+ if (!source.mergeId) {
295+ source.mergeId = nextMergeId;
296+ nextMergeId++;
297+ }
291298 mergedSymbols[source.mergeId] = target;
292299 }
293300
@@ -1267,7 +1274,8 @@ namespace ts {
12671274
12681275 function createType(flags: TypeFlags): Type {
12691276 const result = new Type(checker, flags);
1270- result.id = typeCount++;
1277+ result.id = typeCount;
1278+ typeCount++;
12711279 return result;
12721280 }
12731281
@@ -1823,11 +1831,13 @@ namespace ts {
18231831 }
18241832 if (pos < end) {
18251833 writePunctuation(writer, SyntaxKind.LessThanToken);
1826- writeType(typeArguments[pos++], TypeFormatFlags.None);
1834+ writeType(typeArguments[pos], TypeFormatFlags.None);
1835+ pos++;
18271836 while (pos < end) {
18281837 writePunctuation(writer, SyntaxKind.CommaToken);
18291838 writeSpace(writer);
1830- writeType(typeArguments[pos++], TypeFormatFlags.None);
1839+ writeType(typeArguments[pos], TypeFormatFlags.None);
1840+ pos++;
18311841 }
18321842 writePunctuation(writer, SyntaxKind.GreaterThanToken);
18331843 }
@@ -5636,7 +5646,7 @@ namespace ts {
56365646 return Ternary.False;
56375647 }
56385648 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++ ) {
56405650 const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
56415651 if (!related) {
56425652 return Ternary.False;
@@ -7312,6 +7322,12 @@ namespace ts {
73127322 }
73137323 return type;
73147324 }
7325+ else if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) {
7326+ if (node === binaryExpression.right) {
7327+ return getContextualType(binaryExpression);
7328+ }
7329+ }
7330+
73157331 return undefined;
73167332 }
73177333
@@ -7424,24 +7440,22 @@ namespace ts {
74247440 return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
74257441 }
74267442
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) {
74327449 if (!attrsType || isTypeAny(attrsType)) {
74337450 return undefined;
74347451 }
7435- else {
7436- return getTypeOfPropertyOfType(attrsType, attrib.name.text);
7437- }
7452+ return getTypeOfPropertyOfType(attrsType, (attribute as JsxAttribute).name.text);
74387453 }
7439-
7440- if (expr.kind === SyntaxKind.JsxSpreadAttribute) {
7441- return getJsxElementAttributesType(<JsxOpeningLikeElement>expr.parent);
7454+ else if (attribute.kind === SyntaxKind.JsxSpreadAttribute) {
7455+ return attrsType;
74427456 }
74437457
7444- return undefined ;
7458+ Debug.fail(`Expected JsxAttribute or JsxSpreadAttribute, got ts.SyntaxKind[${kind}]`) ;
74457459 }
74467460
74477461 // Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
@@ -7509,8 +7523,10 @@ namespace ts {
75097523 case SyntaxKind.ParenthesizedExpression:
75107524 return getContextualType(<ParenthesizedExpression>parent);
75117525 case SyntaxKind.JsxExpression:
7526+ return getContextualType(<JsxExpression>parent);
7527+ case SyntaxKind.JsxAttribute:
75127528 case SyntaxKind.JsxSpreadAttribute:
7513- return getContextualTypeForJsxExpression(<JsxExpression >parent);
7529+ return getContextualTypeForJsxAttribute(<JsxAttribute | JsxSpreadAttribute >parent);
75147530 }
75157531 return undefined;
75167532 }
@@ -7898,31 +7914,12 @@ namespace ts {
78987914 return jsxElementType || anyType;
78997915 }
79007916
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-
79147917 function checkJsxElement(node: JsxElement) {
79157918 // Check attributes
79167919 checkJsxOpeningLikeElement(node.openingElement);
79177920
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);
79267923
79277924 // Check children
79287925 for (const child of node.children) {
@@ -8323,14 +8320,13 @@ namespace ts {
83238320 checkGrammarJsxElement(node);
83248321 checkJsxPreconditions(node);
83258322
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;
83348330 }
83358331
83368332 const targetAttributesType = getJsxElementAttributesType(node);
@@ -13801,7 +13797,8 @@ namespace ts {
1380113797 }
1380213798
1380313799 if (autoValue !== undefined) {
13804- getNodeLinks(member).enumMemberValue = autoValue++;
13800+ getNodeLinks(member).enumMemberValue = autoValue;
13801+ autoValue++;
1380513802 }
1380613803 }
1380713804
0 commit comments