MCPcopy
hub / github.com/plotly/dash / getDefaultPropsForClassComponent

Function getDefaultPropsForClassComponent

dash/extract-meta.js:570–604  ·  view source on GitHub ↗
(type, source)

Source from the content-addressed store, hash-verified

568 }, {});
569
570 const getDefaultPropsForClassComponent = (type, source) => {
571 // For class component, the type has its own property, then get the
572 // first declaration and one of them will be either
573 // an ObjectLiteralExpression or an Identifier which get in the
574 // newChild with the proper props.
575 const defaultProps = type.getProperty('defaultProps');
576 if (!defaultProps) {
577 return {};
578 }
579 const decl = defaultProps.getDeclarations()[0];
580 let propValues = {};
581
582 decl.getChildren().forEach(child => {
583 let newChild = child;
584
585 if (ts.isIdentifier(child)) {
586 // There should be two identifier, the first is ignored.
587 const value = source.locals.get(child.escapedText);
588 if (
589 value &&
590 value.valueDeclaration &&
591 ts.isVariableDeclaration(value.valueDeclaration) &&
592 value.valueDeclaration.initializer
593 ) {
594 newChild = value.valueDeclaration.initializer;
595 }
596 }
597
598 const {properties} = newChild;
599 if (properties) {
600 propValues = getDefaultPropsValues(properties);
601 }
602 });
603 return propValues;
604 };
605
606 const getProps = (
607 properties,

Callers 1

gatherComponentsFunction · 0.85

Calls 4

getDefaultPropsValuesFunction · 0.85
getPropertyMethod · 0.80
getChildrenMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…