@builder.io/mitosis 0.0.50-6 → 0.0.50
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.js +6 -0
- package/dist/src/__tests__/builder.test.js +5 -1
- package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.jsx +13 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +19 -0
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +6 -3
- package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component.raw.jsx +12 -0
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +54 -0
- package/dist/src/__tests__/data/blocks/slot.raw.d.ts +5 -0
- package/dist/src/__tests__/data/blocks/slot.raw.jsx +6 -0
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +8 -0
- package/dist/src/__tests__/data/blocks/styles.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/styles.raw.jsx +10 -0
- package/dist/src/__tests__/data/context/simple.context.lite.d.ts +8 -1
- package/dist/src/__tests__/html.test.js +6 -0
- package/dist/src/__tests__/qwik.directive.test.d.ts +1 -0
- package/dist/src/__tests__/qwik.directive.test.js +107 -0
- package/dist/src/__tests__/qwik.test.js +256 -128
- package/dist/src/__tests__/react-native.test.js +12 -0
- package/dist/src/__tests__/react.test.js +12 -0
- package/dist/src/__tests__/svelte.test.js +24 -0
- package/dist/src/__tests__/vue.test.js +12 -0
- package/dist/src/__tests__/webcomponent.test.d.ts +1 -0
- package/dist/src/__tests__/webcomponent.test.js +12 -0
- package/dist/src/constants/html_tags.d.ts +1 -0
- package/dist/src/constants/html_tags.js +119 -0
- package/dist/src/generators/angular.js +7 -4
- package/dist/src/generators/context/react copy.d.ts +8 -0
- package/dist/src/generators/context/react copy.js +28 -0
- package/dist/src/generators/context/solid.d.ts +8 -0
- package/dist/src/generators/context/solid.js +28 -0
- package/dist/src/generators/context/svelte.d.ts +8 -0
- package/dist/src/generators/context/svelte.js +28 -0
- package/dist/src/generators/helpers/context.d.ts +2 -0
- package/dist/src/generators/helpers/context.js +8 -0
- package/dist/src/generators/html.js +20 -14
- package/dist/src/generators/mitosis.js +4 -3
- package/dist/src/generators/qwik/component.js +26 -5
- package/dist/src/generators/qwik/directives.d.ts +14 -5
- package/dist/src/generators/qwik/directives.js +32 -25
- package/dist/src/generators/qwik/handlers.js +3 -4
- package/dist/src/generators/qwik/jsx.js +17 -5
- package/dist/src/generators/qwik/src-generator.d.ts +0 -9
- package/dist/src/generators/qwik/src-generator.js +93 -101
- package/dist/src/generators/qwik/styles.js +8 -11
- package/dist/src/generators/react.js +9 -8
- package/dist/src/generators/solid.js +82 -8
- package/dist/src/generators/stencil/generate.js +5 -3
- package/dist/src/generators/stencil/index.js +5 -1
- package/dist/src/generators/svelte.d.ts +9 -1
- package/dist/src/generators/svelte.js +175 -76
- package/dist/src/generators/vue.d.ts +1 -1
- package/dist/src/generators/vue.js +86 -10
- package/dist/src/helpers/babel-transform copy.d.ts +8 -0
- package/dist/src/helpers/babel-transform copy.js +138 -0
- package/dist/src/helpers/babel-transform.d.ts +4 -7
- package/dist/src/helpers/babel-transform.js +18 -2
- package/dist/src/helpers/babel-transform.test.d.ts +1 -0
- package/dist/src/helpers/babel-transform.test.js +7 -0
- package/dist/src/helpers/create-mitosis-component.js +1 -1
- package/dist/src/helpers/get-state-object-string.js +2 -1
- package/dist/src/helpers/map-refs.js +22 -9
- package/dist/src/helpers/parsers.d.ts +8 -0
- package/dist/src/helpers/parsers.js +66 -0
- package/dist/src/helpers/render-imports.d.ts +2 -4
- package/dist/src/helpers/render-imports.js +32 -14
- package/dist/src/index.d.ts +10 -5
- package/dist/src/index.js +11 -5
- package/dist/src/parsers/builder.d.ts +16 -50
- package/dist/src/parsers/builder.js +22 -40
- package/dist/src/parsers/context.js +5 -1
- package/dist/src/parsers/jsx.d.ts +7 -0
- package/dist/src/parsers/jsx.js +27 -5
- package/dist/src/parsers/liquid.js +5 -1
- package/dist/src/plugins/compile-away-builder-components.js +5 -1
- package/dist/src/symbols/symbol-processor.js +3 -3
- package/dist/src/targets.d.ts +1 -1
- package/dist/src/types/mitosis-component.d.ts +8 -3
- package/dist/test/qwik/Accordion/high.jsx +0 -1
- package/dist/test/qwik/Accordion/low.jsx +171 -65
- package/dist/test/qwik/Accordion/med.jsx +9 -10
- package/dist/test/qwik/For/high.jsx +0 -1
- package/dist/test/qwik/For/low.jsx +25 -58
- package/dist/test/qwik/For/med.jsx +9 -10
- package/dist/test/qwik/Image/high.js +9 -1
- package/dist/test/qwik/Image/low.js +0 -42
- package/dist/test/qwik/Image/med.js +149 -12
- package/dist/test/qwik/Image.slow/high.js +9 -1
- package/dist/test/qwik/Image.slow/low.js +0 -42
- package/dist/test/qwik/Image.slow/med.js +149 -12
- package/dist/{src/types/generators.d.ts → test/qwik/bindings/high.cjs} +0 -0
- package/dist/test/qwik/bindings/low.cjs +33 -0
- package/dist/test/qwik/bindings/med.cjs +12 -0
- package/dist/test/qwik/button/high.js +1 -13
- package/dist/test/qwik/button/low.js +8 -40
- package/dist/test/qwik/button/med.js +36 -11
- package/dist/test/qwik/component/bindings/high.jsx +0 -1
- package/dist/test/qwik/component/bindings/low.jsx +26 -71
- package/dist/test/qwik/component/bindings/med.jsx +48 -39
- package/dist/test/qwik/component/component/inputs/high.cjsx +9 -0
- package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
- package/dist/test/qwik/component/component/inputs/med.cjsx +65 -0
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -1
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +6 -27
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +9 -10
- package/dist/test/qwik/page-with-symbol/high.js +0 -1
- package/dist/test/qwik/page-with-symbol/low.js +15 -52
- package/dist/test/qwik/page-with-symbol/med.js +9 -10
- package/dist/test/qwik/show-hide/high.jsx +9 -0
- package/dist/test/qwik/show-hide/low.jsx +0 -0
- package/dist/test/qwik/show-hide/med.jsx +174 -0
- package/dist/test/qwik/svg/high.js +0 -1
- package/dist/test/qwik/svg/low.js +9 -35
- package/dist/test/qwik/svg/med.js +9 -10
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +4 -39
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -1
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +38 -61
- package/dist/test/qwik/todo/Todo.js/high.js +22 -5
- package/dist/test/qwik/todo/Todo.js/med.js +45 -1
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +4 -39
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -1
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +31 -34
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -12
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +18 -25
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +8 -10
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/dist/src/__tests__/data/blocks/onMount-onUnMount.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/onMount-onUnMount.jsx +0 -13
- package/dist/src/__tests__/data/blocks/onMount.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/onMount.jsx +0 -13
- package/dist/src/types/generators.js +0 -1
|
@@ -63,18 +63,17 @@ function renderHandler(file, symbol, code) {
|
|
|
63
63
|
file.exportConst(symbol, function () {
|
|
64
64
|
this.emit([(0, src_generator_1.arrowFnBlock)([], body)]);
|
|
65
65
|
});
|
|
66
|
-
file.src.emit(src_generator_1.NL);
|
|
67
66
|
}
|
|
68
67
|
function wrapWithUse(file, code) {
|
|
69
68
|
var needsEvent = !!code.match(/\bevent\b/);
|
|
70
69
|
if (needsEvent) {
|
|
71
70
|
return function () {
|
|
72
|
-
this.emit('{'
|
|
71
|
+
this.emit('{');
|
|
73
72
|
needsEvent &&
|
|
74
|
-
this.emit('const event
|
|
73
|
+
this.emit('const event=', (0, src_generator_1.invoke)(file.import(file.qwikModule, 'useEvent'), []), ';');
|
|
75
74
|
var blockContent = stripBlock(code);
|
|
76
75
|
this.emit(blockContent);
|
|
77
|
-
this.emit(
|
|
76
|
+
this.emit('}');
|
|
78
77
|
};
|
|
79
78
|
}
|
|
80
79
|
else {
|
|
@@ -30,7 +30,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
30
30
|
if (children.length == 0)
|
|
31
31
|
return;
|
|
32
32
|
if (root)
|
|
33
|
-
this.emit('('
|
|
33
|
+
this.emit('(');
|
|
34
34
|
var needsFragment = root && children.length > 1;
|
|
35
35
|
file.import(file.qwikModule, 'h');
|
|
36
36
|
if (needsFragment) {
|
|
@@ -61,6 +61,11 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
61
61
|
else {
|
|
62
62
|
if (typeof directive == 'string') {
|
|
63
63
|
directives.set(childName, directive);
|
|
64
|
+
Array.from(directive.matchAll(/(__[^_]+__)/g)).forEach(function (match) {
|
|
65
|
+
var name = match[0];
|
|
66
|
+
var code = directives_1.DIRECTIVES[name];
|
|
67
|
+
typeof code == 'string' && directives.set(name, code);
|
|
68
|
+
});
|
|
64
69
|
if (file.module !== 'med') {
|
|
65
70
|
file.import('./med.js', childName);
|
|
66
71
|
}
|
|
@@ -75,13 +80,20 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
75
80
|
}
|
|
76
81
|
var props = child.properties;
|
|
77
82
|
var css = child.bindings.css;
|
|
83
|
+
var specialBindings = {};
|
|
78
84
|
if (css) {
|
|
79
85
|
props = __assign({}, props);
|
|
80
|
-
|
|
86
|
+
var styleProps = styles.get(css);
|
|
87
|
+
var imageMaxWidth = childName == 'Image' && styleProps.maxWidth;
|
|
88
|
+
if (imageMaxWidth && imageMaxWidth.endsWith('px')) {
|
|
89
|
+
// special case for Images. We want to make sure that we include the maxWidth in a srcset
|
|
90
|
+
specialBindings.srcsetSizes = Number.parseInt(imageMaxWidth);
|
|
91
|
+
}
|
|
92
|
+
props.class = addClass(styleProps.CLASS_NAME, props.class);
|
|
81
93
|
}
|
|
82
94
|
var symbolBindings = {};
|
|
83
95
|
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
84
|
-
_this.jsxBegin(childName, props, __assign(__assign({}, bindings), parentSymbolBindings));
|
|
96
|
+
_this.jsxBegin(childName, props, __assign(__assign(__assign({}, bindings), parentSymbolBindings), specialBindings));
|
|
85
97
|
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
|
|
86
98
|
_this.jsxEnd(childName);
|
|
87
99
|
}
|
|
@@ -91,7 +103,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
91
103
|
this.jsxEndFragment();
|
|
92
104
|
}
|
|
93
105
|
if (root)
|
|
94
|
-
this.emit(
|
|
106
|
+
this.emit(')');
|
|
95
107
|
};
|
|
96
108
|
}
|
|
97
109
|
exports.renderJSXNodes = renderJSXNodes;
|
|
@@ -131,7 +143,7 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
|
131
143
|
continue;
|
|
132
144
|
}
|
|
133
145
|
else if ((handlerBlock = handlers.get(binding))) {
|
|
134
|
-
key = "
|
|
146
|
+
key = "".concat(key, "Qrl");
|
|
135
147
|
binding = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qrl'), [
|
|
136
148
|
(0, src_generator_1.quote)(file.qrlPrefix + 'high.js'),
|
|
137
149
|
(0, src_generator_1.quote)(handlerBlock),
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export declare const WS: string;
|
|
2
|
-
export declare const RS = " ";
|
|
3
|
-
export declare const NL = "\n";
|
|
4
|
-
export declare const INDENT: string;
|
|
5
|
-
export declare const UNINDENT: string;
|
|
6
1
|
export interface SrcBuilderOptions {
|
|
7
2
|
isPretty: boolean;
|
|
8
3
|
isTypeScript: boolean;
|
|
@@ -28,14 +23,10 @@ export declare class File {
|
|
|
28
23
|
toString(): string;
|
|
29
24
|
}
|
|
30
25
|
export declare class SrcBuilder {
|
|
31
|
-
isPretty: boolean;
|
|
32
26
|
isTypeScript: boolean;
|
|
33
27
|
isModule: boolean;
|
|
34
28
|
isJSX: boolean;
|
|
35
29
|
buf: string[];
|
|
36
|
-
wasLastNL: boolean;
|
|
37
|
-
nestingDepth: number;
|
|
38
|
-
offset: number;
|
|
39
30
|
constructor(options: SrcBuilderOptions);
|
|
40
31
|
import(module: string, symbols: string[]): this;
|
|
41
32
|
emit(...values: any[]): this;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 =
|
|
4
|
-
|
|
5
|
-
exports.RS = ' ';
|
|
6
|
-
exports.NL = '\n';
|
|
7
|
-
exports.INDENT = String.fromCharCode(16);
|
|
8
|
-
exports.UNINDENT = String.fromCharCode(17);
|
|
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
|
+
var standalone_1 = require("prettier/standalone");
|
|
9
5
|
var File = /** @class */ (function () {
|
|
10
6
|
function File(filename, options, qwikModule, qrlPrefix) {
|
|
11
7
|
this.imports = new Imports();
|
|
@@ -62,8 +58,21 @@ var File = /** @class */ (function () {
|
|
|
62
58
|
srcImports.import(module, symbols);
|
|
63
59
|
}
|
|
64
60
|
});
|
|
65
|
-
srcImports.
|
|
66
|
-
|
|
61
|
+
var source = srcImports.toString() + this.src.toString();
|
|
62
|
+
if (this.options.isPretty) {
|
|
63
|
+
source = (0, standalone_1.format)(source, {
|
|
64
|
+
parser: 'typescript',
|
|
65
|
+
plugins: [
|
|
66
|
+
// To support running in browsers
|
|
67
|
+
require('prettier/parser-typescript'),
|
|
68
|
+
require('prettier/parser-postcss'),
|
|
69
|
+
require('prettier/parser-html'),
|
|
70
|
+
require('prettier/parser-babel'),
|
|
71
|
+
],
|
|
72
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return source;
|
|
67
76
|
};
|
|
68
77
|
return File;
|
|
69
78
|
}());
|
|
@@ -76,10 +85,6 @@ var spaces = [''];
|
|
|
76
85
|
var SrcBuilder = /** @class */ (function () {
|
|
77
86
|
function SrcBuilder(options) {
|
|
78
87
|
this.buf = [];
|
|
79
|
-
this.wasLastNL = false;
|
|
80
|
-
this.nestingDepth = 0;
|
|
81
|
-
this.offset = 0;
|
|
82
|
-
this.isPretty = options.isPretty;
|
|
83
88
|
this.isTypeScript = options.isTypeScript;
|
|
84
89
|
this.isModule = options.isModule;
|
|
85
90
|
this.isJSX = options.isJSX;
|
|
@@ -87,7 +92,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
87
92
|
SrcBuilder.prototype.import = function (module, symbols) {
|
|
88
93
|
var _this = this;
|
|
89
94
|
if (this.isModule) {
|
|
90
|
-
this.emit('import
|
|
95
|
+
this.emit('import{', symbols, '}from', quote(module), ';');
|
|
91
96
|
}
|
|
92
97
|
else {
|
|
93
98
|
symbols.forEach(function (symbol) {
|
|
@@ -96,7 +101,6 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
96
101
|
});
|
|
97
102
|
});
|
|
98
103
|
}
|
|
99
|
-
this.emit(exports.NL);
|
|
100
104
|
return this;
|
|
101
105
|
};
|
|
102
106
|
SrcBuilder.prototype.emit = function () {
|
|
@@ -128,18 +132,18 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
128
132
|
this.emitList(value);
|
|
129
133
|
}
|
|
130
134
|
else if (typeof value == 'object') {
|
|
131
|
-
this.emit('{'
|
|
135
|
+
this.emit('{');
|
|
132
136
|
var separator = false;
|
|
133
137
|
for (var key in value) {
|
|
134
138
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
135
139
|
if (separator) {
|
|
136
|
-
this.emit(','
|
|
140
|
+
this.emit(',');
|
|
137
141
|
}
|
|
138
|
-
this.emit(possiblyQuotePropertyName(key)).emit(':',
|
|
142
|
+
this.emit(possiblyQuotePropertyName(key)).emit(':', value[key]);
|
|
139
143
|
separator = true;
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
|
-
this.emit(
|
|
146
|
+
this.emit('}');
|
|
143
147
|
}
|
|
144
148
|
else {
|
|
145
149
|
throw new Error('Unexpected value: ' + value);
|
|
@@ -148,35 +152,20 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
148
152
|
return this;
|
|
149
153
|
};
|
|
150
154
|
SrcBuilder.prototype.push = function (value) {
|
|
151
|
-
if (value
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
while (index > 1 && isWhitespace((ch = this.buf[index]))) {
|
|
163
|
-
index--;
|
|
164
|
-
}
|
|
165
|
-
if (ch == ',') {
|
|
166
|
-
this.buf[index] = '';
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (this.isPretty && this.wasLastNL) {
|
|
170
|
-
while (spaces.length <= this.nestingDepth) {
|
|
171
|
-
spaces.push(spaces[spaces.length - 1] + ' ');
|
|
172
|
-
}
|
|
173
|
-
this.buf.push(spaces[this.nestingDepth]);
|
|
174
|
-
}
|
|
175
|
-
this.wasLastNL = value === exports.NL;
|
|
176
|
-
if (this.isPretty || (value !== exports.WS && value !== exports.NL)) {
|
|
177
|
-
this.buf.push(value == exports.WS ? ' ' : value);
|
|
155
|
+
if (value.startsWith(')') ||
|
|
156
|
+
value.startsWith(':') ||
|
|
157
|
+
value.startsWith(']') ||
|
|
158
|
+
value.startsWith('}') ||
|
|
159
|
+
value.startsWith('?')) {
|
|
160
|
+
// clear last ',' or ';';
|
|
161
|
+
var index = this.buf.length - 1;
|
|
162
|
+
var ch = this.buf[index];
|
|
163
|
+
if (ch.endsWith(',') || ch.endsWith(';')) {
|
|
164
|
+
ch = ch.substring(0, ch.length - 1);
|
|
165
|
+
this.buf[index] = ch;
|
|
178
166
|
}
|
|
179
167
|
}
|
|
168
|
+
this.buf.push(value);
|
|
180
169
|
};
|
|
181
170
|
SrcBuilder.prototype.emitList = function (values, sep) {
|
|
182
171
|
if (sep === void 0) { sep = ','; }
|
|
@@ -184,7 +173,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
184
173
|
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
185
174
|
var value = values_1[_i];
|
|
186
175
|
if (separator) {
|
|
187
|
-
this.emit(sep
|
|
176
|
+
this.emit(sep);
|
|
188
177
|
}
|
|
189
178
|
this.emit(value);
|
|
190
179
|
separator = true;
|
|
@@ -204,9 +193,9 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
204
193
|
}
|
|
205
194
|
this.emit(name);
|
|
206
195
|
if (value !== undefined) {
|
|
207
|
-
this.emit(
|
|
196
|
+
this.emit('=', value);
|
|
208
197
|
}
|
|
209
|
-
this.emit(';'
|
|
198
|
+
this.emit(';');
|
|
210
199
|
return this;
|
|
211
200
|
};
|
|
212
201
|
SrcBuilder.prototype.type = function (def) {
|
|
@@ -221,6 +210,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
221
210
|
}
|
|
222
211
|
};
|
|
223
212
|
SrcBuilder.prototype.jsxBegin = function (symbol, props, bindings) {
|
|
213
|
+
var self = this;
|
|
224
214
|
if (symbol == 'div' && ('href' in props || 'href' in bindings)) {
|
|
225
215
|
// HACK: if we contain href then we are `a` not `div`
|
|
226
216
|
symbol = 'a';
|
|
@@ -229,91 +219,93 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
229
219
|
this.emit('<' + symbol);
|
|
230
220
|
}
|
|
231
221
|
else {
|
|
232
|
-
this.emit('h
|
|
222
|
+
this.emit('h(', literalTagName(symbol), ',{');
|
|
233
223
|
}
|
|
234
|
-
var first = true;
|
|
235
224
|
for (var key in props) {
|
|
236
225
|
if (Object.prototype.hasOwnProperty.call(props, key) &&
|
|
237
226
|
!ignoreKey(key) &&
|
|
238
227
|
!Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
239
|
-
|
|
240
|
-
first = false;
|
|
241
|
-
this.isJSX && this.emit(exports.RS, exports.INDENT, exports.INDENT);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
this.isJSX ? this.emit(exports.NL) : this.emit(',', exports.NL);
|
|
245
|
-
}
|
|
246
|
-
this.isJSX ? this.emit(key) : this.emit(possiblyQuotePropertyName(key));
|
|
247
|
-
this.isJSX ? this.emit('=') : this.emit(':', exports.WS);
|
|
248
|
-
this.emit(quote(props[key]));
|
|
228
|
+
emitJsxProp(possiblyQuotePropertyName(key), quote(props[key]));
|
|
249
229
|
}
|
|
250
230
|
}
|
|
251
|
-
|
|
231
|
+
var _loop_1 = function (rawKey) {
|
|
252
232
|
if (Object.prototype.hasOwnProperty.call(bindings, rawKey) &&
|
|
253
233
|
!ignoreKey(rawKey)) {
|
|
254
|
-
var
|
|
234
|
+
var binding_1 = bindings[rawKey];
|
|
255
235
|
var key = lastProperty(rawKey);
|
|
256
|
-
if (
|
|
257
|
-
first = false;
|
|
258
|
-
this.isJSX && this.emit(exports.RS, exports.INDENT, exports.INDENT);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
this.isJSX ? this.emit(exports.NL) : this.emit(',', exports.NL);
|
|
262
|
-
}
|
|
263
|
-
this.isJSX ? this.emit(key) : this.emit(possiblyQuotePropertyName(key));
|
|
264
|
-
this.isJSX ? this.emit('={') : this.emit(':', exports.WS);
|
|
265
|
-
if (binding === props[key]) {
|
|
236
|
+
if (binding_1 === props[key]) {
|
|
266
237
|
// HACK: workaround for the fact that sometimes the `bindings` have string literals
|
|
267
238
|
// We assume that when the binding content equals prop content.
|
|
268
|
-
|
|
239
|
+
binding_1 = quote(binding_1);
|
|
240
|
+
}
|
|
241
|
+
else if (typeof binding_1 == 'string' && isStatement(binding_1)) {
|
|
242
|
+
binding_1 = iif(binding_1);
|
|
243
|
+
}
|
|
244
|
+
if (key === 'hide' || key === 'show') {
|
|
245
|
+
var _a = key == 'hide' ? ['"none"', '"inherit"'] : ['"inherit"', '"none"'], truthy_1 = _a[0], falsy_1 = _a[1];
|
|
246
|
+
emitJsxProp('style', function () {
|
|
247
|
+
this.emit('{display:', binding_1, '?', truthy_1, ':', falsy_1, '}');
|
|
248
|
+
});
|
|
269
249
|
}
|
|
270
|
-
else
|
|
271
|
-
|
|
250
|
+
else {
|
|
251
|
+
emitJsxProp(possiblyQuotePropertyName(key), binding_1);
|
|
272
252
|
}
|
|
273
|
-
this.emit(binding);
|
|
274
|
-
this.isJSX ? this.emit('}') : this.emit();
|
|
275
253
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
};
|
|
255
|
+
for (var rawKey in bindings) {
|
|
256
|
+
_loop_1(rawKey);
|
|
279
257
|
}
|
|
280
258
|
if (this.isJSX) {
|
|
281
|
-
this.emit('>'
|
|
259
|
+
this.emit('>');
|
|
282
260
|
}
|
|
283
261
|
else {
|
|
284
|
-
this.emit(
|
|
262
|
+
this.emit('},');
|
|
263
|
+
}
|
|
264
|
+
function emitJsxProp(key, value) {
|
|
265
|
+
if (self.isJSX) {
|
|
266
|
+
self.emit(' ', key, '=');
|
|
267
|
+
if (typeof value == 'string' && value.startsWith('"')) {
|
|
268
|
+
self.emit(value);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
self.emit('{', value, '}');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
self.emit(key, ':', value, ',');
|
|
276
|
+
}
|
|
285
277
|
}
|
|
286
278
|
};
|
|
287
279
|
SrcBuilder.prototype.jsxEnd = function (symbol) {
|
|
288
280
|
if (this.isJSX) {
|
|
289
|
-
this.emit(
|
|
281
|
+
this.emit('</', symbol, '>');
|
|
290
282
|
}
|
|
291
283
|
else {
|
|
292
|
-
this.emit(
|
|
284
|
+
this.emit('),');
|
|
293
285
|
}
|
|
294
286
|
};
|
|
295
287
|
SrcBuilder.prototype.jsxBeginFragment = function (symbol) {
|
|
296
288
|
if (this.isJSX) {
|
|
297
|
-
this.emit('<>'
|
|
289
|
+
this.emit('<>');
|
|
298
290
|
}
|
|
299
291
|
else {
|
|
300
|
-
this.emit('h
|
|
292
|
+
this.emit('h(', symbol.name, ',null,');
|
|
301
293
|
}
|
|
302
294
|
};
|
|
303
295
|
SrcBuilder.prototype.jsxEndFragment = function () {
|
|
304
296
|
if (this.isJSX) {
|
|
305
|
-
this.emit(
|
|
297
|
+
this.emit('</>');
|
|
306
298
|
}
|
|
307
299
|
else {
|
|
308
|
-
this.emit(
|
|
300
|
+
this.emit(')');
|
|
309
301
|
}
|
|
310
302
|
};
|
|
311
303
|
SrcBuilder.prototype.jsxTextBinding = function (exp) {
|
|
312
304
|
if (this.isJSX) {
|
|
313
|
-
this.emit('{', exp, '}'
|
|
305
|
+
this.emit('{', exp, '}');
|
|
314
306
|
}
|
|
315
307
|
else {
|
|
316
|
-
this.emit(exp
|
|
308
|
+
this.emit(exp);
|
|
317
309
|
}
|
|
318
310
|
};
|
|
319
311
|
SrcBuilder.prototype.toString = function () {
|
|
@@ -365,10 +357,16 @@ var Block = /** @class */ (function () {
|
|
|
365
357
|
}());
|
|
366
358
|
exports.Block = Block;
|
|
367
359
|
function possiblyQuotePropertyName(key) {
|
|
368
|
-
return /^\w[\w\d]*$/.test(key) ? key :
|
|
360
|
+
return /^\w[\w\d]*$/.test(key) ? key : quote(key);
|
|
369
361
|
}
|
|
370
362
|
function quote(text) {
|
|
371
|
-
|
|
363
|
+
var string = JSON.stringify(text);
|
|
364
|
+
// So \u2028 is a line separator character and prettier treats it as such
|
|
365
|
+
// https://www.fileformat.info/info/unicode/char/2028/index.htm
|
|
366
|
+
// That means it can't be inside of a string, so we replace it with `\\u2028`.
|
|
367
|
+
// (see double `\\` vs `\`)
|
|
368
|
+
var parts = string.split('\u2028');
|
|
369
|
+
return parts.join('\\u2028');
|
|
372
370
|
}
|
|
373
371
|
exports.quote = quote;
|
|
374
372
|
function invoke(symbol, args, typeParameters) {
|
|
@@ -381,22 +379,19 @@ function invoke(symbol, args, typeParameters) {
|
|
|
381
379
|
exports.invoke = invoke;
|
|
382
380
|
function arrowFnBlock(args, statements) {
|
|
383
381
|
return function () {
|
|
384
|
-
this.emit('(', args, ')'
|
|
385
|
-
this.emit('{', exports.INDENT, exports.NL)
|
|
386
|
-
.emitList(statements, ';')
|
|
387
|
-
.emit(exports.UNINDENT, exports.NL, '}');
|
|
382
|
+
this.emit('(', args, ')=>{').emitList(statements, ';').emit('}');
|
|
388
383
|
};
|
|
389
384
|
}
|
|
390
385
|
exports.arrowFnBlock = arrowFnBlock;
|
|
391
386
|
function arrowFnValue(args, expression) {
|
|
392
387
|
return function () {
|
|
393
|
-
this.emit('(', args, ')
|
|
388
|
+
this.emit('(', args, ')=>', expression);
|
|
394
389
|
};
|
|
395
390
|
}
|
|
396
391
|
exports.arrowFnValue = arrowFnValue;
|
|
397
392
|
function iif(code) {
|
|
398
393
|
return function () {
|
|
399
|
-
code && this.emit('(()
|
|
394
|
+
code && this.emit('(()=>{', code, '})()');
|
|
400
395
|
};
|
|
401
396
|
}
|
|
402
397
|
exports.iif = iif;
|
|
@@ -409,9 +404,6 @@ function literalTagName(symbol) {
|
|
|
409
404
|
}
|
|
410
405
|
return symbol;
|
|
411
406
|
}
|
|
412
|
-
function isWhitespace(ch) {
|
|
413
|
-
return ch == '' || ch == exports.RS || ch == exports.NL;
|
|
414
|
-
}
|
|
415
407
|
/**
|
|
416
408
|
* Returns `true` if the code is a statement (rather than expression).
|
|
417
409
|
*
|
|
@@ -26,7 +26,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.renderStyles = exports.collectStyles = void 0;
|
|
27
27
|
var json5_1 = __importDefault(require("json5"));
|
|
28
28
|
var dash_case_1 = require("../../helpers/dash-case");
|
|
29
|
-
var src_generator_1 = require("./src-generator");
|
|
30
29
|
function collectStyles(children, styleMap) {
|
|
31
30
|
var nodes = __spreadArray([], children, true);
|
|
32
31
|
while (nodes.length) {
|
|
@@ -55,10 +54,10 @@ function hashCode(text) {
|
|
|
55
54
|
function renderStyles(styles) {
|
|
56
55
|
return function () {
|
|
57
56
|
var _this = this;
|
|
58
|
-
this.emit('`'
|
|
57
|
+
this.emit('`');
|
|
59
58
|
var mediaStyles = [];
|
|
60
59
|
styles.forEach(function (styles) {
|
|
61
|
-
_this.emit('.', styles.CLASS_NAME, /*'.🏷️�', WS,*/ '{'
|
|
60
|
+
_this.emit('.', styles.CLASS_NAME, /*'.🏷️�', WS,*/ '{');
|
|
62
61
|
for (var key in styles) {
|
|
63
62
|
if (key !== 'CLASS_NAME' &&
|
|
64
63
|
Object.prototype.hasOwnProperty.call(styles, key)) {
|
|
@@ -67,28 +66,26 @@ function renderStyles(styles) {
|
|
|
67
66
|
mediaStyles.push(styles.CLASS_NAME, key, value);
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
70
|
-
_this.emit((0, dash_case_1.dashCase)(key), ':',
|
|
69
|
+
_this.emit((0, dash_case_1.dashCase)(key), ':', value, ';');
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
_this.emit(
|
|
73
|
+
_this.emit('}');
|
|
75
74
|
});
|
|
76
75
|
while (mediaStyles.length) {
|
|
77
76
|
var className = mediaStyles.shift();
|
|
78
77
|
var mediaKey = mediaStyles.shift();
|
|
79
78
|
var mediaObj = mediaStyles.shift();
|
|
80
|
-
this.emit(mediaKey,
|
|
81
|
-
this.emit('.', className, /*'.🏷️�', WS,*/ '{', src_generator_1.NL, src_generator_1.INDENT);
|
|
79
|
+
this.emit(mediaKey, '{.', className, /*'.🏷️�',*/ '{');
|
|
82
80
|
for (var key in mediaObj) {
|
|
83
81
|
if (Object.prototype.hasOwnProperty.call(mediaObj, key)) {
|
|
84
82
|
var value = mediaObj[key];
|
|
85
|
-
this.emit((0, dash_case_1.dashCase)(key), ':',
|
|
83
|
+
this.emit((0, dash_case_1.dashCase)(key), ':', value, ';');
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
|
-
this.emit(
|
|
89
|
-
this.emit(src_generator_1.UNINDENT, '}', src_generator_1.NL);
|
|
86
|
+
this.emit('}}');
|
|
90
87
|
}
|
|
91
|
-
this.emit(
|
|
88
|
+
this.emit('`');
|
|
92
89
|
};
|
|
93
90
|
}
|
|
94
91
|
exports.renderStyles = renderStyles;
|
|
@@ -47,6 +47,7 @@ var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
|
47
47
|
var strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
|
|
48
48
|
var plugins_1 = require("../modules/plugins");
|
|
49
49
|
var jsx_1 = require("../parsers/jsx");
|
|
50
|
+
var context_1 = require("./helpers/context");
|
|
50
51
|
var react_native_1 = require("./react-native");
|
|
51
52
|
var wrapInFragment = function (json) {
|
|
52
53
|
return json.children.length !== 1;
|
|
@@ -289,10 +290,6 @@ function getContextString(component, options) {
|
|
|
289
290
|
}
|
|
290
291
|
return str;
|
|
291
292
|
}
|
|
292
|
-
function hasContext(component) {
|
|
293
|
-
return Boolean(Object.keys(component.context.get).length ||
|
|
294
|
-
Object.keys(component.context.set).length);
|
|
295
|
-
}
|
|
296
293
|
var getInitCode = function (json, options) {
|
|
297
294
|
var _a;
|
|
298
295
|
return processBinding(((_a = json.hooks.init) === null || _a === void 0 ? void 0 : _a.code) || '', options);
|
|
@@ -379,7 +376,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
379
376
|
if (useStateCode && useStateCode.includes('useState')) {
|
|
380
377
|
reactLibImports.add('useState');
|
|
381
378
|
}
|
|
382
|
-
if (hasContext(json)) {
|
|
379
|
+
if ((0, context_1.hasContext)(json)) {
|
|
383
380
|
reactLibImports.add('useContext');
|
|
384
381
|
}
|
|
385
382
|
if (refs.size) {
|
|
@@ -387,7 +384,7 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
387
384
|
}
|
|
388
385
|
if (((_a = json.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code) ||
|
|
389
386
|
((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code) ||
|
|
390
|
-
((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.
|
|
387
|
+
((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
391
388
|
reactLibImports.add('useEffect');
|
|
392
389
|
}
|
|
393
390
|
var wrap = wrapInFragment(json) || (componentHasStyles && stylesType === 'styled-jsx');
|
|
@@ -418,8 +415,12 @@ var _componentToReact = function (json, options, isSubComponent) {
|
|
|
418
415
|
: "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
|
|
419
416
|
: '', getContextString(json, options), getRefsString(json), getInitCode(json, options), ((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
|
|
420
417
|
? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onMount.code, options), options), "\n }, [])")
|
|
421
|
-
: '', ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.
|
|
422
|
-
?
|
|
418
|
+
: '', ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
|
|
419
|
+
? json.hooks.onUpdate
|
|
420
|
+
.map(function (hook) { return "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(hook.code, options), options), "\n }, \n ").concat(hook.deps
|
|
421
|
+
? processBinding(updateStateSettersInCode(hook.deps, options), options)
|
|
422
|
+
: '', ")"); })
|
|
423
|
+
.join(';')
|
|
423
424
|
: '', ((_f = json.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code)
|
|
424
425
|
? "useEffect(() => {\n return () => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onUnMount.code, options), options), "\n }\n }, [])")
|
|
425
426
|
: '', wrap ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
|