@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,98 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
6
|
exports.markoFormatHtml = exports.postprocessHtml = exports.preprocessHtml = exports.componentToMarko = void 0;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
const dash_case_1 = require("../../helpers/dash-case");
|
|
8
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
9
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
10
|
+
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
11
|
+
const get_refs_1 = require("../../helpers/get-refs");
|
|
12
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
13
|
+
const has_props_1 = require("../../helpers/has-props");
|
|
14
|
+
const indent_1 = require("../../helpers/indent");
|
|
15
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
16
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
17
|
+
const for_1 = require("../../helpers/nodes/for");
|
|
18
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
19
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
20
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
21
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
22
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
23
|
+
const hash_sum_1 = __importDefault(require("hash-sum"));
|
|
24
|
+
const lodash_1 = require("lodash");
|
|
25
|
+
const standalone_1 = require("prettier/standalone");
|
|
26
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
27
|
+
const plugins_1 = require("../../modules/plugins");
|
|
28
|
+
const on_mount_1 = require("../helpers/on-mount");
|
|
44
29
|
// Having issues with this, so off for now
|
|
45
|
-
|
|
30
|
+
const USE_MARKO_PRETTIER = false;
|
|
46
31
|
/**
|
|
47
32
|
* Return the names of properties (basic literal values) on state
|
|
48
33
|
*/
|
|
49
34
|
function getStatePropertyNames(json) {
|
|
50
|
-
return Object.keys(json.state).filter(
|
|
35
|
+
return Object.keys(json.state).filter((key) => { var _a; return ((_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; });
|
|
51
36
|
}
|
|
52
|
-
|
|
37
|
+
const blockToMarko = (json, options) => {
|
|
53
38
|
var _a, _b, _c, _d, _e;
|
|
54
39
|
if (json.properties._text) {
|
|
55
40
|
return json.properties._text;
|
|
56
41
|
}
|
|
57
42
|
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
58
|
-
return
|
|
43
|
+
return `\${${processBinding(options.component, (_b = json.bindings) === null || _b === void 0 ? void 0 : _b._text.code)}}`;
|
|
59
44
|
}
|
|
60
45
|
if (json.name === 'Fragment') {
|
|
61
|
-
return json.children.map(
|
|
46
|
+
return json.children.map((child) => blockToMarko(child, options)).join('\n');
|
|
62
47
|
}
|
|
63
48
|
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
64
|
-
|
|
65
|
-
return
|
|
49
|
+
const forArguments = (0, for_1.getForArguments)(json).join(',');
|
|
50
|
+
return `<for|${forArguments}| of=(${processBinding(options.component, (_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code)})>
|
|
51
|
+
${json.children
|
|
66
52
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
67
|
-
.map(
|
|
68
|
-
.join('\n')
|
|
53
|
+
.map((item) => blockToMarko(item, options))
|
|
54
|
+
.join('\n')}
|
|
55
|
+
</for>`;
|
|
69
56
|
}
|
|
70
57
|
else if (json.name === 'Show') {
|
|
71
|
-
return
|
|
58
|
+
return `<if(${processBinding(options.component, (_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code)})>
|
|
59
|
+
${json.children
|
|
72
60
|
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
73
|
-
.map(
|
|
74
|
-
.join('\n')
|
|
61
|
+
.map((item) => blockToMarko(item, options))
|
|
62
|
+
.join('\n')}</if>
|
|
63
|
+
${!json.meta.else ? '' : `<else>${blockToMarko(json.meta.else, options)}</else>`}`;
|
|
75
64
|
}
|
|
76
|
-
|
|
77
|
-
str +=
|
|
78
|
-
for (
|
|
79
|
-
|
|
80
|
-
str +=
|
|
65
|
+
let str = '';
|
|
66
|
+
str += `<${json.name} `;
|
|
67
|
+
for (const key in json.properties) {
|
|
68
|
+
const value = json.properties[key];
|
|
69
|
+
str += ` ${key}="${value}" `;
|
|
81
70
|
}
|
|
82
|
-
for (
|
|
83
|
-
|
|
71
|
+
for (const key in json.bindings) {
|
|
72
|
+
const { code, arguments: cusArgs = ['event'], type } = json.bindings[key];
|
|
84
73
|
if (type === 'spread') {
|
|
85
|
-
str +=
|
|
74
|
+
str += ` ...(${code}) `;
|
|
86
75
|
}
|
|
87
76
|
else if (key === 'ref') {
|
|
88
|
-
str +=
|
|
77
|
+
str += ` key="${(0, lodash_1.camelCase)(code)}" `;
|
|
89
78
|
}
|
|
90
79
|
else if (key.startsWith('on')) {
|
|
91
|
-
|
|
92
|
-
str +=
|
|
80
|
+
const useKey = key === 'onChange' && json.name === 'input' ? 'onInput' : key;
|
|
81
|
+
str += ` ${(0, dash_case_1.dashCase)(useKey)}=(${cusArgs.join(',')} => ${processBinding(options.component, code)}) `;
|
|
93
82
|
}
|
|
94
83
|
else if (key !== 'innerHTML') {
|
|
95
|
-
str +=
|
|
84
|
+
str += ` ${key}=(${processBinding(options.component, code)}) `;
|
|
96
85
|
}
|
|
97
86
|
}
|
|
98
87
|
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
@@ -100,24 +89,23 @@ var blockToMarko = function (json, options) {
|
|
|
100
89
|
}
|
|
101
90
|
str += '>';
|
|
102
91
|
if ((_e = json.bindings.innerHTML) === null || _e === void 0 ? void 0 : _e.code) {
|
|
103
|
-
str +=
|
|
92
|
+
str += `$!{${processBinding(options.component, json.bindings.innerHTML.code)}}`;
|
|
104
93
|
}
|
|
105
94
|
if (json.children) {
|
|
106
|
-
str += json.children.map(
|
|
95
|
+
str += json.children.map((item) => blockToMarko(item, options)).join('\n');
|
|
107
96
|
}
|
|
108
|
-
str +=
|
|
97
|
+
str += `</${json.name}>`;
|
|
109
98
|
return str;
|
|
110
99
|
};
|
|
111
|
-
function processBinding(json, code, type) {
|
|
112
|
-
if (type === void 0) { type = 'attribute'; }
|
|
100
|
+
function processBinding(json, code, type = 'attribute') {
|
|
113
101
|
try {
|
|
114
102
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
115
103
|
replaceWith: type === 'state' ? 'input.' : type === 'class' ? 'this.input.' : 'input.',
|
|
116
104
|
includeProps: true,
|
|
117
105
|
includeState: false,
|
|
118
106
|
}), {
|
|
119
|
-
replaceWith:
|
|
120
|
-
|
|
107
|
+
replaceWith: (key) => {
|
|
108
|
+
const isProperty = getStatePropertyNames(json).includes(key);
|
|
121
109
|
if (isProperty) {
|
|
122
110
|
return (type === 'state' || type === 'class' ? 'this.state.' : 'state.') + key;
|
|
123
111
|
}
|
|
@@ -132,118 +120,141 @@ function processBinding(json, code, type) {
|
|
|
132
120
|
return code;
|
|
133
121
|
}
|
|
134
122
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
component:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
123
|
+
const componentToMarko = (userOptions = {}) => ({ component }) => {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
126
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
127
|
+
target: 'marko',
|
|
128
|
+
component,
|
|
129
|
+
defaults: {
|
|
130
|
+
...userOptions,
|
|
131
|
+
component: json,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
if (options.plugins) {
|
|
135
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
136
|
+
}
|
|
137
|
+
let css = (0, collect_css_1.collectCss)(json, {
|
|
138
|
+
prefix: (0, hash_sum_1.default)(json),
|
|
139
|
+
});
|
|
140
|
+
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
141
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `this.${(0, lodash_1.camelCase)(refName)}`);
|
|
142
|
+
if (options.plugins) {
|
|
143
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
144
|
+
}
|
|
145
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
146
|
+
const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
147
|
+
format: 'object',
|
|
148
|
+
data: true,
|
|
149
|
+
functions: false,
|
|
150
|
+
getters: false,
|
|
151
|
+
valueMapper: (code) => processBinding(json, code, 'state'),
|
|
152
|
+
});
|
|
153
|
+
const thisHasProps = (0, has_props_1.hasProps)(json);
|
|
154
|
+
const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
155
|
+
format: 'class',
|
|
156
|
+
data: false,
|
|
157
|
+
functions: true,
|
|
158
|
+
getters: true,
|
|
159
|
+
valueMapper: (code) => processBinding(json, code, 'class'),
|
|
160
|
+
});
|
|
161
|
+
const hasState = dataString.trim().length > 5;
|
|
162
|
+
if (options.prettier !== false) {
|
|
163
|
+
try {
|
|
164
|
+
css = (0, standalone_1.format)(css, {
|
|
165
|
+
parser: 'css',
|
|
166
|
+
plugins: [require('prettier/parser-postcss')],
|
|
167
|
+
});
|
|
156
168
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
format: 'object',
|
|
160
|
-
data: true,
|
|
161
|
-
functions: false,
|
|
162
|
-
getters: false,
|
|
163
|
-
valueMapper: function (code) { return processBinding(json, code, 'state'); },
|
|
164
|
-
});
|
|
165
|
-
var thisHasProps = (0, has_props_1.hasProps)(json);
|
|
166
|
-
var methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
167
|
-
format: 'class',
|
|
168
|
-
data: false,
|
|
169
|
-
functions: true,
|
|
170
|
-
getters: true,
|
|
171
|
-
valueMapper: function (code) { return processBinding(json, code, 'class'); },
|
|
172
|
-
});
|
|
173
|
-
var hasState = dataString.trim().length > 5;
|
|
174
|
-
if (options.prettier !== false) {
|
|
175
|
-
try {
|
|
176
|
-
css = (0, standalone_1.format)(css, {
|
|
177
|
-
parser: 'css',
|
|
178
|
-
plugins: [require('prettier/parser-postcss')],
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
console.warn('Could not format css', err);
|
|
183
|
-
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
console.warn('Could not format css', err);
|
|
184
171
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
172
|
+
}
|
|
173
|
+
let jsString = (0, dedent_1.dedent) `
|
|
174
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
175
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
176
|
+
component: json,
|
|
177
|
+
target: 'marko',
|
|
178
|
+
})}
|
|
179
|
+
|
|
180
|
+
class {
|
|
181
|
+
${methodsString}
|
|
182
|
+
|
|
183
|
+
${!hasState
|
|
184
|
+
? ''
|
|
185
|
+
: `onCreate(${thisHasProps ? 'input' : ''}) {
|
|
186
|
+
this.state = ${dataString}
|
|
187
|
+
}`}
|
|
188
|
+
|
|
189
|
+
${Array.from(domRefs)
|
|
190
|
+
.map((refName) => `get ${(0, lodash_1.camelCase)(refName)}() {
|
|
191
|
+
return this.getEl('${(0, lodash_1.camelCase)(refName)}')
|
|
192
|
+
}`)
|
|
193
|
+
.join('\n')}
|
|
194
|
+
|
|
195
|
+
${!json.hooks.onMount.length
|
|
196
|
+
? ''
|
|
197
|
+
: `onMount() { ${processBinding(json, (0, on_mount_1.stringifySingleScopeOnMount)(json), 'class')} }`}
|
|
198
|
+
${!((_a = json.hooks.onUnMount) === null || _a === void 0 ? void 0 : _a.code)
|
|
199
|
+
? ''
|
|
200
|
+
: `onDestroy() { ${processBinding(json, json.hooks.onUnMount.code, 'class')} }`}
|
|
201
|
+
${!((_b = json.hooks.onUpdate) === null || _b === void 0 ? void 0 : _b.length)
|
|
202
|
+
? ''
|
|
203
|
+
: `onRender() { ${json.hooks.onUpdate
|
|
204
|
+
.map((hook) => processBinding(json, hook.code, 'class'))
|
|
205
|
+
.join('\n\n')} }`}
|
|
206
|
+
}
|
|
207
|
+
`;
|
|
208
|
+
let htmlString = json.children.map((item) => blockToMarko(item, options)).join('\n');
|
|
209
|
+
const cssString = css.length
|
|
210
|
+
? `style {
|
|
211
|
+
${(0, indent_1.indent)(css, 2).trim()}
|
|
212
|
+
}`
|
|
213
|
+
: '';
|
|
214
|
+
if (options.prettier !== false && !USE_MARKO_PRETTIER) {
|
|
215
|
+
try {
|
|
216
|
+
htmlString = markoFormatHtml(htmlString);
|
|
222
217
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
.replace(/(on-[a-z]+)=\(/g, function (_match, group) { return group + '('; })
|
|
226
|
-
// Fix a weird edge case where </if> becomes </if \n > which is invalid in marko
|
|
227
|
-
.replace(/<\/([a-z]+)\s+>/gi, '</$1>');
|
|
228
|
-
var finalStr = "\n".concat(jsString, "\n").concat(cssString, "\n").concat(htmlString, "\n ")
|
|
229
|
-
.replace(/\n{3,}/g, '\n\n')
|
|
230
|
-
.trim();
|
|
231
|
-
if (options.plugins) {
|
|
232
|
-
finalStr = (0, plugins_1.runPreCodePlugins)({ json: json, code: finalStr, plugins: options.plugins });
|
|
218
|
+
catch (err) {
|
|
219
|
+
console.warn('Could not format html', err);
|
|
233
220
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
// plugins: [require('prettier-plugin-marko')],
|
|
240
|
-
// });
|
|
221
|
+
try {
|
|
222
|
+
jsString = (0, standalone_1.format)(jsString, {
|
|
223
|
+
parser: 'typescript',
|
|
224
|
+
plugins: [require('prettier/parser-typescript')],
|
|
225
|
+
});
|
|
241
226
|
}
|
|
242
|
-
|
|
243
|
-
|
|
227
|
+
catch (err) {
|
|
228
|
+
console.warn('Could not format js', err);
|
|
244
229
|
}
|
|
245
|
-
|
|
246
|
-
|
|
230
|
+
}
|
|
231
|
+
htmlString = htmlString
|
|
232
|
+
// Convert on-click=(...) -> on-click(...)
|
|
233
|
+
.replace(/(on-[a-z]+)=\(/g, (_match, group) => group + '(')
|
|
234
|
+
// Fix a weird edge case where </if> becomes </if \n > which is invalid in marko
|
|
235
|
+
.replace(/<\/([a-z]+)\s+>/gi, '</$1>');
|
|
236
|
+
let finalStr = `
|
|
237
|
+
${jsString}
|
|
238
|
+
${cssString}
|
|
239
|
+
${htmlString}
|
|
240
|
+
`
|
|
241
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
242
|
+
.trim();
|
|
243
|
+
if (options.plugins) {
|
|
244
|
+
finalStr = (0, plugins_1.runPreCodePlugins)({ json, code: finalStr, plugins: options.plugins });
|
|
245
|
+
}
|
|
246
|
+
if (USE_MARKO_PRETTIER && options.prettier !== false) {
|
|
247
|
+
// Commented out for now as there are strange module import issues as
|
|
248
|
+
// a result, causing builds to fail
|
|
249
|
+
// format(finalStr, {
|
|
250
|
+
// parser: 'marko',
|
|
251
|
+
// plugins: [require('prettier-plugin-marko')],
|
|
252
|
+
// });
|
|
253
|
+
}
|
|
254
|
+
if (options.plugins) {
|
|
255
|
+
finalStr = (0, plugins_1.runPostCodePlugins)({ json, code: finalStr, plugins: options.plugins });
|
|
256
|
+
}
|
|
257
|
+
return finalStr;
|
|
247
258
|
};
|
|
248
259
|
exports.componentToMarko = componentToMarko;
|
|
249
260
|
/**
|
|
@@ -258,11 +269,11 @@ function preprocessHtml(htmlString) {
|
|
|
258
269
|
.replace(/<for\|/g, '<for |')
|
|
259
270
|
// Convert <if(foo) to <if _="foo", otherwise HTML will think the tag is not just <if> and complain
|
|
260
271
|
// when we close it with </if>
|
|
261
|
-
.replace(/<if\(([\s\S]+?)\)\s*>/g,
|
|
262
|
-
return
|
|
272
|
+
.replace(/<if\(([\s\S]+?)\)\s*>/g, (_match, group) => {
|
|
273
|
+
return `<if _="${encodeAttributeValue(group)}">`;
|
|
263
274
|
})
|
|
264
|
-
.replace(/=\(([\s\S]*?)\)(\s*[a-z\/>])/g,
|
|
265
|
-
return "
|
|
275
|
+
.replace(/=\(([\s\S]*?)\)(\s*[a-z\/>])/g, (_match, group, after) => {
|
|
276
|
+
return `="(${encodeAttributeValue(group)})"${after}`;
|
|
266
277
|
}));
|
|
267
278
|
}
|
|
268
279
|
exports.preprocessHtml = preprocessHtml;
|
|
@@ -274,11 +285,11 @@ exports.preprocessHtml = preprocessHtml;
|
|
|
274
285
|
function postprocessHtml(htmlString) {
|
|
275
286
|
return htmlString
|
|
276
287
|
.replace(/<for \|/g, '<for|')
|
|
277
|
-
.replace(/<if _="([\s\S]+?)"\s*>/g,
|
|
278
|
-
return
|
|
288
|
+
.replace(/<if _="([\s\S]+?)"\s*>/g, (_match, group) => {
|
|
289
|
+
return `<if(${decodeAttributeValue(group)})>`;
|
|
279
290
|
})
|
|
280
|
-
.replace(/="\(([\s\S]*?)\)"(\s*[a-z\/>])/g,
|
|
281
|
-
return
|
|
291
|
+
.replace(/="\(([\s\S]*?)\)"(\s*[a-z\/>])/g, (_match, group, after) => {
|
|
292
|
+
return `=(${decodeAttributeValue(group)})${after}`;
|
|
282
293
|
});
|
|
283
294
|
}
|
|
284
295
|
exports.postprocessHtml = postprocessHtml;
|
|
@@ -301,4 +312,3 @@ function markoFormatHtml(htmlString) {
|
|
|
301
312
|
}));
|
|
302
313
|
}
|
|
303
314
|
exports.markoFormatHtml = markoFormatHtml;
|
|
304
|
-
var templateObject_1;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.minify = void 0;
|
|
4
|
-
function minify(messageParts) {
|
|
5
|
-
|
|
6
|
-
for (
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
var text = '';
|
|
10
|
-
for (var i = 0; i < messageParts.length; i++) {
|
|
11
|
-
var part = messageParts[i];
|
|
4
|
+
function minify(messageParts, ...expressions) {
|
|
5
|
+
let text = '';
|
|
6
|
+
for (let i = 0; i < messageParts.length; i++) {
|
|
7
|
+
const part = messageParts[i];
|
|
12
8
|
text += part;
|
|
13
9
|
if (i < expressions.length) {
|
|
14
10
|
text += expressions[i];
|
|
@@ -19,6 +15,6 @@ function minify(messageParts) {
|
|
|
19
15
|
.replace(/^\s+/, '')
|
|
20
16
|
.replace(/\s+$/, '')
|
|
21
17
|
.replace(/\s+/g, ' ')
|
|
22
|
-
.replace(/\s?([,;\:\-\{\}\(\)\<\>])\s?/g,
|
|
18
|
+
.replace(/\s?([,;\:\-\{\}\(\)\<\>])\s?/g, (_, match) => match);
|
|
23
19
|
}
|
|
24
20
|
exports.minify = minify;
|