@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
|
@@ -4,13 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.iteratorProperty = exports.lastProperty = exports.isStatement = exports.iif = exports.arrowFnValue = exports.arrowFnBlock = exports.invoke = exports.quote = exports.Imports = exports.Symbol = exports.SrcBuilder = exports.File = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const parser_typescript_1 = __importDefault(require("prettier/parser-typescript"));
|
|
8
|
+
const standalone_1 = require("prettier/standalone");
|
|
9
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
10
|
+
const builder_1 = require("../../parsers/builder");
|
|
11
|
+
const stable_serialize_1 = require("./helpers/stable-serialize");
|
|
12
|
+
class File {
|
|
13
|
+
get module() {
|
|
14
|
+
return this.filename.substr(0, this.filename.lastIndexOf('.'));
|
|
15
|
+
}
|
|
16
|
+
get path() {
|
|
17
|
+
return this.filename;
|
|
18
|
+
}
|
|
19
|
+
get contents() {
|
|
20
|
+
return this.toString();
|
|
21
|
+
}
|
|
22
|
+
constructor(filename, options, qwikModule, qrlPrefix) {
|
|
14
23
|
this.imports = new Imports();
|
|
15
24
|
this.exports = new Map();
|
|
16
25
|
this.filename = filename;
|
|
@@ -19,41 +28,19 @@ var File = /** @class */ (function () {
|
|
|
19
28
|
this.qwikModule = qwikModule;
|
|
20
29
|
this.qrlPrefix = qrlPrefix;
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
get: function () {
|
|
24
|
-
return this.filename.substr(0, this.filename.lastIndexOf('.'));
|
|
25
|
-
},
|
|
26
|
-
enumerable: false,
|
|
27
|
-
configurable: true
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(File.prototype, "path", {
|
|
30
|
-
get: function () {
|
|
31
|
-
return this.filename;
|
|
32
|
-
},
|
|
33
|
-
enumerable: false,
|
|
34
|
-
configurable: true
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(File.prototype, "contents", {
|
|
37
|
-
get: function () {
|
|
38
|
-
return this.toString();
|
|
39
|
-
},
|
|
40
|
-
enumerable: false,
|
|
41
|
-
configurable: true
|
|
42
|
-
});
|
|
43
|
-
File.prototype.import = function (module, symbol, as) {
|
|
31
|
+
import(module, symbol, as) {
|
|
44
32
|
return this.imports.get(module, symbol, as);
|
|
45
|
-
}
|
|
46
|
-
|
|
33
|
+
}
|
|
34
|
+
toQrlChunk() {
|
|
47
35
|
return quote(this.qrlPrefix + this.module + '.js');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (locallyVisible === void 0) { locallyVisible = false; }
|
|
36
|
+
}
|
|
37
|
+
exportConst(name, value, locallyVisible = false) {
|
|
51
38
|
if (this.exports.has(name))
|
|
52
39
|
return;
|
|
53
40
|
this.exports.set(name, this.src.isModule ? name : 'exports.' + name);
|
|
54
41
|
this.src.const(name, value, true, locallyVisible);
|
|
55
|
-
}
|
|
56
|
-
|
|
42
|
+
}
|
|
43
|
+
exportDefault(symbolName) {
|
|
57
44
|
if (this.options.isPretty) {
|
|
58
45
|
this.src.emit('\n\n');
|
|
59
46
|
}
|
|
@@ -63,23 +50,22 @@ var File = /** @class */ (function () {
|
|
|
63
50
|
else {
|
|
64
51
|
this.src.emit('module.exports=', symbolName, ';');
|
|
65
52
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
modules.forEach(function (module) {
|
|
53
|
+
}
|
|
54
|
+
toString() {
|
|
55
|
+
const srcImports = new SrcBuilder(this, this.options);
|
|
56
|
+
const imports = this.imports.imports;
|
|
57
|
+
const modules = Array.from(imports.keys()).sort();
|
|
58
|
+
modules.forEach((module) => {
|
|
73
59
|
if (module == '<SELF>')
|
|
74
60
|
return;
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
const symbolMap = imports.get(module);
|
|
62
|
+
const symbols = Array.from(symbolMap.values());
|
|
77
63
|
symbols.sort(symbolSort);
|
|
78
|
-
if (removeExt(module) !== removeExt(
|
|
64
|
+
if (removeExt(module) !== removeExt(this.qrlPrefix + this.filename)) {
|
|
79
65
|
srcImports.import(module, symbols);
|
|
80
66
|
}
|
|
81
67
|
});
|
|
82
|
-
|
|
68
|
+
let source = srcImports.toString() + this.src.toString();
|
|
83
69
|
if (this.options.isPretty) {
|
|
84
70
|
try {
|
|
85
71
|
source = (0, standalone_1.format)(source, {
|
|
@@ -101,19 +87,18 @@ var File = /** @class */ (function () {
|
|
|
101
87
|
}
|
|
102
88
|
}
|
|
103
89
|
return source;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
107
92
|
exports.File = File;
|
|
108
93
|
function symbolSort(a, b) {
|
|
109
94
|
return a.importName < b.importName ? -1 : a.importName === b.importName ? 0 : 1;
|
|
110
95
|
}
|
|
111
96
|
function removeExt(filename) {
|
|
112
|
-
|
|
97
|
+
const indx = filename.lastIndexOf('.');
|
|
113
98
|
return indx == -1 ? filename : filename.substr(0, indx);
|
|
114
99
|
}
|
|
115
|
-
|
|
116
|
-
|
|
100
|
+
class SrcBuilder {
|
|
101
|
+
constructor(file, options) {
|
|
117
102
|
this.buf = [];
|
|
118
103
|
this.jsxDepth = 0;
|
|
119
104
|
/**
|
|
@@ -128,8 +113,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
128
113
|
this.isJSX = options.isJSX;
|
|
129
114
|
this.isBuilder = options.isBuilder;
|
|
130
115
|
}
|
|
131
|
-
|
|
132
|
-
var _this = this;
|
|
116
|
+
import(module, symbols) {
|
|
133
117
|
if (this.isModule) {
|
|
134
118
|
this.emit('import');
|
|
135
119
|
if (symbols.length === 1 && symbols[0].importName === 'default') {
|
|
@@ -137,22 +121,22 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
137
121
|
}
|
|
138
122
|
else {
|
|
139
123
|
this.emit('{');
|
|
140
|
-
symbols.forEach(
|
|
124
|
+
symbols.forEach((symbol) => {
|
|
141
125
|
if (symbol.importName === symbol.localName) {
|
|
142
|
-
|
|
126
|
+
this.emit(symbol.importName);
|
|
143
127
|
}
|
|
144
128
|
else {
|
|
145
|
-
|
|
129
|
+
this.emit(symbol.importName, ' as ', symbol.localName);
|
|
146
130
|
}
|
|
147
|
-
|
|
131
|
+
this.emit(',');
|
|
148
132
|
});
|
|
149
133
|
this.emit('}');
|
|
150
134
|
}
|
|
151
135
|
this.emit('from', quote(module), ';');
|
|
152
136
|
}
|
|
153
137
|
else {
|
|
154
|
-
symbols.forEach(
|
|
155
|
-
|
|
138
|
+
symbols.forEach((symbol) => {
|
|
139
|
+
this.const(symbol.localName, function () {
|
|
156
140
|
this.emit(invoke('require', [quote(module)]));
|
|
157
141
|
if (symbol.importName !== 'default') {
|
|
158
142
|
this.emit('.', symbol.importName);
|
|
@@ -164,14 +148,10 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
164
148
|
this.emit('\n\n');
|
|
165
149
|
}
|
|
166
150
|
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
values[_i] = arguments[_i];
|
|
172
|
-
}
|
|
173
|
-
for (var i = 0; i < values.length; i++) {
|
|
174
|
-
var value = values[i];
|
|
151
|
+
}
|
|
152
|
+
emit(...values) {
|
|
153
|
+
for (let i = 0; i < values.length; i++) {
|
|
154
|
+
const value = values[i];
|
|
175
155
|
if (typeof value == 'function') {
|
|
176
156
|
value.call(this);
|
|
177
157
|
}
|
|
@@ -195,8 +175,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
195
175
|
}
|
|
196
176
|
else if (typeof value == 'object') {
|
|
197
177
|
this.emit('{');
|
|
198
|
-
|
|
199
|
-
for (
|
|
178
|
+
let separator = false;
|
|
179
|
+
for (const key in value) {
|
|
200
180
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
201
181
|
if (separator) {
|
|
202
182
|
this.emit(',');
|
|
@@ -212,8 +192,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
212
192
|
}
|
|
213
193
|
}
|
|
214
194
|
return this;
|
|
215
|
-
}
|
|
216
|
-
|
|
195
|
+
}
|
|
196
|
+
push(value) {
|
|
217
197
|
if (value.startsWith(')') ||
|
|
218
198
|
value.startsWith(':') ||
|
|
219
199
|
value.startsWith(']') ||
|
|
@@ -221,20 +201,18 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
221
201
|
value.startsWith(',') ||
|
|
222
202
|
value.startsWith('?')) {
|
|
223
203
|
// clear last ',' or ';';
|
|
224
|
-
|
|
225
|
-
|
|
204
|
+
let index = this.buf.length - 1;
|
|
205
|
+
let ch = this.buf[index];
|
|
226
206
|
if (ch.endsWith(',') || ch.endsWith(';')) {
|
|
227
207
|
ch = ch.substring(0, ch.length - 1);
|
|
228
208
|
this.buf[index] = ch;
|
|
229
209
|
}
|
|
230
210
|
}
|
|
231
211
|
this.buf.push(value);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
237
|
-
var value = values_1[_i];
|
|
212
|
+
}
|
|
213
|
+
emitList(values, sep = ',') {
|
|
214
|
+
let separator = false;
|
|
215
|
+
for (const value of values) {
|
|
238
216
|
if (separator) {
|
|
239
217
|
this.emit(sep);
|
|
240
218
|
}
|
|
@@ -242,10 +220,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
242
220
|
separator = true;
|
|
243
221
|
}
|
|
244
222
|
return this;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (export_ === void 0) { export_ = false; }
|
|
248
|
-
if (locallyVisible === void 0) { locallyVisible = false; }
|
|
223
|
+
}
|
|
224
|
+
const(name, value, export_ = false, locallyVisible = false) {
|
|
249
225
|
if (export_) {
|
|
250
226
|
this.emit(this.isModule
|
|
251
227
|
? 'export const '
|
|
@@ -260,20 +236,20 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
260
236
|
}
|
|
261
237
|
this.emit(';');
|
|
262
238
|
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
239
|
+
}
|
|
240
|
+
type(def) {
|
|
265
241
|
if (this.isTypeScript) {
|
|
266
242
|
this.emit(':', def);
|
|
267
243
|
}
|
|
268
244
|
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
245
|
+
}
|
|
246
|
+
typeParameters(typeParameters) {
|
|
271
247
|
if (this.isTypeScript && typeParameters && typeParameters.length) {
|
|
272
248
|
this.emit('<', typeParameters, '>');
|
|
273
249
|
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
250
|
+
}
|
|
251
|
+
jsxExpression(expression) {
|
|
252
|
+
const previousJsxDepth = this.jsxDepth;
|
|
277
253
|
try {
|
|
278
254
|
if (previousJsxDepth) {
|
|
279
255
|
this.jsxDepth = 0;
|
|
@@ -287,10 +263,10 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
287
263
|
}
|
|
288
264
|
this.jsxDepth = previousJsxDepth;
|
|
289
265
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
266
|
+
}
|
|
267
|
+
jsxBegin(symbol, props, bindings) {
|
|
292
268
|
this.jsxDepth++;
|
|
293
|
-
|
|
269
|
+
const self = this;
|
|
294
270
|
if (symbol == 'div' && ('href' in props || 'href' in bindings)) {
|
|
295
271
|
// HACK: if we contain href then we are `a` not `div`
|
|
296
272
|
symbol = 'a';
|
|
@@ -301,60 +277,56 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
301
277
|
else {
|
|
302
278
|
this.emit('h(', literalTagName(symbol), ',{');
|
|
303
279
|
}
|
|
304
|
-
for (
|
|
280
|
+
for (const key in props) {
|
|
305
281
|
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
306
282
|
!ignoreKey(key) &&
|
|
307
283
|
!Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
308
284
|
emitJsxProp(key, quote(props[key]));
|
|
309
285
|
}
|
|
310
286
|
}
|
|
311
|
-
|
|
287
|
+
for (const rawKey in bindings) {
|
|
312
288
|
if (bindings[rawKey].type === 'spread') {
|
|
313
|
-
if (
|
|
314
|
-
|
|
289
|
+
if (this.isJSX) {
|
|
290
|
+
this.emit('{...', bindings[rawKey].code, '}');
|
|
315
291
|
}
|
|
316
292
|
else {
|
|
317
|
-
|
|
293
|
+
this.emit('...', bindings[rawKey].code);
|
|
318
294
|
}
|
|
319
295
|
}
|
|
320
296
|
else if (Object.prototype.hasOwnProperty.call(bindings, rawKey) && !ignoreKey(rawKey)) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
297
|
+
let binding = bindings[rawKey];
|
|
298
|
+
binding =
|
|
299
|
+
binding && typeof binding == 'object' && 'code' in binding ? binding.code : binding;
|
|
324
300
|
if (rawKey === 'class' && props.class) {
|
|
325
301
|
// special case for classes as they can have both static and dynamic binding
|
|
326
|
-
|
|
302
|
+
binding = quote(props.class + ' ') + '+' + binding;
|
|
327
303
|
}
|
|
328
|
-
|
|
304
|
+
let key = lastProperty(rawKey);
|
|
329
305
|
if (isEvent(key)) {
|
|
330
306
|
key = key + '$';
|
|
331
|
-
|
|
307
|
+
binding = `${this.file.import(this.file.qwikModule, '$').localName}((event)=>${binding})`;
|
|
332
308
|
}
|
|
333
|
-
else if (!
|
|
334
|
-
|
|
309
|
+
else if (!binding && rawKey in props) {
|
|
310
|
+
binding = quote(props[rawKey]);
|
|
335
311
|
}
|
|
336
|
-
else if (
|
|
312
|
+
else if (binding != null && binding === props[key]) {
|
|
337
313
|
// HACK: workaround for the fact that sometimes the `bindings` have string literals
|
|
338
314
|
// We assume that when the binding content equals prop content.
|
|
339
|
-
|
|
315
|
+
binding = quote(binding);
|
|
340
316
|
}
|
|
341
|
-
else if (typeof
|
|
342
|
-
|
|
317
|
+
else if (typeof binding == 'string' && isStatement(binding)) {
|
|
318
|
+
binding = iif(binding);
|
|
343
319
|
}
|
|
344
320
|
if (key === 'hide' || key === 'show') {
|
|
345
|
-
|
|
321
|
+
let [truthy, falsy] = key == 'hide' ? ['"none"', '"inherit"'] : ['"inherit"', '"none"'];
|
|
346
322
|
emitJsxProp('style', function () {
|
|
347
|
-
this.emit('{display:',
|
|
323
|
+
this.emit('{display:', binding, '?', truthy, ':', falsy, '}');
|
|
348
324
|
});
|
|
349
325
|
}
|
|
350
326
|
else {
|
|
351
|
-
emitJsxProp(key,
|
|
327
|
+
emitJsxProp(key, binding);
|
|
352
328
|
}
|
|
353
329
|
}
|
|
354
|
-
};
|
|
355
|
-
var this_1 = this;
|
|
356
|
-
for (var rawKey in bindings) {
|
|
357
|
-
_loop_1(rawKey);
|
|
358
330
|
}
|
|
359
331
|
if (this.isJSX) {
|
|
360
332
|
if (!this.isSelfClosingTag(symbol)) {
|
|
@@ -388,11 +360,11 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
388
360
|
}
|
|
389
361
|
}
|
|
390
362
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
363
|
+
}
|
|
364
|
+
isSelfClosingTag(symbol) {
|
|
393
365
|
return html_tags_1.SELF_CLOSING_HTML_TAGS.has(String(symbol));
|
|
394
|
-
}
|
|
395
|
-
|
|
366
|
+
}
|
|
367
|
+
jsxEnd(symbol) {
|
|
396
368
|
if (this.isJSX) {
|
|
397
369
|
if (this.isSelfClosingTag(symbol)) {
|
|
398
370
|
this.emit(' />');
|
|
@@ -405,8 +377,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
405
377
|
this.emit('),');
|
|
406
378
|
}
|
|
407
379
|
this.jsxDepth--;
|
|
408
|
-
}
|
|
409
|
-
|
|
380
|
+
}
|
|
381
|
+
jsxBeginFragment(symbol) {
|
|
410
382
|
this.jsxDepth++;
|
|
411
383
|
if (this.isJSX) {
|
|
412
384
|
this.emit('<>');
|
|
@@ -414,8 +386,8 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
414
386
|
else {
|
|
415
387
|
this.emit('h(', symbol.localName, ',null,');
|
|
416
388
|
}
|
|
417
|
-
}
|
|
418
|
-
|
|
389
|
+
}
|
|
390
|
+
jsxEndFragment() {
|
|
419
391
|
this.jsxDepth--;
|
|
420
392
|
if (this.isJSX) {
|
|
421
393
|
this.emit('</>');
|
|
@@ -423,20 +395,19 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
423
395
|
else {
|
|
424
396
|
this.emit(')');
|
|
425
397
|
}
|
|
426
|
-
}
|
|
427
|
-
|
|
398
|
+
}
|
|
399
|
+
jsxTextBinding(exp) {
|
|
428
400
|
if (this.isJSX) {
|
|
429
401
|
this.emit('{', exp, '}');
|
|
430
402
|
}
|
|
431
403
|
else {
|
|
432
404
|
this.emit(exp);
|
|
433
405
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
406
|
+
}
|
|
407
|
+
toString() {
|
|
436
408
|
return this.buf.join('');
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
}());
|
|
409
|
+
}
|
|
410
|
+
}
|
|
440
411
|
exports.SrcBuilder = SrcBuilder;
|
|
441
412
|
function isEvent(name) {
|
|
442
413
|
return name.startsWith('on') && isUppercase(name.charAt(2)) && !name.endsWith('$');
|
|
@@ -444,45 +415,41 @@ function isEvent(name) {
|
|
|
444
415
|
function isUppercase(ch) {
|
|
445
416
|
return ch == ch.toUpperCase();
|
|
446
417
|
}
|
|
447
|
-
|
|
448
|
-
|
|
418
|
+
class Symbol {
|
|
419
|
+
constructor(importName, localName) {
|
|
449
420
|
this.importName = importName;
|
|
450
421
|
this.localName = localName;
|
|
451
422
|
}
|
|
452
|
-
|
|
453
|
-
}());
|
|
423
|
+
}
|
|
454
424
|
exports.Symbol = Symbol;
|
|
455
|
-
|
|
456
|
-
|
|
425
|
+
class Imports {
|
|
426
|
+
constructor() {
|
|
457
427
|
this.imports = new Map();
|
|
458
428
|
}
|
|
459
|
-
|
|
460
|
-
|
|
429
|
+
get(moduleName, symbolName, asVar) {
|
|
430
|
+
let importSymbols = this.imports.get(moduleName);
|
|
461
431
|
if (!importSymbols) {
|
|
462
432
|
importSymbols = new Map();
|
|
463
433
|
this.imports.set(moduleName, importSymbols);
|
|
464
434
|
}
|
|
465
|
-
|
|
435
|
+
let symbol = importSymbols.get(symbolName);
|
|
466
436
|
if (!symbol) {
|
|
467
437
|
symbol = new Symbol(symbolName, asVar || symbolName);
|
|
468
438
|
importSymbols.set(symbolName, symbol);
|
|
469
439
|
}
|
|
470
440
|
return symbol;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
for (
|
|
474
|
-
|
|
475
|
-
for (var _b = 0, _c = Array.from(symbolMap.values()); _b < _c.length; _b++) {
|
|
476
|
-
var symbol = _c[_b];
|
|
441
|
+
}
|
|
442
|
+
hasImport(localName) {
|
|
443
|
+
for (const symbolMap of Array.from(this.imports.values())) {
|
|
444
|
+
for (const symbol of Array.from(symbolMap.values())) {
|
|
477
445
|
if (symbol.localName === localName) {
|
|
478
446
|
return true;
|
|
479
447
|
}
|
|
480
448
|
}
|
|
481
449
|
}
|
|
482
450
|
return false;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
}());
|
|
451
|
+
}
|
|
452
|
+
}
|
|
486
453
|
exports.Imports = Imports;
|
|
487
454
|
function ignoreKey(key) {
|
|
488
455
|
return (key.startsWith('$') ||
|
|
@@ -495,12 +462,12 @@ function possiblyQuotePropertyName(key) {
|
|
|
495
462
|
return /^\w[\w\d]*$/.test(key) ? key : quote(key);
|
|
496
463
|
}
|
|
497
464
|
function quote(text) {
|
|
498
|
-
|
|
465
|
+
const string = (0, stable_serialize_1.stableJSONserialize)(text);
|
|
499
466
|
// So \u2028 is a line separator character and prettier treats it as such
|
|
500
467
|
// https://www.fileformat.info/info/unicode/char/2028/index.htm
|
|
501
468
|
// That means it can't be inside of a string, so we replace it with `\\u2028`.
|
|
502
469
|
// (see double `\\` vs `\`)
|
|
503
|
-
|
|
470
|
+
const parts = string.split('\u2028');
|
|
504
471
|
return parts.join('\\u2028');
|
|
505
472
|
}
|
|
506
473
|
exports.quote = quote;
|
|
@@ -515,9 +482,9 @@ exports.invoke = invoke;
|
|
|
515
482
|
function arrowFnBlock(args, statements, argTypes) {
|
|
516
483
|
return function () {
|
|
517
484
|
this.emit('(');
|
|
518
|
-
for (
|
|
519
|
-
|
|
520
|
-
|
|
485
|
+
for (let i = 0; i < args.length; i++) {
|
|
486
|
+
const arg = args[i];
|
|
487
|
+
const type = argTypes && argTypes[i];
|
|
521
488
|
this.emit(arg);
|
|
522
489
|
if (type && this.file.options.isTypeScript) {
|
|
523
490
|
this.emit(':', type);
|
|
@@ -534,8 +501,8 @@ function arrowFnValue(args, expression) {
|
|
|
534
501
|
};
|
|
535
502
|
}
|
|
536
503
|
exports.arrowFnValue = arrowFnValue;
|
|
537
|
-
|
|
538
|
-
|
|
504
|
+
const _virtual_index = '_virtual_index;';
|
|
505
|
+
const return_virtual_index = 'return _virtual_index;';
|
|
539
506
|
function iif(code) {
|
|
540
507
|
if (!code)
|
|
541
508
|
return;
|
|
@@ -551,7 +518,7 @@ function iif(code) {
|
|
|
551
518
|
};
|
|
552
519
|
}
|
|
553
520
|
exports.iif = iif;
|
|
554
|
-
|
|
521
|
+
const LOWER_CASE = 'a'.charCodeAt(0) - 1;
|
|
555
522
|
function literalTagName(symbol) {
|
|
556
523
|
if (typeof symbol == 'string' &&
|
|
557
524
|
symbol.charCodeAt(0) > LOWER_CASE &&
|
|
@@ -581,9 +548,9 @@ function isStatement(code) {
|
|
|
581
548
|
// Code starting with `(` is most likely an IFF and hence is an expression.
|
|
582
549
|
return false;
|
|
583
550
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
551
|
+
const codeNoStrings = code.replace(STRING_LITERAL, 'STRING_LITERAL');
|
|
552
|
+
const identifiers = codeNoStrings.split(EXPRESSION_SEPARATORS);
|
|
553
|
+
const filteredIdentifiers = identifiers.filter((i) => {
|
|
587
554
|
i = i.trim();
|
|
588
555
|
return i && !i.match(EXPRESSION_IDENTIFIER);
|
|
589
556
|
});
|
|
@@ -591,13 +558,13 @@ function isStatement(code) {
|
|
|
591
558
|
}
|
|
592
559
|
exports.isStatement = isStatement;
|
|
593
560
|
// https://regexr.com/6cppf
|
|
594
|
-
|
|
561
|
+
const STRING_LITERAL = /(["'`])((\\{2})*|((\n|.)*?[^\\](\\{2})*))\1/g;
|
|
595
562
|
// https://regexr.com/6cpk4
|
|
596
|
-
|
|
563
|
+
const EXPRESSION_SEPARATORS = /[()\[\]{}.\?:\-+/*,|&]+/;
|
|
597
564
|
// https://regexr.com/6cpka
|
|
598
|
-
|
|
565
|
+
const EXPRESSION_IDENTIFIER = /^\s*[a-zA-Z0-9_$]+\s*$/;
|
|
599
566
|
function lastProperty(expr) {
|
|
600
|
-
|
|
567
|
+
const parts = expr.split('.');
|
|
601
568
|
return parts[parts.length - 1];
|
|
602
569
|
}
|
|
603
570
|
exports.lastProperty = lastProperty;
|