@builder.io/mitosis 0.4.0 → 0.4.2
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/constants/media-sizes.js +4 -5
- package/dist/src/generators/alpine/generate.js +114 -132
- package/dist/src/generators/alpine/render-mount-hook.js +8 -5
- package/dist/src/generators/alpine/render-update-hooks.js +13 -13
- package/dist/src/generators/angular/helpers.js +19 -9
- package/dist/src/generators/angular/index.js +599 -584
- package/dist/src/generators/builder.js +200 -165
- package/dist/src/generators/context/angular.js +32 -26
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +25 -21
- package/dist/src/generators/context/qwik.js +21 -21
- package/dist/src/generators/context/react.js +22 -22
- package/dist/src/generators/context/rsc.js +20 -22
- package/dist/src/generators/context/solid.js +22 -22
- package/dist/src/generators/context/svelte.js +33 -28
- package/dist/src/generators/context/vue.js +1 -1
- package/dist/src/generators/helpers/context.js +6 -13
- package/dist/src/generators/helpers/functions.js +8 -8
- package/dist/src/generators/helpers/on-mount.js +9 -5
- package/dist/src/generators/helpers/rsc.js +7 -9
- package/dist/src/generators/html.js +995 -534
- package/dist/src/generators/liquid.js +81 -79
- package/dist/src/generators/lit/collect-class-string.js +10 -12
- package/dist/src/generators/lit/generate.js +204 -159
- package/dist/src/generators/marko/generate.js +193 -183
- package/dist/src/generators/minify.js +5 -9
- package/dist/src/generators/mitosis.js +135 -134
- package/dist/src/generators/qwik/component-generator.js +159 -154
- package/dist/src/generators/qwik/component.js +51 -81
- package/dist/src/generators/qwik/directives.js +68 -84
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +6 -7
- package/dist/src/generators/qwik/helpers/convert-method-to-function.js +38 -38
- package/dist/src/generators/qwik/helpers/handlers.js +16 -25
- package/dist/src/generators/qwik/helpers/stable-inject.js +7 -8
- package/dist/src/generators/qwik/helpers/stable-serialize.js +7 -8
- package/dist/src/generators/qwik/helpers/state.js +36 -43
- package/dist/src/generators/qwik/helpers/styles.js +19 -40
- package/dist/src/generators/qwik/jsx.js +63 -75
- package/dist/src/generators/qwik/src-generator.js +134 -167
- package/dist/src/generators/react/blocks.js +122 -127
- package/dist/src/generators/react/generator.js +314 -259
- package/dist/src/generators/react/helpers.js +23 -28
- package/dist/src/generators/react/state.js +34 -51
- package/dist/src/generators/react-native/index.js +72 -84
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +14 -26
- package/dist/src/generators/rsc.js +30 -36
- package/dist/src/generators/solid/blocks.js +46 -43
- package/dist/src/generators/solid/helpers/styles.js +11 -11
- package/dist/src/generators/solid/index.js +199 -190
- package/dist/src/generators/solid/state/helpers.js +76 -90
- package/dist/src/generators/solid/state/signals.js +30 -37
- package/dist/src/generators/solid/state/state.js +35 -48
- package/dist/src/generators/solid/state/store.js +40 -46
- package/dist/src/generators/stencil/collect-class-string.js +10 -12
- package/dist/src/generators/stencil/generate.js +158 -145
- package/dist/src/generators/svelte/blocks.js +146 -144
- package/dist/src/generators/svelte/helpers.js +10 -17
- package/dist/src/generators/svelte/svelte.js +321 -287
- package/dist/src/generators/swift-ui.js +162 -101
- package/dist/src/generators/taro.js +32 -36
- package/dist/src/generators/template.js +71 -74
- package/dist/src/generators/vue/blocks.js +116 -107
- package/dist/src/generators/vue/compositionApi.js +67 -50
- package/dist/src/generators/vue/helpers.js +71 -96
- package/dist/src/generators/vue/optionsApi.js +134 -105
- package/dist/src/generators/vue/vue.js +210 -207
- package/dist/src/helpers/babel-transform.js +40 -63
- package/dist/src/helpers/bindings.js +4 -12
- package/dist/src/helpers/camel-case.js +4 -5
- package/dist/src/helpers/capitalize.js +1 -1
- package/dist/src/helpers/component-file-extensions.js +23 -35
- package/dist/src/helpers/create-mitosis-component.js +22 -26
- package/dist/src/helpers/create-mitosis-context.js +5 -12
- package/dist/src/helpers/create-mitosis-node.js +10 -12
- package/dist/src/helpers/dash-case.js +2 -2
- package/dist/src/helpers/dedent.js +18 -22
- package/dist/src/helpers/event-handlers.js +1 -1
- package/dist/src/helpers/fast-clone.js +1 -1
- package/dist/src/helpers/filter-empty-text-nodes.js +2 -2
- package/dist/src/helpers/generic-format.js +7 -8
- package/dist/src/helpers/get-bindings.js +4 -4
- package/dist/src/helpers/get-components-used.js +3 -3
- package/dist/src/helpers/get-components.js +4 -4
- package/dist/src/helpers/get-custom-imports.js +10 -12
- package/dist/src/helpers/get-prop-functions.js +7 -8
- package/dist/src/helpers/get-props-ref.js +8 -8
- package/dist/src/helpers/get-props.js +12 -13
- package/dist/src/helpers/get-refs.js +4 -4
- package/dist/src/helpers/get-state-object-string.js +42 -61
- package/dist/src/helpers/get-state-used.js +7 -8
- package/dist/src/helpers/get-styles.js +6 -6
- package/dist/src/helpers/getters-to-functions.js +8 -12
- package/dist/src/helpers/handle-missing-state.js +3 -3
- package/dist/src/helpers/has-bindings-text.js +6 -6
- package/dist/src/helpers/has-component.js +4 -4
- package/dist/src/helpers/has-props.js +3 -3
- package/dist/src/helpers/has-stateful-dom.js +4 -4
- package/dist/src/helpers/has.js +3 -3
- package/dist/src/helpers/indent.js +2 -3
- package/dist/src/helpers/is-children.js +4 -5
- package/dist/src/helpers/is-component.js +1 -1
- package/dist/src/helpers/is-html-attribute.js +2 -11
- package/dist/src/helpers/is-mitosis-node.js +1 -1
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/helpers/is-upper-case.js +1 -1
- package/dist/src/helpers/is-valid-attribute-name.js +1 -1
- package/dist/src/helpers/json.js +2 -2
- package/dist/src/helpers/map-refs.js +29 -40
- package/dist/src/helpers/merge-options.js +20 -31
- package/dist/src/helpers/mitosis-imports.js +5 -6
- package/dist/src/helpers/nodes/for.js +2 -3
- package/dist/src/helpers/nullable.js +1 -3
- package/dist/src/helpers/on-event.js +32 -36
- package/dist/src/helpers/output.js +4 -5
- package/dist/src/helpers/parse-node.js +13 -5
- package/dist/src/helpers/parsers.js +10 -14
- package/dist/src/helpers/patterns.js +6 -8
- package/dist/src/helpers/plugins/process-code/index.js +114 -120
- package/dist/src/helpers/plugins/process-signals.js +114 -125
- package/dist/src/helpers/plugins/process-target-blocks.js +18 -20
- package/dist/src/helpers/process-http-requests.js +8 -4
- package/dist/src/helpers/remove-surrounding-block.js +2 -2
- package/dist/src/helpers/render-imports.js +99 -111
- package/dist/src/helpers/replace-identifiers.js +40 -49
- package/dist/src/helpers/replace-new-lines-in-strings.js +3 -3
- package/dist/src/helpers/signals/signals.js +27 -35
- package/dist/src/helpers/slots.js +11 -20
- package/dist/src/helpers/state.js +1 -3
- package/dist/src/helpers/strip-meta-properties.js +6 -6
- package/dist/src/helpers/strip-state-and-props-refs.js +21 -32
- package/dist/src/helpers/styles/collect-css.js +39 -44
- package/dist/src/helpers/styles/collect-styled-components.js +30 -28
- package/dist/src/helpers/styles/helpers.js +23 -29
- package/dist/src/helpers/trace-reference-to-module-path.js +3 -4
- package/dist/src/helpers/transform-state-setters.js +16 -19
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +3 -3
- package/dist/src/helpers/typescript-project.js +25 -25
- package/dist/src/helpers/typescript.js +1 -3
- package/dist/src/modules/plugins.js +20 -28
- package/dist/src/parsers/angular.js +49 -57
- package/dist/src/parsers/builder/builder.js +448 -343
- package/dist/src/parsers/builder/helpers.js +10 -10
- package/dist/src/parsers/context.js +15 -17
- package/dist/src/parsers/jsx/ast.js +11 -11
- package/dist/src/parsers/jsx/component-types.js +22 -32
- package/dist/src/parsers/jsx/context.js +12 -12
- package/dist/src/parsers/jsx/element-parser.js +43 -54
- package/dist/src/parsers/jsx/exports.js +12 -14
- package/dist/src/parsers/jsx/function-parser.js +108 -119
- package/dist/src/parsers/jsx/helpers.js +11 -13
- package/dist/src/parsers/jsx/hooks/helpers.js +14 -16
- package/dist/src/parsers/jsx/hooks/index.js +34 -44
- package/dist/src/parsers/jsx/hooks/use-target.js +27 -27
- package/dist/src/parsers/jsx/imports.js +7 -17
- package/dist/src/parsers/jsx/jsx.js +92 -91
- package/dist/src/parsers/jsx/props-types.js +8 -10
- package/dist/src/parsers/jsx/props.js +15 -23
- package/dist/src/parsers/jsx/signals.js +28 -29
- package/dist/src/parsers/jsx/state.d.ts +2 -4
- package/dist/src/parsers/jsx/state.js +59 -93
- package/dist/src/parsers/svelte/css/index.js +1 -1
- package/dist/src/parsers/svelte/helpers/bindings.js +18 -19
- package/dist/src/parsers/svelte/helpers/children.js +5 -6
- package/dist/src/parsers/svelte/helpers/expressions.js +7 -9
- package/dist/src/parsers/svelte/helpers/hooks.js +2 -2
- package/dist/src/parsers/svelte/helpers/post-process.js +49 -70
- package/dist/src/parsers/svelte/helpers/string.js +5 -5
- package/dist/src/parsers/svelte/html/actions.js +17 -10
- package/dist/src/parsers/svelte/html/each.js +11 -16
- package/dist/src/parsers/svelte/html/element.js +68 -78
- package/dist/src/parsers/svelte/html/fragment.js +3 -3
- package/dist/src/parsers/svelte/html/if-else.js +11 -18
- package/dist/src/parsers/svelte/html/index.js +14 -14
- package/dist/src/parsers/svelte/html/mustache-tag.js +5 -5
- package/dist/src/parsers/svelte/html/slot.js +5 -5
- package/dist/src/parsers/svelte/html/text.js +7 -14
- package/dist/src/parsers/svelte/index.js +23 -72
- package/dist/src/parsers/svelte/instance/context.js +17 -17
- package/dist/src/parsers/svelte/instance/expressions.js +2 -2
- package/dist/src/parsers/svelte/instance/functions.js +35 -30
- package/dist/src/parsers/svelte/instance/hooks.js +4 -5
- package/dist/src/parsers/svelte/instance/imports.js +11 -21
- package/dist/src/parsers/svelte/instance/index.js +22 -22
- package/dist/src/parsers/svelte/instance/properties.js +11 -23
- package/dist/src/parsers/svelte/instance/reactive.js +11 -11
- package/dist/src/parsers/svelte/instance/references.js +13 -13
- package/dist/src/parsers/svelte/instance/statements.js +3 -3
- package/dist/src/parsers/svelte/module/index.js +14 -26
- package/dist/src/parsers/svelte/typescript/index.js +27 -36
- package/dist/src/plugins/compile-away-builder-components.js +223 -156
- package/dist/src/plugins/compile-away-components.js +13 -21
- package/dist/src/plugins/map-styles.js +7 -7
- package/dist/src/symbols/symbol-processor.js +44 -62
- package/dist/src/targets.js +19 -19
- package/dist/src/types/mitosis-node.js +1 -1
- package/package.json +1 -1
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentToQwik = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
5
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
6
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
7
|
+
const on_event_1 = require("../../helpers/on-event");
|
|
8
|
+
const process_code_1 = require("../../helpers/plugins/process-code");
|
|
9
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
10
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
11
|
+
const state_1 = require("../../helpers/state");
|
|
12
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
13
|
+
const standalone_1 = require("prettier/standalone");
|
|
14
|
+
const plugins_1 = require("../../modules/plugins");
|
|
15
|
+
const add_prevent_default_1 = require("./helpers/add-prevent-default");
|
|
16
|
+
const stable_inject_1 = require("./helpers/stable-inject");
|
|
17
|
+
const state_2 = require("./helpers/state");
|
|
18
|
+
const jsx_1 = require("./jsx");
|
|
19
|
+
const src_generator_1 = require("./src-generator");
|
|
20
20
|
Error.stackTraceLimit = 9999;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const DEBUG = false;
|
|
22
|
+
const PLUGINS = [
|
|
23
|
+
() => ({
|
|
24
24
|
json: {
|
|
25
|
-
post:
|
|
25
|
+
post: (json) => {
|
|
26
26
|
(0, add_prevent_default_1.addPreventDefault)(json);
|
|
27
27
|
return json;
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
|
-
})
|
|
30
|
+
}),
|
|
31
31
|
(0, on_event_1.processOnEventHooksPlugin)({ setBindings: false, includeRootEvents: false }),
|
|
32
|
-
(0, process_code_1.CODE_PROCESSOR_PLUGIN)(
|
|
32
|
+
(0, process_code_1.CODE_PROCESSOR_PLUGIN)((codeType, json) => {
|
|
33
33
|
switch (codeType) {
|
|
34
34
|
case 'types':
|
|
35
|
-
return
|
|
35
|
+
return (c) => c;
|
|
36
36
|
case 'bindings':
|
|
37
37
|
case 'state':
|
|
38
38
|
case 'context-set':
|
|
@@ -41,142 +41,138 @@ var PLUGINS = [
|
|
|
41
41
|
case 'properties':
|
|
42
42
|
case 'dynamic-jsx-elements':
|
|
43
43
|
// update signal getters to have `.value`
|
|
44
|
-
return
|
|
44
|
+
return (code, k) => {
|
|
45
45
|
// `ref` should not update the signal value access
|
|
46
46
|
if (k === 'ref') {
|
|
47
47
|
return code;
|
|
48
48
|
}
|
|
49
|
-
Object.keys(json.refs).forEach(
|
|
49
|
+
Object.keys(json.refs).forEach((ref) => {
|
|
50
50
|
code = (0, replace_identifiers_1.replaceIdentifiers)({
|
|
51
|
-
code
|
|
51
|
+
code,
|
|
52
52
|
from: ref,
|
|
53
|
-
to:
|
|
53
|
+
to: (x) => (x === ref ? `${x}.value` : `${ref}.value.${x}`),
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
// update signal getters to have `.value`
|
|
57
|
-
return (0, replace_identifiers_1.replaceStateIdentifier)(
|
|
58
|
-
|
|
57
|
+
return (0, replace_identifiers_1.replaceStateIdentifier)((name) => {
|
|
58
|
+
const state = json.state[name];
|
|
59
59
|
switch (state === null || state === void 0 ? void 0 : state.type) {
|
|
60
60
|
case 'getter':
|
|
61
|
-
return
|
|
61
|
+
return `${name}.value`;
|
|
62
62
|
case 'function':
|
|
63
63
|
case 'method':
|
|
64
64
|
case 'property':
|
|
65
65
|
case undefined:
|
|
66
|
-
return
|
|
66
|
+
return `state.${name}`;
|
|
67
67
|
}
|
|
68
68
|
})(code);
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
}),
|
|
72
72
|
];
|
|
73
|
-
|
|
73
|
+
const DEFAULT_OPTIONS = {
|
|
74
74
|
plugins: PLUGINS,
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
const componentToQwik = (userOptions = {}) => ({ component: _component, path }) => {
|
|
77
|
+
var _a, _b, _c, _d;
|
|
78
|
+
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
79
|
+
let component = (0, fast_clone_1.fastClone)(_component);
|
|
80
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
81
|
+
target: 'qwik',
|
|
82
|
+
component,
|
|
83
|
+
defaults: DEFAULT_OPTIONS,
|
|
84
|
+
userOptions: userOptions,
|
|
85
|
+
});
|
|
86
|
+
component = (0, plugins_1.runPreJsonPlugins)({ json: component, plugins: options.plugins });
|
|
87
|
+
component = (0, plugins_1.runPostJsonPlugins)({ json: component, plugins: options.plugins });
|
|
88
|
+
const isTypeScript = !!options.typescript;
|
|
89
|
+
const file = new src_generator_1.File(component.name + (isTypeScript ? '.ts' : '.js'), {
|
|
90
|
+
isPretty: true,
|
|
91
|
+
isJSX: true,
|
|
92
|
+
isTypeScript: isTypeScript,
|
|
93
|
+
isModule: true,
|
|
94
|
+
isBuilder: false,
|
|
95
|
+
}, '@builder.io/qwik', '');
|
|
96
|
+
try {
|
|
97
|
+
emitImports(file, component);
|
|
98
|
+
emitTypes(file, component);
|
|
99
|
+
emitExports(file, component);
|
|
100
|
+
const metadata = component.meta.useMetadata;
|
|
101
|
+
const isLightComponent = ((_b = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.isLight) || false;
|
|
102
|
+
const mutable = ((_c = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _c === void 0 ? void 0 : _c.mutable) || [];
|
|
103
|
+
const imports = ((_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.imports) || {};
|
|
104
|
+
Object.keys(imports).forEach((key) => file.import(imports[key], key));
|
|
105
|
+
const state = (0, state_2.emitStateMethodsAndRewriteBindings)(file, component, metadata);
|
|
106
|
+
const hasState = (0, state_1.checkHasState)(component);
|
|
107
|
+
let css = null;
|
|
108
|
+
const emitStore = () => { var _a; return hasState && (0, state_2.emitUseStore)({ file, stateInit: state, isDeep: (_a = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _a === void 0 ? void 0 : _a.hasDeepStore }); };
|
|
109
|
+
const componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
|
|
110
|
+
function () {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _a === void 0 ? void 0 : _a.setUseStoreFirst)
|
|
113
|
+
emitStore();
|
|
114
|
+
css = emitUseStyles(file, component);
|
|
115
|
+
emitUseComputed(file, component);
|
|
116
|
+
emitUseContext(file, component);
|
|
117
|
+
emitUseRef(file, component);
|
|
118
|
+
if (!((_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.setUseStoreFirst))
|
|
119
|
+
emitStore();
|
|
120
|
+
emitUseOn(file, component);
|
|
121
|
+
emitUseContextProvider(file, component);
|
|
122
|
+
emitUseClientEffect(file, component);
|
|
123
|
+
emitUseMount(file, component);
|
|
124
|
+
emitUseTask(file, component);
|
|
125
|
+
emitJSX(file, component, mutable);
|
|
126
|
+
},
|
|
127
|
+
], [(component.propsTypeRef || 'any') + (isLightComponent ? '&{key?:any}' : '')]);
|
|
128
|
+
file.src.const(component.name, isLightComponent
|
|
129
|
+
? componentFn
|
|
130
|
+
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentFn]), true, true);
|
|
131
|
+
file.exportDefault(component.name);
|
|
132
|
+
emitStyles(file, css);
|
|
133
|
+
DEBUG && file.exportConst('COMPONENT', JSON.stringify(component));
|
|
134
|
+
let sourceFile = file.toString();
|
|
135
|
+
sourceFile = (0, plugins_1.runPreCodePlugins)({
|
|
136
|
+
json: component,
|
|
137
|
+
code: sourceFile,
|
|
138
|
+
plugins: options.plugins,
|
|
88
139
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
emitImports(file, component);
|
|
101
|
-
emitTypes(file, component);
|
|
102
|
-
emitExports(file, component);
|
|
103
|
-
var metadata_1 = component.meta.useMetadata;
|
|
104
|
-
var isLightComponent = ((_c = (_b = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
|
|
105
|
-
var mutable_1 = ((_d = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
|
|
106
|
-
var imports_1 = ((_e = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _e === void 0 ? void 0 : _e.imports) || {};
|
|
107
|
-
Object.keys(imports_1).forEach(function (key) { return file.import(imports_1[key], key); });
|
|
108
|
-
var state_3 = (0, state_2.emitStateMethodsAndRewriteBindings)(file, component, metadata_1);
|
|
109
|
-
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
110
|
-
var css_1 = null;
|
|
111
|
-
var emitStore_1 = function () { var _a; return hasState_1 && (0, state_2.emitUseStore)({ file: file, stateInit: state_3, isDeep: (_a = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _a === void 0 ? void 0 : _a.hasDeepStore }); };
|
|
112
|
-
var componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
|
|
113
|
-
function () {
|
|
114
|
-
var _a, _b;
|
|
115
|
-
if ((_a = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _a === void 0 ? void 0 : _a.setUseStoreFirst)
|
|
116
|
-
emitStore_1();
|
|
117
|
-
css_1 = emitUseStyles(file, component);
|
|
118
|
-
emitUseComputed(file, component);
|
|
119
|
-
emitUseContext(file, component);
|
|
120
|
-
emitUseRef(file, component);
|
|
121
|
-
if (!((_b = metadata_1 === null || metadata_1 === void 0 ? void 0 : metadata_1.qwik) === null || _b === void 0 ? void 0 : _b.setUseStoreFirst))
|
|
122
|
-
emitStore_1();
|
|
123
|
-
emitUseOn(file, component);
|
|
124
|
-
emitUseContextProvider(file, component);
|
|
125
|
-
emitUseClientEffect(file, component);
|
|
126
|
-
emitUseMount(file, component);
|
|
127
|
-
emitUseTask(file, component);
|
|
128
|
-
emitJSX(file, component, mutable_1);
|
|
129
|
-
},
|
|
130
|
-
], [(component.propsTypeRef || 'any') + (isLightComponent ? '&{key?:any}' : '')]);
|
|
131
|
-
file.src.const(component.name, isLightComponent
|
|
132
|
-
? componentFn
|
|
133
|
-
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentFn]), true, true);
|
|
134
|
-
file.exportDefault(component.name);
|
|
135
|
-
emitStyles(file, css_1);
|
|
136
|
-
DEBUG && file.exportConst('COMPONENT', JSON.stringify(component));
|
|
137
|
-
var sourceFile = file.toString();
|
|
138
|
-
sourceFile = (0, plugins_1.runPreCodePlugins)({
|
|
139
|
-
json: component,
|
|
140
|
-
code: sourceFile,
|
|
141
|
-
plugins: options.plugins,
|
|
142
|
-
});
|
|
143
|
-
sourceFile = (0, plugins_1.runPostCodePlugins)({
|
|
144
|
-
json: component,
|
|
145
|
-
code: sourceFile,
|
|
146
|
-
plugins: options.plugins,
|
|
147
|
-
});
|
|
148
|
-
return sourceFile;
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
console.error(e);
|
|
152
|
-
throw e;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
140
|
+
sourceFile = (0, plugins_1.runPostCodePlugins)({
|
|
141
|
+
json: component,
|
|
142
|
+
code: sourceFile,
|
|
143
|
+
plugins: options.plugins,
|
|
144
|
+
});
|
|
145
|
+
return sourceFile;
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
console.error(e);
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
155
151
|
};
|
|
156
152
|
exports.componentToQwik = componentToQwik;
|
|
157
153
|
function emitExports(file, component) {
|
|
158
|
-
Object.keys(component.exports || {}).forEach(
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
Object.keys(component.exports || {}).forEach((key) => {
|
|
155
|
+
const exportObj = component.exports[key];
|
|
156
|
+
const code = exportObj.code.startsWith('export ') ? exportObj.code : `export ${exportObj.code}`;
|
|
161
157
|
file.src.emit(code);
|
|
162
158
|
});
|
|
163
159
|
}
|
|
164
160
|
function emitUseClientEffect(file, component) {
|
|
165
|
-
component.hooks.onMount.forEach(
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
component.hooks.onMount.forEach((onMount) => {
|
|
162
|
+
const code = onMount.code;
|
|
163
|
+
const hookToUse = onMount.onSSR ? 'useTask$' : 'useVisibleTask$';
|
|
168
164
|
file.src.emit(file.import(file.qwikModule, hookToUse).localName, '(()=>{', code, '});');
|
|
169
165
|
});
|
|
170
166
|
}
|
|
171
167
|
function emitUseMount(file, component) {
|
|
172
168
|
if (component.hooks.onInit) {
|
|
173
|
-
|
|
169
|
+
const code = component.hooks.onInit.code;
|
|
174
170
|
file.src.emit(file.import(file.qwikModule, 'useTask$').localName, '(()=>{', code, '});');
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
function emitUseTask(file, component) {
|
|
178
174
|
if (component.hooks.onUpdate) {
|
|
179
|
-
component.hooks.onUpdate.forEach(
|
|
175
|
+
component.hooks.onUpdate.forEach((onUpdate) => {
|
|
180
176
|
file.src.emit(file.import(file.qwikModule, 'useTask$').localName, '(({track})=>{');
|
|
181
177
|
emitTrackExpressions(file.src, onUpdate.deps);
|
|
182
178
|
file.src.emit((0, babel_transform_1.convertTypeScriptToJS)(onUpdate.code));
|
|
@@ -188,36 +184,36 @@ function emitTrackExpressions(src, deps) {
|
|
|
188
184
|
if (!deps) {
|
|
189
185
|
return;
|
|
190
186
|
}
|
|
191
|
-
|
|
192
|
-
dependencies.forEach(
|
|
193
|
-
src.emit(
|
|
187
|
+
const dependencies = deps.substring(1, deps.length - 1).split(',');
|
|
188
|
+
dependencies.forEach((dep) => {
|
|
189
|
+
src.emit(`track(() => ${dep});`);
|
|
194
190
|
});
|
|
195
191
|
}
|
|
196
192
|
function emitJSX(file, component, mutable) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
193
|
+
const directives = new Map();
|
|
194
|
+
const handlers = new Map();
|
|
195
|
+
const styles = new Map();
|
|
196
|
+
const parentSymbolBindings = {};
|
|
201
197
|
if (file.options.isPretty) {
|
|
202
198
|
file.src.emit('\n\n');
|
|
203
199
|
}
|
|
204
200
|
file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, null, parentSymbolBindings));
|
|
205
201
|
}
|
|
206
202
|
function emitUseContextProvider(file, component) {
|
|
207
|
-
Object.entries(component.context.set).forEach(
|
|
208
|
-
|
|
209
|
-
file.src.emit("".concat(file.import(file.qwikModule, 'useContextProvider').localName, "(").concat(context.name, ", "));
|
|
203
|
+
Object.entries(component.context.set).forEach(([_ctxKey, context]) => {
|
|
204
|
+
file.src.emit(`${file.import(file.qwikModule, 'useContextProvider').localName}(${context.name}, `);
|
|
210
205
|
if (context.ref) {
|
|
211
|
-
file.src.emit(
|
|
206
|
+
file.src.emit(`${context.ref}`);
|
|
212
207
|
}
|
|
213
208
|
else {
|
|
214
|
-
file.src.emit(
|
|
215
|
-
for (
|
|
216
|
-
|
|
217
|
-
file.src.emit("".concat(prop, ": "));
|
|
209
|
+
file.src.emit(`${file.import(file.qwikModule, 'useStore').localName}({`);
|
|
210
|
+
for (const [prop, propValue] of Object.entries(context.value || {})) {
|
|
211
|
+
file.src.emit(`${prop}: `);
|
|
218
212
|
switch (propValue === null || propValue === void 0 ? void 0 : propValue.type) {
|
|
219
213
|
case 'getter':
|
|
220
|
-
file.src.emit(
|
|
214
|
+
file.src.emit(`(()=>{
|
|
215
|
+
${extractGetterBody(propValue.code)}
|
|
216
|
+
})()`);
|
|
221
217
|
break;
|
|
222
218
|
case 'function':
|
|
223
219
|
case 'method':
|
|
@@ -234,30 +230,36 @@ function emitUseContextProvider(file, component) {
|
|
|
234
230
|
});
|
|
235
231
|
}
|
|
236
232
|
function emitUseContext(file, component) {
|
|
237
|
-
Object.keys(component.context.get).forEach(
|
|
238
|
-
|
|
233
|
+
Object.keys(component.context.get).forEach((ctxKey) => {
|
|
234
|
+
const context = component.context.get[ctxKey];
|
|
239
235
|
file.src.emit('const ', ctxKey, '=', file.import(file.qwikModule, 'useContext').localName, '(', context.name, ');');
|
|
240
236
|
});
|
|
241
237
|
}
|
|
242
238
|
function emitUseOn(file, component) {
|
|
243
|
-
component.hooks.onEvent.forEach(
|
|
244
|
-
|
|
239
|
+
component.hooks.onEvent.forEach((hook) => {
|
|
240
|
+
const eventName = `"${hook.eventName}"`;
|
|
245
241
|
if (hook.isRoot) {
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
const wrappedHandlerFn = `${file.import(file.qwikModule, '$').localName}((${hook.eventArgName}, ${hook.elementArgName}) => {
|
|
243
|
+
${hook.code}
|
|
244
|
+
}) as Parameters<typeof useOn>[1]`; // this type hack is needed until https://github.com/BuilderIO/qwik/issues/5398 is fixed
|
|
245
|
+
file.src.emit(file.import(file.qwikModule, 'useOn').localName, `(${eventName}, ${wrappedHandlerFn});`);
|
|
248
246
|
}
|
|
249
247
|
else {
|
|
250
|
-
file.src.emit(file.import(file.qwikModule, 'useVisibleTask$').localName,
|
|
248
|
+
file.src.emit(file.import(file.qwikModule, 'useVisibleTask$').localName, `(() => {
|
|
249
|
+
${hook.refName}.value?.addEventListener(${eventName}, ${(0, on_event_1.getOnEventHandlerName)(hook)});
|
|
250
|
+
return () => ${hook.refName}.value?.removeEventListener(${eventName}, ${(0, on_event_1.getOnEventHandlerName)(hook)});
|
|
251
|
+
})
|
|
252
|
+
`);
|
|
251
253
|
}
|
|
252
254
|
});
|
|
253
255
|
}
|
|
254
256
|
function emitUseRef(file, component) {
|
|
255
|
-
Object.keys(component.refs).forEach(
|
|
256
|
-
file.src.emit(
|
|
257
|
+
Object.keys(component.refs).forEach((refKey) => {
|
|
258
|
+
file.src.emit(`const `, refKey, '=', file.import(file.qwikModule, 'useSignal').localName, `${file.options.isTypeScript ? '<Element>' : ''}();`);
|
|
257
259
|
});
|
|
258
260
|
}
|
|
259
261
|
function emitUseStyles(file, component) {
|
|
260
|
-
|
|
262
|
+
const css = (0, collect_css_1.collectCss)(component, { prefix: component.name });
|
|
261
263
|
if (css) {
|
|
262
264
|
file.src.emit(file.import(file.qwikModule, 'useStylesScoped$').localName, '(STYLES);');
|
|
263
265
|
if (file.options.isPretty) {
|
|
@@ -294,37 +296,40 @@ function emitStyles(file, css) {
|
|
|
294
296
|
function emitTypes(file, component) {
|
|
295
297
|
var _a;
|
|
296
298
|
if (file.options.isTypeScript) {
|
|
297
|
-
(_a = component.types) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
299
|
+
(_a = component.types) === null || _a === void 0 ? void 0 : _a.forEach((t) => file.src.emit(t, '\n'));
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
302
|
function emitImports(file, component) {
|
|
301
303
|
var _a;
|
|
302
304
|
// <SELF> is used for self-referencing within the file.
|
|
303
305
|
file.import('<SELF>', component.name);
|
|
304
|
-
(_a = component.imports) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
305
|
-
|
|
306
|
+
(_a = component.imports) === null || _a === void 0 ? void 0 : _a.forEach((i) => {
|
|
307
|
+
const importPath = (0, render_imports_1.transformImportPath)({
|
|
306
308
|
target: 'qwik',
|
|
307
309
|
theImport: i,
|
|
308
310
|
preserveFileExtensions: false,
|
|
309
311
|
explicitImportFileExtension: false,
|
|
310
312
|
});
|
|
311
|
-
Object.keys(i.imports).forEach(
|
|
312
|
-
|
|
313
|
+
Object.keys(i.imports).forEach((key) => {
|
|
314
|
+
const keyValue = i.imports[key];
|
|
313
315
|
file.import(importPath, keyValue, key);
|
|
314
316
|
});
|
|
315
317
|
});
|
|
316
318
|
}
|
|
317
319
|
function extractGetterBody(code) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
const start = code.indexOf('{');
|
|
321
|
+
const end = code.lastIndexOf('}');
|
|
320
322
|
return code.substring(start + 1, end).trim();
|
|
321
323
|
}
|
|
322
324
|
function emitUseComputed(file, component) {
|
|
323
|
-
for (
|
|
324
|
-
var _b = _a[_i], key = _b[0], stateValue = _b[1];
|
|
325
|
+
for (const [key, stateValue] of Object.entries(component.state)) {
|
|
325
326
|
switch (stateValue === null || stateValue === void 0 ? void 0 : stateValue.type) {
|
|
326
327
|
case 'getter':
|
|
327
|
-
file.src.const(
|
|
328
|
+
file.src.const(`
|
|
329
|
+
${key} = ${file.import(file.qwikModule, 'useComputed$').localName}(() => {
|
|
330
|
+
${extractGetterBody(stateValue.code)}
|
|
331
|
+
})
|
|
332
|
+
`);
|
|
328
333
|
continue;
|
|
329
334
|
}
|
|
330
335
|
}
|