@figma/code-connect 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connect/api.d.ts +38 -6
- package/dist/connect/api.d.ts.map +1 -1
- package/dist/connect/external_types.d.ts +2 -1
- package/dist/connect/external_types.d.ts.map +1 -1
- package/dist/connect/external_types.js +5 -1
- package/dist/connect/external_types.js.map +1 -1
- package/dist/connect/intrinsics.d.ts +4 -1
- package/dist/connect/intrinsics.d.ts.map +1 -1
- package/dist/connect/intrinsics.js +76 -36
- package/dist/connect/intrinsics.js.map +1 -1
- package/dist/connect/modifiers.d.ts +29 -0
- package/dist/connect/modifiers.d.ts.map +1 -0
- package/dist/connect/modifiers.js +109 -0
- package/dist/connect/modifiers.js.map +1 -0
- package/dist/connect/parser_common.d.ts +3 -3
- package/dist/connect/parser_common.d.ts.map +1 -1
- package/dist/connect/parser_common.js +18 -18
- package/dist/connect/parser_common.js.map +1 -1
- package/dist/connect/wizard/embeddings.d.ts +13 -0
- package/dist/connect/wizard/embeddings.d.ts.map +1 -0
- package/dist/connect/wizard/embeddings.js +22 -0
- package/dist/connect/wizard/embeddings.js.map +1 -0
- package/dist/connect/wizard/helpers.d.ts +2 -0
- package/dist/connect/wizard/helpers.d.ts.map +1 -1
- package/dist/connect/wizard/helpers.js +16 -1
- package/dist/connect/wizard/helpers.js.map +1 -1
- package/dist/connect/wizard/prop_mapping.d.ts +7 -17
- package/dist/connect/wizard/prop_mapping.d.ts.map +1 -1
- package/dist/connect/wizard/prop_mapping.js +103 -97
- package/dist/connect/wizard/prop_mapping.js.map +1 -1
- package/dist/connect/wizard/prop_mapping_helpers.d.ts +71 -0
- package/dist/connect/wizard/prop_mapping_helpers.d.ts.map +1 -0
- package/dist/connect/wizard/prop_mapping_helpers.js +176 -0
- package/dist/connect/wizard/prop_mapping_helpers.js.map +1 -0
- package/dist/connect/wizard/run_wizard.d.ts.map +1 -1
- package/dist/connect/wizard/run_wizard.js +48 -23
- package/dist/connect/wizard/run_wizard.js.map +1 -1
- package/dist/connect/wizard/signature_extraction.d.ts +2 -4
- package/dist/connect/wizard/signature_extraction.d.ts.map +1 -1
- package/dist/connect/wizard/signature_extraction.js +119 -33
- package/dist/connect/wizard/signature_extraction.js.map +1 -1
- package/dist/html/external.d.ts +1 -1
- package/dist/html/external.d.ts.map +1 -1
- package/dist/html/external.js +6 -5
- package/dist/html/external.js.map +1 -1
- package/dist/html/index_html.d.ts +1 -1
- package/dist/html/index_html.d.ts.map +1 -1
- package/dist/html/parser.d.ts.map +1 -1
- package/dist/html/parser.js +16 -12
- package/dist/html/parser.js.map +1 -1
- package/dist/html/parser_template_helpers.d.ts +8 -0
- package/dist/html/parser_template_helpers.d.ts.map +1 -1
- package/dist/html/parser_template_helpers.js +19 -3
- package/dist/html/parser_template_helpers.js.map +1 -1
- package/dist/html/types.d.ts +1 -1
- package/dist/html/types.d.ts.map +1 -1
- package/dist/react/create.d.ts.map +1 -1
- package/dist/react/create.js +31 -19
- package/dist/react/create.js.map +1 -1
- package/dist/react/external.d.ts +1 -2
- package/dist/react/external.d.ts.map +1 -1
- package/dist/react/external.js +1 -4
- package/dist/react/external.js.map +1 -1
- package/dist/react/index_react.d.ts +25 -2
- package/dist/react/index_react.d.ts.map +1 -1
- package/dist/react/index_react.js.map +1 -1
- package/dist/react/parser.d.ts +37 -14
- package/dist/react/parser.d.ts.map +1 -1
- package/dist/react/parser.js +102 -194
- package/dist/react/parser.js.map +1 -1
- package/dist/react/parser_template_helpers.d.ts +5 -1
- package/dist/react/parser_template_helpers.d.ts.map +1 -1
- package/dist/react/parser_template_helpers.js +20 -3
- package/dist/react/parser_template_helpers.js.map +1 -1
- package/dist/react/types.d.ts +6 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/storybook/convert.js +1 -1
- package/dist/storybook/convert.js.map +1 -1
- package/dist/storybook/external.d.ts +2 -2
- package/dist/storybook/external.d.ts.map +1 -1
- package/package.json +9 -8
package/dist/react/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/react/create.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAkC;AAClC,mDAAoC;AACpC,4CAAmB;AAQnB,gDAAuB;AACvB,8CAA0D;AAC1D,sDAAkF;AAClF,4DAAyD;AAGzD,SAAgB,aAAa,CAAC,SAAiB;IAC7C,MAAM,UAAU,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;IAC1C,OAAO,CACL,UAAU,KAAK,MAAM;QACrB,UAAU,KAAK,OAAO;QACtB,UAAU,KAAK,KAAK;QACpB,UAAU,KAAK,IAAI;QACnB,UAAU,KAAK,IAAI;QACnB,UAAU,KAAK,KAAK,CACrB,CAAA;AACH,CAAC;AAVD,sCAUC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AACtC,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACxC,MAAM,WAAW,GAAG,IAAI;QACtB,iDAAiD;SAChD,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;QAC1B,gCAAgC;SAC/B,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAA;IAEjC,OAAO,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAA;AAC/B,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY;IACtC,mCAAmC;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;AACzD,CAAC;AAED,SAAS,kCAAkC,CAAC,gBAAkC;IAC5E,IAAI,gBAAgB,IAAI,OAAO,gBAAgB,KAAK,QAAQ,IAAI,MAAM,IAAI,gBAAgB,EAAE,CAAC;QAC3F,OAAO,+BAA+B,CAAC,gBAAgB,CAAC,CAAA;IAC1D,CAAC;IACD,IAA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AAG;;;;2CAI6B,CAAA;IACzC,CAAC;IAED,MAAM,WAAW,GAAG;;SAEb,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,IAAI,UAAU,WAAW;;;;uDAIpC,OAAO;;;gBAG9C,UAAU,MAAM,YAAY;WACjC,WAAW,CAAC,CAAC,CAAC,wBAAwB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC;wBAC5E,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,kBAAkB,EAAE,WAAW,CAAC;;CAE3F,CAAA;IACC,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE;QAC3C,MAAM,EAAE,YAAY;QACpB,IAAI,EAAE,KAAK;QACX,aAAa,EAAE,KAAK;KACrB,CAAC,CAAA;IAEF,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO;YACL,YAAY,EAAE,EAAE;YAChB,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,QAAQ,oCAAoC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9F,CAAA;IACH,CAAC;IACD,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzD,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAErC,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAA;AACvD,CAAC;AApFD,wDAoFC"}
|
package/dist/react/external.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { booleanType, enumType, stringType, nestedPropsType, classNameType, textContentType } from '../connect/external_types';
|
|
2
|
+
import { booleanType, enumType, stringType, nestedPropsType, classNameType, textContentType, instanceType } from '../connect/external_types';
|
|
3
3
|
import { ReactMeta } from './types';
|
|
4
4
|
declare function connectType<P = {}>(_figmaNodeUrl: string, _meta?: ReactMeta<P>): void;
|
|
5
5
|
declare function connectType<P = {}>(_component: any, _figmaNodeUrl: string, _meta?: ReactMeta<P>): void;
|
|
6
|
-
declare function instanceType(_figmaPropName: string): React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
7
6
|
declare function childrenType(_layers: string | string[]): React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
8
7
|
export { booleanType as boolean, enumType as enum, stringType as string, nestedPropsType as nestedProps, classNameType as className, textContentType as textContent, connectType as connect, instanceType as instance, childrenType as children, };
|
|
9
8
|
//# sourceMappingURL=external.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/react/external.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/react/external.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,EACf,YAAY,EACb,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,iBAAS,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;AAC/E,iBAAS,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;AAGhG,iBAAS,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,kFAE/C;AAED,OAAO,EACL,WAAW,IAAI,OAAO,EACtB,QAAQ,IAAI,IAAI,EAChB,UAAU,IAAI,MAAM,EACpB,eAAe,IAAI,WAAW,EAC9B,aAAa,IAAI,SAAS,EAC1B,eAAe,IAAI,WAAW,EAC9B,WAAW,IAAI,OAAO,EACtB,YAAY,IAAI,QAAQ,EACxB,YAAY,IAAI,QAAQ,GACzB,CAAA"}
|
package/dist/react/external.js
CHANGED
|
@@ -32,12 +32,9 @@ Object.defineProperty(exports, "string", { enumerable: true, get: function () {
|
|
|
32
32
|
Object.defineProperty(exports, "nestedProps", { enumerable: true, get: function () { return external_types_1.nestedPropsType; } });
|
|
33
33
|
Object.defineProperty(exports, "className", { enumerable: true, get: function () { return external_types_1.classNameType; } });
|
|
34
34
|
Object.defineProperty(exports, "textContent", { enumerable: true, get: function () { return external_types_1.textContentType; } });
|
|
35
|
+
Object.defineProperty(exports, "instance", { enumerable: true, get: function () { return external_types_1.instanceType; } });
|
|
35
36
|
function connectType(_component, _figmaNodeUrl, _meta) { }
|
|
36
37
|
exports.connect = connectType;
|
|
37
|
-
function instanceType(_figmaPropName) {
|
|
38
|
-
return React.createElement('div');
|
|
39
|
-
}
|
|
40
|
-
exports.instance = instanceType;
|
|
41
38
|
function childrenType(_layers) {
|
|
42
39
|
return React.createElement('div');
|
|
43
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/react/external.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/react/external.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8B;AAC9B,8DAQkC;AAYjB,wFAnBf,4BAAW,OAmBW;AACV,qFAnBZ,yBAAQ,OAmBQ;AACF,uFAnBd,2BAAU,OAmBU;AACD,4FAnBnB,gCAAe,OAmBe;AACb,0FAnBjB,8BAAa,OAmBa;AACP,4FAnBnB,gCAAe,OAmBe;AAEd,yFApBhB,6BAAY,OAoBY;AAd1B,SAAS,WAAW,CAAC,UAAmB,EAAE,aAAsB,EAAE,KAAe,IAAS,CAAC;AAa1E,8BAAO;AAXxB,SAAS,YAAY,CAAC,OAA0B;IAC9C,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AACnC,CAAC;AAWiB,gCAAQ"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { EnumValue, FigmaConnectAPI, ValueOf } from '../connect/api';
|
|
2
|
+
import { EnumValue, FigmaConnectAPI, ValueOf, ConnectedComponent } from '../connect/api';
|
|
3
3
|
import * as StorybookTypes from '../storybook/external';
|
|
4
4
|
import { FigmaConnectClient } from '../client/figma_client';
|
|
5
5
|
import { ReactMeta } from './types';
|
|
6
6
|
declare const _client: FigmaConnectClient;
|
|
7
|
-
declare const _figma: FigmaConnectAPI<JSX.Element> & {
|
|
7
|
+
declare const _figma: FigmaConnectAPI<ConnectedComponent, JSX.Element> & {
|
|
8
8
|
/**
|
|
9
9
|
* Defines a code snippet that displays in Figma when a component is selected. This function has two signatures:
|
|
10
10
|
* - When called with a component reference as the first argument, it will infer metadata such as the import statement
|
|
@@ -82,6 +82,29 @@ declare const _figma: FigmaConnectAPI<JSX.Element> & {
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
nestedProps<V>(layer: string, input: V): V;
|
|
85
|
+
/**
|
|
86
|
+
* Maps a Figma instance-swap property for the connected component. This prop is replaced with
|
|
87
|
+
* a nested connected component matching the Figma instance when viewed in Dev Mode. For example:
|
|
88
|
+
* ```ts
|
|
89
|
+
* props: {
|
|
90
|
+
* icon: figma.instance('Icon'),
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
* Would show the nested example for the component passed to the "Icon" property in Figma.
|
|
94
|
+
*
|
|
95
|
+
* If the nested connected component returns something other than JSX in its `example` function,
|
|
96
|
+
* you can pass a type parameter to `instance` to specify the return type. For example:
|
|
97
|
+
* ```ts
|
|
98
|
+
* props: {
|
|
99
|
+
* icon: figma.instance<string>('Icon')
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
104
|
+
* @returns {ConnectedComponent} The connected component for the instance. The return value
|
|
105
|
+
* can be modified with helper functions such as `getProps` and `render`
|
|
106
|
+
*/
|
|
107
|
+
instance<T = ConnectedComponent>(figmaPropName: string): T;
|
|
85
108
|
};
|
|
86
109
|
export { _figma as figma, _client as client };
|
|
87
110
|
export default _figma;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index_react.d.ts","sourceRoot":"","sources":["../../src/react/index_react.ts"],"names":[],"mappings":";AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"index_react.d.ts","sourceRoot":"","sources":["../../src/react/index_react.ts"],"names":[],"mappings":";AAMA,OAAO,EACL,SAAS,EACT,eAAe,EAEf,OAAO,EACP,kBAAkB,EACnB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,QAAA,MAAM,OAAO,EAAE,kBAAgC,CAAA;AAC/C,QAAA,MAAM,MAAM,EAAE,eAAe,CAAC,kBAAkB,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG;IAC/D;;;;;;;;;;OAUG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,GAAG,E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uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index_react.js","sourceRoot":"","sources":["../../src/react/index_react.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,uEAAuE;AACvE,yEAAyE;AACzE,qEAAqE;AACrE,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;AASvC,kDAAmC;AAGnC,0DAAmD;AAGnD,MAAM,OAAO,GAAuB,IAAA,wBAAS,GAAE,CAAA;AAgHV,yBAAM;AA/G3C,MAAM,MAAM,GA6GR,KAAK,CAAA;AAEU,uBAAK;AACxB,kBAAe,MAAM,CAAA"}
|
package/dist/react/parser.d.ts
CHANGED
|
@@ -2,22 +2,14 @@ import ts from 'typescript';
|
|
|
2
2
|
import { PropMappings } from '../connect/intrinsics';
|
|
3
3
|
import { CodeConnectJSON } from '../connect/figma_connect';
|
|
4
4
|
import { ParserContext, ParseOptions } from '../connect/parser_common';
|
|
5
|
-
export declare function findAndResolveImports(program: ts.Program, sourceFile: ts.SourceFile): Record<string, string>;
|
|
6
|
-
export type ComponentTypeSignature = Record<string, string>;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* if it's optional. Example:
|
|
11
|
-
* {
|
|
12
|
-
* name: string
|
|
13
|
-
* disabled: ?boolean
|
|
14
|
-
* }
|
|
15
|
-
* @param symbol the symbol of the function declaration of the component (in the source file)
|
|
16
|
-
* @param sourceFile the source file with the component definition
|
|
17
|
-
* @param checker
|
|
6
|
+
* Traverses the AST and returns the first JSX element it finds
|
|
7
|
+
* @param node AST node
|
|
18
8
|
* @returns
|
|
19
9
|
*/
|
|
20
|
-
export declare function
|
|
10
|
+
export declare function findJSXElement(node: ts.Node): ts.JsxElement | ts.JsxSelfClosingElement | ts.JsxFragment | undefined;
|
|
11
|
+
export declare function findAndResolveImports(program: ts.Program, sourceFile: ts.SourceFile): Record<string, string>;
|
|
12
|
+
export type ComponentTypeSignature = Record<string, string>;
|
|
21
13
|
/**
|
|
22
14
|
* Extract metadata about the referenced React component. Used by both the
|
|
23
15
|
* Code Connect and Storybook commands.
|
|
@@ -33,6 +25,25 @@ export declare function parseComponentMetadata(node: ts.PropertyAccessExpression
|
|
|
33
25
|
line: number;
|
|
34
26
|
component: string;
|
|
35
27
|
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a render function and ouputs a template string, extracting the code and
|
|
30
|
+
* any import statements matching the JSX elements used in the function body
|
|
31
|
+
*
|
|
32
|
+
* @param exp A function or arrow function expression
|
|
33
|
+
* @param parserContext Parser context
|
|
34
|
+
* @param propMappings Prop mappings object as returned by parseProps
|
|
35
|
+
*
|
|
36
|
+
* @returns The code of the render function and a list of imports
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseRenderFunctionExpression(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings): {
|
|
39
|
+
code: string;
|
|
40
|
+
imports: {
|
|
41
|
+
statement: string;
|
|
42
|
+
file: string;
|
|
43
|
+
}[];
|
|
44
|
+
nestable: boolean;
|
|
45
|
+
referencedProps: Set<string>;
|
|
46
|
+
};
|
|
36
47
|
/**
|
|
37
48
|
* Parses the render function passed to `figma.connect()`, extracting the code and
|
|
38
49
|
* any import statements matching the JSX elements used in the function body
|
|
@@ -43,7 +54,19 @@ export declare function parseComponentMetadata(node: ts.PropertyAccessExpression
|
|
|
43
54
|
*
|
|
44
55
|
* @returns The code of the render function and a list of imports
|
|
45
56
|
*/
|
|
46
|
-
export declare function
|
|
57
|
+
export declare function parseJSXRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings): {
|
|
58
|
+
code: string;
|
|
59
|
+
imports: {
|
|
60
|
+
statement: string;
|
|
61
|
+
file: string;
|
|
62
|
+
}[];
|
|
63
|
+
nestable: boolean;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Parses the render function for a value (i.e. example which returns a string or React
|
|
67
|
+
* component reference, not JSX) passed to `figma.connect()`
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseValueRenderFunction(exp: ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration, parserContext: ParserContext, propMappings?: PropMappings): {
|
|
47
70
|
code: string;
|
|
48
71
|
imports: {
|
|
49
72
|
statement: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/react/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAW3B,OAAO,EAAsB,YAAY,EAAoB,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAIL,aAAa,EASb,YAAY,EACb,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/react/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAW3B,OAAO,EAAsB,YAAY,EAAoB,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAIL,aAAa,EASb,YAAY,EACb,MAAM,0BAA0B,CAAA;AAEjC;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,qBAAqB,GAAG,EAAE,CAAC,WAAW,GAAG,SAAS,CAMvE;AAiED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,0BAanF;AAsED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE3D;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,EAAE,CAAC,wBAAwB,GAAG,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,EACjE,aAAa,EAAE,aAAa,EAC5B,MAAM,CAAC,EAAE,OAAO;;;;GA4GjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAC,mBAAmB,EACtE,aAAa,EAAE,aAAa,EAC5B,YAAY,CAAC,EAAE,YAAY;;;;;;;;EA4L5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAC,mBAAmB,EACtE,aAAa,EAAE,aAAa,EAC5B,YAAY,CAAC,EAAE,YAAY;;;;;;;EAwC5B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAC,mBAAmB,EACtE,aAAa,EAAE,aAAa,EAC5B,YAAY,CAAC,EAAE,YAAY;;;mBAkCd,MAAM;cACX,MAAM;;;EAyBf;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,UA+B1D;AA+LD,wBAAgB,kBAAkB,CAChC,iBAAiB,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,UAItE;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,EAAE,CAAC,cAAc,EACvB,aAAa,EAAE,aAAa,EAC5B,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,GAChC,OAAO,CAAC,eAAe,CAAC,CA6G1B"}
|
package/dist/react/parser.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseReactDoc = exports.getDefaultTemplate = exports.replacePropPlaceholders = exports.
|
|
6
|
+
exports.parseReactDoc = exports.getDefaultTemplate = exports.replacePropPlaceholders = exports.parseValueRenderFunction = exports.parseJSXRenderFunction = exports.parseRenderFunctionExpression = exports.parseComponentMetadata = exports.findAndResolveImports = exports.findJSXElement = void 0;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
const project_1 = require("../connect/project");
|
|
9
9
|
const logging_1 = require("../common/logging");
|
|
@@ -24,6 +24,7 @@ function findJSXElement(node) {
|
|
|
24
24
|
return typescript_1.default.forEachChild(node, findJSXElement);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
exports.findJSXElement = findJSXElement;
|
|
27
28
|
function findBlock(node) {
|
|
28
29
|
if (typescript_1.default.isBlock(node)) {
|
|
29
30
|
return node;
|
|
@@ -139,182 +140,6 @@ function getSourceFilesOfImportedIdentifiers(parserContext, _identifiers) {
|
|
|
139
140
|
}
|
|
140
141
|
return imports;
|
|
141
142
|
}
|
|
142
|
-
function findCallExpression(node) {
|
|
143
|
-
if (typescript_1.default.isCallExpression(node)) {
|
|
144
|
-
return node;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return typescript_1.default.forEachChild(node, findCallExpression);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Traverses the AST and finds the first arrow function declaration
|
|
152
|
-
* @param node
|
|
153
|
-
* @returns
|
|
154
|
-
*/
|
|
155
|
-
function findDescendantArrowFunction(node) {
|
|
156
|
-
if (typescript_1.default.isArrowFunction(node)) {
|
|
157
|
-
return node;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
return typescript_1.default.forEachChild(node, findDescendantArrowFunction);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Traverses the AST and finds the first function expression
|
|
165
|
-
* (handles forwardRef:d component declarations)
|
|
166
|
-
* @param node
|
|
167
|
-
* @returns
|
|
168
|
-
*/
|
|
169
|
-
function findDescendantFunctionExpression(node) {
|
|
170
|
-
if (typescript_1.default.isFunctionExpression(node)) {
|
|
171
|
-
return node;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
return typescript_1.default.forEachChild(node, findDescendantFunctionExpression);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function getDeclarationFromSymbol(symbol) {
|
|
178
|
-
if (!symbol.declarations || !symbol.declarations.length) {
|
|
179
|
-
throw new Error(`No declarations found in symbol ${symbol.escapedName}`);
|
|
180
|
-
}
|
|
181
|
-
return symbol.declarations[0];
|
|
182
|
-
}
|
|
183
|
-
function resolveIdentifierSymbol(identifier, checker) {
|
|
184
|
-
const componentSymbol = checker.getSymbolAtLocation(identifier);
|
|
185
|
-
if (!componentSymbol) {
|
|
186
|
-
throw new Error(`Symbol not found at location ${identifier.getText()}`);
|
|
187
|
-
}
|
|
188
|
-
const componentDeclaration = getDeclarationFromSymbol(componentSymbol);
|
|
189
|
-
if (typescript_1.default.isImportSpecifier(componentDeclaration) || typescript_1.default.isImportClause(componentDeclaration)) {
|
|
190
|
-
let importDeclaration = findParentImportDeclaration(componentDeclaration);
|
|
191
|
-
if (!importDeclaration) {
|
|
192
|
-
throw new Error('No import statement found for component');
|
|
193
|
-
}
|
|
194
|
-
// The component should be imported from another file, we need to follow the
|
|
195
|
-
// aliased symbol to get the correct function definition
|
|
196
|
-
if (componentSymbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
197
|
-
return checker.getAliasedSymbol(componentSymbol);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return componentSymbol;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* This handles a number of cases for finding the function expression of an exported symbol:
|
|
204
|
-
* - A function that is exported directly (function declaration)
|
|
205
|
-
* - A function that is exported as a variable (arrow function)
|
|
206
|
-
* - A function expression wrapped in a forwardRef
|
|
207
|
-
* - A function expression wrapped in a memo call
|
|
208
|
-
* @param declaration an exported function declaration
|
|
209
|
-
* @param checker
|
|
210
|
-
*/
|
|
211
|
-
function findFunctionExpression(declaration, checker, sourceFile) {
|
|
212
|
-
let functionExpression;
|
|
213
|
-
// Example: export function Button() {}
|
|
214
|
-
if (typescript_1.default.isFunctionDeclaration(declaration)) {
|
|
215
|
-
return declaration;
|
|
216
|
-
}
|
|
217
|
-
// Example: export const Button = forwardRef(function Button() {})
|
|
218
|
-
if ((functionExpression = findDescendantFunctionExpression(declaration))) {
|
|
219
|
-
return functionExpression;
|
|
220
|
-
}
|
|
221
|
-
// Example: export const Button = () => {}
|
|
222
|
-
if ((functionExpression = findDescendantArrowFunction(declaration))) {
|
|
223
|
-
return functionExpression;
|
|
224
|
-
}
|
|
225
|
-
// Example: export const MemoButton = memo(Button)
|
|
226
|
-
// Example: export const ButtonWithRef = forwardRef(Button)
|
|
227
|
-
if (typescript_1.default.isVariableDeclaration(declaration)) {
|
|
228
|
-
let componentSymbol = undefined;
|
|
229
|
-
// Example: export const SomeAlias = Button
|
|
230
|
-
if (declaration.initializer && typescript_1.default.isIdentifier(declaration.initializer)) {
|
|
231
|
-
componentSymbol = resolveIdentifierSymbol(declaration.initializer, checker);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
const callExpression = findCallExpression(declaration);
|
|
235
|
-
const component = callExpression.arguments[0];
|
|
236
|
-
// follow the symbol to its declaration, then try to find the function expression again
|
|
237
|
-
componentSymbol = checker.getSymbolAtLocation(component);
|
|
238
|
-
}
|
|
239
|
-
if (!componentSymbol) {
|
|
240
|
-
throw new Error('No symbol found at location');
|
|
241
|
-
}
|
|
242
|
-
const componentDeclaration = getDeclarationFromSymbol(componentSymbol);
|
|
243
|
-
return findFunctionExpression(componentDeclaration, checker, sourceFile);
|
|
244
|
-
}
|
|
245
|
-
throw new parser_common_1.ParserError('Failed to find function expression for component', {
|
|
246
|
-
sourceFile,
|
|
247
|
-
node: declaration,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Extracts the type signature from the interface of a React component as a map of
|
|
252
|
-
* keys to strings representing the type of that property. Appends a '?' to the value
|
|
253
|
-
* if it's optional. Example:
|
|
254
|
-
* {
|
|
255
|
-
* name: string
|
|
256
|
-
* disabled: ?boolean
|
|
257
|
-
* }
|
|
258
|
-
* @param symbol the symbol of the function declaration of the component (in the source file)
|
|
259
|
-
* @param sourceFile the source file with the component definition
|
|
260
|
-
* @param checker
|
|
261
|
-
* @returns
|
|
262
|
-
*/
|
|
263
|
-
function extractComponentTypeSignature(symbol, checker, sourceFile) {
|
|
264
|
-
const declaration = getDeclarationFromSymbol(symbol);
|
|
265
|
-
const ReactInterfaceNames = ['HTMLAttributes', 'Attributes', 'AriaAttributes', 'DOMAttributes'];
|
|
266
|
-
let propsType = null;
|
|
267
|
-
/**
|
|
268
|
-
* Special case for forwardRef as type is passed as generic arg
|
|
269
|
-
*/
|
|
270
|
-
if (typescript_1.default.isVariableDeclaration(declaration)) {
|
|
271
|
-
const callExpression = findCallExpression(declaration);
|
|
272
|
-
if ((callExpression?.expression.getText() === 'forwardRef' ||
|
|
273
|
-
callExpression?.expression.getText() === 'React.forwardRef') &&
|
|
274
|
-
callExpression.typeArguments &&
|
|
275
|
-
callExpression.typeArguments.length === 2) {
|
|
276
|
-
propsType = checker.getTypeAtLocation(callExpression.typeArguments[1]);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (!propsType) {
|
|
280
|
-
const functionExpression = findFunctionExpression(declaration, checker, sourceFile);
|
|
281
|
-
propsType = checker.getTypeAtLocation(functionExpression.parameters[0]);
|
|
282
|
-
}
|
|
283
|
-
if (!propsType) {
|
|
284
|
-
throw new parser_common_1.InternalError(`Failed to extract props from component declaration: ${declaration.getText()}`);
|
|
285
|
-
}
|
|
286
|
-
const propsMap = {};
|
|
287
|
-
const props = propsType.getProperties();
|
|
288
|
-
for (const prop of props) {
|
|
289
|
-
// Skip props that are inherited from React types
|
|
290
|
-
// NOTE: this is pretty naive, in the future we might want to
|
|
291
|
-
// actually traverse the AST to determine if the types are declared
|
|
292
|
-
// in the React namespace
|
|
293
|
-
const parent = getDeclarationFromSymbol(prop).parent;
|
|
294
|
-
if (typescript_1.default.isInterfaceDeclaration(parent)) {
|
|
295
|
-
const parentInterfaceName = parent.name.getText();
|
|
296
|
-
if (ReactInterfaceNames.includes(parentInterfaceName) ||
|
|
297
|
-
(parent.heritageClauses && parent.heritageClauses[0].getText().includes('HTMLAttributes'))) {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (!prop.valueDeclaration) {
|
|
302
|
-
throw new Error(`No valueDeclaration for symbol ${prop.escapedName}`);
|
|
303
|
-
}
|
|
304
|
-
const propType = checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration);
|
|
305
|
-
let propTypeString = checker.typeToString(propType);
|
|
306
|
-
if (propType.isUnion()) {
|
|
307
|
-
// Get the types of the union
|
|
308
|
-
const unionTypes = propType.types;
|
|
309
|
-
// Map each type to its string representation and join them with a comma
|
|
310
|
-
propTypeString = unionTypes.map((type) => checker.typeToString(type)).join(' | ');
|
|
311
|
-
}
|
|
312
|
-
propsMap[prop.name] =
|
|
313
|
-
prop.flags & typescript_1.default.SymbolFlags.Optional ? `?${propTypeString}` : propTypeString;
|
|
314
|
-
}
|
|
315
|
-
return propsMap;
|
|
316
|
-
}
|
|
317
|
-
exports.extractComponentTypeSignature = extractComponentTypeSignature;
|
|
318
143
|
/**
|
|
319
144
|
* Extract metadata about the referenced React component. Used by both the
|
|
320
145
|
* Code Connect and Storybook commands.
|
|
@@ -412,7 +237,7 @@ async function parseComponentMetadata(node, parserContext, silent) {
|
|
|
412
237
|
}
|
|
413
238
|
exports.parseComponentMetadata = parseComponentMetadata;
|
|
414
239
|
/**
|
|
415
|
-
* Parses
|
|
240
|
+
* Parses a render function and ouputs a template string, extracting the code and
|
|
416
241
|
* any import statements matching the JSX elements used in the function body
|
|
417
242
|
*
|
|
418
243
|
* @param exp A function or arrow function expression
|
|
@@ -421,15 +246,14 @@ exports.parseComponentMetadata = parseComponentMetadata;
|
|
|
421
246
|
*
|
|
422
247
|
* @returns The code of the render function and a list of imports
|
|
423
248
|
*/
|
|
424
|
-
function
|
|
249
|
+
function parseRenderFunctionExpression(exp, parserContext, propMappings) {
|
|
425
250
|
const { sourceFile } = parserContext;
|
|
426
|
-
let
|
|
251
|
+
let renderFunctionCode;
|
|
427
252
|
if (exp.parameters.length > 1) {
|
|
428
253
|
throw new parser_common_1.ParserError(`Expected a single props parameter for the render function, got ${exp.parameters.length} parameters`, { sourceFile, node: exp });
|
|
429
254
|
}
|
|
430
255
|
const propsParameter = exp.parameters[0];
|
|
431
|
-
// Keep track of any props which are referenced in the example
|
|
432
|
-
// insert the appropriate `figma.properties` call in the JS template
|
|
256
|
+
// Keep track of any props which are referenced in the example
|
|
433
257
|
const referencedProps = new Set();
|
|
434
258
|
const createPropPlaceholder = (0, parser_common_1.makeCreatePropPlaceholder)({
|
|
435
259
|
propMappings,
|
|
@@ -519,7 +343,7 @@ function parseRenderFunction(exp, parserContext, propMappings) {
|
|
|
519
343
|
let jsx = findJSXElement(exp);
|
|
520
344
|
if (jsx && (!block || (block && block.statements.length <= 1))) {
|
|
521
345
|
// The function body is a single JSX element
|
|
522
|
-
|
|
346
|
+
renderFunctionCode = printer.printNode(typescript_1.default.EmitHint.Unspecified, jsx, sourceFile);
|
|
523
347
|
nestable = true;
|
|
524
348
|
}
|
|
525
349
|
else if (block) {
|
|
@@ -531,13 +355,42 @@ function parseRenderFunction(exp, parserContext, propMappings) {
|
|
|
531
355
|
const functionName = 'Example';
|
|
532
356
|
const functionExpression = typescript_1.default.factory.createFunctionExpression(undefined, undefined, typescript_1.default.factory.createIdentifier(functionName), [], undefined, undefined, block);
|
|
533
357
|
const printer = typescript_1.default.createPrinter();
|
|
534
|
-
|
|
358
|
+
renderFunctionCode = printer.printNode(typescript_1.default.EmitHint.Unspecified, functionExpression, sourceFile);
|
|
535
359
|
}
|
|
536
360
|
else {
|
|
537
361
|
throw new parser_common_1.ParserError(`Expected a single JSX element or a block statement in the render function, got ${exp.getText()}`, { sourceFile, node: exp });
|
|
538
362
|
}
|
|
363
|
+
renderFunctionCode = replacePropPlaceholders(renderFunctionCode);
|
|
364
|
+
// Escape backticks from the example code, as otherwise those would terminate the `figma.tsx` template literal
|
|
365
|
+
renderFunctionCode = renderFunctionCode.replace(/`/g, '\\`');
|
|
366
|
+
// Finally, output the render function as a figma.tsx call
|
|
367
|
+
const figmaTsxCall = `figma.tsx\`${renderFunctionCode}\``;
|
|
368
|
+
// Find all JSX elements in the function body and extract their import
|
|
369
|
+
// statements
|
|
370
|
+
const jsxTags = (0, parser_common_1.findDescendants)(exp, (element) => typescript_1.default.isJsxElement(element) || typescript_1.default.isJsxSelfClosingElement(element));
|
|
371
|
+
const imports = getSourceFilesOfImportedIdentifiers(parserContext, jsxTags.map(compiler_1.getTagName));
|
|
372
|
+
return {
|
|
373
|
+
code: figmaTsxCall,
|
|
374
|
+
imports,
|
|
375
|
+
nestable,
|
|
376
|
+
referencedProps,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
exports.parseRenderFunctionExpression = parseRenderFunctionExpression;
|
|
380
|
+
/**
|
|
381
|
+
* Parses the render function passed to `figma.connect()`, extracting the code and
|
|
382
|
+
* any import statements matching the JSX elements used in the function body
|
|
383
|
+
*
|
|
384
|
+
* @param exp A function or arrow function expression
|
|
385
|
+
* @param parserContext Parser context
|
|
386
|
+
* @param propMappings Prop mappings object as returned by parseProps
|
|
387
|
+
*
|
|
388
|
+
* @returns The code of the render function and a list of imports
|
|
389
|
+
*/
|
|
390
|
+
function parseJSXRenderFunction(exp, parserContext, propMappings) {
|
|
391
|
+
const { sourceFile } = parserContext;
|
|
392
|
+
const { code, imports, nestable, referencedProps } = parseRenderFunctionExpression(exp, parserContext, propMappings);
|
|
539
393
|
let templateCode = '';
|
|
540
|
-
exampleCode = replacePropPlaceholders(exampleCode);
|
|
541
394
|
// Generate the template code
|
|
542
395
|
// Inject React-specific template helper functions
|
|
543
396
|
templateCode = (0, parser_template_helpers_1.getParsedTemplateHelpersString)() + '\n\n';
|
|
@@ -551,21 +404,72 @@ function parseRenderFunction(exp, parserContext, propMappings) {
|
|
|
551
404
|
exp,
|
|
552
405
|
sourceFile,
|
|
553
406
|
});
|
|
554
|
-
|
|
555
|
-
exampleCode = exampleCode.replace(/`/g, '\\`');
|
|
407
|
+
const includeMetadata = propMappings && Object.keys(propMappings).length > 0;
|
|
556
408
|
// Finally, output the example code
|
|
557
|
-
templateCode +=
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const jsxTags = (0, parser_common_1.findDescendants)(exp, (element) => typescript_1.default.isJsxElement(element) || typescript_1.default.isJsxSelfClosingElement(element));
|
|
561
|
-
const imports = getSourceFilesOfImportedIdentifiers(parserContext, jsxTags.map(compiler_1.getTagName));
|
|
409
|
+
templateCode += includeMetadata
|
|
410
|
+
? `export default { ...${code}, metadata: { __props } }\n`
|
|
411
|
+
: `export default ${code}\n`;
|
|
562
412
|
return {
|
|
563
413
|
code: templateCode,
|
|
564
414
|
imports,
|
|
565
415
|
nestable,
|
|
566
416
|
};
|
|
567
417
|
}
|
|
568
|
-
exports.
|
|
418
|
+
exports.parseJSXRenderFunction = parseJSXRenderFunction;
|
|
419
|
+
/**
|
|
420
|
+
* Parses the render function for a value (i.e. example which returns a string or React
|
|
421
|
+
* component reference, not JSX) passed to `figma.connect()`
|
|
422
|
+
*/
|
|
423
|
+
function parseValueRenderFunction(exp, parserContext, propMappings) {
|
|
424
|
+
const { sourceFile } = parserContext;
|
|
425
|
+
const printer = typescript_1.default.createPrinter();
|
|
426
|
+
if (!exp.body) {
|
|
427
|
+
throw new parser_common_1.ParserError('Expected a function body', {
|
|
428
|
+
sourceFile: parserContext.sourceFile,
|
|
429
|
+
node: exp,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
let exampleCode = printer.printNode(typescript_1.default.EmitHint.Unspecified, exp.body, sourceFile);
|
|
433
|
+
const nestable = true;
|
|
434
|
+
let templateCode = '';
|
|
435
|
+
// Generate the template code
|
|
436
|
+
// Inject React-specific template helper functions
|
|
437
|
+
templateCode = (0, parser_template_helpers_1.getParsedTemplateHelpersString)() + '\n\n';
|
|
438
|
+
// Require the template API
|
|
439
|
+
templateCode += `const figma = require('figma')\n\n`;
|
|
440
|
+
// Then we output `const propName = figma.properties.<kind>('propName')` calls
|
|
441
|
+
// for each referenced prop, so these are accessible to the template code.
|
|
442
|
+
templateCode += (0, parser_common_1.getReferencedPropsForTemplate)({
|
|
443
|
+
propMappings,
|
|
444
|
+
exp,
|
|
445
|
+
sourceFile,
|
|
446
|
+
});
|
|
447
|
+
// Escape backticks from the example code
|
|
448
|
+
exampleCode = exampleCode.replace(/`/g, '\\`');
|
|
449
|
+
let imports = [];
|
|
450
|
+
const includeMetadata = propMappings && Object.keys(propMappings).length > 0;
|
|
451
|
+
if (typescript_1.default.isStringLiteral(exp.body)) {
|
|
452
|
+
// The value is a string, which is already wrapped in quotes
|
|
453
|
+
templateCode += includeMetadata
|
|
454
|
+
? `export default { ...figma.value(${exampleCode}), metadata: { __props } }\n`
|
|
455
|
+
: `export default figma.value(${exampleCode})\n`;
|
|
456
|
+
}
|
|
457
|
+
else if (typescript_1.default.isIdentifier(exp.body)) {
|
|
458
|
+
// The value is an identifier, i.e. a React component reference
|
|
459
|
+
const value = `_fcc_reactComponent("${exp.body.getText()}")`;
|
|
460
|
+
const preview = `_fcc_renderPropValue(${value})`;
|
|
461
|
+
templateCode += includeMetadata
|
|
462
|
+
? `export default { ...figma.value(${value}, ${preview}), metadata: { __props } }\n`
|
|
463
|
+
: `export default figma.value(${value}, ${preview})\n`;
|
|
464
|
+
imports = getSourceFilesOfImportedIdentifiers(parserContext, [exp.body.getText()]);
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
code: templateCode,
|
|
468
|
+
imports,
|
|
469
|
+
nestable,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
exports.parseValueRenderFunction = parseValueRenderFunction;
|
|
569
473
|
function replacePropPlaceholders(exampleCode) {
|
|
570
474
|
// Replace React prop placeholders we inserted above (like
|
|
571
475
|
// `reactPropName={__PROP__("figmaPropName")}`) with calls to
|
|
@@ -751,7 +655,11 @@ async function parseReactDoc(node, parserContext, { repoUrl, silent }) {
|
|
|
751
655
|
? await parseComponentMetadata(componentArg, parserContext, silent)
|
|
752
656
|
: undefined;
|
|
753
657
|
const props = propsArg ? (0, intrinsics_1.parsePropsObject)(propsArg, parserContext) : undefined;
|
|
754
|
-
const render = exampleArg
|
|
658
|
+
const render = exampleArg
|
|
659
|
+
? findJSXElement(exampleArg)
|
|
660
|
+
? parseJSXRenderFunction(exampleArg, parserContext, props)
|
|
661
|
+
: parseValueRenderFunction(exampleArg, parserContext, props)
|
|
662
|
+
: undefined;
|
|
755
663
|
const variant = variantArg ? (0, parser_common_1.parseVariant)(variantArg, sourceFile, checker) : undefined;
|
|
756
664
|
const links = linksArg ? (0, parser_common_1.parseLinks)(linksArg, parserContext) : undefined;
|
|
757
665
|
let mappedImports;
|