@agent-scope/babel-plugin 1.20.0 → 1.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +39 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -506,12 +506,48 @@ function safeExtractPropsFromVariableDecl(node, typeMap) {
|
|
|
506
506
|
const props = extractScopePropsWithMap(funcNode, typeMap);
|
|
507
507
|
if (props) return props;
|
|
508
508
|
}
|
|
509
|
+
if (init.type === "CallExpression") {
|
|
510
|
+
const propsTypeArg = extractForwardRefPropsTypeArg(init);
|
|
511
|
+
if (propsTypeArg) {
|
|
512
|
+
const innerFunc = extractFuncNode(init);
|
|
513
|
+
const defaults = innerFunc ? extractDefaultValues(innerFunc.params) : {};
|
|
514
|
+
if (propsTypeArg.type === "TSTypeLiteral") {
|
|
515
|
+
const props = extractPropsFromTypeMembers(propsTypeArg.members, defaults);
|
|
516
|
+
if (Object.keys(props).length > 0) return props;
|
|
517
|
+
} else if (propsTypeArg.type === "TSTypeReference") {
|
|
518
|
+
const refName = resolveTypeReferenceName(propsTypeArg);
|
|
519
|
+
if (refName) {
|
|
520
|
+
const members = typeMap.get(refName);
|
|
521
|
+
if (members) {
|
|
522
|
+
const props = extractPropsFromTypeMembers(members, defaults);
|
|
523
|
+
if (Object.keys(props).length > 0) return props;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
509
529
|
}
|
|
510
530
|
return null;
|
|
511
531
|
} catch {
|
|
512
532
|
return null;
|
|
513
533
|
}
|
|
514
534
|
}
|
|
535
|
+
function extractForwardRefPropsTypeArg(node) {
|
|
536
|
+
if (isReactForwardRefCall(node)) {
|
|
537
|
+
const params = node.typeParameters?.params;
|
|
538
|
+
if (params && params.length >= 2 && params[1]) {
|
|
539
|
+
return params[1];
|
|
540
|
+
}
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
if (node.arguments.length > 0) {
|
|
544
|
+
const first = node.arguments[0];
|
|
545
|
+
if (first?.type === "CallExpression") {
|
|
546
|
+
return extractForwardRefPropsTypeArg(first);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
515
551
|
function extractFuncNode(node) {
|
|
516
552
|
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") {
|
|
517
553
|
return node;
|
|
@@ -521,6 +557,9 @@ function extractFuncNode(node) {
|
|
|
521
557
|
if (first !== void 0 && (first.type === "ArrowFunctionExpression" || first.type === "FunctionExpression")) {
|
|
522
558
|
return first;
|
|
523
559
|
}
|
|
560
|
+
if (first !== void 0 && first.type === "CallExpression") {
|
|
561
|
+
return extractFuncNode(first);
|
|
562
|
+
}
|
|
524
563
|
}
|
|
525
564
|
return null;
|
|
526
565
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/ast-helpers.ts","../src/visitors/component-detector.ts","../src/visitors/prop-type-extractor.ts","../src/visitors/props-injector.ts","../src/visitors/source-injector.ts","../src/index.ts"],"names":["funcNode"],"mappings":";;;;;AAUO,SAAS,gBAAgB,IAAA,EAAuB;AACrD,EAAA,OAAO,QAAA,CAAS,KAAK,IAAI,CAAA;AAC3B;AAKO,SAAS,UAAU,IAAA,EAAgC;AACxD,EAAA,OAAO,IAAA,CAAK,IAAA,KAAS,YAAA,IAAgB,IAAA,CAAK,IAAA,KAAS,aAAA;AACrD;AAMO,SAAS,gBAAgB,IAAA,EAA0C;AACxE,EAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,IAAA,EAAM;AAC5B,IAAA,IAAI,IAAA,CAAK,SAAS,iBAAA,IAAqB,IAAA,CAAK,YAAY,SAAA,CAAU,IAAA,CAAK,QAAQ,CAAA,EAAG;AAChF,MAAA,OAAO,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ACA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,iBAAiB,KAAA,EAA2C;AACnE,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAM,IAAA,EAAM;AAC7B,IAAA,IACE,IAAA,CAAK,IAAA,KAAS,iBAAA,IACd,IAAA,CAAK,QAAA,KACJ,IAAA,CAAK,QAAA,CAAS,IAAA,KAAS,YAAA,IAAgB,IAAA,CAAK,QAAA,CAAS,IAAA,KAAS,aAAA,CAAA,EAC/D;AACA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * AST helper utilities for detecting React component patterns.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n/**\n * Returns true if the identifier name looks like a React component:\n * starts with an uppercase letter.\n */\nexport function isComponentName(name: string): boolean {\n return /^[A-Z]/.test(name);\n}\n\n/**\n * Returns true if the node is a JSX element or JSX fragment.\n */\nexport function isJSXNode(node: BabelTypes.Node): boolean {\n return node.type === \"JSXElement\" || node.type === \"JSXFragment\";\n}\n\n/**\n * Checks whether a return statement (or any node in a function body)\n * contains JSX.\n */\nexport function bodyContainsJSX(node: BabelTypes.BlockStatement): boolean {\n for (const stmt of node.body) {\n if (stmt.type === \"ReturnStatement\" && stmt.argument && isJSXNode(stmt.argument)) {\n return true;\n }\n // Handle ternary / logical returns one level deep\n if (stmt.type === \"ReturnStatement\" && stmt.argument) {\n if (containsJSXExpression(stmt.argument)) return true;\n }\n }\n return false;\n}\n\n/**\n * Recursively checks an expression for JSX nodes (handles ternary, logical, etc).\n */\nexport function containsJSXExpression(\n node:\n | BabelTypes.Expression\n | BabelTypes.SpreadElement\n | BabelTypes.JSXNamespacedName\n | BabelTypes.ArgumentPlaceholder,\n): boolean {\n if (isJSXNode(node as BabelTypes.Node)) return true;\n if (node.type === \"ConditionalExpression\") {\n return containsJSXExpression(node.consequent) || containsJSXExpression(node.alternate);\n }\n if (node.type === \"LogicalExpression\") {\n return containsJSXExpression(node.left) || containsJSXExpression(node.right);\n }\n if (node.type === \"ParenthesizedExpression\") {\n return containsJSXExpression(node.expression);\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.memo(Component) or memo(Component).\n */\nexport function isReactMemoCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"memo\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"memo\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.forwardRef(...) or forwardRef(...).\n */\nexport function isReactForwardRefCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"forwardRef\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"forwardRef\"\n ) {\n return true;\n }\n return false;\n}\n","/**\n * component-detector.ts\n *\n * Identifies React components in the AST. A function is treated as a component if:\n * 1. Its name starts with an uppercase letter.\n * 2. Its body contains a return statement that returns JSX (directly or via conditional).\n *\n * Also handles:\n * - React.memo() and React.forwardRef() wrappers in variable declarations\n * - Default exports of anonymous arrow functions returning JSX\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport {\n bodyContainsJSX,\n containsJSXExpression,\n isComponentName,\n isReactForwardRefCall,\n isReactMemoCall,\n} from \"../utils/ast-helpers.js\";\n\nexport interface DetectedComponent {\n /** Component name (may be \"default\" for anonymous default exports) */\n name: string;\n /** Line number of the component declaration (1-based) */\n line: number;\n /** Column number of the component declaration (0-based) */\n column: number;\n /** The binding identifier node to attach __scopeSource after */\n bindingIdentifierName: string;\n}\n\n/**\n * Try to extract a React component from a FunctionDeclaration node.\n */\nexport function detectFunctionDeclaration(\n node: BabelTypes.FunctionDeclaration,\n): DetectedComponent | null {\n if (!node.id || !isComponentName(node.id.name)) return null;\n if (!node.body || !bodyContainsJSX(node.body)) return null;\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return {\n name: node.id.name,\n line: loc.line,\n column: loc.column,\n bindingIdentifierName: node.id.name,\n };\n}\n\n/**\n * Try to extract a React component from a VariableDeclaration.\n * Handles:\n * const Foo = () => <div/>;\n * const Foo = function() { return <div/>; };\n * const Foo = React.memo(() => <div/>);\n * const Foo = React.forwardRef((ref, props) => <div/>);\n */\nexport function detectVariableDeclaration(\n node: BabelTypes.VariableDeclaration,\n): DetectedComponent | null {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n const name = declarator.id.name;\n if (!isComponentName(name)) continue;\n if (!declarator.init) continue;\n\n if (isFunctionReturningJSX(declarator.init)) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n\n // React.memo(...) or React.forwardRef(...)\n if (\n declarator.init.type === \"CallExpression\" &&\n (isReactMemoCall(declarator.init) || isReactForwardRefCall(declarator.init))\n ) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n }\n return null;\n}\n\n/**\n * Returns true if the given expression is a function/arrow returning JSX.\n */\nfunction isFunctionReturningJSX(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): boolean {\n if (node.type === \"ArrowFunctionExpression\") {\n // Concise body: () => <div/>\n if (node.body.type !== \"BlockStatement\") {\n return containsJSXExpression(node.body);\n }\n return bodyContainsJSX(node.body);\n }\n if (node.type === \"FunctionExpression\") {\n if (!node.body) return false;\n return bodyContainsJSX(node.body);\n }\n return false;\n}\n","/**\n * prop-type-extractor.ts\n *\n * Extracts TypeScript prop type metadata from React component definitions at\n * build time. For each detected component with typed props, emits metadata\n * suitable for building a __scopeProps static property.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface PropMeta {\n type: PropTypeString;\n required: boolean;\n values?: string[];\n defaultValue?: unknown;\n}\n\nexport type PropTypeString =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"union\"\n | \"function\"\n | \"ReactNode\"\n | \"object\"\n | \"array\"\n | \"unknown\";\n\nexport type PropMap = Record<string, PropMeta>;\n\n// ---------------------------------------------------------------------------\n// Type resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Maps a Babel TS type annotation node to a simplified PropTypeString.\n */\nexport function resolvePropType(node: BabelTypes.TSType): PropTypeString {\n switch (node.type) {\n case \"TSStringKeyword\":\n return \"string\";\n case \"TSNumberKeyword\":\n return \"number\";\n case \"TSBooleanKeyword\":\n return \"boolean\";\n case \"TSVoidKeyword\":\n case \"TSUndefinedKeyword\":\n case \"TSNullKeyword\":\n case \"TSNeverKeyword\":\n case \"TSAnyKeyword\":\n case \"TSUnknownKeyword\":\n return \"unknown\";\n\n case \"TSArrayType\":\n case \"TSTupleType\":\n return \"array\";\n\n case \"TSTypeLiteral\":\n case \"TSMappedType\":\n return \"object\";\n\n case \"TSFunctionType\":\n case \"TSConstructorType\":\n return \"function\";\n\n case \"TSTypeReference\": {\n const typeName = resolveTypeReferenceName(node);\n if (\n typeName === \"ReactNode\" ||\n typeName === \"React.ReactNode\" ||\n typeName === \"ReactElement\" ||\n typeName === \"React.ReactElement\"\n ) {\n return \"ReactNode\";\n }\n if (\n typeName === \"MouseEvent\" ||\n typeName === \"KeyboardEvent\" ||\n typeName === \"ChangeEvent\" ||\n typeName === \"FocusEvent\" ||\n typeName === \"SyntheticEvent\" ||\n typeName === \"EventHandler\" ||\n (typeName?.startsWith(\"React.\") && typeName.endsWith(\"Handler\"))\n ) {\n return \"function\";\n }\n return \"unknown\";\n }\n\n case \"TSUnionType\": {\n const members = node.types;\n if (members.length > 0 && members.every((m) => m.type === \"TSLiteralType\")) {\n return \"union\";\n }\n return \"unknown\";\n }\n\n case \"TSIntersectionType\":\n case \"TSConditionalType\":\n case \"TSIndexedAccessType\":\n case \"TSTypeQuery\":\n case \"TSTemplateLiteralType\":\n return \"unknown\";\n\n default:\n return \"unknown\";\n }\n}\n\nfunction resolveTypeReferenceName(node: BabelTypes.TSTypeReference): string | undefined {\n const { typeName } = node;\n if (typeName.type === \"Identifier\") return typeName.name;\n if (typeName.type === \"TSQualifiedName\") {\n const left = typeName.left.type === \"Identifier\" ? typeName.left.name : \"\";\n return `${left}.${typeName.right.name}`;\n }\n return undefined;\n}\n\n// Exported for use in index.ts\nexport { resolveTypeReferenceName };\n\n// ---------------------------------------------------------------------------\n// Literal value extraction\n// ---------------------------------------------------------------------------\n\nfunction extractLiterals(unionNode: BabelTypes.TSUnionType): string[] | undefined {\n const values: string[] = [];\n for (const member of unionNode.types) {\n if (member.type !== \"TSLiteralType\") return undefined;\n const lit = member.literal;\n if (lit.type === \"StringLiteral\") {\n values.push(lit.value);\n } else if (lit.type === \"NumericLiteral\") {\n values.push(String(lit.value));\n } else {\n return undefined;\n }\n }\n return values.length > 0 ? values : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Default value extraction from destructuring\n// ---------------------------------------------------------------------------\n\n/**\n * Walks a function parameter destructuring pattern and returns a map of\n * prop names → their default values.\n */\nexport function extractDefaultValues(\n params: BabelTypes.FunctionDeclaration[\"params\"],\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n if (params.length === 0) return defaults;\n\n const firstParam = params[0];\n if (!firstParam) return defaults;\n\n let pattern: BabelTypes.Node | null = null;\n\n if (firstParam.type === \"ObjectPattern\") {\n pattern = firstParam;\n } else if (firstParam.type === \"AssignmentPattern\" && firstParam.left.type === \"ObjectPattern\") {\n pattern = firstParam.left;\n }\n\n if (pattern?.type === \"ObjectPattern\") {\n for (const prop of pattern.properties) {\n if (prop.type !== \"ObjectProperty\") continue;\n if (prop.key.type !== \"Identifier\") continue;\n const propName = prop.key.name;\n\n if (prop.value.type === \"AssignmentPattern\") {\n const defaultNode = prop.value.right;\n const extracted = extractLiteralValue(defaultNode);\n if (extracted !== undefined) {\n defaults[propName] = extracted;\n }\n }\n }\n }\n\n return defaults;\n}\n\nfunction extractLiteralValue(node: BabelTypes.Node): unknown {\n if (node.type === \"StringLiteral\") return node.value;\n if (node.type === \"NumericLiteral\") return node.value;\n if (node.type === \"BooleanLiteral\") return node.value;\n if (node.type === \"NullLiteral\") return null;\n if (\n node.type === \"UnaryExpression\" &&\n node.operator === \"-\" &&\n node.argument.type === \"NumericLiteral\"\n ) {\n return -node.argument.value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Interface / type alias member resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Extracts prop metadata from TSInterfaceBody members or TSTypeLiteral members.\n */\nexport function extractPropsFromTypeMembers(\n members: BabelTypes.TSTypeElement[],\n defaults: Record<string, unknown>,\n): PropMap {\n const props: PropMap = {};\n\n for (const member of members) {\n if (member.type !== \"TSPropertySignature\") continue;\n if (member.key.type !== \"Identifier\") continue;\n\n const propName = member.key.name;\n const required = !member.optional;\n\n if (!member.typeAnnotation) {\n props[propName] = { type: \"unknown\", required };\n continue;\n }\n\n const tsType = member.typeAnnotation.typeAnnotation;\n let propType = resolvePropType(tsType);\n let values: string[] | undefined;\n\n if (tsType.type === \"TSUnionType\") {\n const literals = extractLiterals(tsType);\n if (literals) {\n propType = \"union\";\n values = literals;\n }\n }\n\n const meta: PropMeta = { type: propType, required };\n if (values) meta.values = values;\n\n const defaultVal = defaults[propName];\n if (defaultVal !== undefined) meta.defaultValue = defaultVal;\n\n props[propName] = meta;\n }\n\n return props;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level: resolve props from a component node\n// ---------------------------------------------------------------------------\n\n/**\n * Given a function node and the program's type declarations, extracts the\n * component's __scopeProps map or returns null if no typed props are found.\n */\nexport function extractScopeProps(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n programBody: BabelTypes.Statement[],\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: function Foo(props: ButtonProps)\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts props from a React.FC<Props> type argument.\n */\nexport function extractScopePropsFromFCTypeArg(\n typeParams: BabelTypes.TSTypeParameterInstantiation | null | undefined,\n programBody: BabelTypes.Statement[],\n defaults: Record<string, unknown>,\n): PropMap | null {\n if (!typeParams || typeParams.params.length === 0) return null;\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) return null;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n if (firstTypeArg.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(firstTypeArg);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Locates interface or type alias members for a given type name in the program body.\n */\nfunction findTypeMembers(\n typeName: string,\n programBody: BabelTypes.Statement[],\n): BabelTypes.TSTypeElement[] | null {\n for (const stmt of programBody) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\" && stmt.id.name === typeName) {\n return stmt.body.body;\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\" &&\n stmt.declaration.id.name === typeName\n ) {\n return stmt.declaration.body.body;\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.id.name === typeName &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.typeAnnotation.members;\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.id.name === typeName &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.declaration.typeAnnotation.members;\n }\n }\n return null;\n}\n","/**\n * props-injector.ts\n *\n * Builds the AST statement that injects the __scopeProps property:\n *\n * ComponentName.__scopeProps = {\n * variant: { type: 'union', required: true, values: ['primary', 'secondary'] },\n * ...\n * };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport type { PropMap, PropMeta } from \"./prop-type-extractor.js\";\n\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n booleanLiteral: typeof BabelTypes.booleanLiteral;\n nullLiteral: typeof BabelTypes.nullLiteral;\n arrayExpression: typeof BabelTypes.arrayExpression;\n}\n\nfunction buildPrimitiveLiteral(t: BabelTypesSubset, value: unknown): BabelTypes.Expression {\n if (typeof value === \"string\") return t.stringLiteral(value);\n if (typeof value === \"number\") return t.numericLiteral(value);\n if (typeof value === \"boolean\") return t.booleanLiteral(value);\n if (value === null) return t.nullLiteral();\n // Fallback — should not reach in practice\n return t.stringLiteral(String(value));\n}\n\nfunction buildPropMetaObject(t: BabelTypesSubset, meta: PropMeta): BabelTypes.ObjectExpression {\n const props: BabelTypes.ObjectProperty[] = [\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(meta.type)),\n t.objectProperty(t.identifier(\"required\"), t.booleanLiteral(meta.required)),\n ];\n\n if (meta.values !== undefined) {\n props.push(\n t.objectProperty(\n t.identifier(\"values\"),\n t.arrayExpression(meta.values.map((v) => t.stringLiteral(v))),\n ),\n );\n }\n\n if (meta.defaultValue !== undefined) {\n props.push(\n t.objectProperty(t.identifier(\"defaultValue\"), buildPrimitiveLiteral(t, meta.defaultValue)),\n );\n }\n\n return t.objectExpression(props);\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeProps = { propA: {...}, propB: {...} };\n */\nexport function buildScopePropsStatement(\n t: BabelTypesSubset,\n name: string,\n props: PropMap,\n): BabelTypes.ExpressionStatement {\n const entries = Object.entries(props).map(([key, meta]) =>\n t.objectProperty(t.identifier(key), buildPropMetaObject(t, meta)),\n );\n\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeProps\")),\n t.objectExpression(entries),\n ),\n );\n}\n","/**\n * source-injector.ts\n *\n * Builds the AST statement that injects the __scopeSource property:\n *\n * ComponentName.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\nexport interface SourceLocation {\n filePath: string;\n line: number;\n column: number;\n}\n\n/**\n * Minimal subset of @babel/types we actually need. Using a structural type\n * instead of `typeof BabelTypes` avoids the `.default` mismatch when Babel\n * re-exports its types namespace differently across bundlers / tsup DTS builds.\n */\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\nexport function buildScopeSourceStatement(\n t: BabelTypesSubset,\n name: string,\n loc: SourceLocation,\n): BabelTypes.ExpressionStatement {\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeSource\")),\n t.objectExpression([\n t.objectProperty(t.identifier(\"filePath\"), t.stringLiteral(loc.filePath)),\n t.objectProperty(t.identifier(\"line\"), t.numericLiteral(loc.line)),\n t.objectProperty(t.identifier(\"column\"), t.numericLiteral(loc.column)),\n ]),\n ),\n );\n}\n","/**\n * @agent-scope/babel-plugin\n *\n * Babel plugin that injects two static properties into React component\n * definitions at compile time:\n *\n * 1. __scopeSource — source location (file, line, column)\n * 2. __scopeProps — TypeScript prop type metadata (when type info is available)\n *\n * Injected shapes:\n * ComponentName.__scopeSource = { filePath: \"src/Button.tsx\", line: 14, column: 0 };\n * ComponentName.__scopeProps = { label: { type: \"string\", required: true }, ... };\n *\n * Usage in babel.config.js:\n * module.exports = { plugins: [\"@agent-scope/babel-plugin\"] };\n *\n * ## Implementation note on type extraction ordering\n *\n * @babel/preset-typescript removes TSInterfaceDeclaration and TSTypeAliasDeclaration\n * nodes from the program body during the same traversal pass. Because Babel traverses\n * top-down, interface declarations (typically defined before the component) are visited\n * and removed BEFORE the FunctionDeclaration visitor fires.\n *\n * To work around this, we use a `Program.enter` visitor to pre-collect all type\n * declarations at the start of the traversal — before any child nodes are visited\n * or removed. The collected type map is stored in plugin state and used during\n * component visitors.\n */\n\nimport type { SourceLocation as ScopeSourceLocation } from \"@agent-scope/core\";\nimport type { types as BabelTypes, NodePath, PluginObj } from \"@babel/core\";\n\nimport {\n detectFunctionDeclaration,\n detectVariableDeclaration,\n} from \"./visitors/component-detector.js\";\nimport type { PropMap } from \"./visitors/prop-type-extractor.js\";\nimport {\n extractDefaultValues,\n extractPropsFromTypeMembers,\n resolveTypeReferenceName,\n} from \"./visitors/prop-type-extractor.js\";\nimport { buildScopePropsStatement } from \"./visitors/props-injector.js\";\nimport { buildScopeSourceStatement } from \"./visitors/source-injector.js\";\n\n// Re-export SourceLocation type for consumers\nexport type { ScopeSourceLocation };\n\n/** Options accepted by the Scope Babel plugin */\nexport interface PluginOptions {\n /** Override the file path injected into __scopeSource (defaults to Babel's filename) */\n filePath?: string;\n}\n\ntype PluginState = { filename?: string; opts: PluginOptions };\n\n/**\n * Per-program type map, keyed by Program node.\n * Using a WeakMap avoids extending Babel's PluginPass type while still giving\n * us file-scoped state that is garbage-collected when the program node is freed.\n */\nconst typeMapsByProgram = new WeakMap<\n BabelTypes.Program,\n Map<string, BabelTypes.TSTypeElement[]>\n>();\n\ntype BabelCore = {\n types: typeof BabelTypes;\n};\n\nexport function scopeBabelPlugin(babel: BabelCore): PluginObj {\n const t = babel.types;\n\n return {\n name: \"@agent-scope/babel-plugin\",\n visitor: {\n /**\n * Pre-collect all top-level type declarations at program entry, before\n * @babel/plugin-transform-typescript removes them during traversal.\n *\n * This fires for the Program node before ANY child visitors, so all\n * TSInterfaceDeclaration and TSTypeAliasDeclaration nodes are still present.\n */\n Program: {\n enter(path: NodePath<BabelTypes.Program>) {\n const typeMap = new Map<string, BabelTypes.TSTypeElement[]>();\n\n for (const stmt of path.node.body) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\") {\n typeMap.set(stmt.id.name, stmt.body.body);\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.body.body);\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.id.name, stmt.typeAnnotation.members);\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.typeAnnotation.members);\n }\n }\n\n typeMapsByProgram.set(path.node, typeMap);\n },\n },\n\n FunctionDeclaration(path: NodePath<BabelTypes.FunctionDeclaration>, state: PluginState) {\n if (path.parentPath?.isExportDefaultDeclaration()) return;\n const component = detectFunctionDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n VariableDeclaration(path: NodePath<BabelTypes.VariableDeclaration>, state: PluginState) {\n const component = detectVariableDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractPropsFromVariableDecl(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n ExportDefaultDeclaration(\n path: NodePath<BabelTypes.ExportDefaultDeclaration>,\n state: PluginState,\n ) {\n const decl = path.node.declaration;\n\n if (decl.type === \"FunctionDeclaration\" && decl.id && decl.body) {\n const component = detectFunctionDeclaration(decl);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(decl, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n return;\n }\n\n if (\n decl.type === \"ArrowFunctionExpression\" ||\n (decl.type === \"FunctionDeclaration\" && !decl.id)\n ) {\n if (!checkAnonymousReturnsJSX(decl)) return;\n const tempName = \"_ScopeDefaultExport\";\n const filePath = resolveFilePath(state);\n const loc = decl.loc?.start ?? { line: 0, column: 0 };\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, tempName, {\n filePath,\n line: loc.line,\n column: loc.column,\n });\n\n const scopeProps = safeExtractScopeProps(\n decl as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n typeMap,\n );\n\n const replacements: BabelTypes.Statement[] = [\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(t.identifier(tempName), decl as BabelTypes.Expression),\n ]),\n sourceStmt,\n ];\n\n if (scopeProps) {\n replacements.push(buildScopePropsStatement(t, tempName, scopeProps));\n }\n\n replacements.push(t.exportDefaultDeclaration(t.identifier(tempName)));\n path.replaceWithMultiple(replacements);\n }\n },\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveFilePath(state: { filename?: string; opts: PluginOptions }): string {\n return state.opts.filePath ?? state.filename ?? \"<unknown>\";\n}\n\nfunction getTypeMap(path: NodePath): Map<string, BabelTypes.TSTypeElement[]> {\n const program = path.findParent((p) => p.isProgram());\n if (!program || !program.isProgram()) return new Map();\n return typeMapsByProgram.get(program.node) ?? new Map();\n}\n\n/**\n * Safe wrapper around extractScopeProps using the pre-collected type map.\n */\nfunction safeExtractScopeProps(\n node:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n return extractScopePropsWithMap(node, typeMap);\n } catch {\n return null;\n }\n}\n\n/**\n * Extracts scope props using the pre-collected type map instead of scanning\n * the (potentially already-stripped) program body.\n */\nfunction extractScopePropsWithMap(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: look up in pre-collected type map\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = typeMap.get(typeName);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts scope props from a VariableDeclaration using the pre-collected type map.\n * Handles:\n * const Foo = (props: FooProps) => ...\n * const Foo: React.FC<FooProps> = (props) => ...\n */\nfunction safeExtractPropsFromVariableDecl(\n node: BabelTypes.VariableDeclaration,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n if (!declarator.init) continue;\n\n const init = declarator.init;\n\n // const Foo: React.FC<Props> = (props) => ...\n if (declarator.id.typeAnnotation?.type === \"TSTypeAnnotation\") {\n const tsType = declarator.id.typeAnnotation.typeAnnotation;\n if (tsType.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(tsType);\n if (\n typeName === \"React.FC\" ||\n typeName === \"FC\" ||\n typeName === \"React.FunctionComponent\" ||\n typeName === \"FunctionComponent\"\n ) {\n const typeParams = tsType.typeParameters;\n const funcNode = extractFuncNode(init);\n const defaults = funcNode ? extractDefaultValues(funcNode.params) : {};\n\n // Resolve type arg using our type map\n if (typeParams && typeParams.params.length > 0) {\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) continue;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (firstTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(firstTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n }\n\n // Direct arrow/function expression with typed params\n const funcNode = extractFuncNode(init);\n if (funcNode) {\n const props = extractScopePropsWithMap(funcNode, typeMap);\n if (props) return props;\n }\n }\n return null;\n } catch {\n return null;\n }\n}\n\nfunction extractFuncNode(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression | null {\n if (node.type === \"ArrowFunctionExpression\" || node.type === \"FunctionExpression\") {\n return node;\n }\n // React.memo(fn) or React.forwardRef(fn)\n if (node.type === \"CallExpression\" && node.arguments.length > 0) {\n const first = node.arguments[0];\n if (\n first !== undefined &&\n (first.type === \"ArrowFunctionExpression\" || first.type === \"FunctionExpression\")\n ) {\n return first as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression;\n }\n }\n return null;\n}\n\nfunction checkAnonymousReturnsJSX(\n decl: BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n): boolean {\n if (decl.type === \"ArrowFunctionExpression\") {\n const body = decl.body;\n if (body.type !== \"BlockStatement\") {\n return body.type === \"JSXElement\" || body.type === \"JSXFragment\";\n }\n return bodyHasJSXReturn(body);\n }\n if (decl.type === \"FunctionDeclaration\" && decl.body) {\n return bodyHasJSXReturn(decl.body);\n }\n return false;\n}\n\nfunction bodyHasJSXReturn(block: BabelTypes.BlockStatement): boolean {\n for (const stmt of block.body) {\n if (\n stmt.type === \"ReturnStatement\" &&\n stmt.argument &&\n (stmt.argument.type === \"JSXElement\" || stmt.argument.type === \"JSXFragment\")\n ) {\n return true;\n }\n }\n return false;\n}\n\nexport default scopeBabelPlugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/ast-helpers.ts","../src/visitors/component-detector.ts","../src/visitors/prop-type-extractor.ts","../src/visitors/props-injector.ts","../src/visitors/source-injector.ts","../src/index.ts"],"names":["funcNode"],"mappings":";;;;;AAUO,SAAS,gBAAgB,IAAA,EAAuB;AACrD,EAAA,OA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["/**\n * AST helper utilities for detecting React component patterns.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n/**\n * Returns true if the identifier name looks like a React component:\n * starts with an uppercase letter.\n */\nexport function isComponentName(name: string): boolean {\n return /^[A-Z]/.test(name);\n}\n\n/**\n * Returns true if the node is a JSX element or JSX fragment.\n */\nexport function isJSXNode(node: BabelTypes.Node): boolean {\n return node.type === \"JSXElement\" || node.type === \"JSXFragment\";\n}\n\n/**\n * Checks whether a return statement (or any node in a function body)\n * contains JSX.\n */\nexport function bodyContainsJSX(node: BabelTypes.BlockStatement): boolean {\n for (const stmt of node.body) {\n if (stmt.type === \"ReturnStatement\" && stmt.argument && isJSXNode(stmt.argument)) {\n return true;\n }\n // Handle ternary / logical returns one level deep\n if (stmt.type === \"ReturnStatement\" && stmt.argument) {\n if (containsJSXExpression(stmt.argument)) return true;\n }\n }\n return false;\n}\n\n/**\n * Recursively checks an expression for JSX nodes (handles ternary, logical, etc).\n */\nexport function containsJSXExpression(\n node:\n | BabelTypes.Expression\n | BabelTypes.SpreadElement\n | BabelTypes.JSXNamespacedName\n | BabelTypes.ArgumentPlaceholder,\n): boolean {\n if (isJSXNode(node as BabelTypes.Node)) return true;\n if (node.type === \"ConditionalExpression\") {\n return containsJSXExpression(node.consequent) || containsJSXExpression(node.alternate);\n }\n if (node.type === \"LogicalExpression\") {\n return containsJSXExpression(node.left) || containsJSXExpression(node.right);\n }\n if (node.type === \"ParenthesizedExpression\") {\n return containsJSXExpression(node.expression);\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.memo(Component) or memo(Component).\n */\nexport function isReactMemoCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"memo\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"memo\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.forwardRef(...) or forwardRef(...).\n */\nexport function isReactForwardRefCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"forwardRef\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"forwardRef\"\n ) {\n return true;\n }\n return false;\n}\n","/**\n * component-detector.ts\n *\n * Identifies React components in the AST. A function is treated as a component if:\n * 1. Its name starts with an uppercase letter.\n * 2. Its body contains a return statement that returns JSX (directly or via conditional).\n *\n * Also handles:\n * - React.memo() and React.forwardRef() wrappers in variable declarations\n * - Default exports of anonymous arrow functions returning JSX\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport {\n bodyContainsJSX,\n containsJSXExpression,\n isComponentName,\n isReactForwardRefCall,\n isReactMemoCall,\n} from \"../utils/ast-helpers.js\";\n\nexport interface DetectedComponent {\n /** Component name (may be \"default\" for anonymous default exports) */\n name: string;\n /** Line number of the component declaration (1-based) */\n line: number;\n /** Column number of the component declaration (0-based) */\n column: number;\n /** The binding identifier node to attach __scopeSource after */\n bindingIdentifierName: string;\n}\n\n/**\n * Try to extract a React component from a FunctionDeclaration node.\n */\nexport function detectFunctionDeclaration(\n node: BabelTypes.FunctionDeclaration,\n): DetectedComponent | null {\n if (!node.id || !isComponentName(node.id.name)) return null;\n if (!node.body || !bodyContainsJSX(node.body)) return null;\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return {\n name: node.id.name,\n line: loc.line,\n column: loc.column,\n bindingIdentifierName: node.id.name,\n };\n}\n\n/**\n * Try to extract a React component from a VariableDeclaration.\n * Handles:\n * const Foo = () => <div/>;\n * const Foo = function() { return <div/>; };\n * const Foo = React.memo(() => <div/>);\n * const Foo = React.forwardRef((ref, props) => <div/>);\n */\nexport function detectVariableDeclaration(\n node: BabelTypes.VariableDeclaration,\n): DetectedComponent | null {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n const name = declarator.id.name;\n if (!isComponentName(name)) continue;\n if (!declarator.init) continue;\n\n if (isFunctionReturningJSX(declarator.init)) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n\n // React.memo(...) or React.forwardRef(...)\n if (\n declarator.init.type === \"CallExpression\" &&\n (isReactMemoCall(declarator.init) || isReactForwardRefCall(declarator.init))\n ) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n }\n return null;\n}\n\n/**\n * Returns true if the given expression is a function/arrow returning JSX.\n */\nfunction isFunctionReturningJSX(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): boolean {\n if (node.type === \"ArrowFunctionExpression\") {\n // Concise body: () => <div/>\n if (node.body.type !== \"BlockStatement\") {\n return containsJSXExpression(node.body);\n }\n return bodyContainsJSX(node.body);\n }\n if (node.type === \"FunctionExpression\") {\n if (!node.body) return false;\n return bodyContainsJSX(node.body);\n }\n return false;\n}\n","/**\n * prop-type-extractor.ts\n *\n * Extracts TypeScript prop type metadata from React component definitions at\n * build time. For each detected component with typed props, emits metadata\n * suitable for building a __scopeProps static property.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface PropMeta {\n type: PropTypeString;\n required: boolean;\n values?: string[];\n defaultValue?: unknown;\n}\n\nexport type PropTypeString =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"union\"\n | \"function\"\n | \"ReactNode\"\n | \"object\"\n | \"array\"\n | \"unknown\";\n\nexport type PropMap = Record<string, PropMeta>;\n\n// ---------------------------------------------------------------------------\n// Type resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Maps a Babel TS type annotation node to a simplified PropTypeString.\n */\nexport function resolvePropType(node: BabelTypes.TSType): PropTypeString {\n switch (node.type) {\n case \"TSStringKeyword\":\n return \"string\";\n case \"TSNumberKeyword\":\n return \"number\";\n case \"TSBooleanKeyword\":\n return \"boolean\";\n case \"TSVoidKeyword\":\n case \"TSUndefinedKeyword\":\n case \"TSNullKeyword\":\n case \"TSNeverKeyword\":\n case \"TSAnyKeyword\":\n case \"TSUnknownKeyword\":\n return \"unknown\";\n\n case \"TSArrayType\":\n case \"TSTupleType\":\n return \"array\";\n\n case \"TSTypeLiteral\":\n case \"TSMappedType\":\n return \"object\";\n\n case \"TSFunctionType\":\n case \"TSConstructorType\":\n return \"function\";\n\n case \"TSTypeReference\": {\n const typeName = resolveTypeReferenceName(node);\n if (\n typeName === \"ReactNode\" ||\n typeName === \"React.ReactNode\" ||\n typeName === \"ReactElement\" ||\n typeName === \"React.ReactElement\"\n ) {\n return \"ReactNode\";\n }\n if (\n typeName === \"MouseEvent\" ||\n typeName === \"KeyboardEvent\" ||\n typeName === \"ChangeEvent\" ||\n typeName === \"FocusEvent\" ||\n typeName === \"SyntheticEvent\" ||\n typeName === \"EventHandler\" ||\n (typeName?.startsWith(\"React.\") && typeName.endsWith(\"Handler\"))\n ) {\n return \"function\";\n }\n return \"unknown\";\n }\n\n case \"TSUnionType\": {\n const members = node.types;\n if (members.length > 0 && members.every((m) => m.type === \"TSLiteralType\")) {\n return \"union\";\n }\n return \"unknown\";\n }\n\n case \"TSIntersectionType\":\n case \"TSConditionalType\":\n case \"TSIndexedAccessType\":\n case \"TSTypeQuery\":\n case \"TSTemplateLiteralType\":\n return \"unknown\";\n\n default:\n return \"unknown\";\n }\n}\n\nfunction resolveTypeReferenceName(node: BabelTypes.TSTypeReference): string | undefined {\n const { typeName } = node;\n if (typeName.type === \"Identifier\") return typeName.name;\n if (typeName.type === \"TSQualifiedName\") {\n const left = typeName.left.type === \"Identifier\" ? typeName.left.name : \"\";\n return `${left}.${typeName.right.name}`;\n }\n return undefined;\n}\n\n// Exported for use in index.ts\nexport { resolveTypeReferenceName };\n\n// ---------------------------------------------------------------------------\n// Literal value extraction\n// ---------------------------------------------------------------------------\n\nfunction extractLiterals(unionNode: BabelTypes.TSUnionType): string[] | undefined {\n const values: string[] = [];\n for (const member of unionNode.types) {\n if (member.type !== \"TSLiteralType\") return undefined;\n const lit = member.literal;\n if (lit.type === \"StringLiteral\") {\n values.push(lit.value);\n } else if (lit.type === \"NumericLiteral\") {\n values.push(String(lit.value));\n } else {\n return undefined;\n }\n }\n return values.length > 0 ? values : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Default value extraction from destructuring\n// ---------------------------------------------------------------------------\n\n/**\n * Walks a function parameter destructuring pattern and returns a map of\n * prop names → their default values.\n */\nexport function extractDefaultValues(\n params: BabelTypes.FunctionDeclaration[\"params\"],\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n if (params.length === 0) return defaults;\n\n const firstParam = params[0];\n if (!firstParam) return defaults;\n\n let pattern: BabelTypes.Node | null = null;\n\n if (firstParam.type === \"ObjectPattern\") {\n pattern = firstParam;\n } else if (firstParam.type === \"AssignmentPattern\" && firstParam.left.type === \"ObjectPattern\") {\n pattern = firstParam.left;\n }\n\n if (pattern?.type === \"ObjectPattern\") {\n for (const prop of pattern.properties) {\n if (prop.type !== \"ObjectProperty\") continue;\n if (prop.key.type !== \"Identifier\") continue;\n const propName = prop.key.name;\n\n if (prop.value.type === \"AssignmentPattern\") {\n const defaultNode = prop.value.right;\n const extracted = extractLiteralValue(defaultNode);\n if (extracted !== undefined) {\n defaults[propName] = extracted;\n }\n }\n }\n }\n\n return defaults;\n}\n\nfunction extractLiteralValue(node: BabelTypes.Node): unknown {\n if (node.type === \"StringLiteral\") return node.value;\n if (node.type === \"NumericLiteral\") return node.value;\n if (node.type === \"BooleanLiteral\") return node.value;\n if (node.type === \"NullLiteral\") return null;\n if (\n node.type === \"UnaryExpression\" &&\n node.operator === \"-\" &&\n node.argument.type === \"NumericLiteral\"\n ) {\n return -node.argument.value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Interface / type alias member resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Extracts prop metadata from TSInterfaceBody members or TSTypeLiteral members.\n */\nexport function extractPropsFromTypeMembers(\n members: BabelTypes.TSTypeElement[],\n defaults: Record<string, unknown>,\n): PropMap {\n const props: PropMap = {};\n\n for (const member of members) {\n if (member.type !== \"TSPropertySignature\") continue;\n if (member.key.type !== \"Identifier\") continue;\n\n const propName = member.key.name;\n const required = !member.optional;\n\n if (!member.typeAnnotation) {\n props[propName] = { type: \"unknown\", required };\n continue;\n }\n\n const tsType = member.typeAnnotation.typeAnnotation;\n let propType = resolvePropType(tsType);\n let values: string[] | undefined;\n\n if (tsType.type === \"TSUnionType\") {\n const literals = extractLiterals(tsType);\n if (literals) {\n propType = \"union\";\n values = literals;\n }\n }\n\n const meta: PropMeta = { type: propType, required };\n if (values) meta.values = values;\n\n const defaultVal = defaults[propName];\n if (defaultVal !== undefined) meta.defaultValue = defaultVal;\n\n props[propName] = meta;\n }\n\n return props;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level: resolve props from a component node\n// ---------------------------------------------------------------------------\n\n/**\n * Given a function node and the program's type declarations, extracts the\n * component's __scopeProps map or returns null if no typed props are found.\n */\nexport function extractScopeProps(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n programBody: BabelTypes.Statement[],\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: function Foo(props: ButtonProps)\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts props from a React.FC<Props> type argument.\n */\nexport function extractScopePropsFromFCTypeArg(\n typeParams: BabelTypes.TSTypeParameterInstantiation | null | undefined,\n programBody: BabelTypes.Statement[],\n defaults: Record<string, unknown>,\n): PropMap | null {\n if (!typeParams || typeParams.params.length === 0) return null;\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) return null;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n if (firstTypeArg.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(firstTypeArg);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Locates interface or type alias members for a given type name in the program body.\n */\nfunction findTypeMembers(\n typeName: string,\n programBody: BabelTypes.Statement[],\n): BabelTypes.TSTypeElement[] | null {\n for (const stmt of programBody) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\" && stmt.id.name === typeName) {\n return stmt.body.body;\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\" &&\n stmt.declaration.id.name === typeName\n ) {\n return stmt.declaration.body.body;\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.id.name === typeName &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.typeAnnotation.members;\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.id.name === typeName &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.declaration.typeAnnotation.members;\n }\n }\n return null;\n}\n","/**\n * props-injector.ts\n *\n * Builds the AST statement that injects the __scopeProps property:\n *\n * ComponentName.__scopeProps = {\n * variant: { type: 'union', required: true, values: ['primary', 'secondary'] },\n * ...\n * };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport type { PropMap, PropMeta } from \"./prop-type-extractor.js\";\n\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n booleanLiteral: typeof BabelTypes.booleanLiteral;\n nullLiteral: typeof BabelTypes.nullLiteral;\n arrayExpression: typeof BabelTypes.arrayExpression;\n}\n\nfunction buildPrimitiveLiteral(t: BabelTypesSubset, value: unknown): BabelTypes.Expression {\n if (typeof value === \"string\") return t.stringLiteral(value);\n if (typeof value === \"number\") return t.numericLiteral(value);\n if (typeof value === \"boolean\") return t.booleanLiteral(value);\n if (value === null) return t.nullLiteral();\n // Fallback — should not reach in practice\n return t.stringLiteral(String(value));\n}\n\nfunction buildPropMetaObject(t: BabelTypesSubset, meta: PropMeta): BabelTypes.ObjectExpression {\n const props: BabelTypes.ObjectProperty[] = [\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(meta.type)),\n t.objectProperty(t.identifier(\"required\"), t.booleanLiteral(meta.required)),\n ];\n\n if (meta.values !== undefined) {\n props.push(\n t.objectProperty(\n t.identifier(\"values\"),\n t.arrayExpression(meta.values.map((v) => t.stringLiteral(v))),\n ),\n );\n }\n\n if (meta.defaultValue !== undefined) {\n props.push(\n t.objectProperty(t.identifier(\"defaultValue\"), buildPrimitiveLiteral(t, meta.defaultValue)),\n );\n }\n\n return t.objectExpression(props);\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeProps = { propA: {...}, propB: {...} };\n */\nexport function buildScopePropsStatement(\n t: BabelTypesSubset,\n name: string,\n props: PropMap,\n): BabelTypes.ExpressionStatement {\n const entries = Object.entries(props).map(([key, meta]) =>\n t.objectProperty(t.identifier(key), buildPropMetaObject(t, meta)),\n );\n\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeProps\")),\n t.objectExpression(entries),\n ),\n );\n}\n","/**\n * source-injector.ts\n *\n * Builds the AST statement that injects the __scopeSource property:\n *\n * ComponentName.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\nexport interface SourceLocation {\n filePath: string;\n line: number;\n column: number;\n}\n\n/**\n * Minimal subset of @babel/types we actually need. Using a structural type\n * instead of `typeof BabelTypes` avoids the `.default` mismatch when Babel\n * re-exports its types namespace differently across bundlers / tsup DTS builds.\n */\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\nexport function buildScopeSourceStatement(\n t: BabelTypesSubset,\n name: string,\n loc: SourceLocation,\n): BabelTypes.ExpressionStatement {\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeSource\")),\n t.objectExpression([\n t.objectProperty(t.identifier(\"filePath\"), t.stringLiteral(loc.filePath)),\n t.objectProperty(t.identifier(\"line\"), t.numericLiteral(loc.line)),\n t.objectProperty(t.identifier(\"column\"), t.numericLiteral(loc.column)),\n ]),\n ),\n );\n}\n","/**\n * @agent-scope/babel-plugin\n *\n * Babel plugin that injects two static properties into React component\n * definitions at compile time:\n *\n * 1. __scopeSource — source location (file, line, column)\n * 2. __scopeProps — TypeScript prop type metadata (when type info is available)\n *\n * Injected shapes:\n * ComponentName.__scopeSource = { filePath: \"src/Button.tsx\", line: 14, column: 0 };\n * ComponentName.__scopeProps = { label: { type: \"string\", required: true }, ... };\n *\n * Usage in babel.config.js:\n * module.exports = { plugins: [\"@agent-scope/babel-plugin\"] };\n *\n * ## Implementation note on type extraction ordering\n *\n * @babel/preset-typescript removes TSInterfaceDeclaration and TSTypeAliasDeclaration\n * nodes from the program body during the same traversal pass. Because Babel traverses\n * top-down, interface declarations (typically defined before the component) are visited\n * and removed BEFORE the FunctionDeclaration visitor fires.\n *\n * To work around this, we use a `Program.enter` visitor to pre-collect all type\n * declarations at the start of the traversal — before any child nodes are visited\n * or removed. The collected type map is stored in plugin state and used during\n * component visitors.\n */\n\nimport type { SourceLocation as ScopeSourceLocation } from \"@agent-scope/core\";\nimport type { types as BabelTypes, NodePath, PluginObj } from \"@babel/core\";\nimport { isReactForwardRefCall } from \"./utils/ast-helpers.js\";\nimport {\n detectFunctionDeclaration,\n detectVariableDeclaration,\n} from \"./visitors/component-detector.js\";\nimport type { PropMap } from \"./visitors/prop-type-extractor.js\";\nimport {\n extractDefaultValues,\n extractPropsFromTypeMembers,\n resolveTypeReferenceName,\n} from \"./visitors/prop-type-extractor.js\";\nimport { buildScopePropsStatement } from \"./visitors/props-injector.js\";\nimport { buildScopeSourceStatement } from \"./visitors/source-injector.js\";\n\n// Re-export SourceLocation type for consumers\nexport type { ScopeSourceLocation };\n\n/** Options accepted by the Scope Babel plugin */\nexport interface PluginOptions {\n /** Override the file path injected into __scopeSource (defaults to Babel's filename) */\n filePath?: string;\n}\n\ntype PluginState = { filename?: string; opts: PluginOptions };\n\n/**\n * Per-program type map, keyed by Program node.\n * Using a WeakMap avoids extending Babel's PluginPass type while still giving\n * us file-scoped state that is garbage-collected when the program node is freed.\n */\nconst typeMapsByProgram = new WeakMap<\n BabelTypes.Program,\n Map<string, BabelTypes.TSTypeElement[]>\n>();\n\ntype BabelCore = {\n types: typeof BabelTypes;\n};\n\nexport function scopeBabelPlugin(babel: BabelCore): PluginObj {\n const t = babel.types;\n\n return {\n name: \"@agent-scope/babel-plugin\",\n visitor: {\n /**\n * Pre-collect all top-level type declarations at program entry, before\n * @babel/plugin-transform-typescript removes them during traversal.\n *\n * This fires for the Program node before ANY child visitors, so all\n * TSInterfaceDeclaration and TSTypeAliasDeclaration nodes are still present.\n */\n Program: {\n enter(path: NodePath<BabelTypes.Program>) {\n const typeMap = new Map<string, BabelTypes.TSTypeElement[]>();\n\n for (const stmt of path.node.body) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\") {\n typeMap.set(stmt.id.name, stmt.body.body);\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.body.body);\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.id.name, stmt.typeAnnotation.members);\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.typeAnnotation.members);\n }\n }\n\n typeMapsByProgram.set(path.node, typeMap);\n },\n },\n\n FunctionDeclaration(path: NodePath<BabelTypes.FunctionDeclaration>, state: PluginState) {\n if (path.parentPath?.isExportDefaultDeclaration()) return;\n const component = detectFunctionDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n VariableDeclaration(path: NodePath<BabelTypes.VariableDeclaration>, state: PluginState) {\n const component = detectVariableDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractPropsFromVariableDecl(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n ExportDefaultDeclaration(\n path: NodePath<BabelTypes.ExportDefaultDeclaration>,\n state: PluginState,\n ) {\n const decl = path.node.declaration;\n\n if (decl.type === \"FunctionDeclaration\" && decl.id && decl.body) {\n const component = detectFunctionDeclaration(decl);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(decl, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n return;\n }\n\n if (\n decl.type === \"ArrowFunctionExpression\" ||\n (decl.type === \"FunctionDeclaration\" && !decl.id)\n ) {\n if (!checkAnonymousReturnsJSX(decl)) return;\n const tempName = \"_ScopeDefaultExport\";\n const filePath = resolveFilePath(state);\n const loc = decl.loc?.start ?? { line: 0, column: 0 };\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, tempName, {\n filePath,\n line: loc.line,\n column: loc.column,\n });\n\n const scopeProps = safeExtractScopeProps(\n decl as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n typeMap,\n );\n\n const replacements: BabelTypes.Statement[] = [\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(t.identifier(tempName), decl as BabelTypes.Expression),\n ]),\n sourceStmt,\n ];\n\n if (scopeProps) {\n replacements.push(buildScopePropsStatement(t, tempName, scopeProps));\n }\n\n replacements.push(t.exportDefaultDeclaration(t.identifier(tempName)));\n path.replaceWithMultiple(replacements);\n }\n },\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveFilePath(state: { filename?: string; opts: PluginOptions }): string {\n return state.opts.filePath ?? state.filename ?? \"<unknown>\";\n}\n\nfunction getTypeMap(path: NodePath): Map<string, BabelTypes.TSTypeElement[]> {\n const program = path.findParent((p) => p.isProgram());\n if (!program || !program.isProgram()) return new Map();\n return typeMapsByProgram.get(program.node) ?? new Map();\n}\n\n/**\n * Safe wrapper around extractScopeProps using the pre-collected type map.\n */\nfunction safeExtractScopeProps(\n node:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n return extractScopePropsWithMap(node, typeMap);\n } catch {\n return null;\n }\n}\n\n/**\n * Extracts scope props using the pre-collected type map instead of scanning\n * the (potentially already-stripped) program body.\n */\nfunction extractScopePropsWithMap(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: look up in pre-collected type map\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = typeMap.get(typeName);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts scope props from a VariableDeclaration using the pre-collected type map.\n * Handles:\n * const Foo = (props: FooProps) => ...\n * const Foo: React.FC<FooProps> = (props) => ...\n */\nfunction safeExtractPropsFromVariableDecl(\n node: BabelTypes.VariableDeclaration,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n if (!declarator.init) continue;\n\n const init = declarator.init;\n\n // const Foo: React.FC<Props> = (props) => ...\n if (declarator.id.typeAnnotation?.type === \"TSTypeAnnotation\") {\n const tsType = declarator.id.typeAnnotation.typeAnnotation;\n if (tsType.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(tsType);\n if (\n typeName === \"React.FC\" ||\n typeName === \"FC\" ||\n typeName === \"React.FunctionComponent\" ||\n typeName === \"FunctionComponent\"\n ) {\n const typeParams = tsType.typeParameters;\n const funcNode = extractFuncNode(init);\n const defaults = funcNode ? extractDefaultValues(funcNode.params) : {};\n\n // Resolve type arg using our type map\n if (typeParams && typeParams.params.length > 0) {\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) continue;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (firstTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(firstTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n }\n\n // Direct arrow/function expression with typed params\n const funcNode = extractFuncNode(init);\n if (funcNode) {\n const props = extractScopePropsWithMap(funcNode, typeMap);\n if (props) return props;\n }\n\n // forwardRef<Ref, Props>(...) — extract props from the second type argument\n if (init.type === \"CallExpression\") {\n const propsTypeArg = extractForwardRefPropsTypeArg(init);\n if (propsTypeArg) {\n const innerFunc = extractFuncNode(init);\n const defaults = innerFunc ? extractDefaultValues(innerFunc.params) : {};\n\n if (propsTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(propsTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (propsTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(propsTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n return null;\n } catch {\n return null;\n }\n}\n\n/**\n * Given a call expression that may be forwardRef<Ref, Props>(...) or\n * memo(forwardRef<Ref, Props>(...)), return the Props type argument node.\n */\nfunction extractForwardRefPropsTypeArg(node: BabelTypes.CallExpression): BabelTypes.TSType | null {\n if (isReactForwardRefCall(node)) {\n const params = node.typeParameters?.params;\n if (params && params.length >= 2 && params[1]) {\n return params[1];\n }\n return null;\n }\n\n // Recurse into nested calls: memo(forwardRef<Ref, Props>(...))\n if (node.arguments.length > 0) {\n const first = node.arguments[0];\n if (first?.type === \"CallExpression\") {\n return extractForwardRefPropsTypeArg(first);\n }\n }\n\n return null;\n}\n\nfunction extractFuncNode(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression | null {\n if (node.type === \"ArrowFunctionExpression\" || node.type === \"FunctionExpression\") {\n return node;\n }\n if (node.type === \"CallExpression\" && node.arguments.length > 0) {\n const first = node.arguments[0];\n if (\n first !== undefined &&\n (first.type === \"ArrowFunctionExpression\" || first.type === \"FunctionExpression\")\n ) {\n return first as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression;\n }\n // Recurse for nested calls like memo(forwardRef(fn))\n if (first !== undefined && first.type === \"CallExpression\") {\n return extractFuncNode(first);\n }\n }\n return null;\n}\n\nfunction checkAnonymousReturnsJSX(\n decl: BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n): boolean {\n if (decl.type === \"ArrowFunctionExpression\") {\n const body = decl.body;\n if (body.type !== \"BlockStatement\") {\n return body.type === \"JSXElement\" || body.type === \"JSXFragment\";\n }\n return bodyHasJSXReturn(body);\n }\n if (decl.type === \"FunctionDeclaration\" && decl.body) {\n return bodyHasJSXReturn(decl.body);\n }\n return false;\n}\n\nfunction bodyHasJSXReturn(block: BabelTypes.BlockStatement): boolean {\n for (const stmt of block.body) {\n if (\n stmt.type === \"ReturnStatement\" &&\n stmt.argument &&\n (stmt.argument.type === \"JSXElement\" || stmt.argument.type === \"JSXFragment\")\n ) {\n return true;\n }\n }\n return false;\n}\n\nexport default scopeBabelPlugin;\n"]}
|
package/dist/index.js
CHANGED
|
@@ -502,12 +502,48 @@ function safeExtractPropsFromVariableDecl(node, typeMap) {
|
|
|
502
502
|
const props = extractScopePropsWithMap(funcNode, typeMap);
|
|
503
503
|
if (props) return props;
|
|
504
504
|
}
|
|
505
|
+
if (init.type === "CallExpression") {
|
|
506
|
+
const propsTypeArg = extractForwardRefPropsTypeArg(init);
|
|
507
|
+
if (propsTypeArg) {
|
|
508
|
+
const innerFunc = extractFuncNode(init);
|
|
509
|
+
const defaults = innerFunc ? extractDefaultValues(innerFunc.params) : {};
|
|
510
|
+
if (propsTypeArg.type === "TSTypeLiteral") {
|
|
511
|
+
const props = extractPropsFromTypeMembers(propsTypeArg.members, defaults);
|
|
512
|
+
if (Object.keys(props).length > 0) return props;
|
|
513
|
+
} else if (propsTypeArg.type === "TSTypeReference") {
|
|
514
|
+
const refName = resolveTypeReferenceName(propsTypeArg);
|
|
515
|
+
if (refName) {
|
|
516
|
+
const members = typeMap.get(refName);
|
|
517
|
+
if (members) {
|
|
518
|
+
const props = extractPropsFromTypeMembers(members, defaults);
|
|
519
|
+
if (Object.keys(props).length > 0) return props;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
505
525
|
}
|
|
506
526
|
return null;
|
|
507
527
|
} catch {
|
|
508
528
|
return null;
|
|
509
529
|
}
|
|
510
530
|
}
|
|
531
|
+
function extractForwardRefPropsTypeArg(node) {
|
|
532
|
+
if (isReactForwardRefCall(node)) {
|
|
533
|
+
const params = node.typeParameters?.params;
|
|
534
|
+
if (params && params.length >= 2 && params[1]) {
|
|
535
|
+
return params[1];
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
if (node.arguments.length > 0) {
|
|
540
|
+
const first = node.arguments[0];
|
|
541
|
+
if (first?.type === "CallExpression") {
|
|
542
|
+
return extractForwardRefPropsTypeArg(first);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
511
547
|
function extractFuncNode(node) {
|
|
512
548
|
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") {
|
|
513
549
|
return node;
|
|
@@ -517,6 +553,9 @@ function extractFuncNode(node) {
|
|
|
517
553
|
if (first !== void 0 && (first.type === "ArrowFunctionExpression" || first.type === "FunctionExpression")) {
|
|
518
554
|
return first;
|
|
519
555
|
}
|
|
556
|
+
if (first !== void 0 && first.type === "CallExpression") {
|
|
557
|
+
return extractFuncNode(first);
|
|
558
|
+
}
|
|
520
559
|
}
|
|
521
560
|
return null;
|
|
522
561
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/ast-helpers.ts","../src/visitors/component-detector.ts","../src/visitors/prop-type-extractor.ts","../src/visitors/props-injector.ts","../src/visitors/source-injector.ts","../src/index.ts"],"names":["funcNode"],"mappings":";AAUO,SAAS,gBAAgB,IAAA,EAAuB;AACrD,EAAA,OAAO,QAAA,CAAS,KAAK,IAAI,CAAA;AAC3B;AAKO,SAAS,UAAU,IAAA,EAAgC;AACxD,EAAA,OAAO,IAAA,CAAK,IAAA,KAAS,YAAA,IAAgB,IAAA,CAAK,IAAA,KAAS,aAAA;AACrD;AAMO,SAAS,gBAAgB,IAAA,EAA0C;AACxE,EAAA,KAAA,MAAW,IAAA,IAAQ,KAAK,IAAA,EAAM;AAC5B,IAAA,IAAI,IAAA,CAAK,SAAS,iBAAA,IAAqB,IAAA,CA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,EAAM;AACpD,IAAA,OAAO,gBAAA,CAAiB,KAAK,IAAI,CAAA;AAAA,EACnC;AACA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,iBAAiB,KAAA,EAA2C;AACnE,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAM,IAAA,EAAM;AAC7B,IAAA,IACE,IAAA,CAAK,IAAA,KAAS,iBAAA,IACd,IAAA,CAAK,QAAA,KACJ,IAAA,CAAK,QAAA,CAAS,IAAA,KAAS,YAAA,IAAgB,IAAA,CAAK,QAAA,CAAS,IAAA,KAAS,aAAA,CAAA,EAC/D;AACA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * AST helper utilities for detecting React component patterns.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n/**\n * Returns true if the identifier name looks like a React component:\n * starts with an uppercase letter.\n */\nexport function isComponentName(name: string): boolean {\n return /^[A-Z]/.test(name);\n}\n\n/**\n * Returns true if the node is a JSX element or JSX fragment.\n */\nexport function isJSXNode(node: BabelTypes.Node): boolean {\n return node.type === \"JSXElement\" || node.type === \"JSXFragment\";\n}\n\n/**\n * Checks whether a return statement (or any node in a function body)\n * contains JSX.\n */\nexport function bodyContainsJSX(node: BabelTypes.BlockStatement): boolean {\n for (const stmt of node.body) {\n if (stmt.type === \"ReturnStatement\" && stmt.argument && isJSXNode(stmt.argument)) {\n return true;\n }\n // Handle ternary / logical returns one level deep\n if (stmt.type === \"ReturnStatement\" && stmt.argument) {\n if (containsJSXExpression(stmt.argument)) return true;\n }\n }\n return false;\n}\n\n/**\n * Recursively checks an expression for JSX nodes (handles ternary, logical, etc).\n */\nexport function containsJSXExpression(\n node:\n | BabelTypes.Expression\n | BabelTypes.SpreadElement\n | BabelTypes.JSXNamespacedName\n | BabelTypes.ArgumentPlaceholder,\n): boolean {\n if (isJSXNode(node as BabelTypes.Node)) return true;\n if (node.type === \"ConditionalExpression\") {\n return containsJSXExpression(node.consequent) || containsJSXExpression(node.alternate);\n }\n if (node.type === \"LogicalExpression\") {\n return containsJSXExpression(node.left) || containsJSXExpression(node.right);\n }\n if (node.type === \"ParenthesizedExpression\") {\n return containsJSXExpression(node.expression);\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.memo(Component) or memo(Component).\n */\nexport function isReactMemoCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"memo\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"memo\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.forwardRef(...) or forwardRef(...).\n */\nexport function isReactForwardRefCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"forwardRef\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"forwardRef\"\n ) {\n return true;\n }\n return false;\n}\n","/**\n * component-detector.ts\n *\n * Identifies React components in the AST. A function is treated as a component if:\n * 1. Its name starts with an uppercase letter.\n * 2. Its body contains a return statement that returns JSX (directly or via conditional).\n *\n * Also handles:\n * - React.memo() and React.forwardRef() wrappers in variable declarations\n * - Default exports of anonymous arrow functions returning JSX\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport {\n bodyContainsJSX,\n containsJSXExpression,\n isComponentName,\n isReactForwardRefCall,\n isReactMemoCall,\n} from \"../utils/ast-helpers.js\";\n\nexport interface DetectedComponent {\n /** Component name (may be \"default\" for anonymous default exports) */\n name: string;\n /** Line number of the component declaration (1-based) */\n line: number;\n /** Column number of the component declaration (0-based) */\n column: number;\n /** The binding identifier node to attach __scopeSource after */\n bindingIdentifierName: string;\n}\n\n/**\n * Try to extract a React component from a FunctionDeclaration node.\n */\nexport function detectFunctionDeclaration(\n node: BabelTypes.FunctionDeclaration,\n): DetectedComponent | null {\n if (!node.id || !isComponentName(node.id.name)) return null;\n if (!node.body || !bodyContainsJSX(node.body)) return null;\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return {\n name: node.id.name,\n line: loc.line,\n column: loc.column,\n bindingIdentifierName: node.id.name,\n };\n}\n\n/**\n * Try to extract a React component from a VariableDeclaration.\n * Handles:\n * const Foo = () => <div/>;\n * const Foo = function() { return <div/>; };\n * const Foo = React.memo(() => <div/>);\n * const Foo = React.forwardRef((ref, props) => <div/>);\n */\nexport function detectVariableDeclaration(\n node: BabelTypes.VariableDeclaration,\n): DetectedComponent | null {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n const name = declarator.id.name;\n if (!isComponentName(name)) continue;\n if (!declarator.init) continue;\n\n if (isFunctionReturningJSX(declarator.init)) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n\n // React.memo(...) or React.forwardRef(...)\n if (\n declarator.init.type === \"CallExpression\" &&\n (isReactMemoCall(declarator.init) || isReactForwardRefCall(declarator.init))\n ) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n }\n return null;\n}\n\n/**\n * Returns true if the given expression is a function/arrow returning JSX.\n */\nfunction isFunctionReturningJSX(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): boolean {\n if (node.type === \"ArrowFunctionExpression\") {\n // Concise body: () => <div/>\n if (node.body.type !== \"BlockStatement\") {\n return containsJSXExpression(node.body);\n }\n return bodyContainsJSX(node.body);\n }\n if (node.type === \"FunctionExpression\") {\n if (!node.body) return false;\n return bodyContainsJSX(node.body);\n }\n return false;\n}\n","/**\n * prop-type-extractor.ts\n *\n * Extracts TypeScript prop type metadata from React component definitions at\n * build time. For each detected component with typed props, emits metadata\n * suitable for building a __scopeProps static property.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface PropMeta {\n type: PropTypeString;\n required: boolean;\n values?: string[];\n defaultValue?: unknown;\n}\n\nexport type PropTypeString =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"union\"\n | \"function\"\n | \"ReactNode\"\n | \"object\"\n | \"array\"\n | \"unknown\";\n\nexport type PropMap = Record<string, PropMeta>;\n\n// ---------------------------------------------------------------------------\n// Type resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Maps a Babel TS type annotation node to a simplified PropTypeString.\n */\nexport function resolvePropType(node: BabelTypes.TSType): PropTypeString {\n switch (node.type) {\n case \"TSStringKeyword\":\n return \"string\";\n case \"TSNumberKeyword\":\n return \"number\";\n case \"TSBooleanKeyword\":\n return \"boolean\";\n case \"TSVoidKeyword\":\n case \"TSUndefinedKeyword\":\n case \"TSNullKeyword\":\n case \"TSNeverKeyword\":\n case \"TSAnyKeyword\":\n case \"TSUnknownKeyword\":\n return \"unknown\";\n\n case \"TSArrayType\":\n case \"TSTupleType\":\n return \"array\";\n\n case \"TSTypeLiteral\":\n case \"TSMappedType\":\n return \"object\";\n\n case \"TSFunctionType\":\n case \"TSConstructorType\":\n return \"function\";\n\n case \"TSTypeReference\": {\n const typeName = resolveTypeReferenceName(node);\n if (\n typeName === \"ReactNode\" ||\n typeName === \"React.ReactNode\" ||\n typeName === \"ReactElement\" ||\n typeName === \"React.ReactElement\"\n ) {\n return \"ReactNode\";\n }\n if (\n typeName === \"MouseEvent\" ||\n typeName === \"KeyboardEvent\" ||\n typeName === \"ChangeEvent\" ||\n typeName === \"FocusEvent\" ||\n typeName === \"SyntheticEvent\" ||\n typeName === \"EventHandler\" ||\n (typeName?.startsWith(\"React.\") && typeName.endsWith(\"Handler\"))\n ) {\n return \"function\";\n }\n return \"unknown\";\n }\n\n case \"TSUnionType\": {\n const members = node.types;\n if (members.length > 0 && members.every((m) => m.type === \"TSLiteralType\")) {\n return \"union\";\n }\n return \"unknown\";\n }\n\n case \"TSIntersectionType\":\n case \"TSConditionalType\":\n case \"TSIndexedAccessType\":\n case \"TSTypeQuery\":\n case \"TSTemplateLiteralType\":\n return \"unknown\";\n\n default:\n return \"unknown\";\n }\n}\n\nfunction resolveTypeReferenceName(node: BabelTypes.TSTypeReference): string | undefined {\n const { typeName } = node;\n if (typeName.type === \"Identifier\") return typeName.name;\n if (typeName.type === \"TSQualifiedName\") {\n const left = typeName.left.type === \"Identifier\" ? typeName.left.name : \"\";\n return `${left}.${typeName.right.name}`;\n }\n return undefined;\n}\n\n// Exported for use in index.ts\nexport { resolveTypeReferenceName };\n\n// ---------------------------------------------------------------------------\n// Literal value extraction\n// ---------------------------------------------------------------------------\n\nfunction extractLiterals(unionNode: BabelTypes.TSUnionType): string[] | undefined {\n const values: string[] = [];\n for (const member of unionNode.types) {\n if (member.type !== \"TSLiteralType\") return undefined;\n const lit = member.literal;\n if (lit.type === \"StringLiteral\") {\n values.push(lit.value);\n } else if (lit.type === \"NumericLiteral\") {\n values.push(String(lit.value));\n } else {\n return undefined;\n }\n }\n return values.length > 0 ? values : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Default value extraction from destructuring\n// ---------------------------------------------------------------------------\n\n/**\n * Walks a function parameter destructuring pattern and returns a map of\n * prop names → their default values.\n */\nexport function extractDefaultValues(\n params: BabelTypes.FunctionDeclaration[\"params\"],\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n if (params.length === 0) return defaults;\n\n const firstParam = params[0];\n if (!firstParam) return defaults;\n\n let pattern: BabelTypes.Node | null = null;\n\n if (firstParam.type === \"ObjectPattern\") {\n pattern = firstParam;\n } else if (firstParam.type === \"AssignmentPattern\" && firstParam.left.type === \"ObjectPattern\") {\n pattern = firstParam.left;\n }\n\n if (pattern?.type === \"ObjectPattern\") {\n for (const prop of pattern.properties) {\n if (prop.type !== \"ObjectProperty\") continue;\n if (prop.key.type !== \"Identifier\") continue;\n const propName = prop.key.name;\n\n if (prop.value.type === \"AssignmentPattern\") {\n const defaultNode = prop.value.right;\n const extracted = extractLiteralValue(defaultNode);\n if (extracted !== undefined) {\n defaults[propName] = extracted;\n }\n }\n }\n }\n\n return defaults;\n}\n\nfunction extractLiteralValue(node: BabelTypes.Node): unknown {\n if (node.type === \"StringLiteral\") return node.value;\n if (node.type === \"NumericLiteral\") return node.value;\n if (node.type === \"BooleanLiteral\") return node.value;\n if (node.type === \"NullLiteral\") return null;\n if (\n node.type === \"UnaryExpression\" &&\n node.operator === \"-\" &&\n node.argument.type === \"NumericLiteral\"\n ) {\n return -node.argument.value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Interface / type alias member resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Extracts prop metadata from TSInterfaceBody members or TSTypeLiteral members.\n */\nexport function extractPropsFromTypeMembers(\n members: BabelTypes.TSTypeElement[],\n defaults: Record<string, unknown>,\n): PropMap {\n const props: PropMap = {};\n\n for (const member of members) {\n if (member.type !== \"TSPropertySignature\") continue;\n if (member.key.type !== \"Identifier\") continue;\n\n const propName = member.key.name;\n const required = !member.optional;\n\n if (!member.typeAnnotation) {\n props[propName] = { type: \"unknown\", required };\n continue;\n }\n\n const tsType = member.typeAnnotation.typeAnnotation;\n let propType = resolvePropType(tsType);\n let values: string[] | undefined;\n\n if (tsType.type === \"TSUnionType\") {\n const literals = extractLiterals(tsType);\n if (literals) {\n propType = \"union\";\n values = literals;\n }\n }\n\n const meta: PropMeta = { type: propType, required };\n if (values) meta.values = values;\n\n const defaultVal = defaults[propName];\n if (defaultVal !== undefined) meta.defaultValue = defaultVal;\n\n props[propName] = meta;\n }\n\n return props;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level: resolve props from a component node\n// ---------------------------------------------------------------------------\n\n/**\n * Given a function node and the program's type declarations, extracts the\n * component's __scopeProps map or returns null if no typed props are found.\n */\nexport function extractScopeProps(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n programBody: BabelTypes.Statement[],\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: function Foo(props: ButtonProps)\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts props from a React.FC<Props> type argument.\n */\nexport function extractScopePropsFromFCTypeArg(\n typeParams: BabelTypes.TSTypeParameterInstantiation | null | undefined,\n programBody: BabelTypes.Statement[],\n defaults: Record<string, unknown>,\n): PropMap | null {\n if (!typeParams || typeParams.params.length === 0) return null;\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) return null;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n if (firstTypeArg.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(firstTypeArg);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Locates interface or type alias members for a given type name in the program body.\n */\nfunction findTypeMembers(\n typeName: string,\n programBody: BabelTypes.Statement[],\n): BabelTypes.TSTypeElement[] | null {\n for (const stmt of programBody) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\" && stmt.id.name === typeName) {\n return stmt.body.body;\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\" &&\n stmt.declaration.id.name === typeName\n ) {\n return stmt.declaration.body.body;\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.id.name === typeName &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.typeAnnotation.members;\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.id.name === typeName &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.declaration.typeAnnotation.members;\n }\n }\n return null;\n}\n","/**\n * props-injector.ts\n *\n * Builds the AST statement that injects the __scopeProps property:\n *\n * ComponentName.__scopeProps = {\n * variant: { type: 'union', required: true, values: ['primary', 'secondary'] },\n * ...\n * };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport type { PropMap, PropMeta } from \"./prop-type-extractor.js\";\n\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n booleanLiteral: typeof BabelTypes.booleanLiteral;\n nullLiteral: typeof BabelTypes.nullLiteral;\n arrayExpression: typeof BabelTypes.arrayExpression;\n}\n\nfunction buildPrimitiveLiteral(t: BabelTypesSubset, value: unknown): BabelTypes.Expression {\n if (typeof value === \"string\") return t.stringLiteral(value);\n if (typeof value === \"number\") return t.numericLiteral(value);\n if (typeof value === \"boolean\") return t.booleanLiteral(value);\n if (value === null) return t.nullLiteral();\n // Fallback — should not reach in practice\n return t.stringLiteral(String(value));\n}\n\nfunction buildPropMetaObject(t: BabelTypesSubset, meta: PropMeta): BabelTypes.ObjectExpression {\n const props: BabelTypes.ObjectProperty[] = [\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(meta.type)),\n t.objectProperty(t.identifier(\"required\"), t.booleanLiteral(meta.required)),\n ];\n\n if (meta.values !== undefined) {\n props.push(\n t.objectProperty(\n t.identifier(\"values\"),\n t.arrayExpression(meta.values.map((v) => t.stringLiteral(v))),\n ),\n );\n }\n\n if (meta.defaultValue !== undefined) {\n props.push(\n t.objectProperty(t.identifier(\"defaultValue\"), buildPrimitiveLiteral(t, meta.defaultValue)),\n );\n }\n\n return t.objectExpression(props);\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeProps = { propA: {...}, propB: {...} };\n */\nexport function buildScopePropsStatement(\n t: BabelTypesSubset,\n name: string,\n props: PropMap,\n): BabelTypes.ExpressionStatement {\n const entries = Object.entries(props).map(([key, meta]) =>\n t.objectProperty(t.identifier(key), buildPropMetaObject(t, meta)),\n );\n\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeProps\")),\n t.objectExpression(entries),\n ),\n );\n}\n","/**\n * source-injector.ts\n *\n * Builds the AST statement that injects the __scopeSource property:\n *\n * ComponentName.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\nexport interface SourceLocation {\n filePath: string;\n line: number;\n column: number;\n}\n\n/**\n * Minimal subset of @babel/types we actually need. Using a structural type\n * instead of `typeof BabelTypes` avoids the `.default` mismatch when Babel\n * re-exports its types namespace differently across bundlers / tsup DTS builds.\n */\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\nexport function buildScopeSourceStatement(\n t: BabelTypesSubset,\n name: string,\n loc: SourceLocation,\n): BabelTypes.ExpressionStatement {\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeSource\")),\n t.objectExpression([\n t.objectProperty(t.identifier(\"filePath\"), t.stringLiteral(loc.filePath)),\n t.objectProperty(t.identifier(\"line\"), t.numericLiteral(loc.line)),\n t.objectProperty(t.identifier(\"column\"), t.numericLiteral(loc.column)),\n ]),\n ),\n );\n}\n","/**\n * @agent-scope/babel-plugin\n *\n * Babel plugin that injects two static properties into React component\n * definitions at compile time:\n *\n * 1. __scopeSource — source location (file, line, column)\n * 2. __scopeProps — TypeScript prop type metadata (when type info is available)\n *\n * Injected shapes:\n * ComponentName.__scopeSource = { filePath: \"src/Button.tsx\", line: 14, column: 0 };\n * ComponentName.__scopeProps = { label: { type: \"string\", required: true }, ... };\n *\n * Usage in babel.config.js:\n * module.exports = { plugins: [\"@agent-scope/babel-plugin\"] };\n *\n * ## Implementation note on type extraction ordering\n *\n * @babel/preset-typescript removes TSInterfaceDeclaration and TSTypeAliasDeclaration\n * nodes from the program body during the same traversal pass. Because Babel traverses\n * top-down, interface declarations (typically defined before the component) are visited\n * and removed BEFORE the FunctionDeclaration visitor fires.\n *\n * To work around this, we use a `Program.enter` visitor to pre-collect all type\n * declarations at the start of the traversal — before any child nodes are visited\n * or removed. The collected type map is stored in plugin state and used during\n * component visitors.\n */\n\nimport type { SourceLocation as ScopeSourceLocation } from \"@agent-scope/core\";\nimport type { types as BabelTypes, NodePath, PluginObj } from \"@babel/core\";\n\nimport {\n detectFunctionDeclaration,\n detectVariableDeclaration,\n} from \"./visitors/component-detector.js\";\nimport type { PropMap } from \"./visitors/prop-type-extractor.js\";\nimport {\n extractDefaultValues,\n extractPropsFromTypeMembers,\n resolveTypeReferenceName,\n} from \"./visitors/prop-type-extractor.js\";\nimport { buildScopePropsStatement } from \"./visitors/props-injector.js\";\nimport { buildScopeSourceStatement } from \"./visitors/source-injector.js\";\n\n// Re-export SourceLocation type for consumers\nexport type { ScopeSourceLocation };\n\n/** Options accepted by the Scope Babel plugin */\nexport interface PluginOptions {\n /** Override the file path injected into __scopeSource (defaults to Babel's filename) */\n filePath?: string;\n}\n\ntype PluginState = { filename?: string; opts: PluginOptions };\n\n/**\n * Per-program type map, keyed by Program node.\n * Using a WeakMap avoids extending Babel's PluginPass type while still giving\n * us file-scoped state that is garbage-collected when the program node is freed.\n */\nconst typeMapsByProgram = new WeakMap<\n BabelTypes.Program,\n Map<string, BabelTypes.TSTypeElement[]>\n>();\n\ntype BabelCore = {\n types: typeof BabelTypes;\n};\n\nexport function scopeBabelPlugin(babel: BabelCore): PluginObj {\n const t = babel.types;\n\n return {\n name: \"@agent-scope/babel-plugin\",\n visitor: {\n /**\n * Pre-collect all top-level type declarations at program entry, before\n * @babel/plugin-transform-typescript removes them during traversal.\n *\n * This fires for the Program node before ANY child visitors, so all\n * TSInterfaceDeclaration and TSTypeAliasDeclaration nodes are still present.\n */\n Program: {\n enter(path: NodePath<BabelTypes.Program>) {\n const typeMap = new Map<string, BabelTypes.TSTypeElement[]>();\n\n for (const stmt of path.node.body) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\") {\n typeMap.set(stmt.id.name, stmt.body.body);\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.body.body);\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.id.name, stmt.typeAnnotation.members);\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.typeAnnotation.members);\n }\n }\n\n typeMapsByProgram.set(path.node, typeMap);\n },\n },\n\n FunctionDeclaration(path: NodePath<BabelTypes.FunctionDeclaration>, state: PluginState) {\n if (path.parentPath?.isExportDefaultDeclaration()) return;\n const component = detectFunctionDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n VariableDeclaration(path: NodePath<BabelTypes.VariableDeclaration>, state: PluginState) {\n const component = detectVariableDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractPropsFromVariableDecl(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n ExportDefaultDeclaration(\n path: NodePath<BabelTypes.ExportDefaultDeclaration>,\n state: PluginState,\n ) {\n const decl = path.node.declaration;\n\n if (decl.type === \"FunctionDeclaration\" && decl.id && decl.body) {\n const component = detectFunctionDeclaration(decl);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(decl, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n return;\n }\n\n if (\n decl.type === \"ArrowFunctionExpression\" ||\n (decl.type === \"FunctionDeclaration\" && !decl.id)\n ) {\n if (!checkAnonymousReturnsJSX(decl)) return;\n const tempName = \"_ScopeDefaultExport\";\n const filePath = resolveFilePath(state);\n const loc = decl.loc?.start ?? { line: 0, column: 0 };\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, tempName, {\n filePath,\n line: loc.line,\n column: loc.column,\n });\n\n const scopeProps = safeExtractScopeProps(\n decl as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n typeMap,\n );\n\n const replacements: BabelTypes.Statement[] = [\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(t.identifier(tempName), decl as BabelTypes.Expression),\n ]),\n sourceStmt,\n ];\n\n if (scopeProps) {\n replacements.push(buildScopePropsStatement(t, tempName, scopeProps));\n }\n\n replacements.push(t.exportDefaultDeclaration(t.identifier(tempName)));\n path.replaceWithMultiple(replacements);\n }\n },\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveFilePath(state: { filename?: string; opts: PluginOptions }): string {\n return state.opts.filePath ?? state.filename ?? \"<unknown>\";\n}\n\nfunction getTypeMap(path: NodePath): Map<string, BabelTypes.TSTypeElement[]> {\n const program = path.findParent((p) => p.isProgram());\n if (!program || !program.isProgram()) return new Map();\n return typeMapsByProgram.get(program.node) ?? new Map();\n}\n\n/**\n * Safe wrapper around extractScopeProps using the pre-collected type map.\n */\nfunction safeExtractScopeProps(\n node:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n return extractScopePropsWithMap(node, typeMap);\n } catch {\n return null;\n }\n}\n\n/**\n * Extracts scope props using the pre-collected type map instead of scanning\n * the (potentially already-stripped) program body.\n */\nfunction extractScopePropsWithMap(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: look up in pre-collected type map\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = typeMap.get(typeName);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts scope props from a VariableDeclaration using the pre-collected type map.\n * Handles:\n * const Foo = (props: FooProps) => ...\n * const Foo: React.FC<FooProps> = (props) => ...\n */\nfunction safeExtractPropsFromVariableDecl(\n node: BabelTypes.VariableDeclaration,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n if (!declarator.init) continue;\n\n const init = declarator.init;\n\n // const Foo: React.FC<Props> = (props) => ...\n if (declarator.id.typeAnnotation?.type === \"TSTypeAnnotation\") {\n const tsType = declarator.id.typeAnnotation.typeAnnotation;\n if (tsType.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(tsType);\n if (\n typeName === \"React.FC\" ||\n typeName === \"FC\" ||\n typeName === \"React.FunctionComponent\" ||\n typeName === \"FunctionComponent\"\n ) {\n const typeParams = tsType.typeParameters;\n const funcNode = extractFuncNode(init);\n const defaults = funcNode ? extractDefaultValues(funcNode.params) : {};\n\n // Resolve type arg using our type map\n if (typeParams && typeParams.params.length > 0) {\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) continue;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (firstTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(firstTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n }\n\n // Direct arrow/function expression with typed params\n const funcNode = extractFuncNode(init);\n if (funcNode) {\n const props = extractScopePropsWithMap(funcNode, typeMap);\n if (props) return props;\n }\n }\n return null;\n } catch {\n return null;\n }\n}\n\nfunction extractFuncNode(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression | null {\n if (node.type === \"ArrowFunctionExpression\" || node.type === \"FunctionExpression\") {\n return node;\n }\n // React.memo(fn) or React.forwardRef(fn)\n if (node.type === \"CallExpression\" && node.arguments.length > 0) {\n const first = node.arguments[0];\n if (\n first !== undefined &&\n (first.type === \"ArrowFunctionExpression\" || first.type === \"FunctionExpression\")\n ) {\n return first as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression;\n }\n }\n return null;\n}\n\nfunction checkAnonymousReturnsJSX(\n decl: BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n): boolean {\n if (decl.type === \"ArrowFunctionExpression\") {\n const body = decl.body;\n if (body.type !== \"BlockStatement\") {\n return body.type === \"JSXElement\" || body.type === \"JSXFragment\";\n }\n return bodyHasJSXReturn(body);\n }\n if (decl.type === \"FunctionDeclaration\" && decl.body) {\n return bodyHasJSXReturn(decl.body);\n }\n return false;\n}\n\nfunction bodyHasJSXReturn(block: BabelTypes.BlockStatement): boolean {\n for (const stmt of block.body) {\n if (\n stmt.type === \"ReturnStatement\" &&\n stmt.argument &&\n (stmt.argument.type === \"JSXElement\" || stmt.argument.type === \"JSXFragment\")\n ) {\n return true;\n }\n }\n return false;\n}\n\nexport default scopeBabelPlugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/ast-helpers.ts","../src/visitors/component-detector.ts","../src/visitors/prop-type-extractor.ts","../src/visitors/props-injector.ts","../src/visitors/source-injector.ts","../src/index.ts"],"names":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A,OAAO,KAAA;AACT;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * AST helper utilities for detecting React component patterns.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n/**\n * Returns true if the identifier name looks like a React component:\n * starts with an uppercase letter.\n */\nexport function isComponentName(name: string): boolean {\n return /^[A-Z]/.test(name);\n}\n\n/**\n * Returns true if the node is a JSX element or JSX fragment.\n */\nexport function isJSXNode(node: BabelTypes.Node): boolean {\n return node.type === \"JSXElement\" || node.type === \"JSXFragment\";\n}\n\n/**\n * Checks whether a return statement (or any node in a function body)\n * contains JSX.\n */\nexport function bodyContainsJSX(node: BabelTypes.BlockStatement): boolean {\n for (const stmt of node.body) {\n if (stmt.type === \"ReturnStatement\" && stmt.argument && isJSXNode(stmt.argument)) {\n return true;\n }\n // Handle ternary / logical returns one level deep\n if (stmt.type === \"ReturnStatement\" && stmt.argument) {\n if (containsJSXExpression(stmt.argument)) return true;\n }\n }\n return false;\n}\n\n/**\n * Recursively checks an expression for JSX nodes (handles ternary, logical, etc).\n */\nexport function containsJSXExpression(\n node:\n | BabelTypes.Expression\n | BabelTypes.SpreadElement\n | BabelTypes.JSXNamespacedName\n | BabelTypes.ArgumentPlaceholder,\n): boolean {\n if (isJSXNode(node as BabelTypes.Node)) return true;\n if (node.type === \"ConditionalExpression\") {\n return containsJSXExpression(node.consequent) || containsJSXExpression(node.alternate);\n }\n if (node.type === \"LogicalExpression\") {\n return containsJSXExpression(node.left) || containsJSXExpression(node.right);\n }\n if (node.type === \"ParenthesizedExpression\") {\n return containsJSXExpression(node.expression);\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.memo(Component) or memo(Component).\n */\nexport function isReactMemoCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"memo\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"memo\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true if the call expression is React.forwardRef(...) or forwardRef(...).\n */\nexport function isReactForwardRefCall(node: BabelTypes.CallExpression): boolean {\n const callee = node.callee;\n if (callee.type === \"Identifier\" && callee.name === \"forwardRef\") return true;\n if (\n callee.type === \"MemberExpression\" &&\n callee.object.type === \"Identifier\" &&\n callee.object.name === \"React\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === \"forwardRef\"\n ) {\n return true;\n }\n return false;\n}\n","/**\n * component-detector.ts\n *\n * Identifies React components in the AST. A function is treated as a component if:\n * 1. Its name starts with an uppercase letter.\n * 2. Its body contains a return statement that returns JSX (directly or via conditional).\n *\n * Also handles:\n * - React.memo() and React.forwardRef() wrappers in variable declarations\n * - Default exports of anonymous arrow functions returning JSX\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport {\n bodyContainsJSX,\n containsJSXExpression,\n isComponentName,\n isReactForwardRefCall,\n isReactMemoCall,\n} from \"../utils/ast-helpers.js\";\n\nexport interface DetectedComponent {\n /** Component name (may be \"default\" for anonymous default exports) */\n name: string;\n /** Line number of the component declaration (1-based) */\n line: number;\n /** Column number of the component declaration (0-based) */\n column: number;\n /** The binding identifier node to attach __scopeSource after */\n bindingIdentifierName: string;\n}\n\n/**\n * Try to extract a React component from a FunctionDeclaration node.\n */\nexport function detectFunctionDeclaration(\n node: BabelTypes.FunctionDeclaration,\n): DetectedComponent | null {\n if (!node.id || !isComponentName(node.id.name)) return null;\n if (!node.body || !bodyContainsJSX(node.body)) return null;\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return {\n name: node.id.name,\n line: loc.line,\n column: loc.column,\n bindingIdentifierName: node.id.name,\n };\n}\n\n/**\n * Try to extract a React component from a VariableDeclaration.\n * Handles:\n * const Foo = () => <div/>;\n * const Foo = function() { return <div/>; };\n * const Foo = React.memo(() => <div/>);\n * const Foo = React.forwardRef((ref, props) => <div/>);\n */\nexport function detectVariableDeclaration(\n node: BabelTypes.VariableDeclaration,\n): DetectedComponent | null {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n const name = declarator.id.name;\n if (!isComponentName(name)) continue;\n if (!declarator.init) continue;\n\n if (isFunctionReturningJSX(declarator.init)) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n\n // React.memo(...) or React.forwardRef(...)\n if (\n declarator.init.type === \"CallExpression\" &&\n (isReactMemoCall(declarator.init) || isReactForwardRefCall(declarator.init))\n ) {\n const loc = node.loc?.start ?? { line: 0, column: 0 };\n return { name, line: loc.line, column: loc.column, bindingIdentifierName: name };\n }\n }\n return null;\n}\n\n/**\n * Returns true if the given expression is a function/arrow returning JSX.\n */\nfunction isFunctionReturningJSX(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): boolean {\n if (node.type === \"ArrowFunctionExpression\") {\n // Concise body: () => <div/>\n if (node.body.type !== \"BlockStatement\") {\n return containsJSXExpression(node.body);\n }\n return bodyContainsJSX(node.body);\n }\n if (node.type === \"FunctionExpression\") {\n if (!node.body) return false;\n return bodyContainsJSX(node.body);\n }\n return false;\n}\n","/**\n * prop-type-extractor.ts\n *\n * Extracts TypeScript prop type metadata from React component definitions at\n * build time. For each detected component with typed props, emits metadata\n * suitable for building a __scopeProps static property.\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface PropMeta {\n type: PropTypeString;\n required: boolean;\n values?: string[];\n defaultValue?: unknown;\n}\n\nexport type PropTypeString =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"union\"\n | \"function\"\n | \"ReactNode\"\n | \"object\"\n | \"array\"\n | \"unknown\";\n\nexport type PropMap = Record<string, PropMeta>;\n\n// ---------------------------------------------------------------------------\n// Type resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Maps a Babel TS type annotation node to a simplified PropTypeString.\n */\nexport function resolvePropType(node: BabelTypes.TSType): PropTypeString {\n switch (node.type) {\n case \"TSStringKeyword\":\n return \"string\";\n case \"TSNumberKeyword\":\n return \"number\";\n case \"TSBooleanKeyword\":\n return \"boolean\";\n case \"TSVoidKeyword\":\n case \"TSUndefinedKeyword\":\n case \"TSNullKeyword\":\n case \"TSNeverKeyword\":\n case \"TSAnyKeyword\":\n case \"TSUnknownKeyword\":\n return \"unknown\";\n\n case \"TSArrayType\":\n case \"TSTupleType\":\n return \"array\";\n\n case \"TSTypeLiteral\":\n case \"TSMappedType\":\n return \"object\";\n\n case \"TSFunctionType\":\n case \"TSConstructorType\":\n return \"function\";\n\n case \"TSTypeReference\": {\n const typeName = resolveTypeReferenceName(node);\n if (\n typeName === \"ReactNode\" ||\n typeName === \"React.ReactNode\" ||\n typeName === \"ReactElement\" ||\n typeName === \"React.ReactElement\"\n ) {\n return \"ReactNode\";\n }\n if (\n typeName === \"MouseEvent\" ||\n typeName === \"KeyboardEvent\" ||\n typeName === \"ChangeEvent\" ||\n typeName === \"FocusEvent\" ||\n typeName === \"SyntheticEvent\" ||\n typeName === \"EventHandler\" ||\n (typeName?.startsWith(\"React.\") && typeName.endsWith(\"Handler\"))\n ) {\n return \"function\";\n }\n return \"unknown\";\n }\n\n case \"TSUnionType\": {\n const members = node.types;\n if (members.length > 0 && members.every((m) => m.type === \"TSLiteralType\")) {\n return \"union\";\n }\n return \"unknown\";\n }\n\n case \"TSIntersectionType\":\n case \"TSConditionalType\":\n case \"TSIndexedAccessType\":\n case \"TSTypeQuery\":\n case \"TSTemplateLiteralType\":\n return \"unknown\";\n\n default:\n return \"unknown\";\n }\n}\n\nfunction resolveTypeReferenceName(node: BabelTypes.TSTypeReference): string | undefined {\n const { typeName } = node;\n if (typeName.type === \"Identifier\") return typeName.name;\n if (typeName.type === \"TSQualifiedName\") {\n const left = typeName.left.type === \"Identifier\" ? typeName.left.name : \"\";\n return `${left}.${typeName.right.name}`;\n }\n return undefined;\n}\n\n// Exported for use in index.ts\nexport { resolveTypeReferenceName };\n\n// ---------------------------------------------------------------------------\n// Literal value extraction\n// ---------------------------------------------------------------------------\n\nfunction extractLiterals(unionNode: BabelTypes.TSUnionType): string[] | undefined {\n const values: string[] = [];\n for (const member of unionNode.types) {\n if (member.type !== \"TSLiteralType\") return undefined;\n const lit = member.literal;\n if (lit.type === \"StringLiteral\") {\n values.push(lit.value);\n } else if (lit.type === \"NumericLiteral\") {\n values.push(String(lit.value));\n } else {\n return undefined;\n }\n }\n return values.length > 0 ? values : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Default value extraction from destructuring\n// ---------------------------------------------------------------------------\n\n/**\n * Walks a function parameter destructuring pattern and returns a map of\n * prop names → their default values.\n */\nexport function extractDefaultValues(\n params: BabelTypes.FunctionDeclaration[\"params\"],\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n if (params.length === 0) return defaults;\n\n const firstParam = params[0];\n if (!firstParam) return defaults;\n\n let pattern: BabelTypes.Node | null = null;\n\n if (firstParam.type === \"ObjectPattern\") {\n pattern = firstParam;\n } else if (firstParam.type === \"AssignmentPattern\" && firstParam.left.type === \"ObjectPattern\") {\n pattern = firstParam.left;\n }\n\n if (pattern?.type === \"ObjectPattern\") {\n for (const prop of pattern.properties) {\n if (prop.type !== \"ObjectProperty\") continue;\n if (prop.key.type !== \"Identifier\") continue;\n const propName = prop.key.name;\n\n if (prop.value.type === \"AssignmentPattern\") {\n const defaultNode = prop.value.right;\n const extracted = extractLiteralValue(defaultNode);\n if (extracted !== undefined) {\n defaults[propName] = extracted;\n }\n }\n }\n }\n\n return defaults;\n}\n\nfunction extractLiteralValue(node: BabelTypes.Node): unknown {\n if (node.type === \"StringLiteral\") return node.value;\n if (node.type === \"NumericLiteral\") return node.value;\n if (node.type === \"BooleanLiteral\") return node.value;\n if (node.type === \"NullLiteral\") return null;\n if (\n node.type === \"UnaryExpression\" &&\n node.operator === \"-\" &&\n node.argument.type === \"NumericLiteral\"\n ) {\n return -node.argument.value;\n }\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Interface / type alias member resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Extracts prop metadata from TSInterfaceBody members or TSTypeLiteral members.\n */\nexport function extractPropsFromTypeMembers(\n members: BabelTypes.TSTypeElement[],\n defaults: Record<string, unknown>,\n): PropMap {\n const props: PropMap = {};\n\n for (const member of members) {\n if (member.type !== \"TSPropertySignature\") continue;\n if (member.key.type !== \"Identifier\") continue;\n\n const propName = member.key.name;\n const required = !member.optional;\n\n if (!member.typeAnnotation) {\n props[propName] = { type: \"unknown\", required };\n continue;\n }\n\n const tsType = member.typeAnnotation.typeAnnotation;\n let propType = resolvePropType(tsType);\n let values: string[] | undefined;\n\n if (tsType.type === \"TSUnionType\") {\n const literals = extractLiterals(tsType);\n if (literals) {\n propType = \"union\";\n values = literals;\n }\n }\n\n const meta: PropMeta = { type: propType, required };\n if (values) meta.values = values;\n\n const defaultVal = defaults[propName];\n if (defaultVal !== undefined) meta.defaultValue = defaultVal;\n\n props[propName] = meta;\n }\n\n return props;\n}\n\n// ---------------------------------------------------------------------------\n// Top-level: resolve props from a component node\n// ---------------------------------------------------------------------------\n\n/**\n * Given a function node and the program's type declarations, extracts the\n * component's __scopeProps map or returns null if no typed props are found.\n */\nexport function extractScopeProps(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n programBody: BabelTypes.Statement[],\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: function Foo(props: ButtonProps)\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts props from a React.FC<Props> type argument.\n */\nexport function extractScopePropsFromFCTypeArg(\n typeParams: BabelTypes.TSTypeParameterInstantiation | null | undefined,\n programBody: BabelTypes.Statement[],\n defaults: Record<string, unknown>,\n): PropMap | null {\n if (!typeParams || typeParams.params.length === 0) return null;\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) return null;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n if (firstTypeArg.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(firstTypeArg);\n if (!typeName) return null;\n const members = findTypeMembers(typeName, programBody);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Locates interface or type alias members for a given type name in the program body.\n */\nfunction findTypeMembers(\n typeName: string,\n programBody: BabelTypes.Statement[],\n): BabelTypes.TSTypeElement[] | null {\n for (const stmt of programBody) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\" && stmt.id.name === typeName) {\n return stmt.body.body;\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\" &&\n stmt.declaration.id.name === typeName\n ) {\n return stmt.declaration.body.body;\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.id.name === typeName &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.typeAnnotation.members;\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.id.name === typeName &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n return stmt.declaration.typeAnnotation.members;\n }\n }\n return null;\n}\n","/**\n * props-injector.ts\n *\n * Builds the AST statement that injects the __scopeProps property:\n *\n * ComponentName.__scopeProps = {\n * variant: { type: 'union', required: true, values: ['primary', 'secondary'] },\n * ...\n * };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\nimport type { PropMap, PropMeta } from \"./prop-type-extractor.js\";\n\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n booleanLiteral: typeof BabelTypes.booleanLiteral;\n nullLiteral: typeof BabelTypes.nullLiteral;\n arrayExpression: typeof BabelTypes.arrayExpression;\n}\n\nfunction buildPrimitiveLiteral(t: BabelTypesSubset, value: unknown): BabelTypes.Expression {\n if (typeof value === \"string\") return t.stringLiteral(value);\n if (typeof value === \"number\") return t.numericLiteral(value);\n if (typeof value === \"boolean\") return t.booleanLiteral(value);\n if (value === null) return t.nullLiteral();\n // Fallback — should not reach in practice\n return t.stringLiteral(String(value));\n}\n\nfunction buildPropMetaObject(t: BabelTypesSubset, meta: PropMeta): BabelTypes.ObjectExpression {\n const props: BabelTypes.ObjectProperty[] = [\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(meta.type)),\n t.objectProperty(t.identifier(\"required\"), t.booleanLiteral(meta.required)),\n ];\n\n if (meta.values !== undefined) {\n props.push(\n t.objectProperty(\n t.identifier(\"values\"),\n t.arrayExpression(meta.values.map((v) => t.stringLiteral(v))),\n ),\n );\n }\n\n if (meta.defaultValue !== undefined) {\n props.push(\n t.objectProperty(t.identifier(\"defaultValue\"), buildPrimitiveLiteral(t, meta.defaultValue)),\n );\n }\n\n return t.objectExpression(props);\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeProps = { propA: {...}, propB: {...} };\n */\nexport function buildScopePropsStatement(\n t: BabelTypesSubset,\n name: string,\n props: PropMap,\n): BabelTypes.ExpressionStatement {\n const entries = Object.entries(props).map(([key, meta]) =>\n t.objectProperty(t.identifier(key), buildPropMetaObject(t, meta)),\n );\n\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeProps\")),\n t.objectExpression(entries),\n ),\n );\n}\n","/**\n * source-injector.ts\n *\n * Builds the AST statement that injects the __scopeSource property:\n *\n * ComponentName.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\n\nimport type * as BabelTypes from \"@babel/types\";\n\nexport interface SourceLocation {\n filePath: string;\n line: number;\n column: number;\n}\n\n/**\n * Minimal subset of @babel/types we actually need. Using a structural type\n * instead of `typeof BabelTypes` avoids the `.default` mismatch when Babel\n * re-exports its types namespace differently across bundlers / tsup DTS builds.\n */\ninterface BabelTypesSubset {\n expressionStatement: typeof BabelTypes.expressionStatement;\n assignmentExpression: typeof BabelTypes.assignmentExpression;\n memberExpression: typeof BabelTypes.memberExpression;\n identifier: typeof BabelTypes.identifier;\n objectExpression: typeof BabelTypes.objectExpression;\n objectProperty: typeof BabelTypes.objectProperty;\n stringLiteral: typeof BabelTypes.stringLiteral;\n numericLiteral: typeof BabelTypes.numericLiteral;\n}\n\n/**\n * Builds an ExpressionStatement AST node representing:\n *\n * <name>.__scopeSource = { filePath: \"...\", line: N, column: N };\n */\nexport function buildScopeSourceStatement(\n t: BabelTypesSubset,\n name: string,\n loc: SourceLocation,\n): BabelTypes.ExpressionStatement {\n return t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.identifier(name), t.identifier(\"__scopeSource\")),\n t.objectExpression([\n t.objectProperty(t.identifier(\"filePath\"), t.stringLiteral(loc.filePath)),\n t.objectProperty(t.identifier(\"line\"), t.numericLiteral(loc.line)),\n t.objectProperty(t.identifier(\"column\"), t.numericLiteral(loc.column)),\n ]),\n ),\n );\n}\n","/**\n * @agent-scope/babel-plugin\n *\n * Babel plugin that injects two static properties into React component\n * definitions at compile time:\n *\n * 1. __scopeSource — source location (file, line, column)\n * 2. __scopeProps — TypeScript prop type metadata (when type info is available)\n *\n * Injected shapes:\n * ComponentName.__scopeSource = { filePath: \"src/Button.tsx\", line: 14, column: 0 };\n * ComponentName.__scopeProps = { label: { type: \"string\", required: true }, ... };\n *\n * Usage in babel.config.js:\n * module.exports = { plugins: [\"@agent-scope/babel-plugin\"] };\n *\n * ## Implementation note on type extraction ordering\n *\n * @babel/preset-typescript removes TSInterfaceDeclaration and TSTypeAliasDeclaration\n * nodes from the program body during the same traversal pass. Because Babel traverses\n * top-down, interface declarations (typically defined before the component) are visited\n * and removed BEFORE the FunctionDeclaration visitor fires.\n *\n * To work around this, we use a `Program.enter` visitor to pre-collect all type\n * declarations at the start of the traversal — before any child nodes are visited\n * or removed. The collected type map is stored in plugin state and used during\n * component visitors.\n */\n\nimport type { SourceLocation as ScopeSourceLocation } from \"@agent-scope/core\";\nimport type { types as BabelTypes, NodePath, PluginObj } from \"@babel/core\";\nimport { isReactForwardRefCall } from \"./utils/ast-helpers.js\";\nimport {\n detectFunctionDeclaration,\n detectVariableDeclaration,\n} from \"./visitors/component-detector.js\";\nimport type { PropMap } from \"./visitors/prop-type-extractor.js\";\nimport {\n extractDefaultValues,\n extractPropsFromTypeMembers,\n resolveTypeReferenceName,\n} from \"./visitors/prop-type-extractor.js\";\nimport { buildScopePropsStatement } from \"./visitors/props-injector.js\";\nimport { buildScopeSourceStatement } from \"./visitors/source-injector.js\";\n\n// Re-export SourceLocation type for consumers\nexport type { ScopeSourceLocation };\n\n/** Options accepted by the Scope Babel plugin */\nexport interface PluginOptions {\n /** Override the file path injected into __scopeSource (defaults to Babel's filename) */\n filePath?: string;\n}\n\ntype PluginState = { filename?: string; opts: PluginOptions };\n\n/**\n * Per-program type map, keyed by Program node.\n * Using a WeakMap avoids extending Babel's PluginPass type while still giving\n * us file-scoped state that is garbage-collected when the program node is freed.\n */\nconst typeMapsByProgram = new WeakMap<\n BabelTypes.Program,\n Map<string, BabelTypes.TSTypeElement[]>\n>();\n\ntype BabelCore = {\n types: typeof BabelTypes;\n};\n\nexport function scopeBabelPlugin(babel: BabelCore): PluginObj {\n const t = babel.types;\n\n return {\n name: \"@agent-scope/babel-plugin\",\n visitor: {\n /**\n * Pre-collect all top-level type declarations at program entry, before\n * @babel/plugin-transform-typescript removes them during traversal.\n *\n * This fires for the Program node before ANY child visitors, so all\n * TSInterfaceDeclaration and TSTypeAliasDeclaration nodes are still present.\n */\n Program: {\n enter(path: NodePath<BabelTypes.Program>) {\n const typeMap = new Map<string, BabelTypes.TSTypeElement[]>();\n\n for (const stmt of path.node.body) {\n // interface FooProps { ... }\n if (stmt.type === \"TSInterfaceDeclaration\") {\n typeMap.set(stmt.id.name, stmt.body.body);\n }\n // export interface FooProps { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSInterfaceDeclaration\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.body.body);\n }\n // type FooProps = { ... }\n if (\n stmt.type === \"TSTypeAliasDeclaration\" &&\n stmt.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.id.name, stmt.typeAnnotation.members);\n }\n // export type FooProps = { ... }\n if (\n stmt.type === \"ExportNamedDeclaration\" &&\n stmt.declaration?.type === \"TSTypeAliasDeclaration\" &&\n stmt.declaration.typeAnnotation.type === \"TSTypeLiteral\"\n ) {\n typeMap.set(stmt.declaration.id.name, stmt.declaration.typeAnnotation.members);\n }\n }\n\n typeMapsByProgram.set(path.node, typeMap);\n },\n },\n\n FunctionDeclaration(path: NodePath<BabelTypes.FunctionDeclaration>, state: PluginState) {\n if (path.parentPath?.isExportDefaultDeclaration()) return;\n const component = detectFunctionDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n VariableDeclaration(path: NodePath<BabelTypes.VariableDeclaration>, state: PluginState) {\n const component = detectVariableDeclaration(path.node);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractPropsFromVariableDecl(path.node, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n },\n\n ExportDefaultDeclaration(\n path: NodePath<BabelTypes.ExportDefaultDeclaration>,\n state: PluginState,\n ) {\n const decl = path.node.declaration;\n\n if (decl.type === \"FunctionDeclaration\" && decl.id && decl.body) {\n const component = detectFunctionDeclaration(decl);\n if (!component) return;\n const filePath = resolveFilePath(state);\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, component.name, {\n filePath,\n line: component.line,\n column: component.column,\n });\n\n const scopeProps = safeExtractScopeProps(decl, typeMap);\n if (scopeProps) {\n const propsStmt = buildScopePropsStatement(t, component.name, scopeProps);\n path.insertAfter(propsStmt);\n path.insertAfter(sourceStmt);\n } else {\n path.insertAfter(sourceStmt);\n }\n return;\n }\n\n if (\n decl.type === \"ArrowFunctionExpression\" ||\n (decl.type === \"FunctionDeclaration\" && !decl.id)\n ) {\n if (!checkAnonymousReturnsJSX(decl)) return;\n const tempName = \"_ScopeDefaultExport\";\n const filePath = resolveFilePath(state);\n const loc = decl.loc?.start ?? { line: 0, column: 0 };\n const typeMap = getTypeMap(path);\n\n const sourceStmt = buildScopeSourceStatement(t, tempName, {\n filePath,\n line: loc.line,\n column: loc.column,\n });\n\n const scopeProps = safeExtractScopeProps(\n decl as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n typeMap,\n );\n\n const replacements: BabelTypes.Statement[] = [\n t.variableDeclaration(\"const\", [\n t.variableDeclarator(t.identifier(tempName), decl as BabelTypes.Expression),\n ]),\n sourceStmt,\n ];\n\n if (scopeProps) {\n replacements.push(buildScopePropsStatement(t, tempName, scopeProps));\n }\n\n replacements.push(t.exportDefaultDeclaration(t.identifier(tempName)));\n path.replaceWithMultiple(replacements);\n }\n },\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveFilePath(state: { filename?: string; opts: PluginOptions }): string {\n return state.opts.filePath ?? state.filename ?? \"<unknown>\";\n}\n\nfunction getTypeMap(path: NodePath): Map<string, BabelTypes.TSTypeElement[]> {\n const program = path.findParent((p) => p.isProgram());\n if (!program || !program.isProgram()) return new Map();\n return typeMapsByProgram.get(program.node) ?? new Map();\n}\n\n/**\n * Safe wrapper around extractScopeProps using the pre-collected type map.\n */\nfunction safeExtractScopeProps(\n node:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n return extractScopePropsWithMap(node, typeMap);\n } catch {\n return null;\n }\n}\n\n/**\n * Extracts scope props using the pre-collected type map instead of scanning\n * the (potentially already-stripped) program body.\n */\nfunction extractScopePropsWithMap(\n funcNode:\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.FunctionExpression,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n const params = funcNode.params;\n if (params.length === 0) return null;\n\n const firstParam = params[0];\n if (!firstParam) return null;\n\n const defaults = extractDefaultValues(params);\n\n let typeAnnotation: BabelTypes.TSType | null = null;\n\n if (firstParam.type === \"Identifier\" || firstParam.type === \"ObjectPattern\") {\n if (firstParam.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = firstParam.typeAnnotation.typeAnnotation;\n }\n } else if (firstParam.type === \"AssignmentPattern\") {\n const left = firstParam.left;\n if (left.type === \"Identifier\" || left.type === \"ObjectPattern\") {\n if (left.typeAnnotation?.type === \"TSTypeAnnotation\") {\n typeAnnotation = left.typeAnnotation.typeAnnotation;\n }\n }\n }\n\n if (!typeAnnotation) return null;\n\n // Inline object type: function Foo({ a }: { a: string })\n if (typeAnnotation.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(typeAnnotation.members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n // Named type reference: look up in pre-collected type map\n if (typeAnnotation.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(typeAnnotation);\n if (!typeName) return null;\n const members = typeMap.get(typeName);\n if (!members) return null;\n const props = extractPropsFromTypeMembers(members, defaults);\n return Object.keys(props).length > 0 ? props : null;\n }\n\n return null;\n}\n\n/**\n * Extracts scope props from a VariableDeclaration using the pre-collected type map.\n * Handles:\n * const Foo = (props: FooProps) => ...\n * const Foo: React.FC<FooProps> = (props) => ...\n */\nfunction safeExtractPropsFromVariableDecl(\n node: BabelTypes.VariableDeclaration,\n typeMap: Map<string, BabelTypes.TSTypeElement[]>,\n): PropMap | null {\n try {\n for (const declarator of node.declarations) {\n if (declarator.id.type !== \"Identifier\") continue;\n if (!declarator.init) continue;\n\n const init = declarator.init;\n\n // const Foo: React.FC<Props> = (props) => ...\n if (declarator.id.typeAnnotation?.type === \"TSTypeAnnotation\") {\n const tsType = declarator.id.typeAnnotation.typeAnnotation;\n if (tsType.type === \"TSTypeReference\") {\n const typeName = resolveTypeReferenceName(tsType);\n if (\n typeName === \"React.FC\" ||\n typeName === \"FC\" ||\n typeName === \"React.FunctionComponent\" ||\n typeName === \"FunctionComponent\"\n ) {\n const typeParams = tsType.typeParameters;\n const funcNode = extractFuncNode(init);\n const defaults = funcNode ? extractDefaultValues(funcNode.params) : {};\n\n // Resolve type arg using our type map\n if (typeParams && typeParams.params.length > 0) {\n const firstTypeArg = typeParams.params[0];\n if (!firstTypeArg) continue;\n\n if (firstTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(firstTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (firstTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(firstTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n }\n\n // Direct arrow/function expression with typed params\n const funcNode = extractFuncNode(init);\n if (funcNode) {\n const props = extractScopePropsWithMap(funcNode, typeMap);\n if (props) return props;\n }\n\n // forwardRef<Ref, Props>(...) — extract props from the second type argument\n if (init.type === \"CallExpression\") {\n const propsTypeArg = extractForwardRefPropsTypeArg(init);\n if (propsTypeArg) {\n const innerFunc = extractFuncNode(init);\n const defaults = innerFunc ? extractDefaultValues(innerFunc.params) : {};\n\n if (propsTypeArg.type === \"TSTypeLiteral\") {\n const props = extractPropsFromTypeMembers(propsTypeArg.members, defaults);\n if (Object.keys(props).length > 0) return props;\n } else if (propsTypeArg.type === \"TSTypeReference\") {\n const refName = resolveTypeReferenceName(propsTypeArg);\n if (refName) {\n const members = typeMap.get(refName);\n if (members) {\n const props = extractPropsFromTypeMembers(members, defaults);\n if (Object.keys(props).length > 0) return props;\n }\n }\n }\n }\n }\n }\n return null;\n } catch {\n return null;\n }\n}\n\n/**\n * Given a call expression that may be forwardRef<Ref, Props>(...) or\n * memo(forwardRef<Ref, Props>(...)), return the Props type argument node.\n */\nfunction extractForwardRefPropsTypeArg(node: BabelTypes.CallExpression): BabelTypes.TSType | null {\n if (isReactForwardRefCall(node)) {\n const params = node.typeParameters?.params;\n if (params && params.length >= 2 && params[1]) {\n return params[1];\n }\n return null;\n }\n\n // Recurse into nested calls: memo(forwardRef<Ref, Props>(...))\n if (node.arguments.length > 0) {\n const first = node.arguments[0];\n if (first?.type === \"CallExpression\") {\n return extractForwardRefPropsTypeArg(first);\n }\n }\n\n return null;\n}\n\nfunction extractFuncNode(\n node: BabelTypes.Expression | BabelTypes.V8IntrinsicIdentifier,\n): BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression | null {\n if (node.type === \"ArrowFunctionExpression\" || node.type === \"FunctionExpression\") {\n return node;\n }\n if (node.type === \"CallExpression\" && node.arguments.length > 0) {\n const first = node.arguments[0];\n if (\n first !== undefined &&\n (first.type === \"ArrowFunctionExpression\" || first.type === \"FunctionExpression\")\n ) {\n return first as BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionExpression;\n }\n // Recurse for nested calls like memo(forwardRef(fn))\n if (first !== undefined && first.type === \"CallExpression\") {\n return extractFuncNode(first);\n }\n }\n return null;\n}\n\nfunction checkAnonymousReturnsJSX(\n decl: BabelTypes.ArrowFunctionExpression | BabelTypes.FunctionDeclaration,\n): boolean {\n if (decl.type === \"ArrowFunctionExpression\") {\n const body = decl.body;\n if (body.type !== \"BlockStatement\") {\n return body.type === \"JSXElement\" || body.type === \"JSXFragment\";\n }\n return bodyHasJSXReturn(body);\n }\n if (decl.type === \"FunctionDeclaration\" && decl.body) {\n return bodyHasJSXReturn(decl.body);\n }\n return false;\n}\n\nfunction bodyHasJSXReturn(block: BabelTypes.BlockStatement): boolean {\n for (const stmt of block.body) {\n if (\n stmt.type === \"ReturnStatement\" &&\n stmt.argument &&\n (stmt.argument.type === \"JSXElement\" || stmt.argument.type === \"JSXFragment\")\n ) {\n return true;\n }\n }\n return false;\n}\n\nexport default scopeBabelPlugin;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-scope/babel-plugin",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.2",
|
|
4
4
|
"description": "Babel plugin for automatic Scope instrumentation via AST transforms",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/core": "^7.29.0",
|
|
34
|
-
"@agent-scope/core": "1.20.
|
|
34
|
+
"@agent-scope/core": "1.20.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/preset-react": "^7.28.5",
|