MCPcopy Create free account
hub / github.com/nodejs/node / tryGetContainingJsxElement

Function tryGetContainingJsxElement

test/fixtures/snapshot/typescript.js:134546–134608  ·  view source on GitHub ↗
(contextToken)

Source from the content-addressed store, hash-verified

134544 }
134545 }
134546 function tryGetContainingJsxElement(contextToken) {
134547 if (contextToken) {
134548 var parent = contextToken.parent;
134549 switch (contextToken.kind) {
134550 case 31 /* SyntaxKind.GreaterThanToken */: // End of a type argument list
134551 case 30 /* SyntaxKind.LessThanSlashToken */:
134552 case 43 /* SyntaxKind.SlashToken */:
134553 case 79 /* SyntaxKind.Identifier */:
134554 case 206 /* SyntaxKind.PropertyAccessExpression */:
134555 case 286 /* SyntaxKind.JsxAttributes */:
134556 case 285 /* SyntaxKind.JsxAttribute */:
134557 case 287 /* SyntaxKind.JsxSpreadAttribute */:
134558 if (parent && (parent.kind === 279 /* SyntaxKind.JsxSelfClosingElement */ || parent.kind === 280 /* SyntaxKind.JsxOpeningElement */)) {
134559 if (contextToken.kind === 31 /* SyntaxKind.GreaterThanToken */) {
134560 var precedingToken = ts.findPrecedingToken(contextToken.pos, sourceFile, /*startNode*/ undefined);
134561 if (!parent.typeArguments || (precedingToken && precedingToken.kind === 43 /* SyntaxKind.SlashToken */))
134562 break;
134563 }
134564 return parent;
134565 }
134566 else if (parent.kind === 285 /* SyntaxKind.JsxAttribute */) {
134567 // Currently we parse JsxOpeningLikeElement as:
134568 // JsxOpeningLikeElement
134569 // attributes: JsxAttributes
134570 // properties: NodeArray<JsxAttributeLike>
134571 return parent.parent.parent;
134572 }
134573 break;
134574 // The context token is the closing } or " of an attribute, which means
134575 // its parent is a JsxExpression, whose parent is a JsxAttribute,
134576 // whose parent is a JsxOpeningLikeElement
134577 case 10 /* SyntaxKind.StringLiteral */:
134578 if (parent && ((parent.kind === 285 /* SyntaxKind.JsxAttribute */) || (parent.kind === 287 /* SyntaxKind.JsxSpreadAttribute */))) {
134579 // Currently we parse JsxOpeningLikeElement as:
134580 // JsxOpeningLikeElement
134581 // attributes: JsxAttributes
134582 // properties: NodeArray<JsxAttributeLike>
134583 return parent.parent.parent;
134584 }
134585 break;
134586 case 19 /* SyntaxKind.CloseBraceToken */:
134587 if (parent &&
134588 parent.kind === 288 /* SyntaxKind.JsxExpression */ &&
134589 parent.parent && parent.parent.kind === 285 /* SyntaxKind.JsxAttribute */) {
134590 // Currently we parse JsxOpeningLikeElement as:
134591 // JsxOpeningLikeElement
134592 // attributes: JsxAttributes
134593 // properties: NodeArray<JsxAttributeLike>
134594 // each JsxAttribute can have initializer as JsxExpression
134595 return parent.parent.parent.parent;
134596 }
134597 if (parent && parent.kind === 287 /* SyntaxKind.JsxSpreadAttribute */) {
134598 // Currently we parse JsxOpeningLikeElement as:
134599 // JsxOpeningLikeElement
134600 // attributes: JsxAttributes
134601 // properties: NodeArray<JsxAttributeLike>
134602 return parent.parent.parent;
134603 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected