@figma/code-connect 1.4.2 → 1.4.3

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.
Files changed (35) hide show
  1. package/README.md +4 -4
  2. package/dist/commands/connect.d.ts +5 -2
  3. package/dist/commands/connect.d.ts.map +1 -1
  4. package/dist/commands/connect.js +32 -19
  5. package/dist/commands/connect.js.map +1 -1
  6. package/dist/commands/filter_project_info.d.ts +7 -0
  7. package/dist/commands/filter_project_info.d.ts.map +1 -0
  8. package/dist/commands/filter_project_info.js +32 -0
  9. package/dist/commands/filter_project_info.js.map +1 -0
  10. package/dist/connect/intrinsics.d.ts +3 -3
  11. package/dist/connect/intrinsics.d.ts.map +1 -1
  12. package/dist/connect/intrinsics.js +21 -10
  13. package/dist/connect/intrinsics.js.map +1 -1
  14. package/dist/connect/migration_helpers.d.ts +10 -3
  15. package/dist/connect/migration_helpers.d.ts.map +1 -1
  16. package/dist/connect/migration_helpers.js +43 -22
  17. package/dist/connect/migration_helpers.js.map +1 -1
  18. package/dist/connect/parser_common.d.ts +3 -2
  19. package/dist/connect/parser_common.d.ts.map +1 -1
  20. package/dist/connect/parser_common.js +2 -2
  21. package/dist/connect/parser_common.js.map +1 -1
  22. package/dist/html/parser.d.ts +2 -2
  23. package/dist/html/parser.d.ts.map +1 -1
  24. package/dist/html/parser.js +7 -5
  25. package/dist/html/parser.js.map +1 -1
  26. package/dist/react/parser.d.ts +3 -3
  27. package/dist/react/parser.d.ts.map +1 -1
  28. package/dist/react/parser.js +9 -7
  29. package/dist/react/parser.js.map +1 -1
  30. package/dist/storybook/convert.d.ts +7 -1
  31. package/dist/storybook/convert.d.ts.map +1 -1
  32. package/dist/storybook/convert.js +11 -4
  33. package/dist/storybook/convert.js.map +1 -1
  34. package/{figma-module.d.ts → figma-types.d.ts} +10 -3
  35. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/html/parser.ts"],"names":[],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AE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;QAC5B,OAAO;QACP,QAAQ;QACR,YAAY,EAAE;YACZ,qEAAqE;YACrE,uDAAuD;YACvD,KAAK;YACL,OAAO;YACP,wEAAwE;YACxE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI;SAC1C;QACD,KAAK;QACL,QAAQ,EAAE;YACR,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO;SAClD;KACF,CAAA;AACH,CAAC","sourcesContent":["import ts, { isReturnStatement, isTemplateExpression, SyntaxKind } from 'typescript'\nimport {\n stripQuotesFromNode,\n parsePropertyOfType,\n parseFunctionArgument,\n} from '../typescript/compiler'\nimport { FIGMA_CONNECT_CALL, PropMappings, parsePropsObject } from '../connect/intrinsics'\nimport { CodeConnectJSON } from '../connect/figma_connect'\nimport { getParsedTemplateHelpersString } from './parser_template_helpers'\nimport { JSDOM } from 'jsdom'\nimport { parse } from 'parse5'\nimport {\n makeCreatePropPlaceholder,\n ParserContext,\n visitPropReferencingNode,\n getReferencedPropsForTemplate,\n ParserError,\n parseLinks,\n parseVariant,\n parseImports,\n ParseOptions,\n} from '../connect/parser_common'\nimport { applyDocumentUrlSubstitutions } from '../connect/helpers'\nimport { CodeConnectParser, DEFAULT_LABEL_PER_PARSER } from '../connect/project'\nimport { SyntaxHighlightLanguage } from '../connect/label_language_mapping'\nimport { format } from 'prettier'\n\nfunction getHtmlTaggedTemplateNode(node: ts.Node): ts.TaggedTemplateExpression | undefined {\n if (ts.isTaggedTemplateExpression(node)) {\n const tag = node.tag\n if (ts.isIdentifier(tag) && tag.text === 'html') {\n return node\n }\n } else if (\n ts.isBlock(node) &&\n node.statements.length === 1 &&\n ts.isReturnStatement(node.statements[0]) &&\n node.statements[0].expression &&\n ts.isTaggedTemplateExpression(node.statements[0].expression) &&\n ts.isIdentifier(node.statements[0].expression.tag) &&\n node.statements[0].expression.tag.text === 'html'\n ) {\n return node.statements[0].expression\n }\n\n return undefined\n}\n\n/**\n * This function converts the HTML template literal into a DOM (using JSDOM) to\n * extract information which is used in generating the template:\n * 1. A dictionary of template placeholders which correspond to HTML attribute\n * values. The key is the placeholder index, and the value is the attribute\n * name. The attribute name is unused (it used to be used in the output, but\n * we need to preserve case to support Angular, which JSDOM can't do unless\n * you use XHTML mode, and that doesn't support attributes without a value).\n * 2. Whether the template is \"nestable\" or not. A template is considered\n * nestable if it has only one top level element.\n *\n * For finding the attribute placeholders, the algorithm is as follows:\n * 1. Build up a full string from the template literal, replacing any value\n * ${placeholders} with `__FIGMA_PLACEHOLDER_0`, where 0 is the placeholder\n * index. This results in a valid HTML string, with placeholders we can later\n * detect.\n * 2. Use JSDOM to turn this into a DOM.\n * 3. Iterate over every node in the DOM, and if the node has any attributes\n * starting `__FIGMA_PLACEHOLDER`, store the info of these attributes. This\n * allows us to know which template literal placeholders correspond to HTML\n * attributes when we construct the template.\n */\nfunction getInfoFromDom(\n templateExp: ts.TemplateExpression | ts.TaggedTemplateExpression,\n parserContext: ParserContext,\n): {\n attributePlaceholders: Record<number, string>\n nestable: boolean\n} {\n let htmlString: string\n\n if (ts.isTemplateExpression(templateExp)) {\n // If this is a template expression, build up the HTML string with\n // identifiable placeholders as described above\n htmlString = templateExp.head.text\n templateExp.templateSpans.forEach((part, index) => {\n htmlString += `__FIGMA_PLACEHOLDER_${index}` + part.literal.text\n })\n } else if (templateExp.template.kind === ts.SyntaxKind.FirstTemplateToken) {\n // This is just a template literal with no placeholders\n htmlString = templateExp.template.text\n } else {\n // This should never happen as we check the type in the calling function\n throw new Error(`Unsupported template type: ${SyntaxKind[templateExp.template.kind]}`)\n }\n\n // First, check for HTML which we cannot handle. JSDOM is quite forgiving,\n // like a browser, but we need to be stricter\n //\n // Duplicate attribute names are handled gracefully by JSDOM (it just keeps\n // one of the attributes), but this breaks our algorithm because some of the\n // placeholders are no longer in the DOM. JSDOM has no way to detect this, but\n // parse5 (which is a library JSDOM uses under the hood) can detect this. We\n // just thrown an error in this case as there's no use case for doing this.\n parse(htmlString, {\n onParseError: (error) => {\n if (error.code === 'duplicate-attribute') {\n throw new ParserError(`Duplicate attribute name in example HTML`, {\n node: templateExp,\n sourceFile: parserContext.sourceFile,\n })\n }\n },\n })\n\n // Try to format the HTML with prettier, to catch any errors due to invalid\n // HTML which would otherwise result in broken formatting in the UI as\n // prettier is less forgiving\n try {\n // pluginSearchDirs: false is needed as otherwise prettier picks up other\n // prettier plugins in our monorepo and fails on CI\n format(htmlString, { parser: 'html', pluginSearchDirs: false })\n } catch (e) {\n throw new ParserError(`Error parsing example HTML. Check the HTML is valid.`, {\n node: templateExp,\n sourceFile: parserContext.sourceFile,\n })\n }\n\n // Create a DOM with JSDOM.\n //\n // JSDOM doesn't work properly in all cases if we parse a DOM without a full\n // document, e.g. Vue templates - when traversing with NodeIterator, it\n // doesn't find all elements. We create a Fragment then append it to a full\n // DOM to work around this. The extra wrapping elements don't matter, as we're\n // only interested in the attributes.\n const fragment = JSDOM.fragment(htmlString)\n const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>')\n dom.window.document.body.appendChild(fragment)\n\n const document = dom.window.document\n const NodeFilter = dom.window.NodeFilter\n\n const attributePlaceholders: Record<number, string> = {}\n\n function iterateNodeIterator(nodeIterator: NodeIterator) {\n let currentNode: Node | null\n\n while ((currentNode = nodeIterator.nextNode())) {\n // I couldn't work out how to do this in a way which satisfies TypeScript,\n // so using a check and a cast\n if (currentNode.nodeType === dom.window.Node.ELEMENT_NODE) {\n // Check for any attributes which correspond to placeholders in the\n // template literal, and store their index and name\n for (let attr of (currentNode as Element).attributes) {\n if (attr.value.startsWith('__FIGMA_PLACEHOLDER_')) {\n attributePlaceholders[parseInt(attr.value.split('__FIGMA_PLACEHOLDER_')[1])] = attr.name\n }\n }\n }\n\n // <TEMPLATE> nodes are not iterated over by default, as they are a way to\n // store a fragment which is not rendered immediately. These are used in\n // e.g. Vue templates, so we need to iterate over them explicitly.\n if (currentNode.nodeName === 'TEMPLATE') {\n const templateContent = (currentNode as HTMLTemplateElement).content\n const templateNodeIterator = document.createNodeIterator(\n templateContent,\n NodeFilter.SHOW_ELEMENT,\n null,\n )\n iterateNodeIterator(templateNodeIterator)\n }\n }\n }\n\n // Iterate over all the nodes in the DOM\n const nodeIterator = document.createNodeIterator(document.body, NodeFilter.SHOW_ELEMENT, null)\n iterateNodeIterator(nodeIterator)\n\n // We check if there is more than one top level child, as we use this as a\n // signal that the template is not \"nestable\" (and so we render an instance\n // pill rather than render the child's code inline in the UI)\n const topLevelChildrenCount = document.body.children.length\n\n return {\n attributePlaceholders,\n nestable: topLevelChildrenCount === 1,\n }\n}\n\nfunction escapeTemplateString(code: string) {\n return code.replace(/`/g, '\\\\`').replace(/\\$\\{/g, '\\\\${')\n}\n\n/**\n * Parses the example template string passed to `figma.connect()`.\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseExampleTemplate(\n exp: ts.ArrowFunction,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n skipTemplateHelpers?: boolean,\n) {\n const { sourceFile } = parserContext\n\n if (exp.parameters.length > 1) {\n throw new ParserError(\n `Expected a single props parameter for the render function, got ${exp.parameters.length} parameters`,\n { sourceFile, node: exp },\n )\n }\n\n const propsParameter = exp.parameters[0]\n\n if (!exp.body) {\n throw new ParserError(`Expected a body for the render function`, { sourceFile, node: exp })\n }\n\n // If the body is a string literal, we generate a `figma.value` statement instead, which just\n // renders the string as-is in code examples\n if (ts.isStringLiteral(exp.body)) {\n const printer = ts.createPrinter()\n if (!exp.body) {\n throw new ParserError('Expected a function body', {\n sourceFile: parserContext.sourceFile,\n node: exp,\n })\n }\n let exampleCode = printer.printNode(ts.EmitHint.Unspecified, exp.body, sourceFile)\n\n let templateCode = ''\n if (!skipTemplateHelpers) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n templateCode += `const figma = require('figma')\\n\\n`\n\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n })\n\n exampleCode = exampleCode.replace(/`/g, '\\\\`')\n\n // Body is a string literal, so there aren't any placeholders\n templateCode += `export default figma.value(${exampleCode})\\n`\n\n return {\n code: templateCode,\n nestable: true,\n }\n }\n\n const templateNode = getHtmlTaggedTemplateNode(exp.body)\n\n if (!templateNode) {\n throw new ParserError(\n `Expected only a tagged template literal as the body of the render function`,\n { sourceFile, node: templateNode },\n )\n }\n\n // Keep track of any props which are referenced in the example so that we can\n // insert the appropriate `figma.properties` call in the JS template\n const referencedProps = new Set<string>()\n let exampleCode = ''\n let nestable = true\n\n if (isTemplateExpression(templateNode.template)) {\n // This is a template expression with placeholders\n\n const createPropPlaceholder = makeCreatePropPlaceholder({\n propMappings,\n referencedProps,\n sourceFile,\n })\n\n // Transform the template to replace any props references with placeholder\n // function calls, normalising the different types of props references\n const transformedTemplate = ts.transform(templateNode.template, [\n (context) => (rootNode) => {\n function visit(node: ts.Node): ts.Node {\n if (ts.isTemplateSpan(node)) {\n const visitResult = visitPropReferencingNode({\n propsParameter,\n node: node.expression,\n createPropPlaceholder,\n useJsx: false,\n })\n\n if (visitResult) {\n return ts.factory.createTemplateSpan(visitResult, node.literal)\n }\n }\n\n return ts.visitEachChild(node, visit, context)\n }\n return ts.visitNode(rootNode, visit) as typeof templateNode.template\n },\n ]).transformed[0] as typeof templateNode.template\n\n // Iterate over the template string spans (i.e. the interleaved strings and\n // placeholders) to build up our example code.\n //\n // Each time we encounter a placeholder (which by this point has been\n // normalised to a __PROP__ placeholder function call), we check if it\n // corresponds to a HTML attribute based on our previous DOM analysis (see\n // getInfoFromDom).\n //\n // If it does, we replace it with a call to\n // `_fcc_renderHtmlAttribute(\"attributeName\", propVariableName), otherwise\n // we replace it with a call to `_fcc_renderHtmlValue(propVariableName)`.\n //\n // We have some additional logic to handle cases where the user accidentally\n // writes `attribute=\"${props.prop}\"` rather than `attribute=${props.prop}`\n // (which is what we show in the docs), as it's easy to make this mistake\n // when copy/pasting.\n\n // Keep track of whether we're inside an attribute value that is wrapped in quotes,\n // so that we can strip the trailing quote if we are\n let insideAttributeWithQuotes = false\n\n const infoFromDom = getInfoFromDom(transformedTemplate, parserContext)\n const { attributePlaceholders } = infoFromDom\n nestable = infoFromDom.nestable\n\n // Handle a chunk of HTML, i.e. a text section of the template string. If\n // the next placeholder is an attribute and this chunk ends with a HTML\n // attribute (i.e. matches a regex like ` text=` or ` text=\"`), we remove the\n // attribute name so that it's not present in the low level template before the\n // call to _fcc_renderHtmlAttribute.\n function handleHtmlChunk(html: string, nextPlaceholderIsAttribute: boolean) {\n // If we were previously inside an attribute value placeholder with quotes\n // surrounding it, remove the leading quote. We do it like this rather\n // than always removing the leading quote to avoid situations where we\n // mistakenly remove a quote that is part of the actual content.\n if (insideAttributeWithQuotes) {\n html = html.replace(/^\"/g, '')\n }\n\n // If the next placeholder is an attribute, then match the start of the\n // attribute (`attribute=`) at the end of this chunk, so that we can\n // remove it from the example code and store the attribute name\n const attributeMatches = html.match(/(.*\\s)([^\\s]+)=\"?$/s)\n if (nextPlaceholderIsAttribute && attributeMatches) {\n // attributeMatches should always have matched here, but we check it\n // anyway so we can fail gracefully if not\n\n // Add the code up to the attribute, not including the ` attribute=`\n // part, as _fcc_renderHtmlAttribute is responsible for (maybe)\n // rendering that\n exampleCode += escapeTemplateString(attributeMatches[1])\n\n // If we are in this block, we know that we've matched an attribute, so\n // store whether it ends with a quote\n insideAttributeWithQuotes = html.endsWith('\"')\n\n // Return the attribute name so we can use it to construct the attribute\n // in the output. We do this rather than extract it from the HTML with\n // JSDOM because we want to preserve case, but do not want to parse the\n // doc as XHTML, so there's no way to do it otherwise.\n return attributeMatches[2]\n } else {\n // No attribute to remove, just add the code\n exampleCode += escapeTemplateString(html)\n insideAttributeWithQuotes = false\n }\n }\n\n // Process the first chunk, which is a special case as it is not in templateSpans\n let maybeAttributeName = handleHtmlChunk(\n transformedTemplate.head.text,\n attributePlaceholders[0] !== undefined,\n )\n\n // For each section of the template string, check that the expression is a\n // prop placeholder, then add the appropriate template function call\n transformedTemplate.templateSpans.forEach((part, index) => {\n if (!ts.isCallExpression(part.expression)) {\n throw new ParserError(\n `Expected a call expression as a placeholder in the template, got ${SyntaxKind[part.expression.kind]}`,\n { sourceFile, node: part.expression },\n )\n }\n\n const propNameArg = part.expression.arguments[0]\n if (!ts.isStringLiteral(propNameArg)) {\n throw new ParserError(\n `Expected a string literal as the argument to the placeholder call, got ${SyntaxKind[propNameArg.kind]}`,\n { sourceFile, node: propNameArg },\n )\n }\n\n const propVariableName = propNameArg.text\n\n if (attributePlaceholders[index]) {\n exampleCode += `\\${_fcc_renderHtmlAttribute('${maybeAttributeName}', ${propVariableName})}`\n } else {\n exampleCode += `\\${_fcc_renderHtmlValue(${propVariableName})}`\n }\n\n // Process the next chunk\n maybeAttributeName = handleHtmlChunk(\n part.literal.text,\n attributePlaceholders[index + 1] !== undefined,\n )\n })\n } else if (templateNode.template.kind === ts.SyntaxKind.FirstTemplateToken) {\n // Template string with no placeholders\n nestable = getInfoFromDom(templateNode, parserContext).nestable\n exampleCode = escapeTemplateString(templateNode.template.text)\n } else {\n throw new ParserError(\n `Expected a template expression as the body of the render function, got ${SyntaxKind[(templateNode.template as any).kind]}`,\n { sourceFile, node: templateNode.template },\n )\n }\n\n let templateCode = ''\n if (!skipTemplateHelpers) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n templateCode += `const figma = require('figma')\\n\\n`\n\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n })\n\n templateCode += `export default figma.html\\`${exampleCode}\\`\\n`\n\n return {\n code: templateCode,\n nestable,\n }\n}\n\nfunction parseFigmaConnectArgs(node: ts.CallExpression, parserContext: ParserContext) {\n const required = true\n\n const figmaNodeUrlArg = parseFunctionArgument(\n node,\n parserContext,\n 0,\n ts.isStringLiteral,\n required,\n `\\`${FIGMA_CONNECT_CALL}\\` must be called with a Figma Component URL as the first argument. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: () => html\\`<button />\\`\n})\\``,\n )!\n\n const configObjArg = parseFunctionArgument(\n node,\n parserContext,\n 1,\n ts.isObjectLiteralExpression,\n true,\n `The second argument to ${FIGMA_CONNECT_CALL}() must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: () => html\\`<button />\\`\n})\\``,\n )\n\n return {\n figmaNodeUrlArg,\n configObjArg,\n }\n}\n\nfunction parseConfigObjectArg(\n configArg: ts.ObjectLiteralExpression | undefined,\n parserContext: ParserContext,\n) {\n if (!configArg) {\n return {\n propsArg: undefined,\n exampleArg: undefined,\n variantArg: undefined,\n importsArg: undefined,\n linksArg: undefined,\n }\n }\n\n const propsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'props',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'props' property must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n props: {\n disabled: figma.boolean('Disabled'),\n text: figma.string('TextContent'),\n },\n example: (props) => html\\`<my-button disabled=\\${props.disabled} label=\\${props.text} />\\`\n})\\``,\n })\n\n const exampleArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'example',\n predicate: ts.isArrowFunction,\n parserContext,\n required: true,\n errorMessage: `The 'example' property must be an arrow function which returns a html tagged template string. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const variantArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'variant',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'variant' property must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n variant: {\n \"Has Icon\": true\n },\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const linksArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'links',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'links' property must be an array literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n links: [\n { name: 'Storybook', url: 'https://storybook.com' }\n ],\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const importsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'imports',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'imports' property must be an array literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n imports: ['import { Button } from \"./Button\"']\n example: (props) => html\\`<my-button />\\`,\n})\\``,\n })\n\n return {\n propsArg,\n exampleArg,\n variantArg,\n linksArg,\n importsArg,\n }\n}\n\nexport async function parseHtmlDoc(\n node: ts.CallExpression,\n parserContext: ParserContext,\n { skipTemplateHelpers }: ParseOptions,\n): Promise<CodeConnectJSON> {\n const { checker, sourceFile, config } = parserContext\n\n // Parse the arguments to the `figma.connect()` call\n const { figmaNodeUrlArg, configObjArg } = parseFigmaConnectArgs(node, parserContext)\n\n const { propsArg, exampleArg, variantArg, linksArg, importsArg } = parseConfigObjectArg(\n configObjArg,\n parserContext,\n )\n\n let figmaNode = stripQuotesFromNode(figmaNodeUrlArg)\n // TODO This logic is duplicated in connect.ts transformDocFromParser due to some type issues\n if (config.documentUrlSubstitutions) {\n figmaNode = applyDocumentUrlSubstitutions(figmaNode as string, config.documentUrlSubstitutions)\n }\n\n const metadata: any = undefined\n\n const props = propsArg ? parsePropsObject(propsArg, parserContext) : undefined\n const render = exampleArg\n ? parseExampleTemplate(exampleArg, parserContext, props, skipTemplateHelpers)\n : undefined\n const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined\n const links = linksArg ? parseLinks(linksArg, parserContext) : undefined\n\n let imports = importsArg ? parseImports(importsArg, parserContext) : undefined\n\n let template\n if (render?.code) {\n template = render.code\n } else {\n throw new ParserError(`${FIGMA_CONNECT_CALL}() requires an example function`, {\n sourceFile,\n node,\n })\n }\n\n return {\n figmaNode,\n label: DEFAULT_LABEL_PER_PARSER.html!,\n language: SyntaxHighlightLanguage.HTML,\n component: metadata?.component,\n source: '',\n sourceLocation: { line: -1 },\n variant,\n template,\n templateData: {\n // TODO: `props` here is currently only used for validation purposes,\n // we should eventually remove it from the JSON payload\n props,\n imports,\n // If there's no render function, the default example is always nestable\n nestable: render ? render.nestable : true,\n },\n links,\n metadata: {\n cliVersion: require('../../package.json').version,\n },\n }\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/html/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0MA,oDAmPC;AAiID,oCAgEC;AA9nBD,yDAAoF;AACpF,qDAI+B;AAC/B,sDAA0F;AAE1F,uEAA0E;AAC1E,iCAA6B;AAC7B,mCAA8B;AAC9B,4DAUiC;AACjC,gDAAkE;AAClE,gDAAgF;AAChF,8EAA2E;AAC3E,uCAAiC;AAEjC,SAAS,yBAAyB,CAAC,IAAa;IAC9C,IAAI,oBAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACpB,IAAI,oBAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;SAAM,IACL,oBAAE,CAAC,OAAO,CAAC,IAAI,CAAC;QAChB,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;QAC5B,oBAAE,CAAC,iBAAiB,CAAC,IAAI,CAA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C,CAAC,SAAS,CAAA;IAExE,IAAI,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,IAAA,4BAAY,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAE9E,IAAI,QAAQ,CAAA;IACZ,IAAI,MAAM,EAAE,IAAI,EAAE,CAAC;QACjB,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;IACxB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,2BAAW,CAAC,GAAG,+BAAkB,iCAAiC,EAAE;YAC5E,UAAU;YACV,IAAI;SACL,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,SAAS;QACT,KAAK,EAAE,kCAAwB,CAAC,IAAK;QACrC,QAAQ,EAAE,gDAAuB,CAAC,IAAI;QACtC,SAAS,EAAE,QAAQ,EAAE,SAAS;QAC9B,MAAM,EAAE,EAAE;QACV,cAAc,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;QAC5B,OAAO;QACP,QAAQ;QACR,YAAY,EAAE;YACZ,qEAAqE;YACrE,uDAAuD;YACvD,KAAK;YACL,OAAO;YACP,wEAAwE;YACxE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI;SAC1C;QACD,KAAK;QACL,QAAQ,EAAE;YACR,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO;SAClD;KACF,CAAA;AACH,CAAC","sourcesContent":["import ts, { isReturnStatement, isTemplateExpression, SyntaxKind } from 'typescript'\nimport {\n stripQuotesFromNode,\n parsePropertyOfType,\n parseFunctionArgument,\n} from '../typescript/compiler'\nimport { FIGMA_CONNECT_CALL, PropMappings, parsePropsObject } from '../connect/intrinsics'\nimport { CodeConnectJSON } from '../connect/figma_connect'\nimport { getParsedTemplateHelpersString } from './parser_template_helpers'\nimport { JSDOM } from 'jsdom'\nimport { parse } from 'parse5'\nimport {\n makeCreatePropPlaceholder,\n ParserContext,\n visitPropReferencingNode,\n getReferencedPropsForTemplate,\n ParserError,\n parseLinks,\n parseVariant,\n parseImports,\n ParseOptions,\n} from '../connect/parser_common'\nimport { applyDocumentUrlSubstitutions } from '../connect/helpers'\nimport { CodeConnectParser, DEFAULT_LABEL_PER_PARSER } from '../connect/project'\nimport { SyntaxHighlightLanguage } from '../connect/label_language_mapping'\nimport { format } from 'prettier'\n\nfunction getHtmlTaggedTemplateNode(node: ts.Node): ts.TaggedTemplateExpression | undefined {\n if (ts.isTaggedTemplateExpression(node)) {\n const tag = node.tag\n if (ts.isIdentifier(tag) && tag.text === 'html') {\n return node\n }\n } else if (\n ts.isBlock(node) &&\n node.statements.length === 1 &&\n ts.isReturnStatement(node.statements[0]) &&\n node.statements[0].expression &&\n ts.isTaggedTemplateExpression(node.statements[0].expression) &&\n ts.isIdentifier(node.statements[0].expression.tag) &&\n node.statements[0].expression.tag.text === 'html'\n ) {\n return node.statements[0].expression\n }\n\n return undefined\n}\n\n/**\n * This function converts the HTML template literal into a DOM (using JSDOM) to\n * extract information which is used in generating the template:\n * 1. A dictionary of template placeholders which correspond to HTML attribute\n * values. The key is the placeholder index, and the value is the attribute\n * name. The attribute name is unused (it used to be used in the output, but\n * we need to preserve case to support Angular, which JSDOM can't do unless\n * you use XHTML mode, and that doesn't support attributes without a value).\n * 2. Whether the template is \"nestable\" or not. A template is considered\n * nestable if it has only one top level element.\n *\n * For finding the attribute placeholders, the algorithm is as follows:\n * 1. Build up a full string from the template literal, replacing any value\n * ${placeholders} with `__FIGMA_PLACEHOLDER_0`, where 0 is the placeholder\n * index. This results in a valid HTML string, with placeholders we can later\n * detect.\n * 2. Use JSDOM to turn this into a DOM.\n * 3. Iterate over every node in the DOM, and if the node has any attributes\n * starting `__FIGMA_PLACEHOLDER`, store the info of these attributes. This\n * allows us to know which template literal placeholders correspond to HTML\n * attributes when we construct the template.\n */\nfunction getInfoFromDom(\n templateExp: ts.TemplateExpression | ts.TaggedTemplateExpression,\n parserContext: ParserContext,\n): {\n attributePlaceholders: Record<number, string>\n nestable: boolean\n} {\n let htmlString: string\n\n if (ts.isTemplateExpression(templateExp)) {\n // If this is a template expression, build up the HTML string with\n // identifiable placeholders as described above\n htmlString = templateExp.head.text\n templateExp.templateSpans.forEach((part, index) => {\n htmlString += `__FIGMA_PLACEHOLDER_${index}` + part.literal.text\n })\n } else if (templateExp.template.kind === ts.SyntaxKind.FirstTemplateToken) {\n // This is just a template literal with no placeholders\n htmlString = templateExp.template.text\n } else {\n // This should never happen as we check the type in the calling function\n throw new Error(`Unsupported template type: ${SyntaxKind[templateExp.template.kind]}`)\n }\n\n // First, check for HTML which we cannot handle. JSDOM is quite forgiving,\n // like a browser, but we need to be stricter\n //\n // Duplicate attribute names are handled gracefully by JSDOM (it just keeps\n // one of the attributes), but this breaks our algorithm because some of the\n // placeholders are no longer in the DOM. JSDOM has no way to detect this, but\n // parse5 (which is a library JSDOM uses under the hood) can detect this. We\n // just thrown an error in this case as there's no use case for doing this.\n parse(htmlString, {\n onParseError: (error) => {\n if (error.code === 'duplicate-attribute') {\n throw new ParserError(`Duplicate attribute name in example HTML`, {\n node: templateExp,\n sourceFile: parserContext.sourceFile,\n })\n }\n },\n })\n\n // Try to format the HTML with prettier, to catch any errors due to invalid\n // HTML which would otherwise result in broken formatting in the UI as\n // prettier is less forgiving\n try {\n // pluginSearchDirs: false is needed as otherwise prettier picks up other\n // prettier plugins in our monorepo and fails on CI\n format(htmlString, { parser: 'html', pluginSearchDirs: false })\n } catch (e) {\n throw new ParserError(`Error parsing example HTML. Check the HTML is valid.`, {\n node: templateExp,\n sourceFile: parserContext.sourceFile,\n })\n }\n\n // Create a DOM with JSDOM.\n //\n // JSDOM doesn't work properly in all cases if we parse a DOM without a full\n // document, e.g. Vue templates - when traversing with NodeIterator, it\n // doesn't find all elements. We create a Fragment then append it to a full\n // DOM to work around this. The extra wrapping elements don't matter, as we're\n // only interested in the attributes.\n const fragment = JSDOM.fragment(htmlString)\n const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>')\n dom.window.document.body.appendChild(fragment)\n\n const document = dom.window.document\n const NodeFilter = dom.window.NodeFilter\n\n const attributePlaceholders: Record<number, string> = {}\n\n function iterateNodeIterator(nodeIterator: NodeIterator) {\n let currentNode: Node | null\n\n while ((currentNode = nodeIterator.nextNode())) {\n // I couldn't work out how to do this in a way which satisfies TypeScript,\n // so using a check and a cast\n if (currentNode.nodeType === dom.window.Node.ELEMENT_NODE) {\n // Check for any attributes which correspond to placeholders in the\n // template literal, and store their index and name\n for (let attr of (currentNode as Element).attributes) {\n if (attr.value.startsWith('__FIGMA_PLACEHOLDER_')) {\n attributePlaceholders[parseInt(attr.value.split('__FIGMA_PLACEHOLDER_')[1])] = attr.name\n }\n }\n }\n\n // <TEMPLATE> nodes are not iterated over by default, as they are a way to\n // store a fragment which is not rendered immediately. These are used in\n // e.g. Vue templates, so we need to iterate over them explicitly.\n if (currentNode.nodeName === 'TEMPLATE') {\n const templateContent = (currentNode as HTMLTemplateElement).content\n const templateNodeIterator = document.createNodeIterator(\n templateContent,\n NodeFilter.SHOW_ELEMENT,\n null,\n )\n iterateNodeIterator(templateNodeIterator)\n }\n }\n }\n\n // Iterate over all the nodes in the DOM\n const nodeIterator = document.createNodeIterator(document.body, NodeFilter.SHOW_ELEMENT, null)\n iterateNodeIterator(nodeIterator)\n\n // We check if there is more than one top level child, as we use this as a\n // signal that the template is not \"nestable\" (and so we render an instance\n // pill rather than render the child's code inline in the UI)\n const topLevelChildrenCount = document.body.children.length\n\n return {\n attributePlaceholders,\n nestable: topLevelChildrenCount === 1,\n }\n}\n\nfunction escapeTemplateString(code: string) {\n return code.replace(/`/g, '\\\\`').replace(/\\$\\{/g, '\\\\${')\n}\n\n/**\n * Parses the example template string passed to `figma.connect()`.\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseExampleTemplate(\n exp: ts.ArrowFunction,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n isForMigration?: boolean,\n) {\n const { sourceFile } = parserContext\n\n if (exp.parameters.length > 1) {\n throw new ParserError(\n `Expected a single props parameter for the render function, got ${exp.parameters.length} parameters`,\n { sourceFile, node: exp },\n )\n }\n\n const propsParameter = exp.parameters[0]\n\n if (!exp.body) {\n throw new ParserError(`Expected a body for the render function`, { sourceFile, node: exp })\n }\n\n // If the body is a string literal, we generate a `figma.value` statement instead, which just\n // renders the string as-is in code examples\n if (ts.isStringLiteral(exp.body)) {\n const printer = ts.createPrinter()\n if (!exp.body) {\n throw new ParserError('Expected a function body', {\n sourceFile: parserContext.sourceFile,\n node: exp,\n })\n }\n let exampleCode = printer.printNode(ts.EmitHint.Unspecified, exp.body, sourceFile)\n\n let templateCode = ''\n if (!isForMigration) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n templateCode += `const figma = require('figma')\\n\\n`\n\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n isForMigration,\n })\n\n exampleCode = exampleCode.replace(/`/g, '\\\\`')\n\n // Body is a string literal, so there aren't any placeholders\n templateCode += `export default figma.value(${exampleCode})\\n`\n\n return {\n code: templateCode,\n nestable: true,\n }\n }\n\n const templateNode = getHtmlTaggedTemplateNode(exp.body)\n\n if (!templateNode) {\n throw new ParserError(\n `Expected only a tagged template literal as the body of the render function`,\n { sourceFile, node: templateNode },\n )\n }\n\n // Keep track of any props which are referenced in the example so that we can\n // insert the appropriate `figma.properties` call in the JS template\n const referencedProps = new Set<string>()\n let exampleCode = ''\n let nestable = true\n\n if (isTemplateExpression(templateNode.template)) {\n // This is a template expression with placeholders\n\n const createPropPlaceholder = makeCreatePropPlaceholder({\n propMappings,\n referencedProps,\n sourceFile,\n })\n\n // Transform the template to replace any props references with placeholder\n // function calls, normalising the different types of props references\n const transformedTemplate = ts.transform(templateNode.template, [\n (context) => (rootNode) => {\n function visit(node: ts.Node): ts.Node {\n if (ts.isTemplateSpan(node)) {\n const visitResult = visitPropReferencingNode({\n propsParameter,\n node: node.expression,\n createPropPlaceholder,\n useJsx: false,\n })\n\n if (visitResult) {\n return ts.factory.createTemplateSpan(visitResult, node.literal)\n }\n }\n\n return ts.visitEachChild(node, visit, context)\n }\n return ts.visitNode(rootNode, visit) as typeof templateNode.template\n },\n ]).transformed[0] as typeof templateNode.template\n\n // Iterate over the template string spans (i.e. the interleaved strings and\n // placeholders) to build up our example code.\n //\n // Each time we encounter a placeholder (which by this point has been\n // normalised to a __PROP__ placeholder function call), we check if it\n // corresponds to a HTML attribute based on our previous DOM analysis (see\n // getInfoFromDom).\n //\n // If it does, we replace it with a call to\n // `_fcc_renderHtmlAttribute(\"attributeName\", propVariableName), otherwise\n // we replace it with a call to `_fcc_renderHtmlValue(propVariableName)`.\n //\n // We have some additional logic to handle cases where the user accidentally\n // writes `attribute=\"${props.prop}\"` rather than `attribute=${props.prop}`\n // (which is what we show in the docs), as it's easy to make this mistake\n // when copy/pasting.\n\n // Keep track of whether we're inside an attribute value that is wrapped in quotes,\n // so that we can strip the trailing quote if we are\n let insideAttributeWithQuotes = false\n\n const infoFromDom = getInfoFromDom(transformedTemplate, parserContext)\n const { attributePlaceholders } = infoFromDom\n nestable = infoFromDom.nestable\n\n // Handle a chunk of HTML, i.e. a text section of the template string. If\n // the next placeholder is an attribute and this chunk ends with a HTML\n // attribute (i.e. matches a regex like ` text=` or ` text=\"`), we remove the\n // attribute name so that it's not present in the low level template before the\n // call to _fcc_renderHtmlAttribute.\n function handleHtmlChunk(html: string, nextPlaceholderIsAttribute: boolean) {\n // If we were previously inside an attribute value placeholder with quotes\n // surrounding it, remove the leading quote. We do it like this rather\n // than always removing the leading quote to avoid situations where we\n // mistakenly remove a quote that is part of the actual content.\n if (insideAttributeWithQuotes) {\n html = html.replace(/^\"/g, '')\n }\n\n // If the next placeholder is an attribute, then match the start of the\n // attribute (`attribute=`) at the end of this chunk, so that we can\n // remove it from the example code and store the attribute name\n const attributeMatches = html.match(/(.*\\s)([^\\s]+)=\"?$/s)\n if (nextPlaceholderIsAttribute && attributeMatches) {\n // attributeMatches should always have matched here, but we check it\n // anyway so we can fail gracefully if not\n\n // Add the code up to the attribute, not including the ` attribute=`\n // part, as _fcc_renderHtmlAttribute is responsible for (maybe)\n // rendering that\n exampleCode += escapeTemplateString(attributeMatches[1])\n\n // If we are in this block, we know that we've matched an attribute, so\n // store whether it ends with a quote\n insideAttributeWithQuotes = html.endsWith('\"')\n\n // Return the attribute name so we can use it to construct the attribute\n // in the output. We do this rather than extract it from the HTML with\n // JSDOM because we want to preserve case, but do not want to parse the\n // doc as XHTML, so there's no way to do it otherwise.\n return attributeMatches[2]\n } else {\n // No attribute to remove, just add the code\n exampleCode += escapeTemplateString(html)\n insideAttributeWithQuotes = false\n }\n }\n\n // Process the first chunk, which is a special case as it is not in templateSpans\n let maybeAttributeName = handleHtmlChunk(\n transformedTemplate.head.text,\n attributePlaceholders[0] !== undefined,\n )\n\n // For each section of the template string, check that the expression is a\n // prop placeholder, then add the appropriate template function call\n transformedTemplate.templateSpans.forEach((part, index) => {\n if (!ts.isCallExpression(part.expression)) {\n throw new ParserError(\n `Expected a call expression as a placeholder in the template, got ${SyntaxKind[part.expression.kind]}`,\n { sourceFile, node: part.expression },\n )\n }\n\n const propNameArg = part.expression.arguments[0]\n if (!ts.isStringLiteral(propNameArg)) {\n throw new ParserError(\n `Expected a string literal as the argument to the placeholder call, got ${SyntaxKind[propNameArg.kind]}`,\n { sourceFile, node: propNameArg },\n )\n }\n\n const propVariableName = propNameArg.text\n\n if (attributePlaceholders[index]) {\n exampleCode += `\\${_fcc_renderHtmlAttribute('${maybeAttributeName}', ${propVariableName})}`\n } else {\n exampleCode += `\\${_fcc_renderHtmlValue(${propVariableName})}`\n }\n\n // Process the next chunk\n maybeAttributeName = handleHtmlChunk(\n part.literal.text,\n attributePlaceholders[index + 1] !== undefined,\n )\n })\n } else if (templateNode.template.kind === ts.SyntaxKind.FirstTemplateToken) {\n // Template string with no placeholders\n nestable = getInfoFromDom(templateNode, parserContext).nestable\n exampleCode = escapeTemplateString(templateNode.template.text)\n } else {\n throw new ParserError(\n `Expected a template expression as the body of the render function, got ${SyntaxKind[(templateNode.template as any).kind]}`,\n { sourceFile, node: templateNode.template },\n )\n }\n\n let templateCode = ''\n if (!isForMigration) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n templateCode += `const figma = require('figma')\\n\\n`\n\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n isForMigration,\n })\n\n templateCode += `export default figma.html\\`${exampleCode}\\`\\n`\n\n return {\n code: templateCode,\n nestable,\n }\n}\n\nfunction parseFigmaConnectArgs(node: ts.CallExpression, parserContext: ParserContext) {\n const required = true\n\n const figmaNodeUrlArg = parseFunctionArgument(\n node,\n parserContext,\n 0,\n ts.isStringLiteral,\n required,\n `\\`${FIGMA_CONNECT_CALL}\\` must be called with a Figma Component URL as the first argument. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: () => html\\`<button />\\`\n})\\``,\n )!\n\n const configObjArg = parseFunctionArgument(\n node,\n parserContext,\n 1,\n ts.isObjectLiteralExpression,\n true,\n `The second argument to ${FIGMA_CONNECT_CALL}() must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: () => html\\`<button />\\`\n})\\``,\n )\n\n return {\n figmaNodeUrlArg,\n configObjArg,\n }\n}\n\nfunction parseConfigObjectArg(\n configArg: ts.ObjectLiteralExpression | undefined,\n parserContext: ParserContext,\n) {\n if (!configArg) {\n return {\n propsArg: undefined,\n exampleArg: undefined,\n variantArg: undefined,\n importsArg: undefined,\n linksArg: undefined,\n }\n }\n\n const propsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'props',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'props' property must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n props: {\n disabled: figma.boolean('Disabled'),\n text: figma.string('TextContent'),\n },\n example: (props) => html\\`<my-button disabled=\\${props.disabled} label=\\${props.text} />\\`\n})\\``,\n })\n\n const exampleArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'example',\n predicate: ts.isArrowFunction,\n parserContext,\n required: true,\n errorMessage: `The 'example' property must be an arrow function which returns a html tagged template string. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const variantArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'variant',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'variant' property must be an object literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n variant: {\n \"Has Icon\": true\n },\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const linksArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'links',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'links' property must be an array literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n links: [\n { name: 'Storybook', url: 'https://storybook.com' }\n ],\n example: (props) => html\\`<my-button />\\`\n})\\``,\n })\n\n const importsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'imports',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'imports' property must be an array literal. Example usage:\n\\`${FIGMA_CONNECT_CALL}('https://www.figma.com/file/123?node-id=1-1', {\n imports: ['import { Button } from \"./Button\"']\n example: (props) => html\\`<my-button />\\`,\n})\\``,\n })\n\n return {\n propsArg,\n exampleArg,\n variantArg,\n linksArg,\n importsArg,\n }\n}\n\nexport async function parseHtmlDoc(\n node: ts.CallExpression,\n parserContext: ParserContext,\n { isForMigration }: ParseOptions,\n): Promise<CodeConnectJSON> {\n const { checker, sourceFile, config } = parserContext\n\n // Parse the arguments to the `figma.connect()` call\n const { figmaNodeUrlArg, configObjArg } = parseFigmaConnectArgs(node, parserContext)\n\n const { propsArg, exampleArg, variantArg, linksArg, importsArg } = parseConfigObjectArg(\n configObjArg,\n parserContext,\n )\n\n let figmaNode = stripQuotesFromNode(figmaNodeUrlArg)\n // TODO This logic is duplicated in connect.ts transformDocFromParser due to some type issues\n if (config.documentUrlSubstitutions) {\n figmaNode = applyDocumentUrlSubstitutions(figmaNode as string, config.documentUrlSubstitutions)\n }\n\n const metadata: any = undefined\n\n const props = propsArg ? parsePropsObject(propsArg, parserContext) : undefined\n const render = exampleArg\n ? parseExampleTemplate(exampleArg, parserContext, props, isForMigration)\n : undefined\n const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined\n const links = linksArg ? parseLinks(linksArg, parserContext) : undefined\n\n let imports = importsArg ? parseImports(importsArg, parserContext) : undefined\n\n let template\n if (render?.code) {\n template = render.code\n } else {\n throw new ParserError(`${FIGMA_CONNECT_CALL}() requires an example function`, {\n sourceFile,\n node,\n })\n }\n\n return {\n figmaNode,\n label: DEFAULT_LABEL_PER_PARSER.html!,\n language: SyntaxHighlightLanguage.HTML,\n component: metadata?.component,\n source: '',\n sourceLocation: { line: -1 },\n variant,\n template,\n templateData: {\n // TODO: `props` here is currently only used for validation purposes,\n // we should eventually remove it from the JSON payload\n props,\n imports,\n // If there's no render function, the default example is always nestable\n nestable: render ? render.nestable : true,\n },\n links,\n metadata: {\n cliVersion: require('../../package.json').version,\n },\n }\n}\n"]}
