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nimport { ParserContext, ParserError } from '../connect/parser_common'\n\n/**\n * Get the default export from a TypeScript source file\n *\n * @param sourceFile TypeScript source file\n * @returns The default export Expression, or undefined if there is no default export\n */\nexport function getDefaultExport(sourceFile: ts.SourceFile): ts.Expression | undefined {\n for (const statement of sourceFile.statements) {\n if (ts.isExportAssignment(statement) && ts.isIdentifier(statement.expression)) {\n // The default export is a reference to another variable\n const identifierName = statement.expression.text\n // Find the variable declaration that matches the identifier\n for (const stmt of sourceFile.statements) {\n if (ts.isVariableStatement(stmt)) {\n for (const declaration of stmt.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name) && declaration.name.text === identifierName) {\n // Return the initializer of the variable declaration\n return declaration.initializer\n }\n }\n }\n }\n } else if (ts.isExportAssignment(statement)) {\n // The default export is not a reference to another variable\n return statement.expression\n }\n }\n}\n/**\n * Perform a breadth-first search to find the first node matching a predicate\n *\n * @param node Node to start the search from\n * @param tsSourceFile SourceFile associated with the node\n * @param predicate Predicate to match\n * @returns The first node matching the predicate, or undefined if no node is found\n */\nexport function bfsFindNode(\n node: ts.Node,\n tsSourceFile: ts.SourceFile,\n predicate: (node: ts.Node) => boolean,\n): ts.Node | undefined {\n const queue = [node]\n while (queue.length > 0) {\n node = queue.shift()!\n if (predicate(node)) {\n return node\n }\n\n if (node && node.getChildCount(tsSourceFile) > 0) {\n queue.push(...node.getChildren(tsSourceFile))\n }\n }\n}\n\n/**\n * Gets a property with the specified name and type (via predicate) from an object literal node\n *\n * @param objectLiteralNode The object literal node potentially containing the property\n * @param propertyName The name of the property to get\n * @param predicate Optional predicate to match\n * @param required Whether the property is required. Defaults to false.\n * If true, an error will be thrown if the property is not found\n * @param errorMessage Optional error message to throw if the property is not found\n * @returns The property, or undefined if the property is not found\n */\nexport function parsePropertyOfType(params: {\n objectLiteralNode: ts.ObjectLiteralExpression\n propertyName: string\n predicate: (node: ts.Node) => node is T\n parserContext: ParserContext\n required?: true\n errorMessage?: string\n}): T\n\nexport function parsePropertyOfType(params: {\n objectLiteralNode: ts.ObjectLiteralExpression\n propertyName: string\n predicate: (node: ts.Node) => node is T\n parserContext: ParserContext\n required?: false\n errorMessage?: string\n}): T | undefined\n\nexport function parsePropertyOfType(params: {\n objectLiteralNode: ts.ObjectLiteralExpression\n propertyName: string\n predicate: (node: ts.Node) => node is T\n parserContext: ParserContext\n required?: boolean\n errorMessage?: string\n}): T | undefined\n\nexport function parsePropertyOfType({\n objectLiteralNode,\n propertyName,\n predicate,\n parserContext,\n required = false,\n errorMessage,\n}: {\n objectLiteralNode: ts.ObjectLiteralExpression\n propertyName: string\n predicate: (node: ts.Node) => node is T\n parserContext: ParserContext\n required?: boolean\n errorMessage?: string\n}): T | undefined {\n const { sourceFile, checker } = parserContext\n const node = objectLiteralNode.properties.find(\n (property) => property.name?.getText() === propertyName,\n )\n\n if (!node) {\n if (!required) {\n return undefined\n } else {\n throw new ParserError(errorMessage ?? `Expected property '${propertyName}' to be present`, {\n sourceFile,\n node: objectLiteralNode,\n })\n }\n }\n\n let initializer: ts.Expression | undefined\n\n if (ts.isPropertyAssignment(node)) {\n if (ts.isIdentifier(node.initializer)) {\n const symbol = checker.getSymbolAtLocation(node.initializer)\n if (symbol) {\n const decl = symbol.valueDeclaration\n if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {\n initializer = decl.initializer\n }\n }\n } else {\n initializer = node.initializer\n }\n }\n\n if (ts.isShorthandPropertyAssignment(node)) {\n const symbol = checker.getShorthandAssignmentValueSymbol(node)\n if (!symbol || !symbol.valueDeclaration || !ts.isVariableDeclaration(symbol.valueDeclaration)) {\n throw new ParserError('Expected shorthand property to be declared in the same file', {\n sourceFile,\n node,\n })\n }\n initializer = symbol.valueDeclaration.initializer\n }\n\n if (!initializer) {\n throw new ParserError(`Expected property ${propertyName} to be a property assignment`, {\n sourceFile,\n node,\n })\n }\n\n // Unwrap `as Type` or `satisfies Type` expressions\n if (ts.isAsExpression(initializer) || ts.isSatisfiesExpression(initializer)) {\n initializer = initializer.expression\n }\n\n if (!predicate(initializer)) {\n throw new ParserError(\n errorMessage ??\n `Unexpected shape of property ${propertyName}, got node type: ${ts.SyntaxKind[initializer.kind]}`,\n {\n sourceFile,\n node: initializer,\n },\n )\n }\n\n return initializer\n}\n\ntype TypeGuard = (a: A) => a is B\ntype GuardType = T extends (o: any) => o is infer U ? U : never\n\n/**\n * Combines several type guards into one.\n *\n * The returned function checks if any of the type guards in the list matches the argument,\n * and infers the type based on the matching type guard.\n *\n * @param guards A list of type guards\n */\nexport function isOneOf>(\n guards: T[],\n): [T] extends [TypeGuard] ? (a: A) => a is GuardType : never\nexport function isOneOf>(guards: T[]) {\n return function (arg: T) {\n return guards.some(function (predicate) {\n return predicate(arg)\n })\n }\n}\n\n/**\n * Gets a function argument with the specified index from a call expression node\n *\n * @param fn The call expression node potentially containing the argument\n * @param parserContext The parser context\n * @param index The index of the argument to get\n * @param predicate Predicate to match\n * @param required Whether the argument is required. Defaults to false.\n * @param errorMessage Optional error message to throw if the argument is not found\n * @returns\n */\nexport function parseFunctionArgument(\n fn: ts.CallExpression,\n parserContext: ParserContext,\n index: number,\n predicate: (node: ts.Node) => node is T,\n required = false,\n errorMessage?: string,\n): T | undefined {\n const { sourceFile } = parserContext\n\n if (fn.arguments.length <= index && !required) {\n return undefined\n }\n\n if (fn.arguments.length <= index) {\n throw new ParserError(\n errorMessage ?? `Expected function to have at least ${index + 1} arguments`,\n {\n sourceFile,\n node: fn,\n },\n )\n }\n\n const arg = fn.arguments[index]\n if (!arg || !predicate(arg)) {\n throw new ParserError(errorMessage ?? `Unexpected shape of argument ${index}`, {\n sourceFile,\n node: fn.arguments[index],\n })\n }\n\n return arg\n}\n\nexport function assertIsPropertyAssignment(\n node: ts.Node,\n sourceFile: ts.SourceFile,\n): asserts node is ts.PropertyAssignment {\n if (!ts.isPropertyAssignment(node)) {\n throw new ParserError(`Expected a property assignment, got ${ts.SyntaxKind[node.kind]}`, {\n node,\n sourceFile,\n })\n }\n}\n\nexport function assertIsStringLiteral(\n node: ts.Node,\n sourceFile: ts.SourceFile,\n msg?: string,\n): asserts node is ts.StringLiteral {\n if (!ts.isStringLiteral(node)) {\n throw new ParserError(msg ?? `Expected a string literal, got ${ts.SyntaxKind[node.kind]}`, {\n node,\n sourceFile,\n })\n }\n}\n\nexport function assertIsArrayLiteralExpression(\n node: ts.Node,\n sourceFile: ts.SourceFile,\n msg?: string,\n): asserts node is ts.ArrayLiteralExpression {\n if (!ts.isArrayLiteralExpression(node)) {\n throw new ParserError(msg ?? `Expected an array literal, got ${ts.SyntaxKind[node.kind]}`, {\n node,\n sourceFile,\n })\n }\n}\n\nexport function assertIsObjectLiteralExpression(\n node: ts.Node,\n sourceFile: ts.SourceFile,\n msg?: string,\n): asserts node is ts.ObjectLiteralExpression {\n if (!ts.isObjectLiteralExpression(node)) {\n throw new ParserError(msg ?? `Expected an object literal, got ${ts.SyntaxKind[node.kind]}`, {\n node,\n sourceFile,\n })\n }\n}\n\nexport function assertIsIdentifier(\n node: ts.Node,\n sourceFile: ts.SourceFile,\n msg?: string,\n): asserts node is ts.Identifier {\n if (!ts.isIdentifier(node)) {\n throw new ParserError(msg ?? `Expected an identifier, got ${ts.SyntaxKind[node.kind]}`, {\n node,\n sourceFile,\n })\n }\n}\n\nfunction convertValueNodeToJs(\n valueNode: ts.Expression,\n sourceFile: ts.SourceFile,\n checker: ts.TypeChecker,\n extraConversionFn?: (node: ts.Expression) => any,\n): any {\n if (ts.isObjectLiteralExpression(valueNode)) {\n // A prop mapping to an object literal, which maps each figma value to a code value\n return convertObjectLiteralToJs(valueNode, sourceFile, checker, extraConversionFn)\n } else {\n // A prop mapping to anything else, which will be passed as a literal value\n if (ts.isStringLiteral(valueNode)) {\n // Accessing `text` directly prevents the value being wrapped in quotes\n return valueNode.text\n } else if (valueNode.kind === ts.SyntaxKind.TrueKeyword) {\n return true\n } else if (valueNode.kind === ts.SyntaxKind.FalseKeyword) {\n return false\n // undefined is not a keyword in TypeScript, but actually translates to an identifier\n // (even though confusingly ts.SyntaxKind.UndefinedKeyword exists)\n } else if (ts.isIdentifier(valueNode) && valueNode.text === 'undefined') {\n return undefined\n } else if (valueNode.kind === ts.SyntaxKind.NullKeyword) {\n return null\n } else if (valueNode.kind === ts.SyntaxKind.NumericLiteral) {\n return parseFloat(valueNode.getText())\n } else if (isTaggedTemplateExpression(valueNode)) {\n // Return the content of the template string without the backticks\n return valueNode.template.getText().replace(/^`/, '').replace(/`$/, '')\n } else {\n return valueNode.getText()\n }\n }\n}\n\n/**\n * Convert an object literal node to a JavaScript object\n *\n * @param objectLiteral The object literal node to convert\n * @param sourceFile The source file containing the object literal\n * @param extraConversionFn Optional function to convert a node to a value. This\n * runs before the default conversion. If this returns undefined, the default\n * conversion will be used. (This does mean there's no way to return undefined)\n * @returns The JavaScript object version of the object literal\n */\nexport function convertObjectLiteralToJs(\n objectLiteral: ts.ObjectLiteralExpression,\n sourceFile: ts.SourceFile,\n checker: ts.TypeChecker,\n extraConversionFn?: (node: ts.Expression) => any,\n) {\n const obj = {} as Record\n const properties = [...objectLiteral.properties]\n\n while (properties.length > 0) {\n const prop = properties.shift()!\n\n // If the value is a spread assignment, we need to resolve the object it's spreading\n // and add its properties to the current object\n if (ts.isSpreadAssignment(prop)) {\n const declaration = bfsFindNode(sourceFile, sourceFile, (node) => {\n return ts.isVariableDeclaration(node) && node.name.getText() === prop.expression.getText()\n }) as ts.VariableDeclaration\n if (!declaration.initializer || !ts.isObjectLiteralExpression(declaration.initializer)) {\n throw new ParserError('Expected spread object to be an object literal', {\n sourceFile,\n node: prop,\n })\n }\n\n for (const prop of declaration.initializer.properties) {\n properties.push(prop)\n }\n continue\n }\n\n assertIsPropertyAssignment(prop, sourceFile)\n if (!ts.isIdentifier(prop.name) && !ts.isStringLiteral(prop.name)) {\n throw new ParserError('Expected property key to be an identifier or String Literal', {\n sourceFile,\n node: prop,\n })\n }\n const key = prop.name.text\n const valueNode = prop.initializer\n\n const extraConversionResult = extraConversionFn && extraConversionFn(valueNode)\n\n if (extraConversionResult !== undefined) {\n obj[key] = extraConversionResult\n } else {\n obj[key] = convertValueNodeToJs(valueNode, sourceFile, checker, extraConversionFn)\n }\n }\n\n return obj\n}\n\n/**\n * Convert an Array literal node to a JavaScript array\n *\n * @param arrayLiteral The array literal node to convert\n * @param sourceFile The source file containing the array literal\n * @param extraConversionFn Optional function to convert a node to a value. This\n * runs before the default conversion. If this returns undefined, the default\n * conversion will be used. (This does mean there's no way to return undefined)\n * @returns The JavaScript object version of the object literal\n */\nexport function convertArrayLiteralToJs(\n arrayLiteral: ts.ArrayLiteralExpression,\n sourceFile: ts.SourceFile,\n checker: ts.TypeChecker,\n extraConversionFn?: (node: ts.Expression) => any,\n) {\n return arrayLiteral.elements.map((element) => {\n const extraConversionResult = extraConversionFn && extraConversionFn(element)\n if (extraConversionResult !== undefined) {\n return extraConversionResult\n } else {\n return convertValueNodeToJs(element, sourceFile, checker, extraConversionFn)\n }\n })\n}\n\nexport function getTagName(element: ts.JsxElement | ts.JsxSelfClosingElement) {\n if (ts.isJsxSelfClosingElement(element)) {\n return element.tagName.getText()\n } else {\n return element.openingElement.tagName.getText()\n }\n}\n\nexport function stripQuotesFromNode(node: ts.StringLiteral) {\n return stripQuotes(node.text)\n}\n\nfunction stripQuotes(text: string) {\n if (text.startsWith('\"') || text.startsWith(\"'\")) {\n return text.substring(1, text.length - 1)\n }\n return text\n}\n\nexport function isUndefinedType(node: ts.Node, checker: ts.TypeChecker): boolean {\n const type = checker.getTypeAtLocation(node)\n return (type.getFlags() & ts.TypeFlags.Undefined) !== 0\n}\n"]}