@builder.io/mitosis 0.0.56-13 → 0.0.56-14
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/src/__tests__/data/basic-context.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-context.raw.jsx +29 -0
- package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.jsx +12 -0
- package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.jsx +17 -0
- package/dist/src/__tests__/data/basic-forwardRef.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-forwardRef.raw.jsx +14 -0
- package/dist/src/__tests__/data/basic-onChange.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-onChange.raw.jsx +17 -0
- package/dist/src/__tests__/data/basic-onUpdate-deps.raw.d.ts +4 -0
- package/dist/src/__tests__/data/basic-onUpdate-deps.raw.jsx +25 -0
- package/dist/src/__tests__/data/basic-onUpdate-return.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-onUpdate-return.raw.jsx +24 -0
- package/dist/src/__tests__/data/basic-ref-assignment.raw.d.ts +4 -0
- package/dist/src/__tests__/data/basic-ref-assignment.raw.jsx +15 -0
- package/dist/src/__tests__/data/basic-ref-usePrevious.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-ref-usePrevious.raw.jsx +35 -0
- package/dist/src/__tests__/data/basic-ref.raw.d.ts +4 -0
- package/dist/src/__tests__/data/basic-ref.raw.jsx +36 -0
- package/dist/src/__tests__/data/basic.raw.d.ts +3 -0
- package/dist/src/__tests__/data/basic.raw.jsx +5 -1
- package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/embed.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/form.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +8 -1
- package/dist/src/__tests__/data/blocks/onInit.raw.jsx +13 -3
- package/dist/src/__tests__/data/types/component-props-interface.raw.d.ts +6 -0
- package/dist/src/__tests__/data/types/component-props-interface.raw.jsx +6 -0
- package/dist/src/__tests__/data/types/component-props-type.raw.d.ts +6 -0
- package/dist/src/__tests__/data/types/component-props-type.raw.jsx +6 -0
- package/dist/src/__tests__/data/types/preserve-typing.raw.d.ts +8 -0
- package/dist/src/__tests__/data/types/preserve-typing.raw.jsx +6 -0
- package/dist/src/generators/angular.js +49 -14
- package/dist/src/generators/html.js +198 -99
- package/dist/src/generators/mitosis.js +28 -9
- package/dist/src/generators/react.d.ts +3 -1
- package/dist/src/generators/react.js +68 -32
- package/dist/src/generators/solid.js +5 -2
- package/dist/src/generators/svelte.js +12 -2
- package/dist/src/generators/vue.js +21 -0
- package/dist/src/helpers/create-mitosis-component.d.ts +1 -1
- package/dist/src/helpers/create-mitosis-component.js +1 -1
- package/dist/src/helpers/get-bindings.d.ts +2 -0
- package/dist/src/helpers/get-bindings.js +18 -0
- package/dist/src/helpers/get-props-ref.d.ts +2 -0
- package/dist/src/helpers/get-props-ref.js +32 -0
- package/dist/src/helpers/has-bindings-text.d.ts +2 -0
- package/dist/src/helpers/has-bindings-text.js +21 -0
- package/dist/src/helpers/has-stateful-dom.d.ts +2 -0
- package/dist/src/helpers/has-stateful-dom.js +21 -0
- package/dist/src/helpers/is-html-attribute.d.ts +1 -1
- package/dist/src/helpers/is-html-attribute.js +2 -1
- package/dist/src/helpers/map-refs.js +4 -1
- package/dist/src/helpers/render-imports.d.ts +3 -1
- package/dist/src/helpers/render-imports.js +8 -2
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +2 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +3 -2
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/parsers/builder.d.ts +23 -23
- package/dist/src/parsers/jsx.d.ts +2 -1
- package/dist/src/parsers/jsx.js +145 -15
- package/dist/src/symbols/symbol-processor.js +3 -3
- package/dist/src/types/mitosis-component.d.ts +30 -10
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './flow';
|
|
2
2
|
export declare type Context<T> = {};
|
|
3
3
|
export declare const useState: <T>(obj: T) => T;
|
|
4
|
-
export declare const useRef: () =>
|
|
4
|
+
export declare const useRef: <T>(obj?: void | T | null | undefined) => T;
|
|
5
5
|
export declare const useContext: <T = {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}>(key: Context<T>) => T;
|
|
@@ -12,7 +12,7 @@ export declare const setContext: <T = {
|
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}>(key: Context<T>, value: Partial<T>) => void;
|
|
14
14
|
export declare const onMount: (fn: () => any) => any;
|
|
15
|
-
export declare const onUpdate: (fn: () => any, deps?: any[]
|
|
15
|
+
export declare const onUpdate: (fn: () => any, deps?: any[]) => any;
|
|
16
16
|
export declare const onCreate: (fn: () => any) => any;
|
|
17
17
|
export declare const onInit: (fn: () => any) => any;
|
|
18
18
|
export declare const onUnMount: (fn: () => any) => any;
|
package/dist/src/index.js
CHANGED
|
@@ -19,7 +19,7 @@ __exportStar(require("./flow"), exports);
|
|
|
19
19
|
// These compile away
|
|
20
20
|
var useState = function (obj) { return obj; };
|
|
21
21
|
exports.useState = useState;
|
|
22
|
-
var useRef = function () { return
|
|
22
|
+
var useRef = function (obj) { return obj; };
|
|
23
23
|
exports.useRef = useRef;
|
|
24
24
|
var useContext = function (key) {
|
|
25
25
|
return null;
|
|
@@ -27,30 +27,27 @@ export declare function extractStateHook(code: string): {
|
|
|
27
27
|
state: any;
|
|
28
28
|
};
|
|
29
29
|
export declare function convertExportDefaultToReturn(code: string): string;
|
|
30
|
-
export declare const createBuilderElement: (options?: Partial<BuilderElement>
|
|
30
|
+
export declare const createBuilderElement: (options?: Partial<BuilderElement>) => BuilderElement;
|
|
31
31
|
export declare const isBuilderElement: (el: unknown) => el is BuilderElement;
|
|
32
32
|
export declare const builderContentToMitosisComponent: (builderContent: BuilderContent, options?: BuilderToMitosisOptions) => {
|
|
33
33
|
subComponents: {
|
|
34
34
|
name: string;
|
|
35
35
|
'@type': "@builder.io/mitosis/component";
|
|
36
36
|
imports: import("..").MitosisImport[];
|
|
37
|
+
exports?: import("..").MitosisExport | undefined;
|
|
37
38
|
meta: import("../types/json").JSONObject & {
|
|
38
39
|
useMetadata?: import("../types/json").JSONObject | undefined;
|
|
39
40
|
};
|
|
40
41
|
inputs: import("..").MitosisComponentInput[];
|
|
41
42
|
state: import("../types/json").JSONObject;
|
|
42
43
|
context: {
|
|
43
|
-
get:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
[key: string]: {
|
|
51
|
-
name: string;
|
|
52
|
-
value?: import("../types/json").JSONObject | undefined;
|
|
53
|
-
};
|
|
44
|
+
get: import("..").ContextGet;
|
|
45
|
+
set: import("..").ContextSet;
|
|
46
|
+
};
|
|
47
|
+
refs: {
|
|
48
|
+
[useRef: string]: {
|
|
49
|
+
typeParameter?: string | undefined;
|
|
50
|
+
argument: string;
|
|
54
51
|
};
|
|
55
52
|
};
|
|
56
53
|
hooks: {
|
|
@@ -64,27 +61,27 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
|
|
|
64
61
|
};
|
|
65
62
|
children: MitosisNode[];
|
|
66
63
|
subComponents: import("..").MitosisComponent[];
|
|
64
|
+
types?: string[] | undefined;
|
|
65
|
+
interfaces?: string[] | undefined;
|
|
66
|
+
propsTypeRef?: string | undefined;
|
|
67
67
|
}[];
|
|
68
68
|
'@type': "@builder.io/mitosis/component";
|
|
69
69
|
name: string;
|
|
70
70
|
imports: import("..").MitosisImport[];
|
|
71
|
+
exports?: import("..").MitosisExport | undefined;
|
|
71
72
|
meta: import("../types/json").JSONObject & {
|
|
72
73
|
useMetadata?: import("../types/json").JSONObject | undefined;
|
|
73
74
|
};
|
|
74
75
|
inputs: import("..").MitosisComponentInput[];
|
|
75
76
|
state: import("../types/json").JSONObject;
|
|
76
77
|
context: {
|
|
77
|
-
get:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
[key: string]: {
|
|
85
|
-
name: string;
|
|
86
|
-
value?: import("../types/json").JSONObject | undefined;
|
|
87
|
-
};
|
|
78
|
+
get: import("..").ContextGet;
|
|
79
|
+
set: import("..").ContextSet;
|
|
80
|
+
};
|
|
81
|
+
refs: {
|
|
82
|
+
[useRef: string]: {
|
|
83
|
+
typeParameter?: string | undefined;
|
|
84
|
+
argument: string;
|
|
88
85
|
};
|
|
89
86
|
};
|
|
90
87
|
hooks: {
|
|
@@ -97,5 +94,8 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
|
|
|
97
94
|
onUpdate?: import("..").extendedHook[] | undefined;
|
|
98
95
|
};
|
|
99
96
|
children: MitosisNode[];
|
|
97
|
+
types?: string[] | undefined;
|
|
98
|
+
interfaces?: string[] | undefined;
|
|
99
|
+
propsTypeRef?: string | undefined;
|
|
100
100
|
};
|
|
101
101
|
export {};
|
|
@@ -2,12 +2,13 @@ import * as babel from '@babel/core';
|
|
|
2
2
|
import { MitosisComponent } from '../types/mitosis-component';
|
|
3
3
|
export declare const selfClosingTags: Set<string>;
|
|
4
4
|
export declare const createFunctionStringLiteral: (node: babel.types.Node) => babel.types.StringLiteral;
|
|
5
|
-
export declare const createFunctionStringLiteralObjectProperty: (key: babel.types.Expression, node: babel.types.Node) => babel.types.ObjectProperty;
|
|
5
|
+
export declare const createFunctionStringLiteralObjectProperty: (key: babel.types.PrivateName | babel.types.Expression, node: babel.types.Node) => babel.types.ObjectProperty;
|
|
6
6
|
export declare const parseStateObject: (object: babel.types.ObjectExpression) => any;
|
|
7
7
|
export declare const METADATA_HOOK_NAME = "useMetadata";
|
|
8
8
|
declare type ParseMitosisOptions = {
|
|
9
9
|
format: 'react' | 'simple';
|
|
10
10
|
jsonHookNames?: string[];
|
|
11
|
+
compileAwayPackages?: string[];
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* This function takes the raw string from a Mitosis component, and converts it into a JSON that can be processed by
|
package/dist/src/parsers/jsx.js
CHANGED
|
@@ -59,6 +59,7 @@ var create_mitosis_component_1 = require("../helpers/create-mitosis-component");
|
|
|
59
59
|
var create_mitosis_node_1 = require("../helpers/create-mitosis-node");
|
|
60
60
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
61
61
|
var replace_idenifiers_1 = require("../helpers/replace-idenifiers");
|
|
62
|
+
var get_bindings_1 = require("../helpers/get-bindings");
|
|
62
63
|
var replace_new_lines_in_strings_1 = require("../helpers/replace-new-lines-in-strings");
|
|
63
64
|
var json_1 = require("../helpers/json");
|
|
64
65
|
var jsxPlugin = require('@babel/plugin-syntax-jsx');
|
|
@@ -172,12 +173,28 @@ var parseCodeJson = function (node) {
|
|
|
172
173
|
var code = (0, generator_1.default)(node).code;
|
|
173
174
|
return (0, json_1.tryParseJson)(code);
|
|
174
175
|
};
|
|
176
|
+
var getPropsTypeRef = function (node) {
|
|
177
|
+
var param = node.params[0];
|
|
178
|
+
// TODO: component function params name must be props
|
|
179
|
+
if (babel.types.isIdentifier(param) &&
|
|
180
|
+
param.name === 'props' &&
|
|
181
|
+
babel.types.isTSTypeAnnotation(param.typeAnnotation)) {
|
|
182
|
+
var paramIdentifier = babel.types.variableDeclaration('let', [
|
|
183
|
+
babel.types.variableDeclarator(param),
|
|
184
|
+
]);
|
|
185
|
+
return (0, generator_1.default)(paramIdentifier)
|
|
186
|
+
.code.replace(/^let\sprops:\s+/, '')
|
|
187
|
+
.replace(/;/g, '');
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
};
|
|
175
191
|
var componentFunctionToJson = function (node, context) {
|
|
176
192
|
var _a;
|
|
177
193
|
var hooks = {};
|
|
178
194
|
var state = {};
|
|
179
195
|
var accessedContext = {};
|
|
180
196
|
var setContext = {};
|
|
197
|
+
var refs = {};
|
|
181
198
|
for (var _i = 0, _b = node.body.body; _i < _b.length; _i++) {
|
|
182
199
|
var item = _b[_i];
|
|
183
200
|
if (types.isExpressionStatement(item)) {
|
|
@@ -191,12 +208,22 @@ var componentFunctionToJson = function (node, context) {
|
|
|
191
208
|
var key = keyNode.name;
|
|
192
209
|
var keyPath = (0, trace_reference_to_module_path_1.traceReferenceToModulePath)(context.builder.component.imports, key);
|
|
193
210
|
var valueNode = expression.arguments[1];
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
if (valueNode) {
|
|
212
|
+
if (types.isObjectExpression(valueNode)) {
|
|
213
|
+
var value = (0, exports.parseStateObject)(valueNode);
|
|
214
|
+
setContext[keyPath] = {
|
|
215
|
+
name: keyNode.name,
|
|
216
|
+
value: value,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
var ref = (0, generator_1.default)(valueNode).code;
|
|
221
|
+
setContext[keyPath] = {
|
|
222
|
+
name: keyNode.name,
|
|
223
|
+
ref: ref,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
200
227
|
}
|
|
201
228
|
}
|
|
202
229
|
else if (expression.callee.name === 'onMount' ||
|
|
@@ -320,6 +347,27 @@ var componentFunctionToJson = function (node, context) {
|
|
|
320
347
|
path: (0, trace_reference_to_module_path_1.traceReferenceToModulePath)(context.builder.component.imports, name_1),
|
|
321
348
|
};
|
|
322
349
|
}
|
|
350
|
+
else {
|
|
351
|
+
var varName = declaration.id.name;
|
|
352
|
+
var name_2 = (0, generator_1.default)(firstArg).code;
|
|
353
|
+
accessedContext[varName] = {
|
|
354
|
+
name: name_2,
|
|
355
|
+
path: '',
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (init.callee.name === 'useRef') {
|
|
361
|
+
if (types.isIdentifier(declaration.id)) {
|
|
362
|
+
var firstArg = init.arguments[0];
|
|
363
|
+
var varName = declaration.id.name;
|
|
364
|
+
refs[varName] = {
|
|
365
|
+
argument: (0, generator_1.default)(firstArg).code,
|
|
366
|
+
};
|
|
367
|
+
// Typescript Parameter
|
|
368
|
+
if (types.isTSTypeParameterInstantiation(init.typeParameters)) {
|
|
369
|
+
refs[varName].typeParameter = (0, generator_1.default)(init.typeParameters.params[0]).code;
|
|
370
|
+
}
|
|
323
371
|
}
|
|
324
372
|
}
|
|
325
373
|
}
|
|
@@ -336,10 +384,21 @@ var componentFunctionToJson = function (node, context) {
|
|
|
336
384
|
children.push(jsxElementToJson(value));
|
|
337
385
|
}
|
|
338
386
|
}
|
|
339
|
-
|
|
387
|
+
var localExports = context.builder.component.exports;
|
|
388
|
+
if (localExports) {
|
|
389
|
+
var bindingsCode_1 = (0, get_bindings_1.getBindingsCode)(children);
|
|
390
|
+
Object.keys(localExports).forEach(function (name) {
|
|
391
|
+
var found = bindingsCode_1.find(function (code) {
|
|
392
|
+
return code.match(new RegExp("\\b".concat(name, "\\b")));
|
|
393
|
+
});
|
|
394
|
+
localExports[name].usedInLocal = Boolean(found);
|
|
395
|
+
});
|
|
396
|
+
context.builder.component.exports = localExports;
|
|
397
|
+
}
|
|
398
|
+
return (0, create_mitosis_component_1.createMitosisComponent)(__assign(__assign({}, context.builder.component), { name: (_a = node.id) === null || _a === void 0 ? void 0 : _a.name, state: state, children: children, refs: refs, hooks: hooks, context: {
|
|
340
399
|
get: accessedContext,
|
|
341
400
|
set: setContext,
|
|
342
|
-
} }));
|
|
401
|
+
}, propsTypeRef: getPropsTypeRef(node) }));
|
|
343
402
|
};
|
|
344
403
|
var jsxElementToJson = function (node) {
|
|
345
404
|
if (types.isJSXText(node)) {
|
|
@@ -658,10 +717,10 @@ function extractContextComponents(json) {
|
|
|
658
717
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
659
718
|
if (item.name.endsWith('.Provider')) {
|
|
660
719
|
var value = (_b = (_a = item.bindings) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.code;
|
|
661
|
-
var
|
|
662
|
-
var refPath = (0, trace_reference_to_module_path_1.traceReferenceToModulePath)(json.imports,
|
|
720
|
+
var name_3 = item.name.split('.')[0];
|
|
721
|
+
var refPath = (0, trace_reference_to_module_path_1.traceReferenceToModulePath)(json.imports, name_3);
|
|
663
722
|
json.context.set[refPath] = {
|
|
664
|
-
name:
|
|
723
|
+
name: name_3,
|
|
665
724
|
value: value
|
|
666
725
|
? (0, exports.parseStateObject)(expressionToNode(value))
|
|
667
726
|
: undefined,
|
|
@@ -679,6 +738,26 @@ function extractContextComponents(json) {
|
|
|
679
738
|
var isImportOrDefaultExport = function (node) {
|
|
680
739
|
return types.isExportDefaultDeclaration(node) || types.isImportDeclaration(node);
|
|
681
740
|
};
|
|
741
|
+
var isTypeOrInterface = function (node) {
|
|
742
|
+
return types.isTSTypeAliasDeclaration(node) ||
|
|
743
|
+
types.isTSInterfaceDeclaration(node) ||
|
|
744
|
+
(types.isExportNamedDeclaration(node) &&
|
|
745
|
+
types.isTSTypeAliasDeclaration(node.declaration)) ||
|
|
746
|
+
(types.isExportNamedDeclaration(node) &&
|
|
747
|
+
types.isTSInterfaceDeclaration(node.declaration));
|
|
748
|
+
};
|
|
749
|
+
var collectTypes = function (node, context) {
|
|
750
|
+
var typeStr = (0, generator_1.default)(node).code;
|
|
751
|
+
var _a = context.builder.component.types, types = _a === void 0 ? [] : _a;
|
|
752
|
+
types.push(typeStr);
|
|
753
|
+
context.builder.component.types = types.filter(Boolean);
|
|
754
|
+
};
|
|
755
|
+
var collectInterfaces = function (node, context) {
|
|
756
|
+
var interfaceStr = (0, generator_1.default)(node).code;
|
|
757
|
+
var _a = context.builder.component.interfaces, interfaces = _a === void 0 ? [] : _a;
|
|
758
|
+
interfaces.push(interfaceStr);
|
|
759
|
+
context.builder.component.interfaces = interfaces.filter(Boolean);
|
|
760
|
+
};
|
|
682
761
|
/**
|
|
683
762
|
* This function takes the raw string from a Mitosis component, and converts it into a JSON that can be processed by
|
|
684
763
|
* each generator function.
|
|
@@ -712,8 +791,38 @@ function parseJsx(jsx, options) {
|
|
|
712
791
|
component: (0, create_mitosis_component_1.createMitosisComponent)(),
|
|
713
792
|
};
|
|
714
793
|
var keepStatements = path.node.body.filter(function (statement) {
|
|
715
|
-
return isImportOrDefaultExport(statement)
|
|
794
|
+
return isImportOrDefaultExport(statement) ||
|
|
795
|
+
isTypeOrInterface(statement);
|
|
796
|
+
});
|
|
797
|
+
var exportsOrLocalVariables = path.node.body.filter(function (statement) {
|
|
798
|
+
return !isImportOrDefaultExport(statement) &&
|
|
799
|
+
!isTypeOrInterface(statement) &&
|
|
800
|
+
!types.isExpressionStatement(statement);
|
|
716
801
|
});
|
|
802
|
+
context.builder.component.exports = exportsOrLocalVariables.reduce(function (pre, node) {
|
|
803
|
+
var name, isFunction;
|
|
804
|
+
if (babel.types.isExportNamedDeclaration(node) &&
|
|
805
|
+
babel.types.isVariableDeclaration(node.declaration) &&
|
|
806
|
+
babel.types.isIdentifier(node.declaration.declarations[0].id)) {
|
|
807
|
+
name = node.declaration.declarations[0].id.name;
|
|
808
|
+
isFunction = babel.types.isFunction(node.declaration.declarations[0].init);
|
|
809
|
+
}
|
|
810
|
+
else if (babel.types.isVariableDeclaration(node) &&
|
|
811
|
+
babel.types.isIdentifier(node.declarations[0].id)) {
|
|
812
|
+
name = node.declarations[0].id.name;
|
|
813
|
+
isFunction = babel.types.isFunction(node.declarations[0].init);
|
|
814
|
+
}
|
|
815
|
+
if (name) {
|
|
816
|
+
pre[name] = {
|
|
817
|
+
code: (0, generator_1.default)(node).code,
|
|
818
|
+
isFunction: isFunction,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
console.warn('export statement without name', node);
|
|
823
|
+
}
|
|
824
|
+
return pre;
|
|
825
|
+
}, {});
|
|
717
826
|
var cutStatements = path.node.body.filter(function (statement) { return !isImportOrDefaultExport(statement); });
|
|
718
827
|
subComponentFunctions = path.node.body
|
|
719
828
|
.filter(function (node) {
|
|
@@ -731,15 +840,20 @@ function parseJsx(jsx, options) {
|
|
|
731
840
|
FunctionDeclaration: function (path, context) {
|
|
732
841
|
var node = path.node;
|
|
733
842
|
if (types.isIdentifier(node.id)) {
|
|
734
|
-
var
|
|
735
|
-
if (
|
|
843
|
+
var name_4 = node.id.name;
|
|
844
|
+
if (name_4[0].toUpperCase() === name_4[0]) {
|
|
736
845
|
path.replaceWith(jsonToAst(componentFunctionToJson(node, context)));
|
|
737
846
|
}
|
|
738
847
|
}
|
|
739
848
|
},
|
|
740
849
|
ImportDeclaration: function (path, context) {
|
|
741
850
|
// @builder.io/mitosis or React imports compile away
|
|
742
|
-
|
|
851
|
+
var customPackages = (options === null || options === void 0 ? void 0 : options.compileAwayPackages) || [];
|
|
852
|
+
if (__spreadArray([
|
|
853
|
+
'react',
|
|
854
|
+
'@builder.io/mitosis',
|
|
855
|
+
'@emotion/react'
|
|
856
|
+
], customPackages, true).includes(path.node.source.value)) {
|
|
743
857
|
path.remove();
|
|
744
858
|
return;
|
|
745
859
|
}
|
|
@@ -769,6 +883,22 @@ function parseJsx(jsx, options) {
|
|
|
769
883
|
var node = path.node;
|
|
770
884
|
path.replaceWith(jsonToAst(jsxElementToJson(node)));
|
|
771
885
|
},
|
|
886
|
+
ExportNamedDeclaration: function (path, context) {
|
|
887
|
+
var node = path.node;
|
|
888
|
+
var newTypeStr = (0, generator_1.default)(node).code;
|
|
889
|
+
if (babel.types.isTSInterfaceDeclaration(node.declaration)) {
|
|
890
|
+
collectInterfaces(path.node, context);
|
|
891
|
+
}
|
|
892
|
+
if (babel.types.isTSTypeAliasDeclaration(node.declaration)) {
|
|
893
|
+
collectTypes(path.node, context);
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
TSTypeAliasDeclaration: function (path, context) {
|
|
897
|
+
collectTypes(path.node, context);
|
|
898
|
+
},
|
|
899
|
+
TSInterfaceDeclaration: function (path, context) {
|
|
900
|
+
collectInterfaces(path.node, context);
|
|
901
|
+
},
|
|
772
902
|
},
|
|
773
903
|
}); },
|
|
774
904
|
],
|
|
@@ -81,7 +81,7 @@ function convertBuilderContentToSymbolHierarchy(content, _a) {
|
|
|
81
81
|
if (cssCode) {
|
|
82
82
|
collectComponentStyles && collectComponentStyles.push((0, minify_1.minify)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), cssCode));
|
|
83
83
|
}
|
|
84
|
-
while (path[0 /* DEPTH */] >= this.path.length) {
|
|
84
|
+
while (path[0 /* Path.DEPTH */] >= this.path.length) {
|
|
85
85
|
path.shift();
|
|
86
86
|
path.shift();
|
|
87
87
|
}
|
|
@@ -97,10 +97,10 @@ function convertBuilderContentToSymbolHierarchy(content, _a) {
|
|
|
97
97
|
collectComponentState[id] = state;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
if (path[0 /* DEPTH */] < this.path.length) {
|
|
100
|
+
if (path[0 /* Path.DEPTH */] < this.path.length) {
|
|
101
101
|
var id = getIdFromSymbol(el);
|
|
102
102
|
hierarchy[id] = [];
|
|
103
|
-
addIfMissing(hierarchy[path[1 /* ID */]], id);
|
|
103
|
+
addIfMissing(hierarchy[path[1 /* Path.ID */]], id);
|
|
104
104
|
path.unshift(this.path.length, id);
|
|
105
105
|
}
|
|
106
106
|
// TODO(misko): This should be `el.content` not `el`
|
|
@@ -27,9 +27,20 @@ export interface MitosisImport {
|
|
|
27
27
|
[key: string]: string | undefined;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
export interface ContextGetInfo {
|
|
31
31
|
name: string;
|
|
32
32
|
path: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ContextSetInfo {
|
|
35
|
+
name: string;
|
|
36
|
+
value?: JSONObject;
|
|
37
|
+
ref?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare type ContextGet = {
|
|
40
|
+
[key: string]: ContextGetInfo;
|
|
41
|
+
};
|
|
42
|
+
export declare type ContextSet = {
|
|
43
|
+
[key: string]: ContextSetInfo;
|
|
33
44
|
};
|
|
34
45
|
export declare type extendedHook = {
|
|
35
46
|
code: string;
|
|
@@ -39,24 +50,31 @@ export declare type MitosisComponentInput = {
|
|
|
39
50
|
name: string;
|
|
40
51
|
defaultValue: any;
|
|
41
52
|
};
|
|
53
|
+
export declare type MitosisExport = {
|
|
54
|
+
[name: string]: {
|
|
55
|
+
code: string;
|
|
56
|
+
usedInLocal?: boolean;
|
|
57
|
+
isFunction?: boolean;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
42
60
|
export declare type MitosisComponent = {
|
|
43
61
|
'@type': '@builder.io/mitosis/component';
|
|
44
62
|
name: string;
|
|
45
63
|
imports: MitosisImport[];
|
|
64
|
+
exports?: MitosisExport;
|
|
46
65
|
meta: JSONObject & {
|
|
47
66
|
useMetadata?: JSONObject;
|
|
48
67
|
};
|
|
49
68
|
inputs: MitosisComponentInput[];
|
|
50
69
|
state: JSONObject;
|
|
51
70
|
context: {
|
|
52
|
-
get:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
71
|
+
get: ContextGet;
|
|
72
|
+
set: ContextSet;
|
|
73
|
+
};
|
|
74
|
+
refs: {
|
|
75
|
+
[useRef: string]: {
|
|
76
|
+
typeParameter?: string;
|
|
77
|
+
argument: string;
|
|
60
78
|
};
|
|
61
79
|
};
|
|
62
80
|
hooks: {
|
|
@@ -70,5 +88,7 @@ export declare type MitosisComponent = {
|
|
|
70
88
|
};
|
|
71
89
|
children: MitosisNode[];
|
|
72
90
|
subComponents: MitosisComponent[];
|
|
91
|
+
types?: string[];
|
|
92
|
+
interfaces?: string[];
|
|
93
|
+
propsTypeRef?: string;
|
|
73
94
|
};
|
|
74
|
-
export {};
|