@builder.io/mitosis 0.0.46 → 0.0.49
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__/angular.test.d.ts +1 -0
- package/dist/src/__tests__/angular.test.js +12 -0
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +6 -0
- package/dist/src/__tests__/data/blocks/onUpdate.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/onUpdate.raw.jsx +10 -0
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +11 -0
- package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +11 -0
- package/dist/src/__tests__/data/blocks/tabs.raw.jsx +24 -0
- package/dist/src/__tests__/qoot.test.d.ts +1 -0
- package/dist/src/__tests__/qoot.test.js +115 -0
- package/dist/src/__tests__/qwik.test.js +68 -9
- package/dist/src/__tests__/react.test.js +12 -0
- package/dist/src/__tests__/svelte.test.d.ts +1 -0
- package/dist/src/__tests__/svelte.test.js +12 -0
- package/dist/src/__tests__/vue.test.js +6 -0
- package/dist/src/generators/angular.js +7 -3
- package/dist/src/generators/builder.js +7 -7
- package/dist/src/generators/html.js +16 -7
- package/dist/src/generators/jsx-lite.d.ts +10 -0
- package/dist/src/generators/jsx-lite.js +176 -0
- package/dist/src/generators/minify.d.ts +1 -0
- package/dist/src/generators/minify.js +24 -0
- package/dist/src/generators/mitosis.js +5 -2
- package/dist/src/generators/qoot.d.ts +21 -0
- package/dist/src/generators/qoot.js +442 -0
- package/dist/src/generators/qwik/component.js +48 -6
- package/dist/src/generators/qwik/directives.d.ts +21 -1
- package/dist/src/generators/qwik/directives.js +93 -13
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +30 -7
- package/dist/src/generators/qwik/src-generator.d.ts +15 -2
- package/dist/src/generators/qwik/src-generator.js +82 -16
- package/dist/src/generators/qwik.d.ts +21 -0
- package/dist/src/generators/qwik.js +458 -0
- package/dist/src/generators/react-native.js +34 -27
- package/dist/src/generators/react.js +36 -14
- package/dist/src/generators/solid.js +5 -2
- package/dist/src/generators/svelte.js +10 -5
- package/dist/src/generators/vue.js +9 -6
- package/dist/src/helpers/create-jsx-lite-component.d.ts +2 -0
- package/dist/src/helpers/create-jsx-lite-component.js +16 -0
- package/dist/src/helpers/create-jsx-lite-context.d.ts +4 -0
- package/dist/src/helpers/create-jsx-lite-context.js +18 -0
- package/dist/src/helpers/create-jsx-lite-node.d.ts +2 -0
- package/dist/src/helpers/create-jsx-lite-node.js +16 -0
- package/dist/src/helpers/get-state-object-string.js +51 -38
- package/dist/src/helpers/is-jsx-lite-node.d.ts +2 -0
- package/dist/src/helpers/is-jsx-lite-node.js +7 -0
- package/dist/src/helpers/map-refs.js +10 -8
- package/dist/src/helpers/patterns.d.ts +2 -0
- package/dist/src/helpers/patterns.js +5 -0
- package/dist/src/helpers/process-http-requests.js +3 -3
- package/dist/src/helpers/process-tag-references.js +4 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +4 -3
- package/dist/src/jsx-types.d.ts +1 -1
- package/dist/src/parsers/builder.d.ts +50 -10
- package/dist/src/parsers/builder.js +37 -7
- package/dist/src/parsers/jsx.js +43 -3
- package/dist/src/parsers/liquid.js +4 -4
- package/dist/src/plugins/compile-away-builder-components.js +40 -20
- package/dist/src/symbols/symbol-processor.d.ts +18 -0
- package/dist/src/symbols/symbol-processor.js +177 -0
- package/dist/src/types/jsx-lite-component.d.ts +63 -0
- package/dist/src/types/jsx-lite-component.js +2 -0
- package/dist/src/types/jsx-lite-context.d.ts +6 -0
- package/dist/src/types/jsx-lite-context.js +2 -0
- package/dist/src/types/jsx-lite-node.d.ts +13 -0
- package/dist/src/types/jsx-lite-node.js +2 -0
- package/dist/src/types/jsx-lite-styles.d.ts +1 -0
- package/dist/src/types/jsx-lite-styles.js +2 -0
- package/dist/src/types/mitosis-component.d.ts +10 -5
- package/dist/test/qoot/Todo/bundle.js +88 -0
- package/dist/test/qoot/Todo/component.ts +17 -0
- package/dist/test/qoot/Todo/onButtonClick.ts +13 -0
- package/dist/test/qoot/Todo/onInput2Blur.ts +11 -0
- package/dist/test/qoot/Todo/onInput2KeyUp.ts +10 -0
- package/dist/test/qoot/Todo/onInputClick.ts +10 -0
- package/dist/test/qoot/Todo/onLabelDblClick.ts +11 -0
- package/dist/test/qoot/Todo/public.ts +4 -0
- package/dist/test/qoot/Todo/template.tsx +46 -0
- package/dist/test/qoot/Todos/component.ts +9 -0
- package/dist/test/qoot/Todos/onInputClick.ts +14 -0
- package/dist/test/qoot/Todos/public.ts +3 -0
- package/dist/test/qoot/Todos/template.tsx +30 -0
- package/dist/test/qwik/{todo → Todo}/Todo.cjs/high.cjs +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.cjs/med.cjs +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.js/high.js +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.js/low.js +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.js/med.js +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{todo → Todo}/Todo.tsx/med.tsx +0 -0
- package/dist/test/qwik/Todo/bundle.js +46 -0
- package/dist/test/qwik/Todo/component.ts +17 -0
- package/dist/test/qwik/Todo/onButtonClick.ts +10 -0
- package/dist/test/qwik/Todo/onInput2Blur.ts +14 -0
- package/dist/test/qwik/Todo/onInput2KeyUp.ts +10 -0
- package/dist/test/qwik/Todo/onInputClick.ts +13 -0
- package/dist/test/qwik/Todo/onLabelDblClick.ts +11 -0
- package/dist/test/qwik/Todo/public.ts +3 -0
- package/dist/test/qwik/Todo/template.tsx +46 -0
- package/dist/test/qwik/Todo.ts +4 -0
- package/dist/test/qwik/Todo_component.ts +17 -0
- package/dist/test/qwik/Todo_onButtonClick.ts +13 -0
- package/dist/test/qwik/Todo_onInput2Blur.ts +14 -0
- package/dist/test/qwik/Todo_onInput2KeyUp.ts +10 -0
- package/dist/test/qwik/Todo_onInputClick.ts +13 -0
- package/dist/test/qwik/Todo_onLabelDblClick.ts +14 -0
- package/dist/test/qwik/Todo_template.tsx +46 -0
- package/dist/test/qwik/{todos → Todos}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{todos → Todos}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{todos → Todos}/Todo.tsx/med.tsx +0 -0
- package/dist/test/qwik/Todos/component.ts +9 -0
- package/dist/test/qwik/Todos/onInputClick.ts +14 -0
- package/dist/test/qwik/Todos/public.ts +3 -0
- package/dist/test/qwik/Todos/template.tsx +30 -0
- package/dist/test/qwik/Todos.ts +3 -0
- package/dist/test/qwik/Todos_component.ts +9 -0
- package/dist/test/qwik/Todos_onInputClick.ts +14 -0
- package/dist/test/qwik/Todos_template.tsx +30 -0
- package/dist/test/qwik/qwik/Image/high.js +1 -0
- package/dist/test/qwik/qwik/Image/low.js +75 -0
- package/dist/test/qwik/qwik/Image/med.js +9 -0
- package/dist/test/qwik/qwik/Image.slow/high.js +1 -0
- package/dist/test/qwik/qwik/Image.slow/low.js +75 -0
- package/dist/test/qwik/qwik/Image.slow/med.js +9 -0
- package/dist/test/qwik/qwik/button/high.js +8 -0
- package/dist/test/qwik/qwik/button/low.js +34 -0
- package/dist/test/qwik/qwik/button/med.js +9 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +1 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +24 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +9 -0
- package/dist/test/qwik/qwik/page-with-symbol/high.js +1 -0
- package/dist/test/qwik/qwik/page-with-symbol/low.js +49 -0
- package/dist/test/qwik/qwik/page-with-symbol/med.js +9 -0
- package/dist/test/qwik/qwik/svg/high.js +1 -0
- package/dist/test/qwik/qwik/svg/low.js +30 -0
- package/dist/test/qwik/qwik/svg/med.js +9 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +31 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +1 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +59 -0
- package/dist/test/qwik/qwik/todo/Todo.js/high.js +5 -0
- package/dist/{src/types/generators.d.ts → test/qwik/qwik/todo/Todo.js/low.js} +0 -0
- package/dist/test/qwik/qwik/todo/Todo.js/med.js +1 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +30 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +1 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +34 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +12 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +24 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/types/generators.js +0 -1
|
@@ -1,24 +1,104 @@
|
|
|
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
|
+
};
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DIRECTIVES = void 0;
|
|
7
|
+
exports.CoreButton = exports.Image = exports.DIRECTIVES = void 0;
|
|
8
|
+
var minify_1 = require("../minify");
|
|
4
9
|
var src_generator_1 = require("./src-generator");
|
|
5
10
|
exports.DIRECTIVES = {
|
|
6
11
|
Show: function (node, blockFn) {
|
|
7
12
|
return function () {
|
|
8
13
|
var expr = node.bindings.when;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
this.isJSX && this.emit('{', src_generator_1.WS);
|
|
15
|
+
this.emit(expr, src_generator_1.WS, '?', src_generator_1.INDENT, src_generator_1.NL);
|
|
16
|
+
blockFn();
|
|
17
|
+
this.emit(':', src_generator_1.WS, 'null', src_generator_1.UNINDENT, src_generator_1.NL);
|
|
18
|
+
this.isJSX && this.emit('}', src_generator_1.NL);
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
For: function (node, blockFn) {
|
|
22
|
+
return function () {
|
|
23
|
+
var expr = node.bindings.each;
|
|
24
|
+
this.isJSX && this.emit('{', src_generator_1.WS);
|
|
25
|
+
this.emit('(', expr, src_generator_1.WS, '||', src_generator_1.WS, '[])');
|
|
26
|
+
this.emit('.map(', '(function(__value__)', src_generator_1.WS, '{', src_generator_1.INDENT, src_generator_1.NL);
|
|
27
|
+
this.emit('var state', src_generator_1.WS, '=', src_generator_1.WS, 'Object.assign({},', src_generator_1.WS, 'this,', src_generator_1.WS, '{', (0, src_generator_1.iteratorProperty)(expr), ':', src_generator_1.WS, '__value__', src_generator_1.WS, '==', src_generator_1.WS, 'null', src_generator_1.WS, '?', src_generator_1.WS, '{}', src_generator_1.WS, ':', src_generator_1.WS, '__value__', '});', src_generator_1.NL);
|
|
28
|
+
this.emit('return', src_generator_1.WS, '(');
|
|
15
29
|
blockFn();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
this.emit(':', src_generator_1.WS, 'null', src_generator_1.UNINDENT, src_generator_1.NL);
|
|
21
|
-
}
|
|
30
|
+
this.emit(')', ';', src_generator_1.UNINDENT, src_generator_1.NL);
|
|
31
|
+
this.emit('}', ').bind(state))', src_generator_1.NL);
|
|
32
|
+
this.isJSX && this.emit('}', src_generator_1.NL);
|
|
22
33
|
};
|
|
23
34
|
},
|
|
35
|
+
Image: (0, minify_1.minify)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), Image),
|
|
36
|
+
CoreButton: (0, minify_1.minify)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), CoreButton),
|
|
24
37
|
};
|
|
38
|
+
function Image(props) {
|
|
39
|
+
var jsx = props.children || [];
|
|
40
|
+
var image = props.image;
|
|
41
|
+
if (image) {
|
|
42
|
+
var isBuilderIoImage = !!(image || '').match(/builder\.io/);
|
|
43
|
+
var imgProps = {
|
|
44
|
+
src: props.image,
|
|
45
|
+
style: "object-fit:".concat(props.backgroundSize ||
|
|
46
|
+
'cover', ";object-position:").concat(props.backgroundPosition || 'center', ";") +
|
|
47
|
+
(props.aspectRatio
|
|
48
|
+
? 'position:absolute;height:100%;width:100%;top:0;left:0'
|
|
49
|
+
: ''),
|
|
50
|
+
sizes: props.sizes,
|
|
51
|
+
alt: props.altText,
|
|
52
|
+
loading: props.lazy ? 'lazy' : undefined,
|
|
53
|
+
srcset: undefined,
|
|
54
|
+
};
|
|
55
|
+
var sizingDiv = h('div', {
|
|
56
|
+
class: 'builder-image-sizer',
|
|
57
|
+
style: "width:100%;padding-top:".concat((props.aspectRatio || 1) *
|
|
58
|
+
100, "%;pointer-events:none;font-size:0"),
|
|
59
|
+
});
|
|
60
|
+
if (isBuilderIoImage) {
|
|
61
|
+
var srcset = ['100', '200', '400', '800', '1200', '1600', '2000']
|
|
62
|
+
.map(function (size) {
|
|
63
|
+
return updateQueryParam(image, 'width', size) + ' ' + size + 'w';
|
|
64
|
+
})
|
|
65
|
+
.concat([image])
|
|
66
|
+
.join(', ');
|
|
67
|
+
imgProps.srcset = srcset;
|
|
68
|
+
jsx = jsx = [
|
|
69
|
+
h('picture', {}, [
|
|
70
|
+
h('source', { type: 'image/webp', srcset: srcset }),
|
|
71
|
+
h('img', imgProps, jsx),
|
|
72
|
+
]),
|
|
73
|
+
sizingDiv,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
jsx = [h('img', imgProps, jsx), sizingDiv];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
var children = props.children ? [jsx].concat(props.children) : [jsx];
|
|
81
|
+
return h(props.href ? 'a' : 'div', { href: props.href, class: props.class }, children);
|
|
82
|
+
function updateQueryParam(uri, key, value) {
|
|
83
|
+
if (uri === void 0) { uri = ''; }
|
|
84
|
+
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
|
85
|
+
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
|
86
|
+
if (uri.match(re)) {
|
|
87
|
+
return uri.replace(re, '$1' + key + '=' + encodeURIComponent(value) + '$2');
|
|
88
|
+
}
|
|
89
|
+
return uri + separator + key + '=' + encodeURIComponent(value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Image = Image;
|
|
93
|
+
function CoreButton(props) {
|
|
94
|
+
var hasLink = !!props.link;
|
|
95
|
+
var hProps = {
|
|
96
|
+
innerHTML: props.text || '',
|
|
97
|
+
href: props.link,
|
|
98
|
+
target: props.openInNewTab ? '_blank' : '_self',
|
|
99
|
+
class: props.class,
|
|
100
|
+
};
|
|
101
|
+
return h(hasLink ? 'a' : props.tagName$ || 'span', hProps);
|
|
102
|
+
}
|
|
103
|
+
exports.CoreButton = CoreButton;
|
|
104
|
+
var templateObject_1, templateObject_2;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
2
|
import { File } from './src-generator';
|
|
3
3
|
import { CssStyles } from './styles';
|
|
4
|
-
export declare function renderJSXNodes(file: File, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, root?: boolean): any;
|
|
4
|
+
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;
|
|
@@ -23,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.renderJSXNodes = void 0;
|
|
24
24
|
var directives_1 = require("./directives");
|
|
25
25
|
var src_generator_1 = require("./src-generator");
|
|
26
|
-
function renderJSXNodes(file, handlers, children, styles, root) {
|
|
26
|
+
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, root) {
|
|
27
27
|
if (root === void 0) { root = true; }
|
|
28
28
|
return function () {
|
|
29
29
|
var _this = this;
|
|
@@ -47,7 +47,7 @@ function renderJSXNodes(file, handlers, children, styles, root) {
|
|
|
47
47
|
else {
|
|
48
48
|
_this.isJSX
|
|
49
49
|
? _this.emit(child.properties._text)
|
|
50
|
-
: _this.jsxTextBinding((0, src_generator_1.
|
|
50
|
+
: _this.jsxTextBinding((0, src_generator_1.quote)(child.properties._text));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
@@ -55,10 +55,16 @@ function renderJSXNodes(file, handlers, children, styles, root) {
|
|
|
55
55
|
var directive = directives_1.DIRECTIVES[childName];
|
|
56
56
|
if (typeof directive == 'function') {
|
|
57
57
|
_this.emit(directive(child, function () {
|
|
58
|
-
return renderJSXNodes(file, handlers, child.children, styles, false).call(_this);
|
|
58
|
+
return renderJSXNodes(file, directives, handlers, child.children, styles, {}, false).call(_this);
|
|
59
59
|
}));
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
+
if (typeof directive == 'string') {
|
|
63
|
+
directives.set(childName, directive);
|
|
64
|
+
if (file.module !== 'med') {
|
|
65
|
+
file.import('./med.js', childName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
62
68
|
if (isSymbol(childName)) {
|
|
63
69
|
// TODO(misko): We are hard coding './med.js' which is not right.
|
|
64
70
|
file.import('./med.js', childName);
|
|
@@ -73,8 +79,10 @@ function renderJSXNodes(file, handlers, children, styles, root) {
|
|
|
73
79
|
props = __assign({}, props);
|
|
74
80
|
props.class = addClass(styles.get(css).CLASS_NAME, props.class);
|
|
75
81
|
}
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
var symbolBindings = {};
|
|
83
|
+
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
84
|
+
_this.jsxBegin(childName, props, __assign(__assign({}, bindings), parentSymbolBindings));
|
|
85
|
+
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
|
|
78
86
|
_this.jsxEnd(childName);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
@@ -100,7 +108,19 @@ function isEmptyTextNode(child) {
|
|
|
100
108
|
function isTextNode(child) {
|
|
101
109
|
return (child.properties._text !== undefined || child.bindings._text !== undefined);
|
|
102
110
|
}
|
|
103
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Rewrites bindings:
|
|
113
|
+
* - Remove `css`
|
|
114
|
+
* - Rewrites event handles
|
|
115
|
+
* - Extracts symbol bindings.
|
|
116
|
+
*
|
|
117
|
+
* @param file
|
|
118
|
+
* @param handlers
|
|
119
|
+
* @param bindings
|
|
120
|
+
* @param symbolBindings Options record which will receive the symbol bindings
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
104
124
|
var outBindings = {};
|
|
105
125
|
for (var key in bindings) {
|
|
106
126
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
@@ -113,9 +133,12 @@ function rewriteHandlers(file, handlers, bindings) {
|
|
|
113
133
|
else if ((handlerBlock = handlers.get(binding))) {
|
|
114
134
|
key = "on:".concat(key.substr(2).toLowerCase());
|
|
115
135
|
binding = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qHook'), [
|
|
116
|
-
(0, src_generator_1.
|
|
136
|
+
(0, src_generator_1.quote)(file.qrlPrefix + 'high#' + handlerBlock),
|
|
117
137
|
]);
|
|
118
138
|
}
|
|
139
|
+
else if (symbolBindings && key.startsWith('symbol.data.')) {
|
|
140
|
+
symbolBindings[(0, src_generator_1.lastProperty)(key)] = binding;
|
|
141
|
+
}
|
|
119
142
|
outBindings[key] = binding;
|
|
120
143
|
}
|
|
121
144
|
}
|
|
@@ -40,7 +40,7 @@ export declare class SrcBuilder {
|
|
|
40
40
|
emit(...values: any[]): this;
|
|
41
41
|
private push;
|
|
42
42
|
emitList(values: any[], sep?: string): this;
|
|
43
|
-
const(name: string, value?: any, exprt?: boolean): this;
|
|
43
|
+
const(name: string, value?: any, exprt?: boolean, locallyVisible?: boolean): this;
|
|
44
44
|
type(def: string): this;
|
|
45
45
|
typeParameters(typeParameters: string[] | undefined): void;
|
|
46
46
|
jsxBegin(symbol: Symbol | string, props: Record<string, any>, bindings: Record<string, any>): void;
|
|
@@ -62,7 +62,20 @@ export declare class Block {
|
|
|
62
62
|
imports: Imports;
|
|
63
63
|
constructor(imports: Imports);
|
|
64
64
|
}
|
|
65
|
-
export declare function
|
|
65
|
+
export declare function quote(text: string): string;
|
|
66
66
|
export declare function invoke(symbol: Symbol | string, args: any[], typeParameters?: string[]): (this: SrcBuilder) => void;
|
|
67
67
|
export declare function arrowFnBlock(args: string[], statements: any[]): (this: SrcBuilder) => void;
|
|
68
68
|
export declare function arrowFnValue(args: string[], expression: any): (this: SrcBuilder) => void;
|
|
69
|
+
export declare function iif(code: any): (this: SrcBuilder) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Returns `true` if the code is a statement (rather than expression).
|
|
72
|
+
*
|
|
73
|
+
* Code is an expression if it is a list of identifiers all connected with a valid separator
|
|
74
|
+
* identifier: [a-z_$](a-z0-9_$)*
|
|
75
|
+
* separator: [()[]{}.-+/*,]
|
|
76
|
+
*
|
|
77
|
+
* it is not 100% but a good enough approximation
|
|
78
|
+
*/
|
|
79
|
+
export declare function isStatement(code: string): boolean;
|
|
80
|
+
export declare function lastProperty(expr: string): string;
|
|
81
|
+
export declare function iteratorProperty(expr: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arrowFnValue = exports.arrowFnBlock = exports.invoke = exports.
|
|
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 = exports.UNINDENT = exports.INDENT = exports.NL = exports.RS = exports.WS = void 0;
|
|
4
4
|
exports.WS = String.fromCharCode(29);
|
|
5
5
|
exports.RS = ' ';
|
|
6
6
|
exports.NL = '\n';
|
|
@@ -41,9 +41,11 @@ var File = /** @class */ (function () {
|
|
|
41
41
|
return this.imports.get(module, symbol);
|
|
42
42
|
};
|
|
43
43
|
File.prototype.toQrl = function (symbol) {
|
|
44
|
-
return
|
|
44
|
+
return quote(this.qrlPrefix + this.module + '#' + symbol);
|
|
45
45
|
};
|
|
46
46
|
File.prototype.exportConst = function (name, value) {
|
|
47
|
+
if (this.exports.has(name))
|
|
48
|
+
return;
|
|
47
49
|
this.exports.set(name, this.src.isModule ? name : 'exports.' + name);
|
|
48
50
|
this.src.const(name, value, true);
|
|
49
51
|
};
|
|
@@ -84,12 +86,12 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
84
86
|
SrcBuilder.prototype.import = function (module, symbols) {
|
|
85
87
|
var _this = this;
|
|
86
88
|
if (this.isModule) {
|
|
87
|
-
this.emit('import', exports.WS, '{', exports.WS, symbols, exports.WS, '}', exports.WS, 'from', exports.WS,
|
|
89
|
+
this.emit('import', exports.WS, '{', exports.WS, symbols, exports.WS, '}', exports.WS, 'from', exports.WS, quote(module), ';', exports.NL);
|
|
88
90
|
}
|
|
89
91
|
else {
|
|
90
92
|
symbols.forEach(function (symbol) {
|
|
91
93
|
_this.const(symbol, function () {
|
|
92
|
-
this.emit(invoke('require', [
|
|
94
|
+
this.emit(invoke('require', [quote(module)]), '.', symbol);
|
|
93
95
|
});
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -188,10 +190,13 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
188
190
|
}
|
|
189
191
|
return this;
|
|
190
192
|
};
|
|
191
|
-
SrcBuilder.prototype.const = function (name, value, exprt) {
|
|
193
|
+
SrcBuilder.prototype.const = function (name, value, exprt, locallyVisible) {
|
|
192
194
|
if (exprt === void 0) { exprt = false; }
|
|
195
|
+
if (locallyVisible === void 0) { locallyVisible = false; }
|
|
193
196
|
if (exprt) {
|
|
194
|
-
this.emit(this.isModule
|
|
197
|
+
this.emit(this.isModule
|
|
198
|
+
? 'export const '
|
|
199
|
+
: (locallyVisible ? 'const ' + name + '=' : '') + 'exports.');
|
|
195
200
|
}
|
|
196
201
|
else {
|
|
197
202
|
this.emit('const ');
|
|
@@ -215,6 +220,10 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
215
220
|
}
|
|
216
221
|
};
|
|
217
222
|
SrcBuilder.prototype.jsxBegin = function (symbol, props, bindings) {
|
|
223
|
+
if (symbol == 'div' && ('href' in props || 'href' in bindings)) {
|
|
224
|
+
// HACK: if we contain href then we are `a` not `div`
|
|
225
|
+
symbol = 'a';
|
|
226
|
+
}
|
|
218
227
|
if (this.isJSX) {
|
|
219
228
|
this.emit('<' + symbol);
|
|
220
229
|
}
|
|
@@ -223,7 +232,9 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
223
232
|
}
|
|
224
233
|
var first = true;
|
|
225
234
|
for (var key in props) {
|
|
226
|
-
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
236
|
+
!ignoreKey(key) &&
|
|
237
|
+
!Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
227
238
|
if (first) {
|
|
228
239
|
first = false;
|
|
229
240
|
this.isJSX && this.emit(exports.RS, exports.INDENT, exports.INDENT);
|
|
@@ -233,12 +244,14 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
233
244
|
}
|
|
234
245
|
this.isJSX ? this.emit(key) : this.emit(possiblyQuotePropertyName(key));
|
|
235
246
|
this.isJSX ? this.emit('=') : this.emit(':', exports.WS);
|
|
236
|
-
this.emit(
|
|
247
|
+
this.emit(quote(props[key]));
|
|
237
248
|
}
|
|
238
249
|
}
|
|
239
|
-
for (var
|
|
240
|
-
if (Object.prototype.hasOwnProperty.call(bindings,
|
|
241
|
-
!ignoreKey(
|
|
250
|
+
for (var rawKey in bindings) {
|
|
251
|
+
if (Object.prototype.hasOwnProperty.call(bindings, rawKey) &&
|
|
252
|
+
!ignoreKey(rawKey)) {
|
|
253
|
+
var binding = bindings[rawKey];
|
|
254
|
+
var key = lastProperty(rawKey);
|
|
242
255
|
if (first) {
|
|
243
256
|
first = false;
|
|
244
257
|
this.isJSX && this.emit(exports.RS, exports.INDENT, exports.INDENT);
|
|
@@ -248,7 +261,15 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
248
261
|
}
|
|
249
262
|
this.isJSX ? this.emit(key) : this.emit(possiblyQuotePropertyName(key));
|
|
250
263
|
this.isJSX ? this.emit('={') : this.emit(':', exports.WS);
|
|
251
|
-
|
|
264
|
+
if (binding === props[key]) {
|
|
265
|
+
// HACK: workaround for the fact that sometimes the `bindings` have string literals
|
|
266
|
+
// We assume that when the binding content equals prop content.
|
|
267
|
+
binding = JSON.stringify(binding);
|
|
268
|
+
}
|
|
269
|
+
else if (typeof binding == 'string' && isStatement(binding)) {
|
|
270
|
+
binding = iif(binding);
|
|
271
|
+
}
|
|
272
|
+
this.emit(binding);
|
|
252
273
|
this.isJSX ? this.emit('}') : this.emit();
|
|
253
274
|
}
|
|
254
275
|
}
|
|
@@ -332,7 +353,8 @@ function ignoreKey(key) {
|
|
|
332
353
|
key.startsWith('_') ||
|
|
333
354
|
key == 'code' ||
|
|
334
355
|
key == '' ||
|
|
335
|
-
key == 'builder-id'
|
|
356
|
+
key == 'builder-id' ||
|
|
357
|
+
key.indexOf('.') !== -1);
|
|
336
358
|
}
|
|
337
359
|
var Block = /** @class */ (function () {
|
|
338
360
|
function Block(imports) {
|
|
@@ -344,10 +366,10 @@ exports.Block = Block;
|
|
|
344
366
|
function possiblyQuotePropertyName(key) {
|
|
345
367
|
return /^\w[\w\d]*$/.test(key) ? key : JSON.stringify(key);
|
|
346
368
|
}
|
|
347
|
-
function
|
|
369
|
+
function quote(text) {
|
|
348
370
|
return JSON.stringify(text);
|
|
349
371
|
}
|
|
350
|
-
exports.
|
|
372
|
+
exports.quote = quote;
|
|
351
373
|
function invoke(symbol, args, typeParameters) {
|
|
352
374
|
return function () {
|
|
353
375
|
this.emit(typeof symbol == 'string' ? symbol : symbol.name);
|
|
@@ -371,15 +393,59 @@ function arrowFnValue(args, expression) {
|
|
|
371
393
|
};
|
|
372
394
|
}
|
|
373
395
|
exports.arrowFnValue = arrowFnValue;
|
|
396
|
+
function iif(code) {
|
|
397
|
+
return function () {
|
|
398
|
+
this.emit('(()', exports.WS, '=>', exports.WS, '{', exports.WS, exports.NL, code, exports.NL, '}', ')()');
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
exports.iif = iif;
|
|
374
402
|
var LOWER_CASE = 'a'.charCodeAt(0) - 1;
|
|
375
403
|
function literalTagName(symbol) {
|
|
376
404
|
if (typeof symbol == 'string' &&
|
|
377
405
|
symbol.charCodeAt(0) > LOWER_CASE &&
|
|
378
406
|
symbol.indexOf('.') === -1) {
|
|
379
|
-
return
|
|
407
|
+
return quote(symbol);
|
|
380
408
|
}
|
|
381
409
|
return symbol;
|
|
382
410
|
}
|
|
383
411
|
function isWhitespace(ch) {
|
|
384
412
|
return ch == '' || ch == exports.RS || ch == exports.NL;
|
|
385
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Returns `true` if the code is a statement (rather than expression).
|
|
416
|
+
*
|
|
417
|
+
* Code is an expression if it is a list of identifiers all connected with a valid separator
|
|
418
|
+
* identifier: [a-z_$](a-z0-9_$)*
|
|
419
|
+
* separator: [()[]{}.-+/*,]
|
|
420
|
+
*
|
|
421
|
+
* it is not 100% but a good enough approximation
|
|
422
|
+
*/
|
|
423
|
+
function isStatement(code) {
|
|
424
|
+
if (code.startsWith('(')) {
|
|
425
|
+
// Code starting with `(` is most likely and IFF and hence is an expression.
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
var codeNoStrings = code.replace(STRING_LITERAL, 'STRING_LITERAL');
|
|
429
|
+
var identifiers = codeNoStrings.split(EXPRESSION_SEPARATORS);
|
|
430
|
+
var filteredIdentifiers = identifiers.filter(function (i) {
|
|
431
|
+
i = i.trim();
|
|
432
|
+
return i && !i.match(EXPRESSION_IDENTIFIER);
|
|
433
|
+
});
|
|
434
|
+
return filteredIdentifiers.length !== 0;
|
|
435
|
+
}
|
|
436
|
+
exports.isStatement = isStatement;
|
|
437
|
+
// https://regexr.com/6cppf
|
|
438
|
+
var STRING_LITERAL = /(["'`])((\\{2})*|((\n|.)*?[^\\](\\{2})*))\1/g;
|
|
439
|
+
// https://regexr.com/6cpk4
|
|
440
|
+
var EXPRESSION_SEPARATORS = /[()\[\]{}.\?:\-+/*,]+/;
|
|
441
|
+
// https://regexr.com/6cpka
|
|
442
|
+
var EXPRESSION_IDENTIFIER = /^\s*[a-zA-Z0-9_$]+\s*$/;
|
|
443
|
+
function lastProperty(expr) {
|
|
444
|
+
var parts = expr.split('.');
|
|
445
|
+
return parts[parts.length - 1];
|
|
446
|
+
}
|
|
447
|
+
exports.lastProperty = lastProperty;
|
|
448
|
+
function iteratorProperty(expr) {
|
|
449
|
+
return lastProperty(expr) + 'Item';
|
|
450
|
+
}
|
|
451
|
+
exports.iteratorProperty = iteratorProperty;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from '../modules/plugins';
|
|
2
|
+
import { MitosisComponent } from '../types/mitosis-component';
|
|
3
|
+
declare type ToQwikOptions = {
|
|
4
|
+
prettier?: boolean;
|
|
5
|
+
plugins?: Plugin[];
|
|
6
|
+
qwikLib?: string;
|
|
7
|
+
qrlPrefix?: string;
|
|
8
|
+
cssNamespace?: string;
|
|
9
|
+
minifyStyles?: boolean;
|
|
10
|
+
qrlSuffix?: string;
|
|
11
|
+
bundle?: boolean;
|
|
12
|
+
format?: 'builder' | 'default';
|
|
13
|
+
};
|
|
14
|
+
export declare type File = {
|
|
15
|
+
path: string;
|
|
16
|
+
contents: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const componentToQwik: (componentJson: MitosisComponent, toQwikOptions?: ToQwikOptions) => Promise<{
|
|
19
|
+
files: File[];
|
|
20
|
+
}>;
|
|
21
|
+
export {};
|