@@ -507,6 +507,7 @@ namespace ts {
507
507
},
508
508
getAugmentedPropertiesOfType,
509
509
getRootSymbols,
510
+ getSymbolOfExpando,
510
511
getContextualType: (nodeIn: Expression, contextFlags?: ContextFlags) => {
511
512
const node = getParseTreeNode(nodeIn, isExpression);
512
513
if (!node) {
@@ -8728,9 +8729,9 @@ namespace ts {
8728
8729
let links = getSymbolLinks(symbol);
8729
8730
const originalLinks = links;
8730
8731
if (!links.type) {
8731
- const jsDeclaration = symbol.valueDeclaration && getDeclarationOfExpando (symbol.valueDeclaration);
8732
- if (jsDeclaration ) {
8733
- const merged = mergeJSSymbols(symbol, getSymbolOfNode(jsDeclaration) );
8732
+ const expando = symbol.valueDeclaration && getSymbolOfExpando (symbol.valueDeclaration, /*allowDeclaration*/ false );
8733
+ if (expando ) {
8734
+ const merged = mergeJSSymbols(symbol, expando );
8734
8735
if (merged) {
8735
8736
// note:we overwrite links because we just cloned the symbol
8736
8737
symbol = links = merged;
@@ -24828,7 +24829,7 @@ namespace ts {
24828
24829
const exprType = checkJsxAttribute(attributeDecl, checkMode);
24829
24830
objectFlags |= getObjectFlags(exprType) & ObjectFlags.PropagatingFlags;
24830
24831
24831
- const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName);
24832
+ const attributeSymbol = createSymbol(SymbolFlags.Property | member.flags, member.escapedName);
24832
24833
attributeSymbol.declarations = member.declarations;
24833
24834
attributeSymbol.parent = member.parent;
24834
24835
if (member.valueDeclaration) {
@@ -24887,7 +24888,7 @@ namespace ts {
24887
24888
const contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes);
24888
24889
const childrenContextualType = contextualType && getTypeOfPropertyOfContextualType(contextualType, jsxChildrenPropertyName);
24889
24890
// If there are children in the body of JSX element, create dummy attribute "children" with the union of children types so that it will pass the attribute checking process
24890
- const childrenPropSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient , jsxChildrenPropertyName);
24891
+ const childrenPropSymbol = createSymbol(SymbolFlags.Property, jsxChildrenPropertyName);
24891
24892
childrenPropSymbol.type = childrenTypes.length === 1 ? childrenTypes[0] :
24892
24893
childrenContextualType && forEachType(childrenContextualType, isTupleLikeType) ? createTupleType(childrenTypes) :
24893
24894
createArrayType(getUnionType(childrenTypes));
@@ -28075,15 +28076,59 @@ namespace ts {
28075
28076
}
28076
28077
28077
28078
function getAssignedClassSymbol(decl: Declaration): Symbol | undefined {
28078
- const assignmentSymbol = decl && decl.parent &&
28079
- (isFunctionDeclaration(decl) && getSymbolOfNode(decl) ||
28080
- isBinaryExpression(decl.parent) && getSymbolOfNode(decl.parent.left) ||
28081
- isVariableDeclaration(decl.parent) && getSymbolOfNode(decl.parent));
28082
- const prototype = assignmentSymbol && assignmentSymbol.exports && assignmentSymbol.exports.get("prototype" as __String);
28083
- const init = prototype && prototype.valueDeclaration && getAssignedJSPrototype(prototype.valueDeclaration);
28079
+ const assignmentSymbol = decl && getSymbolOfExpando(decl, /*allowDeclaration*/ true);
28080
+ const prototype = assignmentSymbol?.exports?.get("prototype" as __String);
28081
+ const init = prototype?.valueDeclaration && getAssignedJSPrototype(prototype.valueDeclaration);
28084
28082
return init ? getSymbolOfNode(init) : undefined;
28085
28083
}
28086
28084
28085
+ function getSymbolOfExpando(node: Node, allowDeclaration: boolean): Symbol | undefined {
28086
+ if (!node.parent) {
28087
+ return undefined;
28088
+ }
28089
+ let name: Expression | BindingName | undefined;
28090
+ let decl: Node | undefined;
28091
+ if (isVariableDeclaration(node.parent) && node.parent.initializer === node) {
28092
+ if (!isInJSFile(node) && !isVarConst(node.parent)) {
28093
+ return undefined;
28094
+ }
28095
+ name = node.parent.name;
28096
+ decl = node.parent;
28097
+ }
28098
+ else if (isBinaryExpression(node.parent)) {
28099
+ const parentNode = node.parent;
28100
+ const parentNodeOperator = node.parent.operatorToken.kind;
28101
+ if (parentNodeOperator === SyntaxKind.EqualsToken && (allowDeclaration || parentNode.right === node)) {
28102
+ name = parentNode.left;
28103
+ decl = name;
28104
+ }
28105
+ else if (parentNodeOperator === SyntaxKind.BarBarToken || parentNodeOperator === SyntaxKind.QuestionQuestionToken) {
28106
+ if (isVariableDeclaration(parentNode.parent) && parentNode.parent.initializer === parentNode) {
28107
+ name = parentNode.parent.name;
28108
+ decl = parentNode.parent;
28109
+ }
28110
+ else if (isBinaryExpression(parentNode.parent) && parentNode.parent.operatorToken.kind === SyntaxKind.EqualsToken && (allowDeclaration || parentNode.parent.right === parentNode)) {
28111
+ name = parentNode.parent.left;
28112
+ decl = name;
28113
+ }
28114
+
28115
+ if (!name || !isBindableStaticNameExpression(name) || !isSameEntityName(name, parentNode.left)) {
28116
+ return undefined;
28117
+ }
28118
+ }
28119
+ }
28120
+ else if (allowDeclaration && isFunctionDeclaration(node)) {
28121
+ name = node.name;
28122
+ decl = node;
28123
+ }
28124
+
28125
+ if (!decl || !name || (!allowDeclaration && !getExpandoInitializer(node, isPrototypeAccess(name)))) {
28126
+ return undefined;
28127
+ }
28128
+ return getSymbolOfNode(decl);
28129
+ }
28130
+
28131
+
28087
28132
function getAssignedJSPrototype(node: Node) {
28088
28133
if (!node.parent) {
28089
28134
return false;
@@ -28160,14 +28205,11 @@ namespace ts {
28160
28205
}
28161
28206
28162
28207
if (isInJSFile(node)) {
28163
- const decl = getDeclarationOfExpando(node);
28164
- if (decl) {
28165
- const jsSymbol = getSymbolOfNode(decl);
28166
- if (jsSymbol?.exports?.size) {
28167
- const jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined, undefined);
28168
- jsAssignmentType.objectFlags |= ObjectFlags.JSLiteral;
28169
- return getIntersectionType([returnType, jsAssignmentType]);
28170
- }
28208
+ const jsSymbol = getSymbolOfExpando(node, /*allowDeclaration*/ false);
28209
+ if (jsSymbol?.exports?.size) {
28210
+ const jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined, undefined);
28211
+ jsAssignmentType.objectFlags |= ObjectFlags.JSLiteral;
28212
+ return getIntersectionType([returnType, jsAssignmentType]);
28171
28213
}
28172
28214
}
28173
28215
0 commit comments