@@ -55,7 +55,7 @@ export declare function parseRenderFunctionExpression(exp: ts.ArrowFunction | ts
55
55
  *
56
56
  * @returns The code of the render function and a list of imports
57
57
  */
58
- export declare function parseJSXRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings, skipTemplateHelpers?: boolean): {
58
+ export declare function parseJSXRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings, isForMigration?: boolean): {
59
59
  code: string;
60
60
  imports: {
61
61
  statement: string;
@@ -68,7 +68,7 @@ export declare function parseJSXRenderFunction(exp: ts.ArrowFunction | ts.Functi
68
68
  * Parses the render function for a value (i.e. example which returns a string or React
69
69
  * component reference, not JSX) passed to `figma.connect()`
70
70
  */
71
- export declare function parseValueRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings, skipTemplateHelpers?: boolean): {
71
+ export declare function parseValueRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings, isForMigration?: boolean): {
72
72
  code: string;
73
73
  imports: {
74
74
  statement: string;
@@ -79,5 +79,5 @@ export declare function parseValueRenderFunction(exp: ts.ArrowFunction | ts.Func
79
79
  };
80
80
  export declare function replacePropPlaceholders(exampleCode: string): string;
81
81
  export declare function getDefaultTemplate(componentMetadata: Awaited<ReturnType<typeof parseComponentMetadata>>): string;
82
- export declare function parseReactDoc(node: ts.CallExpression, parserContext: ParserContext, { repoUrl, silent, skipTemplateHelpers }: ParseOptions): Promise<CodeConnectJSON>;
82
+ export declare function parseReactDoc(node: ts.CallExpression, parserContext: ParserContext, { repoUrl, silent, isForMigration }: ParseOptions): Promise<CodeConnectJSON>;
83
83
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/react/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAmB3B,OAAO,EAAsB,YAAY,EAAoB,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,E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* @returns The code of the render function and a list of imports
398
398
  */
399
- function parseJSXRenderFunction(exp, parserContext, propMappings, skipTemplateHelpers) {
399
+ function parseJSXRenderFunction(exp, parserContext, propMappings, isForMigration) {
400
400
  const { sourceFile } = parserContext;
401
401
  const { code, imports, nestable, referencedProps } = parseRenderFunctionExpression(exp, parserContext, propMappings);
402
402
  let templateCode = '';
403
403
  // Generate the template code
404
404
  // Inject React-specific template helper functions
405
- if (!skipTemplateHelpers) {
405
+ if (!isForMigration) {
406
406
  templateCode = (0, parser_template_helpers_1.getParsedTemplateHelpersString)() + '\n\n';
407
407
  }
408
408
  // Require the template API
@@ -413,6 +413,7 @@ function parseJSXRenderFunction(exp, parserContext, propMappings, skipTemplateHe
413
413
  propMappings,
414
414
  exp,
415
415
  sourceFile,
416
+ isForMigration,
416
417
  });
417
418
  const includeMetadata = propMappings && Object.keys(propMappings).length > 0;
418
419
  // Finally, output the example code
@@ -429,7 +430,7 @@ function parseJSXRenderFunction(exp, parserContext, propMappings, skipTemplateHe
429
430
  * Parses the render function for a value (i.e. example which returns a string or React
430
431
  * component reference, not JSX) passed to `figma.connect()`
431
432
  */
432
- function parseValueRenderFunction(exp, parserContext, propMappings, skipTemplateHelpers) {
433
+ function parseValueRenderFunction(exp, parserContext, propMappings, isForMigration) {
433
434
  const { sourceFile } = parserContext;
434
435
  const printer = typescript_1.default.createPrinter();
435
436
  if (!exp.body) {
@@ -443,7 +444,7 @@ function parseValueRenderFunction(exp, parserContext, propMappings, skipTemplate
443
444
  let templateCode = '';
444
445
  // Generate the template code
445
446
  // Inject React-specific template helper functions
446
- if (!skipTemplateHelpers) {
447
+ if (!isForMigration) {
447
448
  templateCode = (0, parser_template_helpers_1.getParsedTemplateHelpersString)() + '\n\n';
448
449
  }
449
450
  // Require the template API
@@ -454,6 +455,7 @@ function parseValueRenderFunction(exp, parserContext, propMappings, skipTemplate
454
455
  propMappings,
455
456
  exp,
456
457
  sourceFile,
458
+ isForMigration,
457
459
  });
458
460
  // Escape backticks from the example code
459
461
  exampleCode = exampleCode.replace(/`/g, '\\`');
@@ -646,7 +648,7 @@ function getDefaultTemplate(componentMetadata) {
646
648
  const example = `<${componentMetadata.component} />`;
647
649
  return `const figma = require("figma")\n\nexport default figma.tsx\`${example}\``;
648
650
  }
649
- async function parseReactDoc(node, parserContext, { repoUrl, silent, skipTemplateHelpers }) {
651
+ async function parseReactDoc(node, parserContext, { repoUrl, silent, isForMigration }) {
650
652
  const { checker, sourceFile, config } = parserContext;
651
653
  // Parse the arguments to the `figma.connect()` call
652
654
  const { componentArg, figmaNodeUrlArg, configObjArg } = parseFigmaConnectArgs(node, parserContext);
@@ -662,8 +664,8 @@ async function parseReactDoc(node, parserContext, { repoUrl, silent, skipTemplat
662
664
  const props = propsArg ? (0, intrinsics_1.parsePropsObject)(propsArg, parserContext) : undefined;
663
665
  const render = exampleArg
664
666
  ? findJSXElement(exampleArg)
665
- ? parseJSXRenderFunction(exampleArg, parserContext, props, skipTemplateHelpers)
666
- : parseValueRenderFunction(exampleArg, parserContext, props, skipTemplateHelpers)
667
+ ? parseJSXRenderFunction(exampleArg, parserContext, props, isForMigration)
668
+ : parseValueRenderFunction(exampleArg, parserContext, props, isForMigration)
667
669
  : undefined;
668
670
  const variant = variantArg ? (0, parser_common_1.parseVariant)(variantArg, sourceFile, checker) : undefined;
669
671
  const links = linksArg ? (0, parser_common_1.parseLinks)(linksArg, parserContext) : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/react/parser.ts"],"names":[],"mappings":";;;;;AA0CA,wCAQC;AAiED,sDAaC;AAsFD,wDA+GC;AAYD,sEA+LC;AAYD,wDA6CC;AAMD,4DAmEC;AAED,0DA+BC;AA+LD,gDAKC;AAED,sCAiIC;AA1/BD,4DAA2B;AAC3B,gDAM2B;AAC3B,8EAA2E;AAC3E,+CAA0C;AAC1C,qDAO+B;AAC/B,gDAAkE;AAClE,sDAA0F;AAE1F,uEAA0E;AAC1E,4DAaiC;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,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;IACH,CAAC;IAED,OAAO;QACL,SAAS;QACT,KAAK,EAAE,kCAAwB,CAAC,KAAM;QACtC,QAAQ,EAAE,gDAAuB,CAAC,UAAU;QAC5C,SAAS,EAAE,QAAQ,EAAE,SAAS;QAC9B,MAAM,EAAE,QAAQ,EAAE,MAAM;YACtB,CAAC,CAAC,IAAA,0BAAgB,EAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC;YACjF,CAAC,CAAC,EAAE;QACN,cAAc,EAAE,QAAQ,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;QACrF,OAAO;QACP,QAAQ;QACR,YAAY,EAAE;YACZ,qEAAqE;YACrE,uDAAuD;YACvD,KAAK;YACL,OAAO,EAAE,aAAa;YACtB,wEAAwE;YACxE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI;SAC1C;QACD,KAAK;QACL,QAAQ,EAAE;YACR,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO;SAClD;KACF,CAAA;AACH,CAAC","sourcesContent":["import ts from 'typescript'\nimport {\n CodeConnectParser,\n DEFAULT_LABEL_PER_PARSER,\n getRemoteFileUrl,\n mapImportPath,\n mapImportSpecifier,\n} from '../connect/project'\nimport { SyntaxHighlightLanguage } from '../connect/label_language_mapping'\nimport { logger } from '../common/logging'\nimport {\n bfsFindNode,\n getTagName,\n stripQuotesFromNode,\n parsePropertyOfType,\n parseFunctionArgument,\n isOneOf,\n} from '../typescript/compiler'\nimport { applyDocumentUrlSubstitutions } from '../connect/helpers'\nimport { FIGMA_CONNECT_CALL, PropMappings, parsePropsObject } from '../connect/intrinsics'\nimport { CodeConnectJSON } from '../connect/figma_connect'\nimport { getParsedTemplateHelpersString } from './parser_template_helpers'\nimport {\n getPositionInSourceFile,\n InternalError,\n makeCreatePropPlaceholder,\n ParserContext,\n ParserError,\n visitPropReferencingNode,\n getReferencedPropsForTemplate,\n findDescendants,\n parseLinks,\n parseVariant,\n parseImports,\n ParseOptions,\n} from '../connect/parser_common'\n\n/**\n * Traverses the AST and returns the first JSX element it finds\n * @param node AST node\n * @returns\n */\nexport function findJSXElement(\n node: ts.Node,\n): ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment | undefined {\n if (ts.isJsxElement(node) || ts.isJsxFragment(node) || ts.isJsxSelfClosingElement(node)) {\n return node\n } else {\n return ts.forEachChild(node, findJSXElement)\n }\n}\n\nfunction findBlock(node: ts.Node): ts.Block | undefined {\n if (ts.isBlock(node)) {\n return node\n } else {\n return ts.forEachChild(node, findBlock)\n }\n}\n\n/**\n * Walks up the AST from an assignment to find the import declaration\n */\nfunction findParentImportDeclaration(\n declaration: ts.Declaration,\n): ts.ImportDeclaration | undefined {\n let current = declaration\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current\n }\n current = current.parent as ts.Declaration\n }\n}\n\nfunction getImportsOfModule(sourceFile: ts.SourceFile): ts.ImportDeclaration[] {\n const imports: ts.ImportDeclaration[] = []\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node)) {\n imports.push(node)\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n\n return imports\n}\n\nfunction resolveModuleSpecifier(\n program: ts.Program,\n sourceFile: ts.SourceFile,\n importSpecifier: string,\n): string | undefined {\n const compilerHost = ts.createCompilerHost(program.getCompilerOptions())\n const moduleResolutionHost: ts.ModuleResolutionHost = {\n fileExists: compilerHost.fileExists,\n readFile: compilerHost.readFile,\n directoryExists: compilerHost.directoryExists,\n getCurrentDirectory: compilerHost.getCurrentDirectory,\n getDirectories: compilerHost.getDirectories,\n }\n\n const resolvedModule = ts.resolveModuleName(\n importSpecifier,\n sourceFile.fileName,\n program.getCompilerOptions(),\n moduleResolutionHost,\n )\n\n return resolvedModule.resolvedModule?.resolvedFileName\n}\n\n// Traverse the source file and resolve imports\nexport function findAndResolveImports(program: ts.Program, sourceFile: ts.SourceFile) {\n const importSpecifierToFilePath: Record<string, string> = {}\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const importSpecifier = (node.moduleSpecifier as ts.StringLiteral).text\n const resolvedFileName = resolveModuleSpecifier(program, sourceFile, importSpecifier)\n\n if (resolvedFileName) {\n importSpecifierToFilePath[importSpecifier] = resolvedFileName\n }\n }\n })\n return importSpecifierToFilePath\n}\n\n/**\n * Finds all import statements in a file that matches the given identifiers\n *\n * @param parserContext Parser context\n * @param identifiers List of identifiers to find imports for\n * @returns\n */\nfunction getSourceFilesOfImportedIdentifiers(parserContext: ParserContext, _identifiers: string[]) {\n const { sourceFile, resolvedImports } = parserContext\n const importDeclarations = getImportsOfModule(sourceFile)\n const imports: {\n statement: string\n file: string\n moduleSpecifier: string\n }[] = []\n\n const identifiers = _identifiers.map((identifier) => identifier.split('.')[0])\n\n for (const declaration of importDeclarations) {\n let statement = declaration.getText()\n // remove the quotation marks around the module specifier\n const moduleSpecifier = declaration.moduleSpecifier.getText().slice(1, -1)\n\n if (declaration.importClause) {\n // Default imports\n if (declaration.importClause.name) {\n const identifier = declaration.importClause.name.text\n\n if (identifiers.includes(identifier)) {\n imports.push({\n statement,\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n }\n\n if (declaration.importClause.namedBindings) {\n const namedBindings = declaration.importClause.namedBindings\n\n if (ts.isNamedImports(namedBindings)) {\n // Named imports (import { x, y } from 'module')\n // filter out any unused imports from the statement the identifier belongs to\n const elements = namedBindings.elements\n .map((specifier) => specifier.name.text)\n .filter((name) => identifiers.includes(name))\n\n if (elements.length > 0) {\n imports.push({\n statement: statement.replace(/{.*}/s, `{ ${elements.join(', ')} }`),\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n } else if (ts.isNamespaceImport(namedBindings)) {\n // Namespace import (import * as name from 'module')\n const identifier = namedBindings.name.text\n if (identifiers.includes(identifier)) {\n imports.push({\n statement,\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n }\n }\n }\n }\n\n return imports\n}\n\nexport type ComponentTypeSignature = Record<string, string>\n\n/**\n * Extract metadata about the referenced React component. Used by both the\n * Code Connect and Storybook commands.\n *\n * @param parserContext Parser context\n * @param componentSymbol The ts.Symbol from the metadata referencing the\n * component being documented\n * @param node The node being parsed. Used for error logging.\n * @returns Metadata object\n */\nexport async function parseComponentMetadata(\n node: ts.PropertyAccessExpression | ts.Identifier | ts.Expression,\n parserContext: ParserContext,\n silent?: boolean,\n) {\n const { checker, sourceFile } = parserContext\n let componentSymbol = checker.getSymbolAtLocation(node)\n let componentSourceFile = sourceFile\n let component = ''\n let componentDeclaration\n\n // Hacky fix for namespaced components, this probably doesn't work for storybook\n if (ts.isPropertyAccessExpression(node)) {\n componentSymbol = checker.getSymbolAtLocation(node.expression)\n if (!componentSymbol) {\n throw new ParserError(`Could not find symbol for component ${node.expression.getText()}`, {\n sourceFile,\n node,\n })\n }\n }\n\n // Component declared in a different file\n if (\n componentSymbol &&\n componentSymbol.declarations &&\n (ts.isImportSpecifier(componentSymbol.declarations[0]) ||\n ts.isImportClause(componentSymbol.declarations[0]))\n ) {\n let importDeclaration = findParentImportDeclaration(componentSymbol.declarations[0])\n if (!importDeclaration) {\n throw new ParserError(\n 'No import statement found for component, make sure the component is imported',\n {\n sourceFile,\n node,\n },\n )\n }\n\n // The component should be imported from another file, we need to follow the\n // aliased symbol to get the correct function definition\n if (componentSymbol.flags & ts.SymbolFlags.Alias) {\n componentSymbol = checker.getAliasedSymbol(componentSymbol)\n }\n\n if (!componentSymbol || !componentSymbol.declarations) {\n if (!silent) {\n logger.warn(\n `Import for ${node.getText()} could not be resolved, make sure that your \\`include\\` globs in \\`figma.config.json\\` matches the component source file (in addition to the Code Connect file). If you're using path aliases, make sure to include the same aliases in \\`figma.config.json\\` with the \\`paths\\` option.`,\n )\n }\n return {\n source: '',\n line: 0,\n component: node.getText(),\n }\n }\n\n // If we haven't found the component declaration by now, it's likely because it's\n // assigned to an object/namespace, for example: `export const Button = { Primary: () => <button /> }`,\n // so we need to find the function declaration by traversing the AST in that file.\n if (!ts.isFunctionDeclaration(componentSymbol.declarations[0])) {\n const sourceFile = componentSymbol.declarations[0].getSourceFile()\n bfsFindNode(sourceFile, sourceFile, (node) => {\n if (\n (ts.isFunctionDeclaration(node) || ts.isVariableDeclaration(node)) &&\n node.name &&\n componentSymbol?.name &&\n node.name.getText() === componentSymbol.name\n ) {\n componentSymbol = checker.getSymbolAtLocation(node.name)\n return true\n }\n return false\n })\n }\n\n componentDeclaration = componentSymbol.declarations[0]\n componentSourceFile = componentDeclaration.getSourceFile()\n } else {\n componentDeclaration = componentSymbol?.declarations?.[0]\n }\n\n const source = componentSourceFile.fileName\n\n if (!source) {\n throw new InternalError(\n `Could not find source file for component ${component} - is this file included in the directory passed to \\`figma connect <dir>\\`?`,\n )\n }\n\n if (!componentDeclaration) {\n throw new ParserError(`Could not find declaration for component ${component}`, {\n sourceFile,\n node,\n })\n }\n\n const line = getPositionInSourceFile(componentDeclaration, componentSourceFile).line\n if (line === undefined) {\n throw new InternalError(\n `Could not determine line number for component ${componentDeclaration.getStart(sourceFile)}`,\n )\n }\n\n return {\n source,\n line,\n component: node.getText(),\n }\n}\n\n/**\n * Parses a render function and ouputs a template string, extracting the code and\n * any import statements matching the JSX elements used in the function body\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseRenderFunctionExpression(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n) {\n const { sourceFile } = parserContext\n\n let renderFunctionCode: string\n\n if (exp.parameters.length > 1) {\n throw new ParserError(\n `Expected a single props parameter for the render function, got ${exp.parameters.length} parameters`,\n { sourceFile, node: exp },\n )\n }\n\n const propsParameter = exp.parameters[0]\n\n // Keep track of any props which are referenced in the example\n const referencedProps = new Set<string>()\n\n const createPropPlaceholder = makeCreatePropPlaceholder({\n propMappings,\n referencedProps,\n sourceFile,\n })\n\n // Find all property access expressions in the function body and replace them\n // with a function call like `__PROP__(\"propName\")`, so that we can easily\n // find them in the next step to convert them into\n // `${_fcc_renderReactProp(...)` in the template string.\n //\n // Doing it this way means we can normalize the different ways in which props\n // can be accessed using the compiler API, which is much easier than using a\n // regex, then in the next step we can use a simple regex to convert that into\n // the template string.\n if (propsParameter) {\n exp = ts.transform(exp, [\n (context) => (rootNode) => {\n function visit(node: ts.Node): ts.Node {\n const visitResult = visitPropReferencingNode({\n propsParameter,\n node,\n createPropPlaceholder,\n useJsx: true,\n })\n\n if (visitResult) {\n return visitResult\n }\n\n // object assignment using destructured reference, e.g `prop={{ key: value }}`\n // (`{{ key: props.value }}` syntax will be captured by the `props.` notation branch above)\n if (\n ts.isObjectBindingPattern(propsParameter.name) &&\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.initializer) &&\n propsParameter.name.elements.find((el) =>\n node.initializer.getText().startsWith(el.name.getText()),\n )\n ) {\n return ts.factory.createPropertyAssignment(\n node.name,\n createPropPlaceholder({ name: node.initializer.getText(), node }),\n )\n }\n // object assignment using destructured reference as a shorthand, e.g `prop={{ value }}`\n if (\n ts.isObjectBindingPattern(propsParameter.name) &&\n ts.isShorthandPropertyAssignment(node) &&\n propsParameter.name.elements.find((el) =>\n node.name.getText().startsWith(el.name.getText()),\n )\n ) {\n return ts.factory.createPropertyAssignment(\n node.name,\n createPropPlaceholder({ name: node.name.getText(), node }),\n )\n }\n\n // Replaces {...props} with all the prop mapped props we know about,\n // e.g. <Button {...props} /> becomes:\n // <Button prop1={__PROP__(\"prop1\")} prop2={__PROP__(\"prop2\")} />.\n if (\n ts.isJsxSpreadAttribute(node) &&\n ts.isIdentifier(node.expression) &&\n // example: (props) => (...)\n (node.expression.getText() === propsParameter.name.getText() ||\n // example: ({ prop1, prop2 ...props }) => (...)\n (ts.isObjectBindingPattern(propsParameter.name) &&\n propsParameter.name.elements.find(\n (el) => el.dotDotDotToken && el.name.getText() === node.expression?.getText(),\n )))\n ) {\n // if we have an object binding pattern ({ prop1, prop2 ...props }),\n // exclude the props that are already destructured (prop1, prop2)\n const propsToExclude = ts.isObjectBindingPattern(propsParameter.name)\n ? propsParameter.name.elements\n .filter((el) => !el.dotDotDotToken)\n .map((el) => el.name.getText())\n : []\n const props = propMappings\n ? Object.keys(propMappings)\n .filter((prop) => !propsToExclude.includes(prop))\n .map((prop) => {\n return ts.factory.createJsxAttribute(\n ts.factory.createIdentifier(prop),\n createPropPlaceholder({\n name: prop,\n node,\n wrapInJsxExpression: true,\n }) as ts.JsxExpression,\n )\n })\n : []\n\n if (propMappings) {\n for (const key of Object.keys(propMappings)) {\n referencedProps.add(key)\n }\n }\n\n return props as any\n }\n\n return ts.visitEachChild(node, visit, context)\n }\n return ts.visitNode(rootNode, visit) as\n | ts.ArrowFunction\n | ts.FunctionExpression\n | ts.FunctionDeclaration\n },\n ]).transformed[0] as typeof exp\n }\n\n const printer = ts.createPrinter()\n const block = findBlock(exp)\n let nestable = false\n let jsx = findJSXElement(exp)\n\n if (jsx && (!block || (block && block.statements.length <= 1))) {\n // The function body is a single JSX element\n renderFunctionCode = printer.printNode(ts.EmitHint.Unspecified, jsx, sourceFile)\n nestable = true\n } else if (block) {\n // The function body has more stuff in it, so we wrap the body in a function\n // expression. Why not just print the exact function passed to `render`?\n // Because the parameters to that function are not actually referenced in\n // the rendered code snippet in Figma - they're mapped to values on the\n // Figma instance.\n const functionName = 'Example'\n const functionExpression = ts.factory.createFunctionExpression(\n undefined,\n undefined,\n ts.factory.createIdentifier(functionName),\n [],\n undefined,\n undefined,\n block,\n )\n const printer = ts.createPrinter()\n renderFunctionCode = printer.printNode(ts.EmitHint.Unspecified, functionExpression, sourceFile)\n } else {\n throw new ParserError(\n `Expected a single JSX element or a block statement in the render function, got ${exp.getText()}`,\n { sourceFile, node: exp },\n )\n }\n\n renderFunctionCode = replacePropPlaceholders(renderFunctionCode)\n\n // Escape backticks from the example code, as otherwise those would terminate the `figma.tsx` template literal\n renderFunctionCode = renderFunctionCode.replace(/`/g, '\\\\`')\n\n // Finally, output the render function as a figma.tsx call\n const figmaTsxCall = `figma.tsx\\`${renderFunctionCode}\\``\n\n // Find all JSX elements in the function body and extract their import\n // statements\n const jsxTags = findDescendants(\n exp,\n (element) => ts.isJsxElement(element) || ts.isJsxSelfClosingElement(element),\n ) as (ts.JsxElement | ts.JsxSelfClosingElement)[]\n const imports = getSourceFilesOfImportedIdentifiers(parserContext, jsxTags.map(getTagName))\n\n return {\n code: figmaTsxCall,\n imports,\n nestable,\n referencedProps,\n }\n}\n\n/**\n * Parses the render function passed to `figma.connect()`, extracting the code and\n * any import statements matching the JSX elements used in the function body\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseJSXRenderFunction(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n skipTemplateHelpers?: boolean,\n) {\n const { sourceFile } = parserContext\n\n const { code, imports, nestable, referencedProps } = parseRenderFunctionExpression(\n exp,\n parserContext,\n propMappings,\n )\n\n let templateCode = ''\n\n // Generate the template code\n // Inject React-specific template helper functions\n if (!skipTemplateHelpers) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n // Require the template API\n templateCode += `const figma = require('figma')\\n\\n`\n\n // Then we output `const propName = figma.properties.<kind>('propName')` calls\n // for each referenced prop, so these are accessible to the template code.\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n })\n\n const includeMetadata = propMappings && Object.keys(propMappings).length > 0\n\n // Finally, output the example code\n templateCode += includeMetadata\n ? `export default { ...${code}, metadata: { __props } }\\n`\n : `export default ${code}\\n`\n\n return {\n code: templateCode,\n imports,\n nestable,\n }\n}\n\n/**\n * Parses the render function for a value (i.e. example which returns a string or React\n * component reference, not JSX) passed to `figma.connect()`\n */\nexport function parseValueRenderFunction(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n skipTemplateHelpers?: boolean,\n) {\n const { sourceFile } = parserContext\n const printer = ts.createPrinter()\n if (!exp.body) {\n throw new ParserError('Expected a function body', {\n sourceFile: parserContext.sourceFile,\n node: exp,\n })\n }\n\n let exampleCode = printer.printNode(ts.EmitHint.Unspecified, exp.body, sourceFile)\n const nestable = true\n\n let templateCode = ''\n // Generate the template code\n // Inject React-specific template helper functions\n if (!skipTemplateHelpers) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n // Require the template API\n templateCode += `const figma = require('figma')\\n\\n`\n\n // Then we output `const propName = figma.properties.<kind>('propName')` calls\n // for each referenced prop, so these are accessible to the template code.\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n })\n\n // Escape backticks from the example code\n exampleCode = exampleCode.replace(/`/g, '\\\\`')\n\n let imports: {\n statement: string\n file: string\n moduleSpecifier: string\n }[] = []\n\n const includeMetadata = propMappings && Object.keys(propMappings).length > 0\n\n if (ts.isStringLiteral(exp.body)) {\n // The value is a string, which is already wrapped in quotes\n templateCode += includeMetadata\n ? `export default { ...figma.value(${exampleCode}), metadata: { __props } }\\n`\n : `export default figma.value(${exampleCode})\\n`\n } else if (ts.isIdentifier(exp.body)) {\n // The value is an identifier, i.e. a React component reference\n const value = `_fcc_reactComponent(\"${exp.body.getText()}\")`\n const preview = `_fcc_renderPropValue(${value})`\n templateCode += includeMetadata\n ? `export default { ...figma.value(${value}, ${preview}), metadata: { __props } }\\n`\n : `export default figma.value(${value}, ${preview})\\n`\n imports = getSourceFilesOfImportedIdentifiers(parserContext, [exp.body.getText()])\n }\n\n return {\n code: templateCode,\n imports,\n nestable,\n }\n}\n\nexport function replacePropPlaceholders(exampleCode: string) {\n // Replace React prop placeholders we inserted above (like\n // `reactPropName={__PROP__(\"figmaPropName\")}`) with calls to\n // _fcc_renderReactProp, which renders them correctly (see\n // parser_template_helpers.ts)\n exampleCode = exampleCode.replace(\n // match \" reactPropName={__PROP__(\"figmaPropName\")}\" and extract the names\n // We allow hyphens in prop names (unlike React) to support rendering HTML attributes\n / ([A-Za-z0-9\\-]+)=\\{__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)\\}/g,\n (_match, reactPropName, figmaPropName) => {\n return `\\${_fcc_renderReactProp('${reactPropName}', ${figmaPropName})}`\n },\n )\n\n // Replace React children placeholders like `${__PROP__(\"propName\")}` with\n // calls to _fcc_renderReactChildren, which renders them correctly (see\n // parser_template_helpers.ts)\n exampleCode = exampleCode.replace(\n /\\{__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)\\}/g,\n (_match, figmaPropName) => {\n return `\\${_fcc_renderReactChildren(${figmaPropName})}`\n },\n )\n\n // Assume any remaining placeholders are values, e.g.\n // - { prop: __PROP__(\"propName\") }\n // - useState(__PROP__(\"propName\"))\n // These never need special treatment based on their type.\n return exampleCode.replace(/__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)/g, (_match, figmaPropName) => {\n return `\\${_fcc_renderPropValue(${figmaPropName})}`\n })\n}\n\nfunction followIdentifierToStringLiteralDeclaration(\n node: ts.Identifier | ts.StringLiteral,\n parserContext: ParserContext,\n errMessage: string,\n) {\n const { checker } = parserContext\n let result = node\n\n if (node && ts.isIdentifier(node)) {\n const symbol = checker.getSymbolAtLocation(node)\n if (symbol) {\n const decl = symbol.valueDeclaration\n if (\n decl &&\n ts.isVariableDeclaration(decl) &&\n decl.initializer &&\n ts.isStringLiteral(decl.initializer)\n ) {\n result = decl.initializer\n }\n }\n }\n\n // If we followed the identifier to its declaration and it's not a string literal,\n // throw an error\n if (!result || !ts.isStringLiteral(result)) {\n throw new ParserError(errMessage, {\n node: result,\n sourceFile: parserContext.sourceFile,\n })\n }\n\n return result\n}\n\nfunction parseFigmaConnectArgs(node: ts.CallExpression, parserContext: ParserContext) {\n const required = true\n const first = parseFunctionArgument(\n node,\n parserContext,\n 0,\n isOneOf([ts.isIdentifier, ts.isPropertyAccessExpression, ts.isStringLiteral]),\n required,\n `\\`${FIGMA_CONNECT_CALL}\\` must be called with a reference to a Component or a Figma Component URL as the first argument. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1')\\``,\n )!\n\n let figmaNodeUrlArg: ts.StringLiteral\n let componentArg: ts.Identifier | ts.PropertyAccessExpression | undefined\n let configObjArgIndex\n\n // This function has two signatures. If the first arg is a string literal, it's the Figma node URL, and\n // it won't have a component reference.\n if (ts.isStringLiteral(first)) {\n figmaNodeUrlArg = first\n componentArg = undefined\n configObjArgIndex = 1\n } else {\n // If the first argument is not a string literal, it must be a component reference,\n // and the second argument must be the Figma node URL\n componentArg = first\n configObjArgIndex = 2\n\n const invalidTypeErrorMsg = `The second argument to ${FIGMA_CONNECT_CALL}() must be a string literal (the URL of the Figma node). Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1')\\``\n\n let arg = parseFunctionArgument(\n node,\n parserContext,\n 1,\n isOneOf([ts.isIdentifier, ts.isStringLiteral]),\n required,\n invalidTypeErrorMsg,\n )!\n\n figmaNodeUrlArg = followIdentifierToStringLiteralDeclaration(\n arg,\n parserContext,\n invalidTypeErrorMsg,\n )\n }\n\n const configObjArg = parseFunctionArgument(\n node,\n parserContext,\n configObjArgIndex,\n ts.isObjectLiteralExpression,\n false /* not required */,\n `The third argument to ${FIGMA_CONNECT_CALL}() must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', { render: () => <Button /> })\\``,\n )\n\n return {\n componentArg,\n figmaNodeUrlArg,\n configObjArg,\n }\n}\n\nfunction parseConfigObjectArg(\n configArg: ts.ObjectLiteralExpression | undefined,\n parserContext: ParserContext,\n) {\n if (!configArg) {\n return {\n propsArg: undefined,\n exampleArg: undefined,\n variantArg: undefined,\n importsArg: undefined,\n linksArg: undefined,\n }\n }\n\n const propsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'props',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'props' property must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n props: {\n disabled: figma.boolean('Disabled'),\n text: figma.string('TextContent'),\n }\n })\\``,\n })\n\n const exampleArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'example',\n predicate: isOneOf([ts.isArrowFunction, ts.isFunctionExpression]),\n parserContext,\n required: false,\n errorMessage: `The 'example' property must be an inline function or arrow function. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n example: () => <Button />\n })\\``,\n })\n\n const variantArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'variant',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'variant' property must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n variant: {\n \"Has Icon\": true\n }\n })\\``,\n })\n\n const linksArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'links',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'links' property must be an array literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n links: [\n { name: 'Storybook', url: 'https://storybook.com' }\n ]\n })\\``,\n })\n\n const importsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'imports',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'imports' property must be an array literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n imports: ['import { Button } from \"./Button\"']\n })\\``,\n })\n\n return {\n propsArg,\n exampleArg,\n variantArg,\n linksArg,\n importsArg,\n }\n}\n\nexport function getDefaultTemplate(\n componentMetadata: Awaited<ReturnType<typeof parseComponentMetadata>>,\n) {\n const example = `<${componentMetadata.component} />`\n return `const figma = require(\"figma\")\\n\\nexport default figma.tsx\\`${example}\\``\n}\n\nexport async function parseReactDoc(\n node: ts.CallExpression,\n parserContext: ParserContext,\n { repoUrl, silent, skipTemplateHelpers }: ParseOptions,\n): Promise<CodeConnectJSON> {\n const { checker, sourceFile, config } = parserContext\n\n // Parse the arguments to the `figma.connect()` call\n const { componentArg, figmaNodeUrlArg, configObjArg } = parseFigmaConnectArgs(node, parserContext)\n\n const { propsArg, exampleArg, variantArg, linksArg, importsArg } = parseConfigObjectArg(\n configObjArg,\n parserContext,\n )\n\n let figmaNode = stripQuotesFromNode(figmaNodeUrlArg)\n // TODO This logic is duplicated in connect.ts transformDocFromParser due to some type issues\n if (config.documentUrlSubstitutions) {\n figmaNode = applyDocumentUrlSubstitutions(figmaNode as string, config.documentUrlSubstitutions)\n }\n const metadata = componentArg\n ? await parseComponentMetadata(componentArg, parserContext, silent)\n : undefined\n\n const props = propsArg ? parsePropsObject(propsArg, parserContext) : undefined\n const render = exampleArg\n ? findJSXElement(exampleArg)\n ? parseJSXRenderFunction(exampleArg, parserContext, props, skipTemplateHelpers)\n : parseValueRenderFunction(exampleArg, parserContext, props, skipTemplateHelpers)\n : undefined\n const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined\n const links = linksArg ? parseLinks(linksArg, parserContext) : undefined\n\n let mappedImports: string[]\n if (importsArg) {\n mappedImports = parseImports(importsArg, parserContext)\n } else {\n // If no template function was provided, construct one and add the import\n // statement for the component\n let imports = render?.imports\n ? render.imports\n : metadata !== undefined\n ? getSourceFilesOfImportedIdentifiers(parserContext, [metadata.component])\n : []\n\n if (imports.length === 0 && metadata?.component) {\n // If no imports were found, it might mean that the component is not imported, or\n // that the `figma.connect` call is in the same file as the component. In the latter\n // case - we'll want to generate one\n const fileName = metadata.source.split('/').pop()?.split('.')[0]\n const relativeImportPath = `./${fileName}`\n imports = [\n {\n statement: `import { ${metadata.component} } from '${relativeImportPath}'`,\n file: sourceFile.fileName,\n moduleSpecifier: relativeImportPath,\n },\n ]\n }\n\n mappedImports = [\n ...new Set(\n imports.map((imp) => {\n if (config) {\n // First try to map the original import specifier directly (preserves user's intent)\n // e.g., '@/AlertTitle' -> '@acme/package/AlertTitle'\n if (typeof imp.moduleSpecifier === 'string') {\n const mappedFromSpecifier = mapImportSpecifier(imp.moduleSpecifier, config)\n if (mappedFromSpecifier) {\n return imp.statement.replace(\n /['\"]([@\\.\\/a-zA-Z0-9_-]*)['\"]/,\n `'${mappedFromSpecifier}'`,\n )\n }\n }\n // Fall back to mapping based on resolved file path (for relative imports)\n const mappedPath = mapImportPath(imp.file, config)\n if (mappedPath) {\n return imp.statement.replace(/['\"]([@\\.\\/a-zA-Z0-9_-]*)['\"]/, `'${mappedPath}'`)\n }\n }\n return imp.statement\n }),\n ),\n ]\n }\n\n if (mappedImports.length === 0 && metadata?.component) {\n logger.warn(\n `The import statement for ${metadata.component} could not be automatically resolved, make sure the component is imported (if not colocating) and that the path mappings are correct in your figma.config.json`,\n )\n }\n\n let template\n if (render?.code) {\n template = render.code\n } else if (metadata) {\n template = getDefaultTemplate(metadata)\n } else {\n throw new ParserError(\n `${FIGMA_CONNECT_CALL}() requires either a component argument or an example function`,\n { sourceFile, node },\n )\n }\n\n return {\n figmaNode,\n label: DEFAULT_LABEL_PER_PARSER.react!,\n language: SyntaxHighlightLanguage.TypeScript,\n component: metadata?.component,\n source: metadata?.source\n ? getRemoteFileUrl(metadata.source, repoUrl, parserContext.config?.defaultBranch)\n : '',\n sourceLocation: metadata?.line !== undefined ? { line: metadata.line } : { line: -1 },\n variant,\n template,\n templateData: {\n // TODO: `props` here is currently only used for validation purposes,\n // we should eventually remove it from the JSON payload\n props,\n imports: mappedImports,\n // If there's no render function, the default example is always nestable\n nestable: render ? render.nestable : true,\n },\n links,\n metadata: {\n cliVersion: require('../../package.json').version,\n },\n }\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/react/parser.ts"],"names":[],"mappings":";;;;;AA0CA,wCAQC;AAiED,sDAaC;AAsFD,wDA+GC;AAYD,sEA+LC;AAYD,wDA8CC;AAMD,4DAoEC;AAED,0DA+BC;AA+LD,gDAKC;AAED,sCAiIC;AA5/BD,4DAA2B;AAC3B,gDAM2B;AAC3B,8EAA2E;AAC3E,+CAA0C;AAC1C,qDAO+B;AAC/B,gDAAkE;AAClE,sDAA0F;AAE1F,uEAA0E;AAC1E,4DAaiC;AAEjC;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,IAAa;IAEb,IAAI,oBAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,oBAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,oBAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;QACxF,OAAO,IAAI,CAAA;IACb,CAAC;SAAM,CAAC;QACN,OAAO,oBAAE,CAAC,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;IAC9C,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,IAAI,oBAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;SAAM,CAAC;QACN,OAAO,oBAAE,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACzC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,2BAA2B,CAClC,WAA2B;IAE3B,IAAI,OAAO,GAAG,WAA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tB,wEAAwE;YACxE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI;SAC1C;QACD,KAAK;QACL,QAAQ,EAAE;YACR,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO;SAClD;KACF,CAAA;AACH,CAAC","sourcesContent":["import ts from 'typescript'\nimport {\n CodeConnectParser,\n DEFAULT_LABEL_PER_PARSER,\n getRemoteFileUrl,\n mapImportPath,\n mapImportSpecifier,\n} from '../connect/project'\nimport { SyntaxHighlightLanguage } from '../connect/label_language_mapping'\nimport { logger } from '../common/logging'\nimport {\n bfsFindNode,\n getTagName,\n stripQuotesFromNode,\n parsePropertyOfType,\n parseFunctionArgument,\n isOneOf,\n} from '../typescript/compiler'\nimport { applyDocumentUrlSubstitutions } from '../connect/helpers'\nimport { FIGMA_CONNECT_CALL, PropMappings, parsePropsObject } from '../connect/intrinsics'\nimport { CodeConnectJSON } from '../connect/figma_connect'\nimport { getParsedTemplateHelpersString } from './parser_template_helpers'\nimport {\n getPositionInSourceFile,\n InternalError,\n makeCreatePropPlaceholder,\n ParserContext,\n ParserError,\n visitPropReferencingNode,\n getReferencedPropsForTemplate,\n findDescendants,\n parseLinks,\n parseVariant,\n parseImports,\n ParseOptions,\n} from '../connect/parser_common'\n\n/**\n * Traverses the AST and returns the first JSX element it finds\n * @param node AST node\n * @returns\n */\nexport function findJSXElement(\n node: ts.Node,\n): ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment | undefined {\n if (ts.isJsxElement(node) || ts.isJsxFragment(node) || ts.isJsxSelfClosingElement(node)) {\n return node\n } else {\n return ts.forEachChild(node, findJSXElement)\n }\n}\n\nfunction findBlock(node: ts.Node): ts.Block | undefined {\n if (ts.isBlock(node)) {\n return node\n } else {\n return ts.forEachChild(node, findBlock)\n }\n}\n\n/**\n * Walks up the AST from an assignment to find the import declaration\n */\nfunction findParentImportDeclaration(\n declaration: ts.Declaration,\n): ts.ImportDeclaration | undefined {\n let current = declaration\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current\n }\n current = current.parent as ts.Declaration\n }\n}\n\nfunction getImportsOfModule(sourceFile: ts.SourceFile): ts.ImportDeclaration[] {\n const imports: ts.ImportDeclaration[] = []\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node)) {\n imports.push(node)\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n\n return imports\n}\n\nfunction resolveModuleSpecifier(\n program: ts.Program,\n sourceFile: ts.SourceFile,\n importSpecifier: string,\n): string | undefined {\n const compilerHost = ts.createCompilerHost(program.getCompilerOptions())\n const moduleResolutionHost: ts.ModuleResolutionHost = {\n fileExists: compilerHost.fileExists,\n readFile: compilerHost.readFile,\n directoryExists: compilerHost.directoryExists,\n getCurrentDirectory: compilerHost.getCurrentDirectory,\n getDirectories: compilerHost.getDirectories,\n }\n\n const resolvedModule = ts.resolveModuleName(\n importSpecifier,\n sourceFile.fileName,\n program.getCompilerOptions(),\n moduleResolutionHost,\n )\n\n return resolvedModule.resolvedModule?.resolvedFileName\n}\n\n// Traverse the source file and resolve imports\nexport function findAndResolveImports(program: ts.Program, sourceFile: ts.SourceFile) {\n const importSpecifierToFilePath: Record<string, string> = {}\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const importSpecifier = (node.moduleSpecifier as ts.StringLiteral).text\n const resolvedFileName = resolveModuleSpecifier(program, sourceFile, importSpecifier)\n\n if (resolvedFileName) {\n importSpecifierToFilePath[importSpecifier] = resolvedFileName\n }\n }\n })\n return importSpecifierToFilePath\n}\n\n/**\n * Finds all import statements in a file that matches the given identifiers\n *\n * @param parserContext Parser context\n * @param identifiers List of identifiers to find imports for\n * @returns\n */\nfunction getSourceFilesOfImportedIdentifiers(parserContext: ParserContext, _identifiers: string[]) {\n const { sourceFile, resolvedImports } = parserContext\n const importDeclarations = getImportsOfModule(sourceFile)\n const imports: {\n statement: string\n file: string\n moduleSpecifier: string\n }[] = []\n\n const identifiers = _identifiers.map((identifier) => identifier.split('.')[0])\n\n for (const declaration of importDeclarations) {\n let statement = declaration.getText()\n // remove the quotation marks around the module specifier\n const moduleSpecifier = declaration.moduleSpecifier.getText().slice(1, -1)\n\n if (declaration.importClause) {\n // Default imports\n if (declaration.importClause.name) {\n const identifier = declaration.importClause.name.text\n\n if (identifiers.includes(identifier)) {\n imports.push({\n statement,\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n }\n\n if (declaration.importClause.namedBindings) {\n const namedBindings = declaration.importClause.namedBindings\n\n if (ts.isNamedImports(namedBindings)) {\n // Named imports (import { x, y } from 'module')\n // filter out any unused imports from the statement the identifier belongs to\n const elements = namedBindings.elements\n .map((specifier) => specifier.name.text)\n .filter((name) => identifiers.includes(name))\n\n if (elements.length > 0) {\n imports.push({\n statement: statement.replace(/{.*}/s, `{ ${elements.join(', ')} }`),\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n } else if (ts.isNamespaceImport(namedBindings)) {\n // Namespace import (import * as name from 'module')\n const identifier = namedBindings.name.text\n if (identifiers.includes(identifier)) {\n imports.push({\n statement,\n file: resolvedImports[moduleSpecifier],\n moduleSpecifier,\n })\n }\n }\n }\n }\n }\n\n return imports\n}\n\nexport type ComponentTypeSignature = Record<string, string>\n\n/**\n * Extract metadata about the referenced React component. Used by both the\n * Code Connect and Storybook commands.\n *\n * @param parserContext Parser context\n * @param componentSymbol The ts.Symbol from the metadata referencing the\n * component being documented\n * @param node The node being parsed. Used for error logging.\n * @returns Metadata object\n */\nexport async function parseComponentMetadata(\n node: ts.PropertyAccessExpression | ts.Identifier | ts.Expression,\n parserContext: ParserContext,\n silent?: boolean,\n) {\n const { checker, sourceFile } = parserContext\n let componentSymbol = checker.getSymbolAtLocation(node)\n let componentSourceFile = sourceFile\n let component = ''\n let componentDeclaration\n\n // Hacky fix for namespaced components, this probably doesn't work for storybook\n if (ts.isPropertyAccessExpression(node)) {\n componentSymbol = checker.getSymbolAtLocation(node.expression)\n if (!componentSymbol) {\n throw new ParserError(`Could not find symbol for component ${node.expression.getText()}`, {\n sourceFile,\n node,\n })\n }\n }\n\n // Component declared in a different file\n if (\n componentSymbol &&\n componentSymbol.declarations &&\n (ts.isImportSpecifier(componentSymbol.declarations[0]) ||\n ts.isImportClause(componentSymbol.declarations[0]))\n ) {\n let importDeclaration = findParentImportDeclaration(componentSymbol.declarations[0])\n if (!importDeclaration) {\n throw new ParserError(\n 'No import statement found for component, make sure the component is imported',\n {\n sourceFile,\n node,\n },\n )\n }\n\n // The component should be imported from another file, we need to follow the\n // aliased symbol to get the correct function definition\n if (componentSymbol.flags & ts.SymbolFlags.Alias) {\n componentSymbol = checker.getAliasedSymbol(componentSymbol)\n }\n\n if (!componentSymbol || !componentSymbol.declarations) {\n if (!silent) {\n logger.warn(\n `Import for ${node.getText()} could not be resolved, make sure that your \\`include\\` globs in \\`figma.config.json\\` matches the component source file (in addition to the Code Connect file). If you're using path aliases, make sure to include the same aliases in \\`figma.config.json\\` with the \\`paths\\` option.`,\n )\n }\n return {\n source: '',\n line: 0,\n component: node.getText(),\n }\n }\n\n // If we haven't found the component declaration by now, it's likely because it's\n // assigned to an object/namespace, for example: `export const Button = { Primary: () => <button /> }`,\n // so we need to find the function declaration by traversing the AST in that file.\n if (!ts.isFunctionDeclaration(componentSymbol.declarations[0])) {\n const sourceFile = componentSymbol.declarations[0].getSourceFile()\n bfsFindNode(sourceFile, sourceFile, (node) => {\n if (\n (ts.isFunctionDeclaration(node) || ts.isVariableDeclaration(node)) &&\n node.name &&\n componentSymbol?.name &&\n node.name.getText() === componentSymbol.name\n ) {\n componentSymbol = checker.getSymbolAtLocation(node.name)\n return true\n }\n return false\n })\n }\n\n componentDeclaration = componentSymbol.declarations[0]\n componentSourceFile = componentDeclaration.getSourceFile()\n } else {\n componentDeclaration = componentSymbol?.declarations?.[0]\n }\n\n const source = componentSourceFile.fileName\n\n if (!source) {\n throw new InternalError(\n `Could not find source file for component ${component} - is this file included in the directory passed to \\`figma connect <dir>\\`?`,\n )\n }\n\n if (!componentDeclaration) {\n throw new ParserError(`Could not find declaration for component ${component}`, {\n sourceFile,\n node,\n })\n }\n\n const line = getPositionInSourceFile(componentDeclaration, componentSourceFile).line\n if (line === undefined) {\n throw new InternalError(\n `Could not determine line number for component ${componentDeclaration.getStart(sourceFile)}`,\n )\n }\n\n return {\n source,\n line,\n component: node.getText(),\n }\n}\n\n/**\n * Parses a render function and ouputs a template string, extracting the code and\n * any import statements matching the JSX elements used in the function body\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseRenderFunctionExpression(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n) {\n const { sourceFile } = parserContext\n\n let renderFunctionCode: string\n\n if (exp.parameters.length > 1) {\n throw new ParserError(\n `Expected a single props parameter for the render function, got ${exp.parameters.length} parameters`,\n { sourceFile, node: exp },\n )\n }\n\n const propsParameter = exp.parameters[0]\n\n // Keep track of any props which are referenced in the example\n const referencedProps = new Set<string>()\n\n const createPropPlaceholder = makeCreatePropPlaceholder({\n propMappings,\n referencedProps,\n sourceFile,\n })\n\n // Find all property access expressions in the function body and replace them\n // with a function call like `__PROP__(\"propName\")`, so that we can easily\n // find them in the next step to convert them into\n // `${_fcc_renderReactProp(...)` in the template string.\n //\n // Doing it this way means we can normalize the different ways in which props\n // can be accessed using the compiler API, which is much easier than using a\n // regex, then in the next step we can use a simple regex to convert that into\n // the template string.\n if (propsParameter) {\n exp = ts.transform(exp, [\n (context) => (rootNode) => {\n function visit(node: ts.Node): ts.Node {\n const visitResult = visitPropReferencingNode({\n propsParameter,\n node,\n createPropPlaceholder,\n useJsx: true,\n })\n\n if (visitResult) {\n return visitResult\n }\n\n // object assignment using destructured reference, e.g `prop={{ key: value }}`\n // (`{{ key: props.value }}` syntax will be captured by the `props.` notation branch above)\n if (\n ts.isObjectBindingPattern(propsParameter.name) &&\n ts.isPropertyAssignment(node) &&\n ts.isIdentifier(node.initializer) &&\n propsParameter.name.elements.find((el) =>\n node.initializer.getText().startsWith(el.name.getText()),\n )\n ) {\n return ts.factory.createPropertyAssignment(\n node.name,\n createPropPlaceholder({ name: node.initializer.getText(), node }),\n )\n }\n // object assignment using destructured reference as a shorthand, e.g `prop={{ value }}`\n if (\n ts.isObjectBindingPattern(propsParameter.name) &&\n ts.isShorthandPropertyAssignment(node) &&\n propsParameter.name.elements.find((el) =>\n node.name.getText().startsWith(el.name.getText()),\n )\n ) {\n return ts.factory.createPropertyAssignment(\n node.name,\n createPropPlaceholder({ name: node.name.getText(), node }),\n )\n }\n\n // Replaces {...props} with all the prop mapped props we know about,\n // e.g. <Button {...props} /> becomes:\n // <Button prop1={__PROP__(\"prop1\")} prop2={__PROP__(\"prop2\")} />.\n if (\n ts.isJsxSpreadAttribute(node) &&\n ts.isIdentifier(node.expression) &&\n // example: (props) => (...)\n (node.expression.getText() === propsParameter.name.getText() ||\n // example: ({ prop1, prop2 ...props }) => (...)\n (ts.isObjectBindingPattern(propsParameter.name) &&\n propsParameter.name.elements.find(\n (el) => el.dotDotDotToken && el.name.getText() === node.expression?.getText(),\n )))\n ) {\n // if we have an object binding pattern ({ prop1, prop2 ...props }),\n // exclude the props that are already destructured (prop1, prop2)\n const propsToExclude = ts.isObjectBindingPattern(propsParameter.name)\n ? propsParameter.name.elements\n .filter((el) => !el.dotDotDotToken)\n .map((el) => el.name.getText())\n : []\n const props = propMappings\n ? Object.keys(propMappings)\n .filter((prop) => !propsToExclude.includes(prop))\n .map((prop) => {\n return ts.factory.createJsxAttribute(\n ts.factory.createIdentifier(prop),\n createPropPlaceholder({\n name: prop,\n node,\n wrapInJsxExpression: true,\n }) as ts.JsxExpression,\n )\n })\n : []\n\n if (propMappings) {\n for (const key of Object.keys(propMappings)) {\n referencedProps.add(key)\n }\n }\n\n return props as any\n }\n\n return ts.visitEachChild(node, visit, context)\n }\n return ts.visitNode(rootNode, visit) as\n | ts.ArrowFunction\n | ts.FunctionExpression\n | ts.FunctionDeclaration\n },\n ]).transformed[0] as typeof exp\n }\n\n const printer = ts.createPrinter()\n const block = findBlock(exp)\n let nestable = false\n let jsx = findJSXElement(exp)\n\n if (jsx && (!block || (block && block.statements.length <= 1))) {\n // The function body is a single JSX element\n renderFunctionCode = printer.printNode(ts.EmitHint.Unspecified, jsx, sourceFile)\n nestable = true\n } else if (block) {\n // The function body has more stuff in it, so we wrap the body in a function\n // expression. Why not just print the exact function passed to `render`?\n // Because the parameters to that function are not actually referenced in\n // the rendered code snippet in Figma - they're mapped to values on the\n // Figma instance.\n const functionName = 'Example'\n const functionExpression = ts.factory.createFunctionExpression(\n undefined,\n undefined,\n ts.factory.createIdentifier(functionName),\n [],\n undefined,\n undefined,\n block,\n )\n const printer = ts.createPrinter()\n renderFunctionCode = printer.printNode(ts.EmitHint.Unspecified, functionExpression, sourceFile)\n } else {\n throw new ParserError(\n `Expected a single JSX element or a block statement in the render function, got ${exp.getText()}`,\n { sourceFile, node: exp },\n )\n }\n\n renderFunctionCode = replacePropPlaceholders(renderFunctionCode)\n\n // Escape backticks from the example code, as otherwise those would terminate the `figma.tsx` template literal\n renderFunctionCode = renderFunctionCode.replace(/`/g, '\\\\`')\n\n // Finally, output the render function as a figma.tsx call\n const figmaTsxCall = `figma.tsx\\`${renderFunctionCode}\\``\n\n // Find all JSX elements in the function body and extract their import\n // statements\n const jsxTags = findDescendants(\n exp,\n (element) => ts.isJsxElement(element) || ts.isJsxSelfClosingElement(element),\n ) as (ts.JsxElement | ts.JsxSelfClosingElement)[]\n const imports = getSourceFilesOfImportedIdentifiers(parserContext, jsxTags.map(getTagName))\n\n return {\n code: figmaTsxCall,\n imports,\n nestable,\n referencedProps,\n }\n}\n\n/**\n * Parses the render function passed to `figma.connect()`, extracting the code and\n * any import statements matching the JSX elements used in the function body\n *\n * @param exp A function or arrow function expression\n * @param parserContext Parser context\n * @param propMappings Prop mappings object as returned by parseProps\n *\n * @returns The code of the render function and a list of imports\n */\nexport function parseJSXRenderFunction(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n isForMigration?: boolean,\n) {\n const { sourceFile } = parserContext\n\n const { code, imports, nestable, referencedProps } = parseRenderFunctionExpression(\n exp,\n parserContext,\n propMappings,\n )\n\n let templateCode = ''\n\n // Generate the template code\n // Inject React-specific template helper functions\n if (!isForMigration) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n // Require the template API\n templateCode += `const figma = require('figma')\\n\\n`\n\n // Then we output `const propName = figma.properties.<kind>('propName')` calls\n // for each referenced prop, so these are accessible to the template code.\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n isForMigration,\n })\n\n const includeMetadata = propMappings && Object.keys(propMappings).length > 0\n\n // Finally, output the example code\n templateCode += includeMetadata\n ? `export default { ...${code}, metadata: { __props } }\\n`\n : `export default ${code}\\n`\n\n return {\n code: templateCode,\n imports,\n nestable,\n }\n}\n\n/**\n * Parses the render function for a value (i.e. example which returns a string or React\n * component reference, not JSX) passed to `figma.connect()`\n */\nexport function parseValueRenderFunction(\n exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration,\n parserContext: ParserContext,\n propMappings?: PropMappings,\n isForMigration?: boolean,\n) {\n const { sourceFile } = parserContext\n const printer = ts.createPrinter()\n if (!exp.body) {\n throw new ParserError('Expected a function body', {\n sourceFile: parserContext.sourceFile,\n node: exp,\n })\n }\n\n let exampleCode = printer.printNode(ts.EmitHint.Unspecified, exp.body, sourceFile)\n const nestable = true\n\n let templateCode = ''\n // Generate the template code\n // Inject React-specific template helper functions\n if (!isForMigration) {\n templateCode = getParsedTemplateHelpersString() + '\\n\\n'\n }\n\n // Require the template API\n templateCode += `const figma = require('figma')\\n\\n`\n\n // Then we output `const propName = figma.properties.<kind>('propName')` calls\n // for each referenced prop, so these are accessible to the template code.\n templateCode += getReferencedPropsForTemplate({\n propMappings,\n exp,\n sourceFile,\n isForMigration,\n })\n\n // Escape backticks from the example code\n exampleCode = exampleCode.replace(/`/g, '\\\\`')\n\n let imports: {\n statement: string\n file: string\n moduleSpecifier: string\n }[] = []\n\n const includeMetadata = propMappings && Object.keys(propMappings).length > 0\n\n if (ts.isStringLiteral(exp.body)) {\n // The value is a string, which is already wrapped in quotes\n templateCode += includeMetadata\n ? `export default { ...figma.value(${exampleCode}), metadata: { __props } }\\n`\n : `export default figma.value(${exampleCode})\\n`\n } else if (ts.isIdentifier(exp.body)) {\n // The value is an identifier, i.e. a React component reference\n const value = `_fcc_reactComponent(\"${exp.body.getText()}\")`\n const preview = `_fcc_renderPropValue(${value})`\n templateCode += includeMetadata\n ? `export default { ...figma.value(${value}, ${preview}), metadata: { __props } }\\n`\n : `export default figma.value(${value}, ${preview})\\n`\n imports = getSourceFilesOfImportedIdentifiers(parserContext, [exp.body.getText()])\n }\n\n return {\n code: templateCode,\n imports,\n nestable,\n }\n}\n\nexport function replacePropPlaceholders(exampleCode: string) {\n // Replace React prop placeholders we inserted above (like\n // `reactPropName={__PROP__(\"figmaPropName\")}`) with calls to\n // _fcc_renderReactProp, which renders them correctly (see\n // parser_template_helpers.ts)\n exampleCode = exampleCode.replace(\n // match \" reactPropName={__PROP__(\"figmaPropName\")}\" and extract the names\n // We allow hyphens in prop names (unlike React) to support rendering HTML attributes\n / ([A-Za-z0-9\\-]+)=\\{__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)\\}/g,\n (_match, reactPropName, figmaPropName) => {\n return `\\${_fcc_renderReactProp('${reactPropName}', ${figmaPropName})}`\n },\n )\n\n // Replace React children placeholders like `${__PROP__(\"propName\")}` with\n // calls to _fcc_renderReactChildren, which renders them correctly (see\n // parser_template_helpers.ts)\n exampleCode = exampleCode.replace(\n /\\{__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)\\}/g,\n (_match, figmaPropName) => {\n return `\\${_fcc_renderReactChildren(${figmaPropName})}`\n },\n )\n\n // Assume any remaining placeholders are values, e.g.\n // - { prop: __PROP__(\"propName\") }\n // - useState(__PROP__(\"propName\"))\n // These never need special treatment based on their type.\n return exampleCode.replace(/__PROP__\\(\"([A-Za-z0-9_\\.]+)\"\\)/g, (_match, figmaPropName) => {\n return `\\${_fcc_renderPropValue(${figmaPropName})}`\n })\n}\n\nfunction followIdentifierToStringLiteralDeclaration(\n node: ts.Identifier | ts.StringLiteral,\n parserContext: ParserContext,\n errMessage: string,\n) {\n const { checker } = parserContext\n let result = node\n\n if (node && ts.isIdentifier(node)) {\n const symbol = checker.getSymbolAtLocation(node)\n if (symbol) {\n const decl = symbol.valueDeclaration\n if (\n decl &&\n ts.isVariableDeclaration(decl) &&\n decl.initializer &&\n ts.isStringLiteral(decl.initializer)\n ) {\n result = decl.initializer\n }\n }\n }\n\n // If we followed the identifier to its declaration and it's not a string literal,\n // throw an error\n if (!result || !ts.isStringLiteral(result)) {\n throw new ParserError(errMessage, {\n node: result,\n sourceFile: parserContext.sourceFile,\n })\n }\n\n return result\n}\n\nfunction parseFigmaConnectArgs(node: ts.CallExpression, parserContext: ParserContext) {\n const required = true\n const first = parseFunctionArgument(\n node,\n parserContext,\n 0,\n isOneOf([ts.isIdentifier, ts.isPropertyAccessExpression, ts.isStringLiteral]),\n required,\n `\\`${FIGMA_CONNECT_CALL}\\` must be called with a reference to a Component or a Figma Component URL as the first argument. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1')\\``,\n )!\n\n let figmaNodeUrlArg: ts.StringLiteral\n let componentArg: ts.Identifier | ts.PropertyAccessExpression | undefined\n let configObjArgIndex\n\n // This function has two signatures. If the first arg is a string literal, it's the Figma node URL, and\n // it won't have a component reference.\n if (ts.isStringLiteral(first)) {\n figmaNodeUrlArg = first\n componentArg = undefined\n configObjArgIndex = 1\n } else {\n // If the first argument is not a string literal, it must be a component reference,\n // and the second argument must be the Figma node URL\n componentArg = first\n configObjArgIndex = 2\n\n const invalidTypeErrorMsg = `The second argument to ${FIGMA_CONNECT_CALL}() must be a string literal (the URL of the Figma node). Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1')\\``\n\n let arg = parseFunctionArgument(\n node,\n parserContext,\n 1,\n isOneOf([ts.isIdentifier, ts.isStringLiteral]),\n required,\n invalidTypeErrorMsg,\n )!\n\n figmaNodeUrlArg = followIdentifierToStringLiteralDeclaration(\n arg,\n parserContext,\n invalidTypeErrorMsg,\n )\n }\n\n const configObjArg = parseFunctionArgument(\n node,\n parserContext,\n configObjArgIndex,\n ts.isObjectLiteralExpression,\n false /* not required */,\n `The third argument to ${FIGMA_CONNECT_CALL}() must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', { render: () => <Button /> })\\``,\n )\n\n return {\n componentArg,\n figmaNodeUrlArg,\n configObjArg,\n }\n}\n\nfunction parseConfigObjectArg(\n configArg: ts.ObjectLiteralExpression | undefined,\n parserContext: ParserContext,\n) {\n if (!configArg) {\n return {\n propsArg: undefined,\n exampleArg: undefined,\n variantArg: undefined,\n importsArg: undefined,\n linksArg: undefined,\n }\n }\n\n const propsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'props',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'props' property must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n props: {\n disabled: figma.boolean('Disabled'),\n text: figma.string('TextContent'),\n }\n })\\``,\n })\n\n const exampleArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'example',\n predicate: isOneOf([ts.isArrowFunction, ts.isFunctionExpression]),\n parserContext,\n required: false,\n errorMessage: `The 'example' property must be an inline function or arrow function. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n example: () => <Button />\n })\\``,\n })\n\n const variantArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'variant',\n predicate: ts.isObjectLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'variant' property must be an object literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n variant: {\n \"Has Icon\": true\n }\n })\\``,\n })\n\n const linksArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'links',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'links' property must be an array literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n links: [\n { name: 'Storybook', url: 'https://storybook.com' }\n ]\n })\\``,\n })\n\n const importsArg = parsePropertyOfType({\n objectLiteralNode: configArg,\n propertyName: 'imports',\n predicate: ts.isArrayLiteralExpression,\n parserContext,\n required: false,\n errorMessage: `The 'imports' property must be an array literal. Example usage:\n \\`${FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {\n imports: ['import { Button } from \"./Button\"']\n })\\``,\n })\n\n return {\n propsArg,\n exampleArg,\n variantArg,\n linksArg,\n importsArg,\n }\n}\n\nexport function getDefaultTemplate(\n componentMetadata: Awaited<ReturnType<typeof parseComponentMetadata>>,\n) {\n const example = `<${componentMetadata.component} />`\n return `const figma = require(\"figma\")\\n\\nexport default figma.tsx\\`${example}\\``\n}\n\nexport async function parseReactDoc(\n node: ts.CallExpression,\n parserContext: ParserContext,\n { repoUrl, silent, isForMigration }: ParseOptions,\n): Promise<CodeConnectJSON> {\n const { checker, sourceFile, config } = parserContext\n\n // Parse the arguments to the `figma.connect()` call\n const { componentArg, figmaNodeUrlArg, configObjArg } = parseFigmaConnectArgs(node, parserContext)\n\n const { propsArg, exampleArg, variantArg, linksArg, importsArg } = parseConfigObjectArg(\n configObjArg,\n parserContext,\n )\n\n let figmaNode = stripQuotesFromNode(figmaNodeUrlArg)\n // TODO This logic is duplicated in connect.ts transformDocFromParser due to some type issues\n if (config.documentUrlSubstitutions) {\n figmaNode = applyDocumentUrlSubstitutions(figmaNode as string, config.documentUrlSubstitutions)\n }\n const metadata = componentArg\n ? await parseComponentMetadata(componentArg, parserContext, silent)\n : undefined\n\n const props = propsArg ? parsePropsObject(propsArg, parserContext) : undefined\n const render = exampleArg\n ? findJSXElement(exampleArg)\n ? parseJSXRenderFunction(exampleArg, parserContext, props, isForMigration)\n : parseValueRenderFunction(exampleArg, parserContext, props, isForMigration)\n : undefined\n const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined\n const links = linksArg ? parseLinks(linksArg, parserContext) : undefined\n\n let mappedImports: string[]\n if (importsArg) {\n mappedImports = parseImports(importsArg, parserContext)\n } else {\n // If no template function was provided, construct one and add the import\n // statement for the component\n let imports = render?.imports\n ? render.imports\n : metadata !== undefined\n ? getSourceFilesOfImportedIdentifiers(parserContext, [metadata.component])\n : []\n\n if (imports.length === 0 && metadata?.component) {\n // If no imports were found, it might mean that the component is not imported, or\n // that the `figma.connect` call is in the same file as the component. In the latter\n // case - we'll want to generate one\n const fileName = metadata.source.split('/').pop()?.split('.')[0]\n const relativeImportPath = `./${fileName}`\n imports = [\n {\n statement: `import { ${metadata.component} } from '${relativeImportPath}'`,\n file: sourceFile.fileName,\n moduleSpecifier: relativeImportPath,\n },\n ]\n }\n\n mappedImports = [\n ...new Set(\n imports.map((imp) => {\n if (config) {\n // First try to map the original import specifier directly (preserves user's intent)\n // e.g., '@/AlertTitle' -> '@acme/package/AlertTitle'\n if (typeof imp.moduleSpecifier === 'string') {\n const mappedFromSpecifier = mapImportSpecifier(imp.moduleSpecifier, config)\n if (mappedFromSpecifier) {\n return imp.statement.replace(\n /['\"]([@\\.\\/a-zA-Z0-9_-]*)['\"]/,\n `'${mappedFromSpecifier}'`,\n )\n }\n }\n // Fall back to mapping based on resolved file path (for relative imports)\n const mappedPath = mapImportPath(imp.file, config)\n if (mappedPath) {\n return imp.statement.replace(/['\"]([@\\.\\/a-zA-Z0-9_-]*)['\"]/, `'${mappedPath}'`)\n }\n }\n return imp.statement\n }),\n ),\n ]\n }\n\n if (mappedImports.length === 0 && metadata?.component) {\n logger.warn(\n `The import statement for ${metadata.component} could not be automatically resolved, make sure the component is imported (if not colocating) and that the path mappings are correct in your figma.config.json`,\n )\n }\n\n let template\n if (render?.code) {\n template = render.code\n } else if (metadata) {\n template = getDefaultTemplate(metadata)\n } else {\n throw new ParserError(\n `${FIGMA_CONNECT_CALL}() requires either a component argument or an example function`,\n { sourceFile, node },\n )\n }\n\n return {\n figmaNode,\n label: DEFAULT_LABEL_PER_PARSER.react!,\n language: SyntaxHighlightLanguage.TypeScript,\n component: metadata?.component,\n source: metadata?.source\n ? getRemoteFileUrl(metadata.source, repoUrl, parserContext.config?.defaultBranch)\n : '',\n sourceLocation: metadata?.line !== undefined ? { line: metadata.line } : { line: -1 },\n variant,\n template,\n templateData: {\n // TODO: `props` here is currently only used for validation purposes,\n // we should eventually remove it from the JSON payload\n props,\n imports: mappedImports,\n // If there's no render function, the default example is always nestable\n nestable: render ? render.nestable : true,\n },\n links,\n metadata: {\n cliVersion: require('../../package.json').version,\n },\n }\n}\n"]}
@@ -10,6 +10,12 @@ interface ConvertStorybookFilesArgs {
10
10
  * Information about the project
11
11
  */
12
12
  projectInfo: ReactProjectInfo;
13
+ /**
14
+ * Whether this conversion is for the migrate command. When true, template
15
+ * helper function definitions are omitted from the template (they will be
16
+ * replaced by server-side helpers during migration).
17
+ */
18
+ isForMigration?: boolean;
13
19
  }
14
20
  /**
15
21
  * Converts all Storyboook files in a directory into Code Connect objects. If a file
@@ -19,6 +25,6 @@ interface ConvertStorybookFilesArgs {
19
25
  * @param args
20
26
  * @returns An array of Code Connect objects
21
27
  */
22
- export declare function convertStorybookFiles({ projectInfo, storiesGlob, }: ConvertStorybookFilesArgs): Promise<CodeConnectJSON[]>;
28
+ export declare function convertStorybookFiles({ projectInfo, storiesGlob, isForMigration, }: ConvertStorybookFilesArgs): Promise<CodeConnectJSON[]>;
23
29
  export {};
24
30
  //# sourceMappingURL=convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/storybook/convert.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,gBAAgB,EAGjB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAc1D,UAAU,yBAAyB;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,WAAW,EAAE,gBAAgB,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,WAAW,EACX,WAAgC,GACjC,EAAE,yBAAyB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAaxD"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/storybook/convert.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,gBAAgB,EAGjB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAc1D,UAAU,yBAAyB;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,WAAW,EAAE,gBAAgB,CAAA;IAE7B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,WAAW,EACX,WAAgC,EAChC,cAAsB,GACvB,EAAE,yBAAyB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAoBxD"}