MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getJSXAttributeValue

Method getJSXAttributeValue

compiler/companion/src/JSXProcessor.ts:1390–1428  ·  view source on GitHub ↗
(value: ts.Node, output: JSXOutputState)

Source from the content-addressed store, hash-verified

1388 }
1389
1390 private getJSXAttributeValue(value: ts.Node, output: JSXOutputState): JSXAttributeValue {
1391 if (value.kind === ts.SyntaxKind.JsxExpression) {
1392 const children = value.getChildren();
1393
1394 if (children.length !== 3) {
1395 this.onError(value, `Should have 3 tokens (got ${children.length})`);
1396 }
1397
1398 const expression = children[1];
1399
1400 if (expression.kind === ts.SyntaxKind.NumericLiteral || expression.kind === ts.SyntaxKind.StringLiteral) {
1401 // Shortcut for numeric and string literals, they are never changing so we can consider them constants
1402 return {
1403 value: expression as ts.LiteralExpression,
1404 kind: JSXAttributeValueKind.static,
1405 };
1406 }
1407
1408 if (
1409 ts.isPropertyAccessExpression(expression) &&
1410 this.isExpressionNonStaticMethodDeclaration(expression, output)
1411 ) {
1412 this.onError(
1413 value,
1414 'Resolved TSX attribute value is a method declaration. Please make sure to use a lambda as a stored property to avoid unintentional scoping of `this`, for example `private yourLambdaProperty = () => { ... }`',
1415 );
1416 }
1417
1418 return {
1419 value: expression as ts.Expression,
1420 kind: JSXAttributeValueKind.dynamic,
1421 };
1422 } else {
1423 return {
1424 value: value as ts.Expression,
1425 kind: JSXAttributeValueKind.static,
1426 };
1427 }
1428 }
1429
1430 private extractJSXAttribute(
1431 attribute: ts.Node,

Callers 1

extractJSXAttributeMethod · 0.95

Calls 3

onErrorMethod · 0.95
getChildrenMethod · 0.65

Tested by

no test coverage detected