@builder.io/mitosis 0.0.56-99 → 0.0.56
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/content-slot-jsx.raw.jsx +4 -1
- package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +5 -1
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +3 -3
- package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
- package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
- package/dist/src/__tests__/shared.d.ts +7 -2
- package/dist/src/__tests__/shared.js +66 -9
- package/dist/src/constants/method-literal-prefix.d.ts +0 -1
- package/dist/src/constants/method-literal-prefix.js +0 -3
- package/dist/src/generators/angular.d.ts +2 -2
- package/dist/src/generators/angular.js +5 -3
- package/dist/src/generators/builder.d.ts +4 -11
- package/dist/src/generators/builder.js +3 -2
- package/dist/src/generators/context/svelte.d.ts +3 -0
- package/dist/src/generators/context/svelte.js +3 -0
- package/dist/src/generators/helpers/functions.d.ts +2 -0
- package/dist/src/generators/helpers/functions.js +28 -0
- package/dist/src/generators/html.d.ts +3 -3
- package/dist/src/generators/html.js +9 -7
- package/dist/src/generators/liquid.d.ts +2 -2
- package/dist/src/generators/liquid.js +4 -4
- package/dist/src/generators/lit/generate.d.ts +2 -2
- package/dist/src/generators/lit/generate.js +3 -2
- package/dist/src/generators/marko/generate.d.ts +2 -2
- package/dist/src/generators/marko/generate.js +10 -8
- package/dist/src/generators/mitosis.d.ts +3 -4
- package/dist/src/generators/mitosis.js +3 -2
- package/dist/src/generators/qwik/component-generator.d.ts +2 -2
- package/dist/src/generators/qwik/component-generator.js +49 -55
- package/dist/src/generators/qwik/component.d.ts +0 -1
- package/dist/src/generators/qwik/component.js +22 -19
- package/dist/src/generators/qwik/directives.d.ts +1 -0
- package/dist/src/generators/qwik/directives.js +11 -14
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +9 -5
- package/dist/src/generators/qwik/src-generator.js +9 -3
- package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
- package/dist/src/generators/qwik/stable-serialize.js +51 -0
- package/dist/src/generators/react/generator.d.ts +6 -0
- package/dist/src/generators/{react.js → react/generator.js} +58 -150
- package/dist/src/generators/react/helpers.d.ts +2 -0
- package/dist/src/generators/react/helpers.js +14 -0
- package/dist/src/generators/react/index.d.ts +2 -0
- package/dist/src/generators/react/index.js +18 -0
- package/dist/src/generators/react/state.d.ts +9 -0
- package/dist/src/generators/react/state.js +107 -0
- package/dist/src/generators/react/types.d.ts +10 -0
- package/dist/src/generators/react/types.js +2 -0
- package/dist/src/generators/react-native.d.ts +2 -2
- package/dist/src/generators/solid/index.d.ts +3 -0
- package/dist/src/generators/{solid.js → solid/index.js} +80 -40
- package/dist/src/generators/solid/state.d.ts +19 -0
- package/dist/src/generators/solid/state.js +144 -0
- package/dist/src/generators/solid/types.d.ts +6 -0
- package/dist/src/generators/solid/types.js +2 -0
- package/dist/src/generators/stencil/generate.d.ts +2 -2
- package/dist/src/generators/stencil/generate.js +5 -2
- package/dist/src/generators/svelte.d.ts +6 -7
- package/dist/src/generators/svelte.js +43 -40
- package/dist/src/generators/swift-ui.d.ts +3 -5
- package/dist/src/generators/swift-ui.js +3 -2
- package/dist/src/generators/template.d.ts +2 -2
- package/dist/src/generators/template.js +3 -2
- package/dist/src/generators/vue.d.ts +5 -3
- package/dist/src/generators/vue.js +256 -113
- package/dist/src/helpers/babel-transform.d.ts +3 -1
- package/dist/src/helpers/babel-transform.js +52 -56
- package/dist/src/helpers/get-bindings.js +3 -5
- package/dist/src/helpers/get-state-object-string.js +24 -21
- package/dist/src/helpers/getters-to-functions.js +1 -11
- package/dist/src/helpers/map-refs.js +25 -25
- package/dist/src/helpers/nodes/for.d.ts +4 -0
- package/dist/src/helpers/nodes/for.js +13 -0
- package/dist/src/helpers/nullable.d.ts +2 -0
- package/dist/src/helpers/nullable.js +7 -0
- package/dist/src/helpers/parse-reactive-script.js +66 -78
- package/dist/src/helpers/patterns.d.ts +2 -0
- package/dist/src/helpers/patterns.js +5 -1
- package/dist/src/helpers/render-imports.js +3 -3
- package/dist/src/helpers/replace-identifiers.d.ts +5 -0
- package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
- package/dist/src/helpers/slots.d.ts +2 -0
- package/dist/src/helpers/slots.js +15 -1
- package/dist/src/helpers/state.d.ts +0 -2
- package/dist/src/helpers/state.js +1 -10
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +43 -31
- package/dist/src/helpers/styles/helpers.d.ts +3 -2
- package/dist/src/parsers/angular.js +2 -2
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/builder.js +61 -43
- package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
- package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/helpers/state.d.ts +3 -0
- package/dist/src/parsers/helpers/state.js +30 -0
- package/dist/src/parsers/jsx/component-types.d.ts +1 -1
- package/dist/src/parsers/jsx/component-types.js +15 -2
- package/dist/src/parsers/jsx/context.js +1 -1
- package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
- package/dist/src/parsers/jsx/element-parser.js +243 -0
- package/dist/src/parsers/jsx/exports.d.ts +3 -0
- package/dist/src/parsers/jsx/exports.js +78 -0
- package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
- package/dist/src/parsers/jsx/function-parser.js +291 -0
- package/dist/src/parsers/jsx/helpers.d.ts +2 -0
- package/dist/src/parsers/jsx/helpers.js +30 -1
- package/dist/src/parsers/jsx/imports.d.ts +7 -0
- package/dist/src/parsers/jsx/imports.js +65 -0
- package/dist/src/parsers/jsx/index.d.ts +1 -1
- package/dist/src/parsers/jsx/index.js +1 -2
- package/dist/src/parsers/jsx/jsx.js +29 -516
- package/dist/src/parsers/jsx/state.d.ts +2 -3
- package/dist/src/parsers/jsx/state.js +15 -22
- package/dist/src/plugins/compile-away-builder-components.js +6 -0
- package/dist/src/symbols/symbol-processor.js +3 -0
- package/dist/src/targets.d.ts +21 -28
- package/dist/src/targets.js +2 -2
- package/dist/src/types/config.d.ts +11 -1
- package/dist/src/types/mitosis-component.d.ts +12 -6
- package/dist/src/types/mitosis-component.js +11 -0
- package/dist/src/types/mitosis-context.d.ts +2 -2
- package/dist/src/types/mitosis-node.d.ts +14 -5
- package/dist/src/types/mitosis-node.js +3 -0
- package/dist/src/types/transpiler.d.ts +6 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -9
- package/dist/src/__tests__/angular.test.d.ts +0 -1
- package/dist/src/__tests__/angular.test.js +0 -10
- package/dist/src/__tests__/builder.test.d.ts +0 -1
- package/dist/src/__tests__/builder.test.js +0 -235
- package/dist/src/__tests__/context.test.d.ts +0 -1
- package/dist/src/__tests__/context.test.js +0 -35
- package/dist/src/__tests__/hash-code.test.d.ts +0 -1
- package/dist/src/__tests__/hash-code.test.js +0 -11
- package/dist/src/__tests__/html.test.d.ts +0 -1
- package/dist/src/__tests__/html.test.js +0 -7
- package/dist/src/__tests__/liquid.test.d.ts +0 -1
- package/dist/src/__tests__/liquid.test.js +0 -7
- package/dist/src/__tests__/lit.test.d.ts +0 -1
- package/dist/src/__tests__/lit.test.js +0 -7
- package/dist/src/__tests__/marko.test.d.ts +0 -1
- package/dist/src/__tests__/marko.test.js +0 -14
- package/dist/src/__tests__/parse-jsx.test.d.ts +0 -1
- package/dist/src/__tests__/parse-jsx.test.js +0 -37
- package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/convert-method-to-function.test.js +0 -37
- package/dist/src/__tests__/qwik/src-generator.test.d.ts +0 -1
- package/dist/src/__tests__/qwik/src-generator.test.js +0 -65
- package/dist/src/__tests__/qwik.directive.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.directive.test.js +0 -108
- package/dist/src/__tests__/qwik.test.d.ts +0 -1
- package/dist/src/__tests__/qwik.test.js +0 -465
- package/dist/src/__tests__/react-native.test.d.ts +0 -1
- package/dist/src/__tests__/react-native.test.js +0 -7
- package/dist/src/__tests__/react.test.d.ts +0 -1
- package/dist/src/__tests__/react.test.js +0 -20
- package/dist/src/__tests__/solid.test.d.ts +0 -1
- package/dist/src/__tests__/solid.test.js +0 -10
- package/dist/src/__tests__/stencil.test.d.ts +0 -1
- package/dist/src/__tests__/stencil.test.js +0 -7
- package/dist/src/__tests__/styles.test.d.ts +0 -1
- package/dist/src/__tests__/styles.test.js +0 -23
- package/dist/src/__tests__/svelte.test.d.ts +0 -1
- package/dist/src/__tests__/svelte.test.js +0 -7
- package/dist/src/__tests__/vue.test.d.ts +0 -1
- package/dist/src/__tests__/vue.test.js +0 -7
- package/dist/src/__tests__/webcomponent.test.d.ts +0 -1
- package/dist/src/__tests__/webcomponent.test.js +0 -15
- package/dist/src/constants/function-literal-prefix.d.ts +0 -1
- package/dist/src/constants/function-literal-prefix.js +0 -4
- package/dist/src/generators/react.d.ts +0 -14
- package/dist/src/generators/solid.d.ts +0 -5
- package/dist/src/helpers/babel-transform.test.d.ts +0 -1
- package/dist/src/helpers/babel-transform.test.js +0 -7
- package/dist/src/helpers/generic-format.test.d.ts +0 -1
- package/dist/src/helpers/generic-format.test.js +0 -8
- package/dist/src/helpers/remove-surrounding-block.test.d.ts +0 -1
- package/dist/src/helpers/remove-surrounding-block.test.js +0 -9
- package/dist/src/helpers/render-imports.test.d.ts +0 -1
- package/dist/src/helpers/render-imports.test.js +0 -33
- package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.d.ts +0 -1
- package/dist/src/helpers/styles/collect-css.test.js +0 -18
- package/dist/test/qwik/Accordion/high.jsx +0 -0
- package/dist/test/qwik/Accordion/low.jsx +0 -240
- package/dist/test/qwik/Accordion/med.jsx +0 -4
- package/dist/test/qwik/For/high.jsx +0 -0
- package/dist/test/qwik/For/low.jsx +0 -52
- package/dist/test/qwik/For/med.jsx +0 -4
- package/dist/test/qwik/Image/high.js +0 -9
- package/dist/test/qwik/Image/low.js +0 -0
- package/dist/test/qwik/Image/med.js +0 -155
- package/dist/test/qwik/Image.slow/high.js +0 -9
- package/dist/test/qwik/Image.slow/low.js +0 -0
- package/dist/test/qwik/Image.slow/med.js +0 -155
- package/dist/test/qwik/bindings/high.cjs +0 -0
- package/dist/test/qwik/bindings/low.cjs +0 -45
- package/dist/test/qwik/bindings/med.cjs +0 -3
- package/dist/test/qwik/button/high.js +0 -3
- package/dist/test/qwik/button/low.js +0 -25
- package/dist/test/qwik/button/med.js +0 -31
- package/dist/test/qwik/component/bindings/high.jsx +0 -0
- package/dist/test/qwik/component/bindings/low.jsx +0 -104
- package/dist/test/qwik/component/bindings/med.jsx +0 -7
- package/dist/test/qwik/component/component/inputs/high.cjsx +0 -9
- package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
- package/dist/test/qwik/component/component/inputs/med.cjsx +0 -68
- package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
- package/dist/test/qwik/for-loop.bindings/low.cjs +0 -56
- package/dist/test/qwik/for-loop.bindings/med.cjs +0 -5
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +0 -26
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +0 -4
- package/dist/test/qwik/mount/high.cjs +0 -0
- package/dist/test/qwik/mount/low.cjs +0 -47
- package/dist/test/qwik/mount/med.cjs +0 -3
- package/dist/test/qwik/page-with-symbol/high.js +0 -0
- package/dist/test/qwik/page-with-symbol/low.js +0 -33
- package/dist/test/qwik/page-with-symbol/med.js +0 -4
- package/dist/test/qwik/show-hide/high.jsx +0 -9
- package/dist/test/qwik/show-hide/low.jsx +0 -0
- package/dist/test/qwik/show-hide/med.jsx +0 -181
- package/dist/test/qwik/svg/high.js +0 -0
- package/dist/test/qwik/svg/low.js +0 -30
- package/dist/test/qwik/svg/med.js +0 -4
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +0 -19
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +0 -51
- package/dist/test/qwik/todo/Todo.js/high.js +0 -19
- package/dist/test/qwik/todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/todo/Todo.js/med.js +0 -47
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +0 -19
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +0 -43
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -7
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +0 -32
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +0 -4
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -8,24 +8,30 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
8
8
|
}
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.componentToQwik = void 0;
|
|
13
16
|
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
14
17
|
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
15
18
|
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
19
|
+
var mitosis_component_1 = require("../../types/mitosis-component");
|
|
16
20
|
var state_1 = require("../../helpers/state");
|
|
17
21
|
var add_prevent_default_1 = require("./add-prevent-default");
|
|
18
22
|
var convert_method_to_function_1 = require("./convert-method-to-function");
|
|
19
23
|
var jsx_1 = require("./jsx");
|
|
20
24
|
var src_generator_1 = require("./src-generator");
|
|
21
25
|
var plugins_1 = require("../../modules/plugins");
|
|
26
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
27
|
+
var stable_serialize_1 = require("./stable-serialize");
|
|
22
28
|
Error.stackTraceLimit = 9999;
|
|
23
29
|
// TODO(misko): styles are not processed.
|
|
24
30
|
var DEBUG = false;
|
|
25
31
|
var componentToQwik = function (userOptions) {
|
|
26
32
|
if (userOptions === void 0) { userOptions = {}; }
|
|
27
33
|
return function (_a) {
|
|
28
|
-
var _b, _c, _d;
|
|
34
|
+
var _b, _c, _d, _e;
|
|
29
35
|
var _component = _a.component, path = _a.path;
|
|
30
36
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
31
37
|
var component = (0, fast_clone_1.fastClone)(_component);
|
|
@@ -48,7 +54,8 @@ var componentToQwik = function (userOptions) {
|
|
|
48
54
|
emitTypes(file, component);
|
|
49
55
|
var metadata = component.meta.useMetadata || {};
|
|
50
56
|
var isLightComponent = ((_c = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
|
|
51
|
-
var
|
|
57
|
+
var mutable_1 = ((_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
|
|
58
|
+
var imports_1 = (_e = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _e === void 0 ? void 0 : _e.imports;
|
|
52
59
|
imports_1 && Object.keys(imports_1).forEach(function (key) { return file.import(imports_1[key], key); });
|
|
53
60
|
var state_2 = emitStateMethodsAndRewriteBindings(file, component, metadata);
|
|
54
61
|
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
@@ -64,7 +71,7 @@ var componentToQwik = function (userOptions) {
|
|
|
64
71
|
emitUseWatch(file, component);
|
|
65
72
|
emitUseCleanup(file, component);
|
|
66
73
|
emitTagNameHack(file, component);
|
|
67
|
-
emitJSX(file, component);
|
|
74
|
+
emitJSX(file, component, mutable_1);
|
|
68
75
|
},
|
|
69
76
|
], [component.propsTypeRef || 'any']);
|
|
70
77
|
file.src.const(component.name, isLightComponent
|
|
@@ -72,7 +79,7 @@ var componentToQwik = function (userOptions) {
|
|
|
72
79
|
: (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentBody]), true, true);
|
|
73
80
|
file.exportDefault(component.name);
|
|
74
81
|
emitStyles(file, css_1);
|
|
75
|
-
DEBUG && file.exportConst('COMPONENT',
|
|
82
|
+
DEBUG && file.exportConst('COMPONENT', (0, stable_serialize_1.stableJSONserialize)(component));
|
|
76
83
|
return '// GENERATED BY MITOSIS\n\n' + file.toString();
|
|
77
84
|
}
|
|
78
85
|
catch (e) {
|
|
@@ -126,12 +133,19 @@ function emitUseCleanup(file, component) {
|
|
|
126
133
|
file.src.emit(file.import(file.qwikModule, 'useCleanup$').localName, '(()=>{', code, '});');
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
|
-
function emitJSX(file, component) {
|
|
136
|
+
function emitJSX(file, component, mutable) {
|
|
130
137
|
var directives = new Map();
|
|
131
138
|
var handlers = new Map();
|
|
132
139
|
var styles = new Map();
|
|
133
140
|
var parentSymbolBindings = {};
|
|
134
|
-
|
|
141
|
+
var mutablePredicate = mutable.length > 0
|
|
142
|
+
? function (code) {
|
|
143
|
+
return !!mutable.find(function (txt) {
|
|
144
|
+
return code.indexOf(txt) !== -1;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
: undefined;
|
|
148
|
+
file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings, mutablePredicate));
|
|
135
149
|
}
|
|
136
150
|
function emitUseContextProvider(file, component) {
|
|
137
151
|
Object.keys(component.context.set).forEach(function (ctxKey) {
|
|
@@ -141,14 +155,14 @@ function emitUseContextProvider(file, component) {
|
|
|
141
155
|
Object.keys(context.value).forEach(function (prop) {
|
|
142
156
|
var propValue = context.value[prop];
|
|
143
157
|
file.src.emit(prop, ':');
|
|
144
|
-
if (
|
|
145
|
-
file.src.emit('(()=>{', extractGetterBody(propValue), '})(),');
|
|
158
|
+
if ((propValue === null || propValue === void 0 ? void 0 : propValue.type) === 'getter') {
|
|
159
|
+
file.src.emit('(()=>{', extractGetterBody(propValue.code), '})(),');
|
|
146
160
|
}
|
|
147
161
|
else if (typeof propValue == 'function') {
|
|
148
162
|
throw new Error('Qwik: Functions are not supported in context');
|
|
149
163
|
}
|
|
150
164
|
else {
|
|
151
|
-
file.src.emit(
|
|
165
|
+
file.src.emit((0, stable_serialize_1.stableJSONserialize)(propValue));
|
|
152
166
|
}
|
|
153
167
|
});
|
|
154
168
|
file.src.emit('})', ');');
|
|
@@ -186,7 +200,7 @@ function emitUseStore(file, stateInit) {
|
|
|
186
200
|
var hasState = state && Object.keys(state).length > 0;
|
|
187
201
|
if (hasState) {
|
|
188
202
|
file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName, '(');
|
|
189
|
-
file.src.emit(
|
|
203
|
+
file.src.emit((0, stable_serialize_1.stableJSONserialize)(state));
|
|
190
204
|
file.src.emit(');');
|
|
191
205
|
}
|
|
192
206
|
else {
|
|
@@ -208,26 +222,21 @@ function emitStateMethodsAndRewriteBindings(file, component, metadata) {
|
|
|
208
222
|
rewriteCodeExpr(component, methodMap, lexicalArgs, (_a = metadata.qwik) === null || _a === void 0 ? void 0 : _a.replace);
|
|
209
223
|
return state;
|
|
210
224
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (typeof value == 'string') {
|
|
220
|
-
if (value.startsWith(CODE_PREFIX) || key == 'code') {
|
|
221
|
-
var code_1 = (0, convert_method_to_function_1.convertMethodToFunction)(value, methodMap, lexicalArgs);
|
|
222
|
-
replace &&
|
|
223
|
-
Object.keys(replace).forEach(function (key) { return (code_1 = code_1.replace(key, replace[key])); });
|
|
224
|
-
obj[key] = code_1;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
rewriteCodeExpr(value, methodMap, lexicalArgs, replace);
|
|
228
|
-
});
|
|
225
|
+
var checkIsObjectWithCodeBlock = function (obj) {
|
|
226
|
+
return typeof obj == 'object' && (obj === null || obj === void 0 ? void 0 : obj.code) && typeof obj.code === 'string';
|
|
227
|
+
};
|
|
228
|
+
function rewriteCodeExpr(component, methodMap, lexicalArgs, replace) {
|
|
229
|
+
if (replace === void 0) { replace = {}; }
|
|
230
|
+
(0, traverse_1.default)(component).forEach(function (item) {
|
|
231
|
+
if (!((0, mitosis_component_1.checkIsCodeValue)(item) || checkIsObjectWithCodeBlock(item))) {
|
|
232
|
+
return;
|
|
229
233
|
}
|
|
230
|
-
|
|
234
|
+
var code = (0, convert_method_to_function_1.convertMethodToFunction)(item.code, methodMap, lexicalArgs);
|
|
235
|
+
Object.keys(replace).forEach(function (key) {
|
|
236
|
+
code = code.replace(key, replace[key]);
|
|
237
|
+
});
|
|
238
|
+
item.code = code;
|
|
239
|
+
});
|
|
231
240
|
}
|
|
232
241
|
function getLexicalScopeVars(component) {
|
|
233
242
|
return __spreadArray(__spreadArray(['props', 'state'], Object.keys(component.refs), true), Object.keys(component.context.get), true);
|
|
@@ -243,30 +252,25 @@ function emitImports(file, component) {
|
|
|
243
252
|
});
|
|
244
253
|
});
|
|
245
254
|
}
|
|
246
|
-
var CODE_PREFIX = '@builder.io/mitosis/';
|
|
247
|
-
var FUNCTION = CODE_PREFIX + 'function:';
|
|
248
|
-
var METHOD = CODE_PREFIX + 'method:';
|
|
249
|
-
var GETTER = CODE_PREFIX + 'method:get ';
|
|
250
255
|
function emitStateMethods(file, componentState, lexicalArgs) {
|
|
251
256
|
var stateValues = {};
|
|
252
257
|
var stateInit = [stateValues];
|
|
253
258
|
var methodMap = stateToMethodOrGetter(componentState);
|
|
254
259
|
Object.keys(componentState).forEach(function (key) {
|
|
255
|
-
var
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
if (codeIisGetter) {
|
|
260
|
+
var stateValue = componentState[key];
|
|
261
|
+
if ((0, mitosis_component_1.checkIsCodeValue)(stateValue)) {
|
|
262
|
+
var code = stateValue.code;
|
|
263
|
+
var prefixIdx = 0;
|
|
264
|
+
if (stateValue.type === 'getter') {
|
|
261
265
|
prefixIdx += 'get '.length;
|
|
262
266
|
}
|
|
263
|
-
else if (
|
|
267
|
+
else if (stateValue.type === 'function') {
|
|
264
268
|
prefixIdx += 'function '.length;
|
|
265
269
|
}
|
|
266
270
|
code = code.substring(prefixIdx);
|
|
267
271
|
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', "(".concat(lexicalArgs.join(','), ","));
|
|
268
272
|
var functionName = code.split(/\(/)[0];
|
|
269
|
-
if (
|
|
273
|
+
if (stateValue.type === 'getter') {
|
|
270
274
|
stateInit.push("state.".concat(key, "=").concat(functionName, "(").concat(lexicalArgs.join(','), ")"));
|
|
271
275
|
}
|
|
272
276
|
if (!file.options.isTypeScript) {
|
|
@@ -276,7 +280,7 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
276
280
|
file.exportConst(functionName, 'function ' + code, true);
|
|
277
281
|
}
|
|
278
282
|
else {
|
|
279
|
-
stateValues[key] = code;
|
|
283
|
+
stateValues[key] = stateValue === null || stateValue === void 0 ? void 0 : stateValue.code;
|
|
280
284
|
}
|
|
281
285
|
});
|
|
282
286
|
return stateInit;
|
|
@@ -284,15 +288,6 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
284
288
|
function convertTypeScriptToJS(code) {
|
|
285
289
|
return (0, babel_transform_1.babelTransformExpression)(code, {});
|
|
286
290
|
}
|
|
287
|
-
function isGetter(code) {
|
|
288
|
-
return typeof code === 'string' && code.startsWith(GETTER);
|
|
289
|
-
}
|
|
290
|
-
function isCode(code) {
|
|
291
|
-
return typeof code === 'string' && code.startsWith(CODE_PREFIX);
|
|
292
|
-
}
|
|
293
|
-
function isFunction(code) {
|
|
294
|
-
return typeof code === 'string' && code.startsWith(FUNCTION);
|
|
295
|
-
}
|
|
296
291
|
function extractGetterBody(code) {
|
|
297
292
|
var start = code.indexOf('{');
|
|
298
293
|
var end = code.lastIndexOf('}');
|
|
@@ -301,10 +296,9 @@ function extractGetterBody(code) {
|
|
|
301
296
|
function stateToMethodOrGetter(state) {
|
|
302
297
|
var methodMap = {};
|
|
303
298
|
Object.keys(state).forEach(function (key) {
|
|
304
|
-
var
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
methodMap[key] = code.startsWith(GETTER) ? 'getter' : 'method';
|
|
299
|
+
var stateVal = state[key];
|
|
300
|
+
if ((stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'getter' || (stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'method') {
|
|
301
|
+
methodMap[key] = stateVal.type;
|
|
308
302
|
}
|
|
309
303
|
});
|
|
310
304
|
return methodMap;
|
|
@@ -16,7 +16,6 @@ export declare function createFileSet(options?: QwikOptions): FileSet;
|
|
|
16
16
|
export declare function addComponent(fileSet: FileSet, component: MitosisComponent, opts?: {
|
|
17
17
|
isRoot?: boolean;
|
|
18
18
|
shareStyles?: boolean;
|
|
19
|
-
hostProps?: Record<string, string>;
|
|
20
19
|
}): void;
|
|
21
20
|
export declare function renderUseLexicalScope(file: File): (this: SrcBuilder) => SrcBuilder;
|
|
22
21
|
export declare function addCommonStyles(fileSet: FileSet): void;
|
|
@@ -21,11 +21,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.addCommonStyles = exports.renderUseLexicalScope = exports.addComponent = exports.createFileSet = void 0;
|
|
24
|
-
var create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
25
24
|
var compile_away_builder_components_1 = require("../../plugins/compile-away-builder-components");
|
|
26
25
|
var handlers_1 = require("./handlers");
|
|
27
26
|
var jsx_1 = require("./jsx");
|
|
28
27
|
var src_generator_1 = require("./src-generator");
|
|
28
|
+
var stable_serialize_1 = require("./stable-serialize");
|
|
29
29
|
var styles_1 = require("./styles");
|
|
30
30
|
function createFileSet(options) {
|
|
31
31
|
if (options === void 0) { options = {}; }
|
|
@@ -43,7 +43,7 @@ function createFileSet(options) {
|
|
|
43
43
|
med: new src_generator_1.File('med.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
44
44
|
low: new src_generator_1.File('low.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
45
45
|
};
|
|
46
|
-
Object.defineProperty(fileSet, '
|
|
46
|
+
Object.defineProperty(fileSet, 'CommonStyles', {
|
|
47
47
|
enumerable: false,
|
|
48
48
|
value: { styles: new Map(), symbolName: null },
|
|
49
49
|
});
|
|
@@ -51,11 +51,11 @@ function createFileSet(options) {
|
|
|
51
51
|
}
|
|
52
52
|
exports.createFileSet = createFileSet;
|
|
53
53
|
function getCommonStyles(fileSet) {
|
|
54
|
-
return fileSet['
|
|
54
|
+
return fileSet['CommonStyles'];
|
|
55
55
|
}
|
|
56
56
|
function addComponent(fileSet, component, opts) {
|
|
57
57
|
if (opts === void 0) { opts = {}; }
|
|
58
|
-
var _opts = __assign({ isRoot: false, shareStyles: false
|
|
58
|
+
var _opts = __assign({ isRoot: false, shareStyles: false }, opts);
|
|
59
59
|
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), {
|
|
60
60
|
// A set of components that should not be compiled away because they are implemented as runtime components.
|
|
61
61
|
Image: undefined, CoreButton: undefined }));
|
|
@@ -74,32 +74,33 @@ function addComponent(fileSet, component, opts) {
|
|
|
74
74
|
if (styles.size) {
|
|
75
75
|
if (_opts.shareStyles) {
|
|
76
76
|
if (_opts.isRoot) {
|
|
77
|
-
var symbolName = componentName + '
|
|
77
|
+
var symbolName = componentName + 'Styles';
|
|
78
78
|
getCommonStyles(fileSet).symbolName = symbolName;
|
|
79
79
|
useStyles = generateStyles(onRenderFile, fileSet.low, symbolName, false);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
var symbolName = componentName + '
|
|
83
|
+
var symbolName = componentName + 'Styles';
|
|
84
84
|
onRenderFile.exportConst(symbolName, (0, styles_1.renderStyles)(styles));
|
|
85
85
|
useStyles = generateStyles(onRenderFile, onRenderFile, symbolName, true);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
if (component.meta.cssCode) {
|
|
89
|
+
var symbolName = componentName + 'UsrStyles';
|
|
90
|
+
onRenderFile.exportConst(symbolName, (0, stable_serialize_1.stableJSONserialize)(component.meta.cssCode));
|
|
91
|
+
useStyles = (function (fns) {
|
|
92
|
+
return function () {
|
|
93
|
+
var _this = this;
|
|
94
|
+
fns.forEach(function (fn) { return fn.apply(_this); });
|
|
95
|
+
};
|
|
96
|
+
})([useStyles, generateStyles(onRenderFile, onRenderFile, symbolName, false)]);
|
|
97
|
+
}
|
|
88
98
|
var directives = new Map();
|
|
89
99
|
var rootChildren = component.children;
|
|
90
|
-
if (_opts.hostProps) {
|
|
91
|
-
rootChildren = [
|
|
92
|
-
(0, create_mitosis_node_1.createMitosisNode)({
|
|
93
|
-
name: 'Host',
|
|
94
|
-
properties: _opts.hostProps,
|
|
95
|
-
children: component.children,
|
|
96
|
-
}),
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
100
|
addComponentOnMount(onRenderFile, function () {
|
|
100
101
|
return this.emit('return ', (0, jsx_1.renderJSXNodes)(onRenderFile, directives, handlers, rootChildren, styles, {}), ';');
|
|
101
102
|
}, componentName, component, useStyles);
|
|
102
|
-
componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, onRenderFile, componentName + '
|
|
103
|
+
componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, onRenderFile, componentName + 'OnMount')], ['any', 'any']));
|
|
103
104
|
directives.forEach(function (code, name) {
|
|
104
105
|
fileSet.med.import(fileSet.med.qwikModule, 'h');
|
|
105
106
|
fileSet.med.exportConst(name, code, true);
|
|
@@ -108,7 +109,9 @@ function addComponent(fileSet, component, opts) {
|
|
|
108
109
|
exports.addComponent = addComponent;
|
|
109
110
|
function generateStyles(fromFile, dstFile, symbol, scoped) {
|
|
110
111
|
return function () {
|
|
111
|
-
this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? '
|
|
112
|
+
this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? 'useStylesScopedQrl' : 'useStylesQrl'), [
|
|
113
|
+
generateQrl(fromFile, dstFile, symbol),
|
|
114
|
+
]), ';');
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
function addBuilderBlockClass(children) {
|
|
@@ -138,10 +141,10 @@ function addComponentOnMount(componentFile, onRenderEmit, componentName, compone
|
|
|
138
141
|
if (component.inputs) {
|
|
139
142
|
component.inputs.forEach(function (input) {
|
|
140
143
|
input.defaultValue !== undefined &&
|
|
141
|
-
inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=',
|
|
144
|
+
inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=', (0, stable_serialize_1.stableJSONserialize)(input.defaultValue), ';');
|
|
142
145
|
});
|
|
143
146
|
}
|
|
144
|
-
componentFile.exportConst(componentName + '
|
|
147
|
+
componentFile.exportConst(componentName + 'OnMount', function () {
|
|
145
148
|
var _this = this;
|
|
146
149
|
this.emit((0, src_generator_1.arrowFnValue)(['props'], function () {
|
|
147
150
|
var _a;
|
|
@@ -18,6 +18,7 @@ interface ImageProps {
|
|
|
18
18
|
lazy?: boolean;
|
|
19
19
|
class?: string;
|
|
20
20
|
children?: any[];
|
|
21
|
+
noWebp?: boolean;
|
|
21
22
|
}
|
|
22
23
|
export declare function Image(props: ImageProps): any;
|
|
23
24
|
export declare function __passThroughProps__(dstProps: Record<string, any>, srcProps: Record<string, any>): Record<string, any>;
|
|
@@ -5,6 +5,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.CoreButton = exports.__passThroughProps__ = exports.Image = exports.DIRECTIVES = void 0;
|
|
8
|
+
var for_1 = require("../../helpers/nodes/for");
|
|
8
9
|
var minify_1 = require("../minify");
|
|
9
10
|
var src_generator_1 = require("./src-generator");
|
|
10
11
|
exports.DIRECTIVES = {
|
|
@@ -27,32 +28,28 @@ exports.DIRECTIVES = {
|
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
30
|
},
|
|
30
|
-
For: function (
|
|
31
|
+
For: function (_node, blockFn) {
|
|
31
32
|
return function () {
|
|
32
33
|
var _this = this;
|
|
33
34
|
var _a;
|
|
35
|
+
var node = _node;
|
|
34
36
|
var expr = (_a = node.bindings.each) === null || _a === void 0 ? void 0 : _a.code;
|
|
35
37
|
this.jsxExpression(function () {
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
_this.emit('(', expr, '||[]).map('
|
|
38
|
+
var forArgs = (0, for_1.getForArguments)(node);
|
|
39
|
+
var forName = forArgs[0];
|
|
40
|
+
_this.emit('(', expr, '||[]).map(');
|
|
41
|
+
_this.isBuilder && _this.emit('(('), _this.emit('function(', forArgs, '){');
|
|
39
42
|
if (_this.isBuilder) {
|
|
40
43
|
_this.emit('var state=Object.assign({},this,{', (0, src_generator_1.iteratorProperty)(expr), ':', forName, '==null?{}:', forName, '});');
|
|
41
44
|
}
|
|
42
45
|
_this.emit('return(');
|
|
43
46
|
blockFn();
|
|
44
|
-
_this.emit(');}
|
|
47
|
+
_this.emit(');}');
|
|
48
|
+
_this.isBuilder && _this.emit(').bind(state))');
|
|
49
|
+
_this.emit(')');
|
|
45
50
|
});
|
|
46
51
|
};
|
|
47
52
|
},
|
|
48
|
-
Host: function (node, blockFn) {
|
|
49
|
-
return function () {
|
|
50
|
-
var host = this.file.import(this.file.qwikModule, 'Host').localName;
|
|
51
|
-
this.jsxBegin(host, node.properties, node.bindings);
|
|
52
|
-
blockFn();
|
|
53
|
-
this.jsxEnd(host);
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
53
|
Image: (0, minify_1.minify)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), Image),
|
|
57
54
|
CoreButton: (0, minify_1.minify)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), CoreButton),
|
|
58
55
|
__passThroughProps__: (0, minify_1.minify)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["", ""], ["", ""])), __passThroughProps__),
|
|
@@ -62,7 +59,7 @@ function Image(props) {
|
|
|
62
59
|
var jsx = props.children || [];
|
|
63
60
|
var image = props.image;
|
|
64
61
|
if (image) {
|
|
65
|
-
var isBuilderIoImage = !!(image || '').match(/\.builder\.io/);
|
|
62
|
+
var isBuilderIoImage = !!(image || '').match(/\.builder\.io/) && !props.noWebp;
|
|
66
63
|
var isPixel = (_a = props.builderBlock) === null || _a === void 0 ? void 0 : _a.id.startsWith('builder-pixel-');
|
|
67
64
|
var imgProps = {
|
|
68
65
|
src: props.image,
|
|
@@ -13,4 +13,4 @@ import { CssStyles } from './styles';
|
|
|
13
13
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, root?: boolean): any;
|
|
16
|
+
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, mutablePredicate?: (code: string) => boolean, root?: boolean): any;
|
|
@@ -36,7 +36,7 @@ var src_generator_1 = require("./src-generator");
|
|
|
36
36
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
37
37
|
* @returns
|
|
38
38
|
*/
|
|
39
|
-
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, root) {
|
|
39
|
+
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, mutablePredicate, root) {
|
|
40
40
|
if (root === void 0) { root = true; }
|
|
41
41
|
return function () {
|
|
42
42
|
var _this = this;
|
|
@@ -121,9 +121,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
var symbolBindings = {};
|
|
124
|
-
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
124
|
+
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings, mutablePredicate);
|
|
125
125
|
_this.jsxBegin(childName, props, __assign(__assign(__assign({}, bindings), parentSymbolBindings), specialBindings));
|
|
126
|
-
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
|
|
126
|
+
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, mutablePredicate, false).call(_this);
|
|
127
127
|
_this.jsxEnd(childName);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -138,7 +138,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
138
138
|
children = children.filter(function (c) { return !isEmptyTextNode(c); });
|
|
139
139
|
var childNeedsFragment = children.length > 1 || (children.length && isTextNode(children[0]));
|
|
140
140
|
childNeedsFragment && srcBuilder.jsxBeginFragment(fragmentSymbol);
|
|
141
|
-
renderJSXNodes(file, directives, handlers, children, styles, {}, false).call(srcBuilder);
|
|
141
|
+
renderJSXNodes(file, directives, handlers, children, styles, {}, mutablePredicate, false).call(srcBuilder);
|
|
142
142
|
childNeedsFragment && srcBuilder.jsxEndFragment();
|
|
143
143
|
};
|
|
144
144
|
}
|
|
@@ -182,7 +182,7 @@ function isSlotProjection(child) {
|
|
|
182
182
|
* @param symbolBindings Options record which will receive the symbol bindings
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
|
-
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
185
|
+
function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredicate) {
|
|
186
186
|
var _a;
|
|
187
187
|
var outBindings = {};
|
|
188
188
|
for (var key in bindings) {
|
|
@@ -207,6 +207,10 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
|
207
207
|
else if (key.startsWith('component.options.')) {
|
|
208
208
|
key = (0, src_generator_1.lastProperty)(key);
|
|
209
209
|
}
|
|
210
|
+
if (mutablePredicate && bindingExpr && mutablePredicate(bindingExpr)) {
|
|
211
|
+
file.import(file.qwikModule, 'mutable');
|
|
212
|
+
bindingExpr = "mutable(".concat(bindingExpr, ")");
|
|
213
|
+
}
|
|
210
214
|
outBindings[key] = { code: bindingExpr };
|
|
211
215
|
}
|
|
212
216
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.iteratorProperty = exports.lastProperty = exports.isStatement = exports.iif = exports.arrowFnValue = exports.arrowFnBlock = exports.invoke = exports.quote = exports.Block = exports.Imports = exports.Symbol = exports.SrcBuilder = exports.File = void 0;
|
|
4
4
|
var standalone_1 = require("prettier/standalone");
|
|
5
|
+
var builder_1 = require("../../parsers/builder");
|
|
6
|
+
var stable_serialize_1 = require("./stable-serialize");
|
|
5
7
|
var File = /** @class */ (function () {
|
|
6
8
|
function File(filename, options, qwikModule, qrlPrefix) {
|
|
7
9
|
this.imports = new Imports();
|
|
@@ -320,7 +322,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
320
322
|
key = key + '$';
|
|
321
323
|
binding_1 = "(event)=>".concat(binding_1);
|
|
322
324
|
}
|
|
323
|
-
if (!binding_1 && rawKey in props) {
|
|
325
|
+
else if (!binding_1 && rawKey in props) {
|
|
324
326
|
binding_1 = quote(props[rawKey]);
|
|
325
327
|
}
|
|
326
328
|
else if (binding_1 != null && binding_1 === props[key]) {
|
|
@@ -476,7 +478,7 @@ function possiblyQuotePropertyName(key) {
|
|
|
476
478
|
return /^\w[\w\d]*$/.test(key) ? key : quote(key);
|
|
477
479
|
}
|
|
478
480
|
function quote(text) {
|
|
479
|
-
var string =
|
|
481
|
+
var string = (0, stable_serialize_1.stableJSONserialize)(text);
|
|
480
482
|
// So \u2028 is a line separator character and prettier treats it as such
|
|
481
483
|
// https://www.fileformat.info/info/unicode/char/2028/index.htm
|
|
482
484
|
// That means it can't be inside of a string, so we replace it with `\\u2028`.
|
|
@@ -524,6 +526,9 @@ function iif(code) {
|
|
|
524
526
|
if (code.endsWith(_virtual_index) && !code.endsWith(return_virtual_index)) {
|
|
525
527
|
code = code.substr(0, code.length - _virtual_index.length) + return_virtual_index;
|
|
526
528
|
}
|
|
529
|
+
if (code.indexOf('export') !== -1) {
|
|
530
|
+
code = (0, builder_1.convertExportDefaultToReturn)(code);
|
|
531
|
+
}
|
|
527
532
|
return function () {
|
|
528
533
|
code && this.emit('(()=>{', code, '})()');
|
|
529
534
|
};
|
|
@@ -549,7 +554,8 @@ function literalTagName(symbol) {
|
|
|
549
554
|
*/
|
|
550
555
|
function isStatement(code) {
|
|
551
556
|
code = code.trim();
|
|
552
|
-
if (code.startsWith('(')
|
|
557
|
+
if ((code.startsWith('(') && code.endsWith(')')) ||
|
|
558
|
+
(code.startsWith('{') && code.endsWith('}'))) {
|
|
553
559
|
// Code starting with `(` is most likely and IFF and hence is an expression.
|
|
554
560
|
return false;
|
|
555
561
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stableJSONserialize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Same as JSON.stringify, but sorts keys ensuring that the output is stable across runs.
|
|
6
|
+
* @param obj
|
|
7
|
+
* @returns JSON serialized string
|
|
8
|
+
*/
|
|
9
|
+
function stableJSONserialize(obj) {
|
|
10
|
+
var output = [];
|
|
11
|
+
_serialize(output, obj);
|
|
12
|
+
return output.join('');
|
|
13
|
+
}
|
|
14
|
+
exports.stableJSONserialize = stableJSONserialize;
|
|
15
|
+
function _serialize(output, obj) {
|
|
16
|
+
if (obj == null) {
|
|
17
|
+
output.push('null');
|
|
18
|
+
}
|
|
19
|
+
else if (typeof obj === 'object') {
|
|
20
|
+
if (Array.isArray(obj)) {
|
|
21
|
+
output.push('[');
|
|
22
|
+
var sep = '';
|
|
23
|
+
for (var i = 0; i < obj.length; i++) {
|
|
24
|
+
output.push(sep);
|
|
25
|
+
_serialize(output, obj[i]);
|
|
26
|
+
sep = ',';
|
|
27
|
+
}
|
|
28
|
+
output.push(']');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
var keys = Object.keys(obj).sort();
|
|
32
|
+
output.push('{');
|
|
33
|
+
var sep = '';
|
|
34
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
35
|
+
var key = keys_1[_i];
|
|
36
|
+
var value = obj[key];
|
|
37
|
+
if (value !== undefined) {
|
|
38
|
+
output.push(sep);
|
|
39
|
+
output.push(JSON.stringify(key));
|
|
40
|
+
output.push(':');
|
|
41
|
+
_serialize(output, value);
|
|
42
|
+
sep = ',';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
output.push('}');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
output.push(JSON.stringify(obj));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TranspilerGenerator } from '../../types/transpiler';
|
|
2
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
3
|
+
import { ToReactOptions } from './types';
|
|
4
|
+
export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, parentSlots?: any[]) => string;
|
|
5
|
+
export declare const componentToPreact: TranspilerGenerator<ToReactOptions>;
|
|
6
|
+
export declare const componentToReact: TranspilerGenerator<ToReactOptions>;
|