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

Method extractJSXAttribute

compiler/companion/src/JSXProcessor.ts:1430–1467  ·  view source on GitHub ↗
(
    attribute: ts.Node,
    output: JSXOutputState,
    transformContext: ts.TransformationContext,
  )

Source from the content-addressed store, hash-verified

1428 }
1429
1430 private extractJSXAttribute(
1431 attribute: ts.Node,
1432 output: JSXOutputState,
1433 transformContext: ts.TransformationContext,
1434 ): JSXAttribute {
1435 const children = attribute.getChildren();
1436 if (!children.length) {
1437 this.onError(attribute, 'Could not resolve JSX attribute');
1438 }
1439
1440 this.checkNodeKind(children[0], ts.SyntaxKind.Identifier);
1441 if (children.length != 1 && children.length !== 3) {
1442 this.onError(attribute, `Should have 1 or 3 tokens (got ${children.length})`);
1443 }
1444
1445 const name = children[0].getText();
1446
1447 if (name.indexOf('-') >= 0) {
1448 this.onError(attribute, `JSX attributes cannot contain dashes`);
1449 }
1450
1451 let value: JSXAttributeValue;
1452
1453 if (children.length === 3) {
1454 value = this.getJSXAttributeValue(children[2], output);
1455 } else {
1456 value = {
1457 value: transformContext.factory.createTrue(),
1458 kind: JSXAttributeValueKind.static,
1459 };
1460 }
1461
1462 return {
1463 node: attribute,
1464 name,
1465 value,
1466 };
1467 }
1468
1469 private extractJSXSpreadAttribute(node: ts.Node): JSXAttributeValue {
1470 const children = node.getChildren();

Callers 1

extractJSXAttributesMethod · 0.95

Calls 6

onErrorMethod · 0.95
checkNodeKindMethod · 0.95
getJSXAttributeValueMethod · 0.95
getChildrenMethod · 0.65
getTextMethod · 0.65
indexOfMethod · 0.45

Tested by

no test coverage detected