@builder.io/mitosis 0.0.57 → 0.0.59
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/blocks/button.raw.jsx +2 -2
- package/dist/src/__tests__/data/blocks/image.raw.jsx +2 -2
- package/dist/src/__tests__/data/blocks/root-fragment-multi-node.raw.d.ts +7 -0
- package/dist/src/__tests__/data/blocks/root-fragment-multi-node.raw.jsx +18 -0
- package/dist/src/__tests__/data/default-props/default-props.raw.jsx +2 -2
- package/dist/src/__tests__/shared.d.ts +2 -2
- package/dist/src/__tests__/shared.js +72 -70
- package/dist/src/generators/angular.js +9 -3
- package/dist/src/generators/context/qwik.js +1 -1
- package/dist/src/generators/qwik/component-generator.js +19 -9
- package/dist/src/generators/qwik/src-generator.js +2 -0
- package/dist/src/generators/vue.js +13 -4
- package/dist/src/helpers/render-imports.js +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/parsers/jsx/jsx.d.ts +1 -1
- package/dist/src/parsers/jsx/jsx.js +7 -6
- package/dist/src/parsers/jsx/types.d.ts +1 -1
- package/dist/src/types/config.d.ts +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
4
|
function Button(props) {
|
|
5
|
-
return (
|
|
5
|
+
return (<div>
|
|
6
6
|
<mitosis_1.Show when={props.link}>
|
|
7
7
|
<a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
|
|
8
8
|
{props.text}
|
|
@@ -13,6 +13,6 @@ function Button(props) {
|
|
|
13
13
|
{props.text}
|
|
14
14
|
</button>
|
|
15
15
|
</mitosis_1.Show>
|
|
16
|
-
|
|
16
|
+
</div>);
|
|
17
17
|
}
|
|
18
18
|
exports.default = Button;
|
|
@@ -45,7 +45,7 @@ function Image(props) {
|
|
|
45
45
|
window.removeEventListener('scroll', state.scrollListener);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
return (
|
|
48
|
+
return (<div>
|
|
49
49
|
<picture ref={pictureRef}>
|
|
50
50
|
<mitosis_1.Show when={!state.useLazyLoading() || load}>
|
|
51
51
|
<img alt={props.altText} aria-role={props.altText ? 'presentation' : undefined} css={{
|
|
@@ -60,6 +60,6 @@ function Image(props) {
|
|
|
60
60
|
<source srcset={props.srcset}/>
|
|
61
61
|
</picture>
|
|
62
62
|
{props.children}
|
|
63
|
-
|
|
63
|
+
</div>);
|
|
64
64
|
}
|
|
65
65
|
exports.default = Image;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function Button(props) {
|
|
5
|
+
return (<>
|
|
6
|
+
<mitosis_1.Show when={props.link}>
|
|
7
|
+
<a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
|
|
8
|
+
{props.text}
|
|
9
|
+
</a>
|
|
10
|
+
</mitosis_1.Show>
|
|
11
|
+
<mitosis_1.Show when={!props.link}>
|
|
12
|
+
<button {...props.attributes} type="button">
|
|
13
|
+
{props.text}
|
|
14
|
+
</button>
|
|
15
|
+
</mitosis_1.Show>
|
|
16
|
+
</>);
|
|
17
|
+
}
|
|
18
|
+
exports.default = Button;
|
|
@@ -7,7 +7,7 @@ function Button(props) {
|
|
|
7
7
|
link: 'https://builder.io/',
|
|
8
8
|
openLinkInNewTab: false,
|
|
9
9
|
});
|
|
10
|
-
return (
|
|
10
|
+
return (<div>
|
|
11
11
|
<mitosis_1.Show when={props.link}>
|
|
12
12
|
<a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
|
|
13
13
|
{props.text}
|
|
@@ -18,6 +18,6 @@ function Button(props) {
|
|
|
18
18
|
{props.text}
|
|
19
19
|
</button>
|
|
20
20
|
</mitosis_1.Show>
|
|
21
|
-
|
|
21
|
+
</div>);
|
|
22
22
|
}
|
|
23
23
|
exports.default = Button;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TranspilerGenerator } from '../types/transpiler';
|
|
1
|
+
import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
|
|
2
2
|
import { Target } from '../types/config';
|
|
3
3
|
export declare const runTestsForJsx: () => void;
|
|
4
|
-
export declare const runTestsForTarget: <X>({ target, generator, options, }: {
|
|
4
|
+
export declare const runTestsForTarget: <X extends BaseTranspilerOptions>({ target, generator, options, }: {
|
|
5
5
|
target: Target;
|
|
6
6
|
generator: TranspilerGenerator<X, string>;
|
|
7
7
|
options: X;
|
|
@@ -13,65 +13,67 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.runTestsForTarget = exports.runTestsForJsx = void 0;
|
|
15
15
|
var jsx_1 = require("../parsers/jsx");
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
16
|
+
var getRawFile = function (path) { return require(path); };
|
|
17
|
+
var basicForShow = getRawFile('./data/basic-for-show.raw');
|
|
18
|
+
var basicOnMountUpdate = getRawFile('./data/basic-onMount-update.raw');
|
|
19
|
+
var basicContext = getRawFile('./data/basic-context.raw');
|
|
20
|
+
var basicOutputsMeta = getRawFile('./data/basic-outputs-meta.raw');
|
|
21
|
+
var basicOutputs = getRawFile('./data/basic-outputs.raw');
|
|
22
|
+
var subComponent = getRawFile('./data/sub-component.lite.jsx');
|
|
23
|
+
var basic = getRawFile('./data/basic.raw');
|
|
24
|
+
var basicMitosis = getRawFile('./data/basic-custom-mitosis-package.raw');
|
|
25
|
+
var basicChildComponent = getRawFile('./data/basic-child-component.raw');
|
|
26
|
+
var basicFor = getRawFile('./data/basic-for.raw');
|
|
27
|
+
var basicRef = getRawFile('./data/basic-ref.raw');
|
|
28
|
+
var basicForwardRef = getRawFile('./data/basic-forwardRef.raw');
|
|
29
|
+
var basicForwardRefMetadata = getRawFile('./data/basic-forwardRef-metadata.raw');
|
|
30
|
+
var basicRefPrevious = getRawFile('./data/basic-ref-usePrevious.raw');
|
|
31
|
+
var basicRefAssignment = getRawFile('./data/basic-ref-assignment.raw');
|
|
32
|
+
var propsDestructure = getRawFile('./data/basic-props-destructure.raw');
|
|
33
|
+
var nestedStyles = getRawFile('./data/nested-styles.lite');
|
|
34
|
+
var preserveExportOrLocalStatement = getRawFile('./data/basic-preserve-export-or-local-statement.raw');
|
|
35
|
+
var propsType = getRawFile('./data/types/component-props-type.raw');
|
|
36
|
+
var propsInterface = getRawFile('./data/types/component-props-interface.raw');
|
|
37
|
+
var preserveTyping = getRawFile('./data/types/preserve-typing.raw');
|
|
38
|
+
var typeDependency = getRawFile('./data/types/type-dependency.raw');
|
|
39
|
+
var defaultProps = getRawFile('./data/default-props/default-props.raw');
|
|
40
|
+
var classRaw = getRawFile('./data/styles/class.raw');
|
|
41
|
+
var className = getRawFile('./data/styles/className.raw');
|
|
42
|
+
var classAndClassName = getRawFile('./data/styles/class-and-className.raw');
|
|
43
|
+
var classState = getRawFile('./data/styles/classState.raw');
|
|
44
|
+
var button = getRawFile('./data/blocks/button.raw');
|
|
45
|
+
var classNameJsx = getRawFile('./data/blocks/classname-jsx.raw');
|
|
46
|
+
var columns = getRawFile('./data/blocks/columns.raw');
|
|
47
|
+
var contentSlotHtml = getRawFile('./data/blocks/content-slot-html.raw');
|
|
48
|
+
var contentSlotJsx = getRawFile('./data/blocks/content-slot-jsx.raw');
|
|
49
|
+
var customCode = getRawFile('./data/blocks/custom-code.raw');
|
|
50
|
+
var formBlock = getRawFile('./data/blocks/form.raw');
|
|
51
|
+
var image = getRawFile('./data/blocks/image.raw');
|
|
52
|
+
var imageState = getRawFile('./data/blocks/img-state.raw');
|
|
53
|
+
var img = getRawFile('./data/blocks/img.raw');
|
|
54
|
+
var inputBlock = getRawFile('./data/blocks/input.raw');
|
|
55
|
+
var multipleOnUpdate = getRawFile('./data/blocks/multiple-onUpdate.raw');
|
|
56
|
+
var multipleOnUpdateWithDeps = getRawFile('./data/blocks/multiple-onUpdateWithDeps.raw');
|
|
57
|
+
var onInit = getRawFile('./data/blocks/onInit.raw');
|
|
58
|
+
var onInitonMount = getRawFile('./data/blocks/onInit-onMount.raw');
|
|
59
|
+
var onMount = getRawFile('./data/blocks/onMount.raw');
|
|
60
|
+
var onUpdate = getRawFile('./data/blocks/onUpdate.raw');
|
|
61
|
+
var onUpdateWithDeps = getRawFile('./data/blocks/onUpdateWithDeps.raw');
|
|
62
|
+
var rawText = getRawFile('./data/blocks/raw-text.raw');
|
|
63
|
+
var section = getRawFile('./data/blocks/section.raw');
|
|
64
|
+
var sectionState = getRawFile('./data/blocks/section-state.raw');
|
|
65
|
+
var selectBlock = getRawFile('./data/blocks/select.raw');
|
|
66
|
+
var selfRefCompWChildren = getRawFile('./data/blocks/self-referencing-component-with-children.raw');
|
|
67
|
+
var selfRefComp = getRawFile('./data/blocks/self-referencing-component.raw');
|
|
68
|
+
var slotHtml = getRawFile('./data/blocks/slot-html.raw');
|
|
69
|
+
var slotJsx = getRawFile('./data/blocks/slot-jsx.raw');
|
|
70
|
+
var stamped = getRawFile('./data/blocks/stamped-io.raw');
|
|
71
|
+
var submitButtonBlock = getRawFile('./data/blocks/submit-button.raw');
|
|
72
|
+
var text = getRawFile('./data/blocks/text.raw');
|
|
73
|
+
var textarea = getRawFile('./data/blocks/textarea.raw');
|
|
74
|
+
var video = getRawFile('./data/blocks/video.raw');
|
|
75
|
+
var builderRenderContent = getRawFile('./data/blocks/builder-render-content.raw');
|
|
76
|
+
var rootFragmentMultiNode = getRawFile('./data/blocks/root-fragment-multi-node.raw');
|
|
75
77
|
var path = 'test-path';
|
|
76
78
|
var BASIC_TESTS = {
|
|
77
79
|
Basic: basic,
|
|
@@ -104,7 +106,7 @@ var BASIC_TESTS = {
|
|
|
104
106
|
defaultProps: defaultProps,
|
|
105
107
|
preserveTyping: preserveTyping,
|
|
106
108
|
typeDependency: typeDependency,
|
|
107
|
-
defaultValsWithTypes:
|
|
109
|
+
defaultValsWithTypes: getRawFile('./data/types/component-with-default-values-types.raw'),
|
|
108
110
|
'import types': builderRenderContent,
|
|
109
111
|
subComponent: subComponent,
|
|
110
112
|
nestedStyles: nestedStyles,
|
|
@@ -122,6 +124,7 @@ var BASIC_TESTS = {
|
|
|
122
124
|
'class + ClassName + css': classAndClassName,
|
|
123
125
|
'self-referencing component with children': selfRefCompWChildren,
|
|
124
126
|
'self-referencing component': selfRefComp,
|
|
127
|
+
rootFragmentMultiNode: rootFragmentMultiNode,
|
|
125
128
|
};
|
|
126
129
|
var SLOTS_TESTS = {
|
|
127
130
|
ContentSlotJSX: contentSlotJsx,
|
|
@@ -146,15 +149,15 @@ var FORWARD_REF_TESTS = {
|
|
|
146
149
|
basicForwardRefMetadata: basicForwardRefMetadata,
|
|
147
150
|
};
|
|
148
151
|
var SHOW_TESTS = {
|
|
149
|
-
rootShow:
|
|
150
|
-
nestedShow:
|
|
151
|
-
showWithFor:
|
|
152
|
+
rootShow: getRawFile('./data/blocks/rootShow.raw'),
|
|
153
|
+
nestedShow: getRawFile('./data/show/nested-show.raw'),
|
|
154
|
+
showWithFor: getRawFile('./data/show/show-with-for.raw'),
|
|
152
155
|
};
|
|
153
156
|
var ADVANCED_REF = {
|
|
154
|
-
AdvancedRef:
|
|
157
|
+
AdvancedRef: getRawFile('./data/advanced-ref.raw'),
|
|
155
158
|
};
|
|
156
159
|
var ON_UPDATE_RETURN = {
|
|
157
|
-
basicOnUpdateReturn:
|
|
160
|
+
basicOnUpdateReturn: getRawFile('./data/basic-onUpdate-return.raw'),
|
|
158
161
|
};
|
|
159
162
|
var JSX_TESTS = [
|
|
160
163
|
BASIC_TESTS,
|
|
@@ -346,14 +349,13 @@ var runTestsForTarget = function (_a) {
|
|
|
346
349
|
testsArray.forEach(function (tests) {
|
|
347
350
|
Object.keys(tests).forEach(function (key) {
|
|
348
351
|
test(key, function () {
|
|
352
|
+
var component = (0, jsx_1.parseJsx)(tests[key], { typescript: options.typescript });
|
|
353
|
+
var getOutput = function () { return generator(options)({ component: component, path: path }); };
|
|
349
354
|
try {
|
|
350
|
-
|
|
351
|
-
var output = generator(options)({ component: component, path: path });
|
|
352
|
-
expect(output).toMatchSnapshot();
|
|
355
|
+
expect(getOutput()).toMatchSnapshot();
|
|
353
356
|
}
|
|
354
357
|
catch (error) {
|
|
355
|
-
|
|
356
|
-
throw error;
|
|
358
|
+
expect(getOutput).toThrowErrorMatchingSnapshot();
|
|
357
359
|
}
|
|
358
360
|
});
|
|
359
361
|
});
|
|
@@ -52,14 +52,20 @@ var mappers = {
|
|
|
52
52
|
Slot: function (json, options, blockOptions) {
|
|
53
53
|
return "<ng-content ".concat(Object.keys(json.bindings)
|
|
54
54
|
.map(function (binding) {
|
|
55
|
-
var _a, _b
|
|
55
|
+
var _a, _b;
|
|
56
56
|
if (binding === 'name') {
|
|
57
57
|
var selector = (0, lodash_1.kebabCase)((_b = (_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.replace('props.slot', ''));
|
|
58
58
|
return "select=\"[".concat(selector, "]\"");
|
|
59
59
|
}
|
|
60
|
-
return "".concat((_c = json.bindings[binding]) === null || _c === void 0 ? void 0 : _c.code);
|
|
61
60
|
})
|
|
62
|
-
.join('\n'), "
|
|
61
|
+
.join('\n'), ">").concat(Object.keys(json.bindings)
|
|
62
|
+
.map(function (binding) {
|
|
63
|
+
var _a;
|
|
64
|
+
if (binding !== 'name') {
|
|
65
|
+
return "".concat((_a = json.bindings[binding]) === null || _a === void 0 ? void 0 : _a.code);
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
.join('\n'), "</ng-content>");
|
|
63
69
|
},
|
|
64
70
|
};
|
|
65
71
|
// TODO: Maybe in the future allow defining `string | function` as values
|
|
@@ -6,7 +6,7 @@ var contextToQwik = function (options) {
|
|
|
6
6
|
if (options === void 0) { options = {}; }
|
|
7
7
|
return function (_a) {
|
|
8
8
|
var context = _a.context;
|
|
9
|
-
var str = "\n import { createContext } from '@builder.io/qwik';\n\n export default createContext(\"".concat(context.name, "\")\n ");
|
|
9
|
+
var str = "\n import { createContext } from '@builder.io/qwik';\n\n export default createContext<any>(\"".concat(context.name, "\")\n ");
|
|
10
10
|
if (options.format !== false) {
|
|
11
11
|
try {
|
|
12
12
|
str = (0, standalone_1.format)(str, {
|
|
@@ -42,10 +42,11 @@ var componentToQwik = function (userOptions) {
|
|
|
42
42
|
if (userOptions.plugins) {
|
|
43
43
|
component = (0, plugins_1.runPostJsonPlugins)(component, userOptions.plugins);
|
|
44
44
|
}
|
|
45
|
-
var
|
|
45
|
+
var isTypeScript = !!userOptions.typescript;
|
|
46
|
+
var file = new src_generator_1.File(component.name + (isTypeScript ? '.ts' : '.js'), {
|
|
46
47
|
isPretty: true,
|
|
47
48
|
isJSX: true,
|
|
48
|
-
isTypeScript:
|
|
49
|
+
isTypeScript: isTypeScript,
|
|
49
50
|
isModule: true,
|
|
50
51
|
isBuilder: false,
|
|
51
52
|
}, '@builder.io/qwik', '');
|
|
@@ -60,7 +61,7 @@ var componentToQwik = function (userOptions) {
|
|
|
60
61
|
var state_2 = emitStateMethodsAndRewriteBindings(file, component, metadata);
|
|
61
62
|
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
62
63
|
var css_1 = null;
|
|
63
|
-
var
|
|
64
|
+
var componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
|
|
64
65
|
function () {
|
|
65
66
|
css_1 = emitUseStyles(file, component);
|
|
66
67
|
emitUseContext(file, component);
|
|
@@ -73,14 +74,19 @@ var componentToQwik = function (userOptions) {
|
|
|
73
74
|
emitTagNameHack(file, component);
|
|
74
75
|
emitJSX(file, component, mutable_1);
|
|
75
76
|
},
|
|
76
|
-
], [component.propsTypeRef || 'any']);
|
|
77
|
+
], [component.propsTypeRef + (isLightComponent ? '&{key?:any}' : '') || 'any']);
|
|
77
78
|
file.src.const(component.name, isLightComponent
|
|
78
|
-
?
|
|
79
|
-
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [
|
|
79
|
+
? componentFn
|
|
80
|
+
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentFn]), true, true);
|
|
80
81
|
file.exportDefault(component.name);
|
|
81
82
|
emitStyles(file, css_1);
|
|
82
83
|
DEBUG && file.exportConst('COMPONENT', (0, stable_serialize_1.stableJSONserialize)(component));
|
|
83
|
-
|
|
84
|
+
var sourceFile = '// GENERATED BY MITOSIS\n\n' + file.toString();
|
|
85
|
+
if (userOptions.plugins) {
|
|
86
|
+
sourceFile = (0, plugins_1.runPreCodePlugins)(sourceFile, userOptions.plugins);
|
|
87
|
+
sourceFile = (0, plugins_1.runPostCodePlugins)(sourceFile, userOptions.plugins);
|
|
88
|
+
}
|
|
89
|
+
return sourceFile;
|
|
84
90
|
}
|
|
85
91
|
catch (e) {
|
|
86
92
|
console.error(e);
|
|
@@ -199,13 +205,17 @@ function emitUseStore(file, stateInit) {
|
|
|
199
205
|
var state = stateInit[0];
|
|
200
206
|
var hasState = state && Object.keys(state).length > 0;
|
|
201
207
|
if (hasState) {
|
|
202
|
-
file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName
|
|
208
|
+
file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName);
|
|
209
|
+
if (file.options.isTypeScript) {
|
|
210
|
+
file.src.emit('<any>');
|
|
211
|
+
}
|
|
212
|
+
file.src.emit('(');
|
|
203
213
|
file.src.emit((0, stable_serialize_1.stableJSONserialize)(state));
|
|
204
214
|
file.src.emit(');');
|
|
205
215
|
}
|
|
206
216
|
else {
|
|
207
217
|
// TODO hack for now so that `state` variable is defined, even though it is never read.
|
|
208
|
-
file.src.emit('const state={};');
|
|
218
|
+
file.src.emit('const state={tagName:""' + (file.options.isTypeScript ? 'as any' : '') + '};');
|
|
209
219
|
}
|
|
210
220
|
}
|
|
211
221
|
function emitTypes(file, component) {
|
|
@@ -358,6 +358,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
358
358
|
if (value) {
|
|
359
359
|
if (key === 'innerHTML')
|
|
360
360
|
key = 'dangerouslySetInnerHTML';
|
|
361
|
+
if (key === 'dataSet')
|
|
362
|
+
return; // ignore
|
|
361
363
|
if (self.isJSX) {
|
|
362
364
|
self.emit(' ', key, '=');
|
|
363
365
|
if (typeof value == 'string' && value.startsWith('"') && value.endsWith('"')) {
|
|
@@ -108,7 +108,10 @@ function processBinding(code, _options, json, includeProps) {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
var NODE_MAPPERS = {
|
|
111
|
-
Fragment: function (json, options) {
|
|
111
|
+
Fragment: function (json, options, scope) {
|
|
112
|
+
if (options.vueVersion === 2 && (scope === null || scope === void 0 ? void 0 : scope.isRootNode)) {
|
|
113
|
+
throw new Error('Vue 2 template should have a single root element');
|
|
114
|
+
}
|
|
112
115
|
return json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
|
|
113
116
|
},
|
|
114
117
|
For: function (_json, options) {
|
|
@@ -133,12 +136,18 @@ var NODE_MAPPERS = {
|
|
|
133
136
|
var _a, _b, _c, _d, _e;
|
|
134
137
|
var _f, _g;
|
|
135
138
|
var ifValue = (0, slots_1.replaceSlotsInString)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code), function (slotName) { return "$slots.".concat(slotName); });
|
|
139
|
+
var defaultShowTemplate = "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat(encodeQuotes(ifValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat((0, is_mitosis_node_1.isMitosisNode)(json.meta.else)
|
|
140
|
+
? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
|
|
141
|
+
: '', "\n ");
|
|
136
142
|
switch (options.vueVersion) {
|
|
137
143
|
case 3:
|
|
138
|
-
return
|
|
139
|
-
? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
|
|
140
|
-
: '', "\n ");
|
|
144
|
+
return defaultShowTemplate;
|
|
141
145
|
case 2:
|
|
146
|
+
// if it is not the root node, the default show template can be used
|
|
147
|
+
// as Vue 2 only has this limitation at root level
|
|
148
|
+
if (!(scope === null || scope === void 0 ? void 0 : scope.isRootNode)) {
|
|
149
|
+
return defaultShowTemplate;
|
|
150
|
+
}
|
|
142
151
|
// Vue 2 can only handle one root element, so we just take the first one.
|
|
143
152
|
// TO-DO: warn user of multi-children Show.
|
|
144
153
|
var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
|
|
@@ -110,7 +110,7 @@ var renderImport = function (_a) {
|
|
|
110
110
|
console.warn('Vue: Async Component imports cannot include named imports. Dropping async import. This might break your code.');
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
return "const ".concat(importValue, " = () => import('").concat(path, "').then(x => x.default)");
|
|
113
|
+
return "const ".concat(importValue, " = () => import('").concat(path, "')\n .then(x => x.default)\n .catch(err => { \n console.error('Error while attempting to dynamically import component ").concat(importValue, " at ").concat(path, "', err);\n throw err;\n });");
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
return importValue ? "import ".concat(importValue, " from '").concat(path, "';") : "import '".concat(path, "';");
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.useDefaultProps = exports.useMetadata = exports.onError = exports.useDynamicTag = exports.onUnMount = exports.onInit = exports.onCreate = exports.onUpdate = exports.onMount = exports.setContext = exports.createContext = exports.useContext = exports.useRef = exports.useState = exports.useStore = void 0;
|
|
18
18
|
__exportStar(require("./flow"), exports);
|
|
19
19
|
// These compile away
|
|
20
|
-
var useStore = function (obj) {
|
|
20
|
+
var useStore = function (obj) {
|
|
21
|
+
throw new Error('useStore: Mitosis hook should have been compiled away');
|
|
22
|
+
return obj;
|
|
23
|
+
};
|
|
21
24
|
exports.useStore = useStore;
|
|
22
25
|
var useState = function (obj) {
|
|
23
26
|
throw new Error('useState: Mitosis hook should have been compiled away');
|
|
@@ -7,4 +7,4 @@ import { ParseMitosisOptions } from './types';
|
|
|
7
7
|
* @param jsx string representation of the Mitosis component
|
|
8
8
|
* @returns A JSON representation of the Mitosis component
|
|
9
9
|
*/
|
|
10
|
-
export declare function parseJsx(jsx: string,
|
|
10
|
+
export declare function parseJsx(jsx: string, _options?: Partial<ParseMitosisOptions>): MitosisComponent;
|
|
@@ -72,10 +72,10 @@ var beforeParse = function (path) {
|
|
|
72
72
|
* @param jsx string representation of the Mitosis component
|
|
73
73
|
* @returns A JSON representation of the Mitosis component
|
|
74
74
|
*/
|
|
75
|
-
function parseJsx(jsx,
|
|
76
|
-
if (
|
|
77
|
-
var useOptions = __assign({ format: 'react' }, options);
|
|
75
|
+
function parseJsx(jsx, _options) {
|
|
76
|
+
if (_options === void 0) { _options = {}; }
|
|
78
77
|
var subComponentFunctions = [];
|
|
78
|
+
var options = __assign({ typescript: false }, _options);
|
|
79
79
|
var output = babel.transform(jsx, {
|
|
80
80
|
configFile: false,
|
|
81
81
|
babelrc: false,
|
|
@@ -89,7 +89,8 @@ function parseJsx(jsx, options) {
|
|
|
89
89
|
// If left to its default `false`, then this will strip away:
|
|
90
90
|
// - unused JS imports
|
|
91
91
|
// - types imports within regular JS import syntax
|
|
92
|
-
|
|
92
|
+
// When outputting to TS, we must set it to `true` to preserve these imports.
|
|
93
|
+
onlyRemoveTypeImports: options.typescript,
|
|
93
94
|
},
|
|
94
95
|
],
|
|
95
96
|
],
|
|
@@ -118,7 +119,7 @@ function parseJsx(jsx, options) {
|
|
|
118
119
|
return !types.isExportDefaultDeclaration(node) && types.isFunctionDeclaration(node);
|
|
119
120
|
})
|
|
120
121
|
.map(function (node) { return "export default ".concat((0, generator_1.default)(node).code); });
|
|
121
|
-
var preComponentCode = (0, function_1.pipe)(path.node.body.filter(function (statement) { return !(0, helpers_1.isImportOrDefaultExport)(statement); }), function (statements) { return (0, metadata_1.collectMetadata)(statements, context.builder.component,
|
|
122
|
+
var preComponentCode = (0, function_1.pipe)(path.node.body.filter(function (statement) { return !(0, helpers_1.isImportOrDefaultExport)(statement); }), function (statements) { return (0, metadata_1.collectMetadata)(statements, context.builder.component, options); }, types.program, generator_1.default, function (generatorResult) { return generatorResult.code; });
|
|
122
123
|
// TODO: support multiple? e.g. for others to add imports?
|
|
123
124
|
context.builder.component.hooks.preComponent = { code: preComponentCode };
|
|
124
125
|
path.replaceWith(types.program(keepStatements));
|
|
@@ -171,7 +172,7 @@ function parseJsx(jsx, options) {
|
|
|
171
172
|
var parsed = (0, json_1.tryParseJson)(toParse);
|
|
172
173
|
(0, state_1.mapStateIdentifiers)(parsed);
|
|
173
174
|
(0, context_1.extractContextComponents)(parsed);
|
|
174
|
-
parsed.subComponents = subComponentFunctions.map(function (item) { return parseJsx(item,
|
|
175
|
+
parsed.subComponents = subComponentFunctions.map(function (item) { return parseJsx(item, options); });
|
|
175
176
|
return parsed;
|
|
176
177
|
}
|
|
177
178
|
exports.parseJsx = parseJsx;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
2
|
export declare type ParseMitosisOptions = {
|
|
3
|
-
format: 'react' | 'simple';
|
|
4
3
|
jsonHookNames?: string[];
|
|
5
4
|
compileAwayPackages?: string[];
|
|
5
|
+
typescript: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare type Context = {
|
|
8
8
|
builder: {
|
|
@@ -59,6 +59,11 @@ export declare type MitosisConfig = {
|
|
|
59
59
|
* Configure a custom parser function which takes a string and returns MitosisJSON
|
|
60
60
|
* Defaults to the JSXParser of this project (src/parsers/jsx)
|
|
61
61
|
*/
|
|
62
|
-
parser?: (code: string) => MitosisComponent;
|
|
62
|
+
parser?: (code: string, path?: string) => MitosisComponent;
|
|
63
|
+
/**
|
|
64
|
+
* Configure a custom function that provides the output path for each target.
|
|
65
|
+
* If you provide this function, you must provide a value for every target yourself.
|
|
66
|
+
*/
|
|
67
|
+
getTargetPath?: (target: Target) => string;
|
|
63
68
|
};
|
|
64
69
|
export {};
|