@builder.io/mitosis 0.0.56-103 → 0.0.56-104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +4 -1
- package/dist/src/__tests__/shared.d.ts +1 -0
- package/dist/src/__tests__/shared.js +32 -4
- package/dist/src/constants/method-literal-prefix.d.ts +0 -1
- package/dist/src/constants/method-literal-prefix.js +0 -3
- package/dist/src/generators/qwik/component-generator.js +45 -52
- package/dist/src/generators/qwik/component.d.ts +0 -1
- package/dist/src/generators/qwik/component.js +20 -18
- package/dist/src/generators/qwik/directives.d.ts +1 -0
- package/dist/src/generators/qwik/directives.js +7 -11
- package/dist/src/generators/qwik/jsx.d.ts +1 -1
- package/dist/src/generators/qwik/jsx.js +9 -5
- package/dist/src/generators/qwik/src-generator.js +7 -2
- package/dist/src/generators/react/state.js +18 -20
- package/dist/src/generators/solid/state.js +20 -20
- package/dist/src/generators/svelte.js +9 -14
- package/dist/src/generators/vue.js +19 -11
- package/dist/src/helpers/babel-transform.d.ts +3 -1
- package/dist/src/helpers/babel-transform.js +52 -54
- package/dist/src/helpers/get-state-object-string.js +24 -21
- package/dist/src/helpers/getters-to-functions.js +1 -11
- package/dist/src/helpers/map-refs.js +25 -25
- package/dist/src/helpers/parse-reactive-script.js +66 -78
- package/dist/src/helpers/patterns.d.ts +2 -0
- package/dist/src/helpers/patterns.js +5 -1
- package/dist/src/helpers/render-imports.js +1 -1
- package/dist/src/helpers/replace-identifiers.d.ts +5 -0
- package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
- package/dist/src/helpers/slots.d.ts +2 -0
- package/dist/src/helpers/slots.js +15 -1
- package/dist/src/helpers/state.d.ts +1 -10
- package/dist/src/helpers/state.js +1 -37
- package/dist/src/parsers/builder.d.ts +2 -2
- package/dist/src/parsers/builder.js +55 -37
- package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
- package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/helpers/state.d.ts +3 -0
- package/dist/src/parsers/helpers/state.js +30 -0
- package/dist/src/parsers/jsx/context.js +1 -1
- package/dist/src/parsers/jsx/index.d.ts +1 -1
- package/dist/src/parsers/jsx/index.js +1 -2
- package/dist/src/parsers/jsx/jsx.js +2 -3
- package/dist/src/parsers/jsx/state.d.ts +1 -2
- package/dist/src/parsers/jsx/state.js +11 -18
- package/dist/src/plugins/compile-away-builder-components.js +6 -0
- package/dist/src/symbols/symbol-processor.js +3 -0
- package/dist/src/types/mitosis-component.d.ts +12 -5
- package/dist/src/types/mitosis-component.js +11 -0
- package/dist/src/types/mitosis-context.d.ts +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/constants/function-literal-prefix.d.ts +0 -1
- package/dist/src/constants/function-literal-prefix.js +0 -4
- package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
3
4
|
function ContentSlotJsxCode(props) {
|
|
4
5
|
return (<div>
|
|
5
|
-
{props.slotTesting}
|
|
6
|
+
<mitosis_1.Show when={props.slotTesting}>
|
|
7
|
+
<div>{props.slotTesting}</div>
|
|
8
|
+
</mitosis_1.Show>
|
|
6
9
|
<div>
|
|
7
10
|
<hr />
|
|
8
11
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runTestsForTarget = void 0;
|
|
3
|
+
exports.runTestsForTarget = exports.runTestsForJsx = void 0;
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
5
|
var basicForShow = require('./data/basic-for-show.raw');
|
|
6
6
|
var basicOnMountUpdate = require('./data/basic-onMount-update.raw');
|
|
@@ -143,6 +143,17 @@ var ADVANCED_REF = {
|
|
|
143
143
|
var ON_UPDATE_RETURN = {
|
|
144
144
|
basicOnUpdateReturn: require('./data/basic-onUpdate-return.raw'),
|
|
145
145
|
};
|
|
146
|
+
var JSX_TESTS = [
|
|
147
|
+
BASIC_TESTS,
|
|
148
|
+
SLOTS_TESTS,
|
|
149
|
+
SHOW_TESTS,
|
|
150
|
+
FORWARD_REF_TESTS,
|
|
151
|
+
MULTI_ON_UPDATE_TESTS,
|
|
152
|
+
FORM_BLOCK_TESTS,
|
|
153
|
+
ADVANCED_REF,
|
|
154
|
+
ON_UPDATE_RETURN,
|
|
155
|
+
FOR_SHOW_TESTS,
|
|
156
|
+
];
|
|
146
157
|
var TESTS_FOR_TARGET = {
|
|
147
158
|
react: [
|
|
148
159
|
BASIC_TESTS,
|
|
@@ -284,6 +295,17 @@ var TESTS_FOR_TARGET = {
|
|
|
284
295
|
FOR_SHOW_TESTS,
|
|
285
296
|
],
|
|
286
297
|
};
|
|
298
|
+
var runTestsForJsx = function () {
|
|
299
|
+
JSX_TESTS.forEach(function (tests) {
|
|
300
|
+
Object.keys(tests).forEach(function (key) {
|
|
301
|
+
test(key, function () {
|
|
302
|
+
var component = (0, jsx_1.parseJsx)(tests[key]);
|
|
303
|
+
expect(component).toMatchSnapshot();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
exports.runTestsForJsx = runTestsForJsx;
|
|
287
309
|
var runTestsForTarget = function (target, generator) {
|
|
288
310
|
var testsArray = TESTS_FOR_TARGET[target];
|
|
289
311
|
test('Remove Internal mitosis package', function () {
|
|
@@ -297,9 +319,15 @@ var runTestsForTarget = function (target, generator) {
|
|
|
297
319
|
testsArray.forEach(function (tests) {
|
|
298
320
|
Object.keys(tests).forEach(function (key) {
|
|
299
321
|
test(key, function () {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
322
|
+
try {
|
|
323
|
+
var component = (0, jsx_1.parseJsx)(tests[key]);
|
|
324
|
+
var output = generator({ component: component, path: path });
|
|
325
|
+
expect(output).toMatchSnapshot();
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.log('failed to parse', error);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
303
331
|
});
|
|
304
332
|
});
|
|
305
333
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const methodLiteralPrefix = "@builder.io/mitosis/method:";
|
|
@@ -8,24 +8,29 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
8
8
|
}
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.componentToQwik = void 0;
|
|
13
16
|
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
14
17
|
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
15
18
|
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
19
|
+
var mitosis_component_1 = require("../../types/mitosis-component");
|
|
16
20
|
var state_1 = require("../../helpers/state");
|
|
17
21
|
var add_prevent_default_1 = require("./add-prevent-default");
|
|
18
22
|
var convert_method_to_function_1 = require("./convert-method-to-function");
|
|
19
23
|
var jsx_1 = require("./jsx");
|
|
20
24
|
var src_generator_1 = require("./src-generator");
|
|
21
25
|
var plugins_1 = require("../../modules/plugins");
|
|
26
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
22
27
|
Error.stackTraceLimit = 9999;
|
|
23
28
|
// TODO(misko): styles are not processed.
|
|
24
29
|
var DEBUG = false;
|
|
25
30
|
var componentToQwik = function (userOptions) {
|
|
26
31
|
if (userOptions === void 0) { userOptions = {}; }
|
|
27
32
|
return function (_a) {
|
|
28
|
-
var _b, _c, _d;
|
|
33
|
+
var _b, _c, _d, _e;
|
|
29
34
|
var _component = _a.component, path = _a.path;
|
|
30
35
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
31
36
|
var component = (0, fast_clone_1.fastClone)(_component);
|
|
@@ -48,7 +53,8 @@ var componentToQwik = function (userOptions) {
|
|
|
48
53
|
emitTypes(file, component);
|
|
49
54
|
var metadata = component.meta.useMetadata || {};
|
|
50
55
|
var isLightComponent = ((_c = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _b === void 0 ? void 0 : _b.component) === null || _c === void 0 ? void 0 : _c.isLight) || false;
|
|
51
|
-
var
|
|
56
|
+
var mutable_1 = ((_d = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _d === void 0 ? void 0 : _d.mutable) || [];
|
|
57
|
+
var imports_1 = (_e = metadata === null || metadata === void 0 ? void 0 : metadata.qwik) === null || _e === void 0 ? void 0 : _e.imports;
|
|
52
58
|
imports_1 && Object.keys(imports_1).forEach(function (key) { return file.import(imports_1[key], key); });
|
|
53
59
|
var state_2 = emitStateMethodsAndRewriteBindings(file, component, metadata);
|
|
54
60
|
var hasState_1 = (0, state_1.checkHasState)(component);
|
|
@@ -64,7 +70,7 @@ var componentToQwik = function (userOptions) {
|
|
|
64
70
|
emitUseWatch(file, component);
|
|
65
71
|
emitUseCleanup(file, component);
|
|
66
72
|
emitTagNameHack(file, component);
|
|
67
|
-
emitJSX(file, component);
|
|
73
|
+
emitJSX(file, component, mutable_1);
|
|
68
74
|
},
|
|
69
75
|
], [component.propsTypeRef || 'any']);
|
|
70
76
|
file.src.const(component.name, isLightComponent
|
|
@@ -126,12 +132,19 @@ function emitUseCleanup(file, component) {
|
|
|
126
132
|
file.src.emit(file.import(file.qwikModule, 'useCleanup$').localName, '(()=>{', code, '});');
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
|
-
function emitJSX(file, component) {
|
|
135
|
+
function emitJSX(file, component, mutable) {
|
|
130
136
|
var directives = new Map();
|
|
131
137
|
var handlers = new Map();
|
|
132
138
|
var styles = new Map();
|
|
133
139
|
var parentSymbolBindings = {};
|
|
134
|
-
|
|
140
|
+
var mutablePredicate = mutable.length > 0
|
|
141
|
+
? function (code) {
|
|
142
|
+
return !!mutable.find(function (txt) {
|
|
143
|
+
return code.indexOf(txt) !== -1;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
: undefined;
|
|
147
|
+
file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings, mutablePredicate));
|
|
135
148
|
}
|
|
136
149
|
function emitUseContextProvider(file, component) {
|
|
137
150
|
Object.keys(component.context.set).forEach(function (ctxKey) {
|
|
@@ -141,8 +154,8 @@ function emitUseContextProvider(file, component) {
|
|
|
141
154
|
Object.keys(context.value).forEach(function (prop) {
|
|
142
155
|
var propValue = context.value[prop];
|
|
143
156
|
file.src.emit(prop, ':');
|
|
144
|
-
if (
|
|
145
|
-
file.src.emit('(()=>{', extractGetterBody(propValue), '})(),');
|
|
157
|
+
if ((propValue === null || propValue === void 0 ? void 0 : propValue.type) === 'getter') {
|
|
158
|
+
file.src.emit('(()=>{', extractGetterBody(propValue.code), '})(),');
|
|
146
159
|
}
|
|
147
160
|
else if (typeof propValue == 'function') {
|
|
148
161
|
throw new Error('Qwik: Functions are not supported in context');
|
|
@@ -208,26 +221,21 @@ function emitStateMethodsAndRewriteBindings(file, component, metadata) {
|
|
|
208
221
|
rewriteCodeExpr(component, methodMap, lexicalArgs, (_a = metadata.qwik) === null || _a === void 0 ? void 0 : _a.replace);
|
|
209
222
|
return state;
|
|
210
223
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (typeof value == 'string') {
|
|
220
|
-
if (value.startsWith(CODE_PREFIX) || key == 'code') {
|
|
221
|
-
var code_1 = (0, convert_method_to_function_1.convertMethodToFunction)(value, methodMap, lexicalArgs);
|
|
222
|
-
replace &&
|
|
223
|
-
Object.keys(replace).forEach(function (key) { return (code_1 = code_1.replace(key, replace[key])); });
|
|
224
|
-
obj[key] = code_1;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
rewriteCodeExpr(value, methodMap, lexicalArgs, replace);
|
|
228
|
-
});
|
|
224
|
+
var checkIsObjectWithCodeBlock = function (obj) {
|
|
225
|
+
return typeof obj == 'object' && (obj === null || obj === void 0 ? void 0 : obj.code) && typeof obj.code === 'string';
|
|
226
|
+
};
|
|
227
|
+
function rewriteCodeExpr(component, methodMap, lexicalArgs, replace) {
|
|
228
|
+
if (replace === void 0) { replace = {}; }
|
|
229
|
+
(0, traverse_1.default)(component).forEach(function (item) {
|
|
230
|
+
if (!((0, mitosis_component_1.checkIsCodeValue)(item) || checkIsObjectWithCodeBlock(item))) {
|
|
231
|
+
return;
|
|
229
232
|
}
|
|
230
|
-
|
|
233
|
+
var code = (0, convert_method_to_function_1.convertMethodToFunction)(item.code, methodMap, lexicalArgs);
|
|
234
|
+
Object.keys(replace).forEach(function (key) {
|
|
235
|
+
code = code.replace(key, replace[key]);
|
|
236
|
+
});
|
|
237
|
+
item.code = code;
|
|
238
|
+
});
|
|
231
239
|
}
|
|
232
240
|
function getLexicalScopeVars(component) {
|
|
233
241
|
return __spreadArray(__spreadArray(['props', 'state'], Object.keys(component.refs), true), Object.keys(component.context.get), true);
|
|
@@ -243,30 +251,25 @@ function emitImports(file, component) {
|
|
|
243
251
|
});
|
|
244
252
|
});
|
|
245
253
|
}
|
|
246
|
-
var CODE_PREFIX = '@builder.io/mitosis/';
|
|
247
|
-
var FUNCTION = CODE_PREFIX + 'function:';
|
|
248
|
-
var METHOD = CODE_PREFIX + 'method:';
|
|
249
|
-
var GETTER = CODE_PREFIX + 'method:get ';
|
|
250
254
|
function emitStateMethods(file, componentState, lexicalArgs) {
|
|
251
255
|
var stateValues = {};
|
|
252
256
|
var stateInit = [stateValues];
|
|
253
257
|
var methodMap = stateToMethodOrGetter(componentState);
|
|
254
258
|
Object.keys(componentState).forEach(function (key) {
|
|
255
|
-
var
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
if (codeIisGetter) {
|
|
259
|
+
var stateValue = componentState[key];
|
|
260
|
+
if ((0, mitosis_component_1.checkIsCodeValue)(stateValue)) {
|
|
261
|
+
var code = stateValue.code;
|
|
262
|
+
var prefixIdx = 0;
|
|
263
|
+
if (stateValue.type === 'getter') {
|
|
261
264
|
prefixIdx += 'get '.length;
|
|
262
265
|
}
|
|
263
|
-
else if (
|
|
266
|
+
else if (stateValue.type === 'function') {
|
|
264
267
|
prefixIdx += 'function '.length;
|
|
265
268
|
}
|
|
266
269
|
code = code.substring(prefixIdx);
|
|
267
270
|
code = (0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs).replace('(', "(".concat(lexicalArgs.join(','), ","));
|
|
268
271
|
var functionName = code.split(/\(/)[0];
|
|
269
|
-
if (
|
|
272
|
+
if (stateValue.type === 'getter') {
|
|
270
273
|
stateInit.push("state.".concat(key, "=").concat(functionName, "(").concat(lexicalArgs.join(','), ")"));
|
|
271
274
|
}
|
|
272
275
|
if (!file.options.isTypeScript) {
|
|
@@ -276,7 +279,7 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
276
279
|
file.exportConst(functionName, 'function ' + code, true);
|
|
277
280
|
}
|
|
278
281
|
else {
|
|
279
|
-
stateValues[key] = code;
|
|
282
|
+
stateValues[key] = stateValue === null || stateValue === void 0 ? void 0 : stateValue.code;
|
|
280
283
|
}
|
|
281
284
|
});
|
|
282
285
|
return stateInit;
|
|
@@ -284,15 +287,6 @@ function emitStateMethods(file, componentState, lexicalArgs) {
|
|
|
284
287
|
function convertTypeScriptToJS(code) {
|
|
285
288
|
return (0, babel_transform_1.babelTransformExpression)(code, {});
|
|
286
289
|
}
|
|
287
|
-
function isGetter(code) {
|
|
288
|
-
return typeof code === 'string' && code.startsWith(GETTER);
|
|
289
|
-
}
|
|
290
|
-
function isCode(code) {
|
|
291
|
-
return typeof code === 'string' && code.startsWith(CODE_PREFIX);
|
|
292
|
-
}
|
|
293
|
-
function isFunction(code) {
|
|
294
|
-
return typeof code === 'string' && code.startsWith(FUNCTION);
|
|
295
|
-
}
|
|
296
290
|
function extractGetterBody(code) {
|
|
297
291
|
var start = code.indexOf('{');
|
|
298
292
|
var end = code.lastIndexOf('}');
|
|
@@ -301,10 +295,9 @@ function extractGetterBody(code) {
|
|
|
301
295
|
function stateToMethodOrGetter(state) {
|
|
302
296
|
var methodMap = {};
|
|
303
297
|
Object.keys(state).forEach(function (key) {
|
|
304
|
-
var
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
methodMap[key] = code.startsWith(GETTER) ? 'getter' : 'method';
|
|
298
|
+
var stateVal = state[key];
|
|
299
|
+
if ((stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'getter' || (stateVal === null || stateVal === void 0 ? void 0 : stateVal.type) === 'method') {
|
|
300
|
+
methodMap[key] = stateVal.type;
|
|
308
301
|
}
|
|
309
302
|
});
|
|
310
303
|
return methodMap;
|
|
@@ -16,7 +16,6 @@ export declare function createFileSet(options?: QwikOptions): FileSet;
|
|
|
16
16
|
export declare function addComponent(fileSet: FileSet, component: MitosisComponent, opts?: {
|
|
17
17
|
isRoot?: boolean;
|
|
18
18
|
shareStyles?: boolean;
|
|
19
|
-
hostProps?: Record<string, string>;
|
|
20
19
|
}): void;
|
|
21
20
|
export declare function renderUseLexicalScope(file: File): (this: SrcBuilder) => SrcBuilder;
|
|
22
21
|
export declare function addCommonStyles(fileSet: FileSet): void;
|
|
@@ -21,7 +21,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.addCommonStyles = exports.renderUseLexicalScope = exports.addComponent = exports.createFileSet = void 0;
|
|
24
|
-
var create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
25
24
|
var compile_away_builder_components_1 = require("../../plugins/compile-away-builder-components");
|
|
26
25
|
var handlers_1 = require("./handlers");
|
|
27
26
|
var jsx_1 = require("./jsx");
|
|
@@ -43,7 +42,7 @@ function createFileSet(options) {
|
|
|
43
42
|
med: new src_generator_1.File('med.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
44
43
|
low: new src_generator_1.File('low.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
45
44
|
};
|
|
46
|
-
Object.defineProperty(fileSet, '
|
|
45
|
+
Object.defineProperty(fileSet, 'CommonStyles', {
|
|
47
46
|
enumerable: false,
|
|
48
47
|
value: { styles: new Map(), symbolName: null },
|
|
49
48
|
});
|
|
@@ -51,11 +50,11 @@ function createFileSet(options) {
|
|
|
51
50
|
}
|
|
52
51
|
exports.createFileSet = createFileSet;
|
|
53
52
|
function getCommonStyles(fileSet) {
|
|
54
|
-
return fileSet['
|
|
53
|
+
return fileSet['CommonStyles'];
|
|
55
54
|
}
|
|
56
55
|
function addComponent(fileSet, component, opts) {
|
|
57
56
|
if (opts === void 0) { opts = {}; }
|
|
58
|
-
var _opts = __assign({ isRoot: false, shareStyles: false
|
|
57
|
+
var _opts = __assign({ isRoot: false, shareStyles: false }, opts);
|
|
59
58
|
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), {
|
|
60
59
|
// A set of components that should not be compiled away because they are implemented as runtime components.
|
|
61
60
|
Image: undefined, CoreButton: undefined }));
|
|
@@ -74,32 +73,33 @@ function addComponent(fileSet, component, opts) {
|
|
|
74
73
|
if (styles.size) {
|
|
75
74
|
if (_opts.shareStyles) {
|
|
76
75
|
if (_opts.isRoot) {
|
|
77
|
-
var symbolName = componentName + '
|
|
76
|
+
var symbolName = componentName + 'Styles';
|
|
78
77
|
getCommonStyles(fileSet).symbolName = symbolName;
|
|
79
78
|
useStyles = generateStyles(onRenderFile, fileSet.low, symbolName, false);
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
else {
|
|
83
|
-
var symbolName = componentName + '
|
|
82
|
+
var symbolName = componentName + 'Styles';
|
|
84
83
|
onRenderFile.exportConst(symbolName, (0, styles_1.renderStyles)(styles));
|
|
85
84
|
useStyles = generateStyles(onRenderFile, onRenderFile, symbolName, true);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
87
|
+
if (component.meta.cssCode) {
|
|
88
|
+
var symbolName = componentName + 'UsrStyles';
|
|
89
|
+
onRenderFile.exportConst(symbolName, JSON.stringify(component.meta.cssCode));
|
|
90
|
+
useStyles = (function (fns) {
|
|
91
|
+
return function () {
|
|
92
|
+
var _this = this;
|
|
93
|
+
fns.forEach(function (fn) { return fn.apply(_this); });
|
|
94
|
+
};
|
|
95
|
+
})([useStyles, generateStyles(onRenderFile, onRenderFile, symbolName, false)]);
|
|
96
|
+
}
|
|
88
97
|
var directives = new Map();
|
|
89
98
|
var rootChildren = component.children;
|
|
90
|
-
if (_opts.hostProps) {
|
|
91
|
-
rootChildren = [
|
|
92
|
-
(0, create_mitosis_node_1.createMitosisNode)({
|
|
93
|
-
name: 'Host',
|
|
94
|
-
properties: _opts.hostProps,
|
|
95
|
-
children: component.children,
|
|
96
|
-
}),
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
99
|
addComponentOnMount(onRenderFile, function () {
|
|
100
100
|
return this.emit('return ', (0, jsx_1.renderJSXNodes)(onRenderFile, directives, handlers, rootChildren, styles, {}), ';');
|
|
101
101
|
}, componentName, component, useStyles);
|
|
102
|
-
componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, onRenderFile, componentName + '
|
|
102
|
+
componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, onRenderFile, componentName + 'OnMount')], ['any', 'any']));
|
|
103
103
|
directives.forEach(function (code, name) {
|
|
104
104
|
fileSet.med.import(fileSet.med.qwikModule, 'h');
|
|
105
105
|
fileSet.med.exportConst(name, code, true);
|
|
@@ -108,7 +108,9 @@ function addComponent(fileSet, component, opts) {
|
|
|
108
108
|
exports.addComponent = addComponent;
|
|
109
109
|
function generateStyles(fromFile, dstFile, symbol, scoped) {
|
|
110
110
|
return function () {
|
|
111
|
-
this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? '
|
|
111
|
+
this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? 'useStylesScopedQrl' : 'useStylesQrl'), [
|
|
112
|
+
generateQrl(fromFile, dstFile, symbol),
|
|
113
|
+
]), ';');
|
|
112
114
|
};
|
|
113
115
|
}
|
|
114
116
|
function addBuilderBlockClass(children) {
|
|
@@ -141,7 +143,7 @@ function addComponentOnMount(componentFile, onRenderEmit, componentName, compone
|
|
|
141
143
|
inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=', JSON.stringify(input.defaultValue), ';');
|
|
142
144
|
});
|
|
143
145
|
}
|
|
144
|
-
componentFile.exportConst(componentName + '
|
|
146
|
+
componentFile.exportConst(componentName + 'OnMount', function () {
|
|
145
147
|
var _this = this;
|
|
146
148
|
this.emit((0, src_generator_1.arrowFnValue)(['props'], function () {
|
|
147
149
|
var _a;
|
|
@@ -18,6 +18,7 @@ interface ImageProps {
|
|
|
18
18
|
lazy?: boolean;
|
|
19
19
|
class?: string;
|
|
20
20
|
children?: any[];
|
|
21
|
+
noWebp?: boolean;
|
|
21
22
|
}
|
|
22
23
|
export declare function Image(props: ImageProps): any;
|
|
23
24
|
export declare function __passThroughProps__(dstProps: Record<string, any>, srcProps: Record<string, any>): Record<string, any>;
|
|
@@ -35,24 +35,20 @@ exports.DIRECTIVES = {
|
|
|
35
35
|
this.jsxExpression(function () {
|
|
36
36
|
var forName = node.properties._forName || '_';
|
|
37
37
|
var indexName = node.properties._indexName;
|
|
38
|
-
_this.emit('(', expr, '||[]).map('
|
|
38
|
+
_this.emit('(', expr, '||[]).map(');
|
|
39
|
+
_this.isBuilder && _this.emit('(('),
|
|
40
|
+
_this.emit('function(', forName, indexName ? ',' : '', indexName ? indexName : '', '){');
|
|
39
41
|
if (_this.isBuilder) {
|
|
40
42
|
_this.emit('var state=Object.assign({},this,{', (0, src_generator_1.iteratorProperty)(expr), ':', forName, '==null?{}:', forName, '});');
|
|
41
43
|
}
|
|
42
44
|
_this.emit('return(');
|
|
43
45
|
blockFn();
|
|
44
|
-
_this.emit(');}
|
|
46
|
+
_this.emit(');}');
|
|
47
|
+
_this.isBuilder && _this.emit(').bind(state))');
|
|
48
|
+
_this.emit(')');
|
|
45
49
|
});
|
|
46
50
|
};
|
|
47
51
|
},
|
|
48
|
-
Host: function (node, blockFn) {
|
|
49
|
-
return function () {
|
|
50
|
-
var host = this.file.import(this.file.qwikModule, 'Host').localName;
|
|
51
|
-
this.jsxBegin(host, node.properties, node.bindings);
|
|
52
|
-
blockFn();
|
|
53
|
-
this.jsxEnd(host);
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
52
|
Image: (0, minify_1.minify)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), Image),
|
|
57
53
|
CoreButton: (0, minify_1.minify)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), CoreButton),
|
|
58
54
|
__passThroughProps__: (0, minify_1.minify)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["", ""], ["", ""])), __passThroughProps__),
|
|
@@ -62,7 +58,7 @@ function Image(props) {
|
|
|
62
58
|
var jsx = props.children || [];
|
|
63
59
|
var image = props.image;
|
|
64
60
|
if (image) {
|
|
65
|
-
var isBuilderIoImage = !!(image || '').match(/\.builder\.io/);
|
|
61
|
+
var isBuilderIoImage = !!(image || '').match(/\.builder\.io/) && !props.noWebp;
|
|
66
62
|
var isPixel = (_a = props.builderBlock) === null || _a === void 0 ? void 0 : _a.id.startsWith('builder-pixel-');
|
|
67
63
|
var imgProps = {
|
|
68
64
|
src: props.image,
|
|
@@ -13,4 +13,4 @@ import { CssStyles } from './styles';
|
|
|
13
13
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, root?: boolean): any;
|
|
16
|
+
export declare function renderJSXNodes(file: File, directives: Map<string, string>, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, parentSymbolBindings: Record<string, string>, mutablePredicate?: (code: string) => boolean, root?: boolean): any;
|
|
@@ -36,7 +36,7 @@ var src_generator_1 = require("./src-generator");
|
|
|
36
36
|
* @param root True if this is the root JSX, and may need a Fragment wrapper.
|
|
37
37
|
* @returns
|
|
38
38
|
*/
|
|
39
|
-
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, root) {
|
|
39
|
+
function renderJSXNodes(file, directives, handlers, children, styles, parentSymbolBindings, mutablePredicate, root) {
|
|
40
40
|
if (root === void 0) { root = true; }
|
|
41
41
|
return function () {
|
|
42
42
|
var _this = this;
|
|
@@ -121,9 +121,9 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
var symbolBindings = {};
|
|
124
|
-
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings);
|
|
124
|
+
var bindings = rewriteHandlers(file, handlers, child.bindings, symbolBindings, mutablePredicate);
|
|
125
125
|
_this.jsxBegin(childName, props, __assign(__assign(__assign({}, bindings), parentSymbolBindings), specialBindings));
|
|
126
|
-
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, false).call(_this);
|
|
126
|
+
renderJSXNodes(file, directives, handlers, child.children, styles, symbolBindings, mutablePredicate, false).call(_this);
|
|
127
127
|
_this.jsxEnd(childName);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -138,7 +138,7 @@ function renderJSXNodes(file, directives, handlers, children, styles, parentSymb
|
|
|
138
138
|
children = children.filter(function (c) { return !isEmptyTextNode(c); });
|
|
139
139
|
var childNeedsFragment = children.length > 1 || (children.length && isTextNode(children[0]));
|
|
140
140
|
childNeedsFragment && srcBuilder.jsxBeginFragment(fragmentSymbol);
|
|
141
|
-
renderJSXNodes(file, directives, handlers, children, styles, {}, false).call(srcBuilder);
|
|
141
|
+
renderJSXNodes(file, directives, handlers, children, styles, {}, mutablePredicate, false).call(srcBuilder);
|
|
142
142
|
childNeedsFragment && srcBuilder.jsxEndFragment();
|
|
143
143
|
};
|
|
144
144
|
}
|
|
@@ -182,7 +182,7 @@ function isSlotProjection(child) {
|
|
|
182
182
|
* @param symbolBindings Options record which will receive the symbol bindings
|
|
183
183
|
* @returns
|
|
184
184
|
*/
|
|
185
|
-
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
185
|
+
function rewriteHandlers(file, handlers, bindings, symbolBindings, mutablePredicate) {
|
|
186
186
|
var _a;
|
|
187
187
|
var outBindings = {};
|
|
188
188
|
for (var key in bindings) {
|
|
@@ -207,6 +207,10 @@ function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
|
207
207
|
else if (key.startsWith('component.options.')) {
|
|
208
208
|
key = (0, src_generator_1.lastProperty)(key);
|
|
209
209
|
}
|
|
210
|
+
if (mutablePredicate && bindingExpr && mutablePredicate(bindingExpr)) {
|
|
211
|
+
file.import(file.qwikModule, 'mutable');
|
|
212
|
+
bindingExpr = "mutable(".concat(bindingExpr, ")");
|
|
213
|
+
}
|
|
210
214
|
outBindings[key] = { code: bindingExpr };
|
|
211
215
|
}
|
|
212
216
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.iteratorProperty = exports.lastProperty = exports.isStatement = exports.iif = exports.arrowFnValue = exports.arrowFnBlock = exports.invoke = exports.quote = exports.Block = exports.Imports = exports.Symbol = exports.SrcBuilder = exports.File = void 0;
|
|
4
4
|
var standalone_1 = require("prettier/standalone");
|
|
5
|
+
var builder_1 = require("../../parsers/builder");
|
|
5
6
|
var File = /** @class */ (function () {
|
|
6
7
|
function File(filename, options, qwikModule, qrlPrefix) {
|
|
7
8
|
this.imports = new Imports();
|
|
@@ -320,7 +321,7 @@ var SrcBuilder = /** @class */ (function () {
|
|
|
320
321
|
key = key + '$';
|
|
321
322
|
binding_1 = "(event)=>".concat(binding_1);
|
|
322
323
|
}
|
|
323
|
-
if (!binding_1 && rawKey in props) {
|
|
324
|
+
else if (!binding_1 && rawKey in props) {
|
|
324
325
|
binding_1 = quote(props[rawKey]);
|
|
325
326
|
}
|
|
326
327
|
else if (binding_1 != null && binding_1 === props[key]) {
|
|
@@ -524,6 +525,9 @@ function iif(code) {
|
|
|
524
525
|
if (code.endsWith(_virtual_index) && !code.endsWith(return_virtual_index)) {
|
|
525
526
|
code = code.substr(0, code.length - _virtual_index.length) + return_virtual_index;
|
|
526
527
|
}
|
|
528
|
+
if (code.indexOf('export') !== -1) {
|
|
529
|
+
code = (0, builder_1.convertExportDefaultToReturn)(code);
|
|
530
|
+
}
|
|
527
531
|
return function () {
|
|
528
532
|
code && this.emit('(()=>{', code, '})()');
|
|
529
533
|
};
|
|
@@ -549,7 +553,8 @@ function literalTagName(symbol) {
|
|
|
549
553
|
*/
|
|
550
554
|
function isStatement(code) {
|
|
551
555
|
code = code.trim();
|
|
552
|
-
if (code.startsWith('(')
|
|
556
|
+
if ((code.startsWith('(') && code.endsWith(')')) ||
|
|
557
|
+
(code.startsWith('{') && code.endsWith('}'))) {
|
|
553
558
|
// Code starting with `(` is most likely and IFF and hence is an expression.
|
|
554
559
|
return false;
|
|
555
560
|
}
|
|
@@ -7,13 +7,12 @@ exports.updateStateSettersInCode = exports.updateStateSetters = exports.getUseSt
|
|
|
7
7
|
var core_1 = require("@babel/core");
|
|
8
8
|
var json5_1 = __importDefault(require("json5"));
|
|
9
9
|
var traverse_1 = __importDefault(require("traverse"));
|
|
10
|
-
var function_literal_prefix_1 = require("../../constants/function-literal-prefix");
|
|
11
|
-
var method_literal_prefix_1 = require("../../constants/method-literal-prefix");
|
|
12
10
|
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
13
11
|
var capitalize_1 = require("../../helpers/capitalize");
|
|
14
12
|
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
15
13
|
var function_1 = require("fp-ts/lib/function");
|
|
16
14
|
var helpers_1 = require("./helpers");
|
|
15
|
+
var patterns_1 = require("../../helpers/patterns");
|
|
17
16
|
/**
|
|
18
17
|
* Removes all `this.` references.
|
|
19
18
|
*/
|
|
@@ -37,25 +36,26 @@ var processStateValue = function (options) {
|
|
|
37
36
|
var mapValue = valueMapper(options);
|
|
38
37
|
return function (_a) {
|
|
39
38
|
var key = _a[0], stateVal = _a[1];
|
|
39
|
+
var getDefaultCase = function () {
|
|
40
|
+
return (0, function_1.pipe)(value, json5_1.default.stringify, mapValue, function (x) { return "const [".concat(key, ", ").concat(getSetStateFnName(key), "] = useState(() => (").concat(x, "))"); });
|
|
41
|
+
};
|
|
40
42
|
var value = stateVal === null || stateVal === void 0 ? void 0 : stateVal.code;
|
|
43
|
+
var type = stateVal === null || stateVal === void 0 ? void 0 : stateVal.type;
|
|
41
44
|
if (typeof value === 'string') {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var useValue = methodValue.replace(/^(get )?/, 'function ');
|
|
52
|
-
return mapValue(useValue);
|
|
45
|
+
switch (type) {
|
|
46
|
+
case 'getter':
|
|
47
|
+
return (0, function_1.pipe)(value, patterns_1.replaceGetterWithFunction, mapValue);
|
|
48
|
+
case 'function':
|
|
49
|
+
return mapValue(value);
|
|
50
|
+
case 'method':
|
|
51
|
+
return (0, function_1.pipe)(value, patterns_1.prefixWithFunction, mapValue);
|
|
52
|
+
default:
|
|
53
|
+
return getDefaultCase();
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return defaultCase;
|
|
56
|
+
else {
|
|
57
|
+
return getDefaultCase();
|
|
58
|
+
}
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
var getUseStateCode = function (json, options) {
|
|
@@ -97,9 +97,7 @@ var updateStateSettersInCode = function (value, options) {
|
|
|
97
97
|
if (node.left.object.name === 'state') {
|
|
98
98
|
// TODO: ultimately support other property access like strings
|
|
99
99
|
var propertyName = node.left.property.name;
|
|
100
|
-
path.replaceWith(core_1.types.callExpression(core_1.types.identifier(
|
|
101
|
-
node.right,
|
|
102
|
-
]));
|
|
100
|
+
path.replaceWith(core_1.types.callExpression(core_1.types.identifier(getSetStateFnName(propertyName)), [node.right]));
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
103
|
}
|