@builder.io/mitosis 0.0.50-7 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/__tests__/angular.test.d.ts +1 -0
- package/dist/src/__tests__/angular.test.js +18 -0
- package/dist/src/__tests__/builder.test.d.ts +1 -0
- package/dist/src/__tests__/builder.test.js +235 -0
- package/dist/src/__tests__/context.test.d.ts +1 -0
- package/dist/src/__tests__/context.test.js +35 -0
- 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/slot.raw.d.ts +5 -0
- package/dist/src/__tests__/data/blocks/slot.raw.jsx +6 -0
- package/dist/src/__tests__/data/context/simple.context.lite.d.ts +8 -1
- package/dist/src/__tests__/html.test.d.ts +1 -0
- package/dist/src/__tests__/html.test.js +18 -0
- package/dist/src/__tests__/liquid.test.d.ts +1 -0
- package/dist/src/__tests__/liquid.test.js +108 -0
- package/dist/src/__tests__/parse-jsx.test.d.ts +1 -0
- package/dist/src/__tests__/parse-jsx.test.js +15 -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.d.ts +1 -0
- package/dist/src/__tests__/qwik.test.js +434 -0
- package/dist/src/__tests__/react-native.test.d.ts +1 -0
- package/dist/src/__tests__/react-native.test.js +140 -0
- package/dist/src/__tests__/react.test.d.ts +1 -0
- package/dist/src/__tests__/react.test.js +141 -0
- package/dist/src/__tests__/solid.test.d.ts +1 -0
- package/dist/src/__tests__/solid.test.js +102 -0
- package/dist/src/__tests__/stencil.test.d.ts +1 -0
- package/dist/src/__tests__/stencil.test.js +102 -0
- package/dist/src/__tests__/svelte.test.d.ts +1 -0
- package/dist/src/__tests__/svelte.test.js +36 -0
- package/dist/src/__tests__/vue.test.d.ts +1 -0
- package/dist/src/__tests__/vue.test.js +139 -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/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 +11 -7
- package/dist/src/generators/mitosis.js +4 -3
- package/dist/src/generators/qwik/component.js +9 -13
- 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.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/generic-format.test.d.ts +1 -0
- package/dist/src/helpers/generic-format.test.js +8 -0
- 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/remove-surrounding-block.test.d.ts +1 -0
- package/dist/src/helpers/remove-surrounding-block.test.js +9 -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 +12 -50
- package/dist/src/parsers/builder.js +13 -35
- 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/targets.d.ts +1 -1
- package/dist/src/types/mitosis-component.d.ts +2 -3
- package/dist/test/qwik/Accordion/high.jsx +0 -0
- package/dist/test/qwik/Accordion/low.jsx +207 -0
- package/dist/test/qwik/Accordion/med.jsx +10 -0
- package/dist/test/qwik/For/high.jsx +0 -0
- package/dist/test/qwik/For/low.jsx +33 -0
- package/dist/test/qwik/For/med.jsx +10 -0
- package/dist/test/qwik/Image/high.js +9 -0
- package/dist/test/qwik/Image/low.js +0 -0
- package/dist/test/qwik/Image/med.js +149 -0
- package/dist/test/qwik/Image.slow/high.js +9 -0
- package/dist/test/qwik/Image.slow/low.js +0 -0
- package/dist/test/qwik/Image.slow/med.js +149 -0
- package/dist/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 +3 -0
- package/dist/test/qwik/button/low.js +11 -0
- package/dist/test/qwik/button/med.js +37 -0
- package/dist/test/qwik/component/bindings/high.jsx +0 -0
- package/dist/test/qwik/component/bindings/low.jsx +43 -0
- package/dist/test/qwik/component/bindings/med.jsx +53 -0
- 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 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +12 -0
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +10 -0
- package/dist/test/qwik/page-with-symbol/high.js +0 -0
- package/dist/test/qwik/page-with-symbol/low.js +19 -0
- package/dist/test/qwik/page-with-symbol/med.js +10 -0
- 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 -0
- package/dist/test/qwik/svg/low.js +13 -0
- package/dist/test/qwik/svg/med.js +10 -0
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +23 -0
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +48 -0
- package/dist/test/qwik/todo/Todo.js/high.js +22 -0
- package/dist/test/qwik/todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/todo/Todo.js/med.js +45 -0
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +22 -0
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +41 -0
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +7 -0
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +27 -0
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +9 -0
- package/package.json +9 -7
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var directives_1 = require("../generators/qwik/directives");
|
|
4
|
+
describe('qwik directives', function () {
|
|
5
|
+
var partial = expect.objectContaining;
|
|
6
|
+
beforeEach(function () {
|
|
7
|
+
global.h = mockH;
|
|
8
|
+
});
|
|
9
|
+
afterEach(function () { return (global.h = undefined); });
|
|
10
|
+
describe('Image', function () {
|
|
11
|
+
test('altText', function () {
|
|
12
|
+
expect((0, directives_1.Image)({ altText: 'foo', image: 'http://some.url' }).children[0][0]).toEqual(partial({
|
|
13
|
+
tag: 'img',
|
|
14
|
+
props: partial({ src: 'http://some.url', alt: 'foo' }),
|
|
15
|
+
}));
|
|
16
|
+
expect((0, directives_1.Image)({ image: 'http://some.url' }).children[0][0]).toEqual(partial({
|
|
17
|
+
tag: 'img',
|
|
18
|
+
props: partial({ src: 'http://some.url', role: 'presentation' }),
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
test('builder-pixel is eager', function () {
|
|
22
|
+
expect((0, directives_1.Image)({
|
|
23
|
+
builderBlock: { id: 'builder-pixel-foo' },
|
|
24
|
+
image: 'http://some.url',
|
|
25
|
+
}).children[0][0]).toEqual(partial({
|
|
26
|
+
tag: 'img',
|
|
27
|
+
props: partial({ loading: 'eager' }),
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
test('images are lazy loaded', function () {
|
|
31
|
+
expect((0, directives_1.Image)({
|
|
32
|
+
image: 'http://some.url',
|
|
33
|
+
}).children[0][0]).toEqual(partial({
|
|
34
|
+
tag: 'img',
|
|
35
|
+
props: partial({ loading: 'lazy' }),
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
test('builder.io URLs are served using webp', function () {
|
|
39
|
+
expect(find('source', (0, directives_1.Image)({
|
|
40
|
+
image: 'http://foo.builder.io/foo',
|
|
41
|
+
}))).toEqual(partial({
|
|
42
|
+
tag: 'source',
|
|
43
|
+
props: partial({
|
|
44
|
+
srcset: srcSet('http://foo.builder.io/foo?format=webp'),
|
|
45
|
+
type: 'image/webp',
|
|
46
|
+
}),
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
test('maxWidth is added to the srcs', function () {
|
|
50
|
+
expect(find('source', (0, directives_1.Image)({
|
|
51
|
+
image: 'http://foo.builder.io/foo',
|
|
52
|
+
srcsetSizes: '1234 456',
|
|
53
|
+
}))).toEqual(partial({
|
|
54
|
+
tag: 'source',
|
|
55
|
+
props: partial({
|
|
56
|
+
srcset: srcSet('http://foo.builder.io/foo?format=webp', '1234 456'),
|
|
57
|
+
type: 'image/webp',
|
|
58
|
+
}),
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
test('anchor should wrap in <a>', function () {
|
|
62
|
+
expect(find('a', (0, directives_1.Image)({
|
|
63
|
+
image: 'http://some.url',
|
|
64
|
+
href: 'my-url',
|
|
65
|
+
}))).toEqual(partial({
|
|
66
|
+
tag: 'a',
|
|
67
|
+
props: partial({ href: 'my-url' }),
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
function find(tag, jsx) {
|
|
73
|
+
if (tag == jsx.tag)
|
|
74
|
+
return jsx;
|
|
75
|
+
return findInChildren(tag, jsx.children);
|
|
76
|
+
function findInChildren(tag, jsxs) {
|
|
77
|
+
var value = undefined;
|
|
78
|
+
for (var i = 0; i < jsxs.length; i++) {
|
|
79
|
+
var jsx_1 = jsxs[i];
|
|
80
|
+
if (Array.isArray(jsx_1)) {
|
|
81
|
+
value = findInChildren(tag, jsx_1);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
value = find(tag, jsx_1);
|
|
85
|
+
}
|
|
86
|
+
if (value)
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var mockH = function (tag, props, children) { return ({
|
|
93
|
+
tag: tag,
|
|
94
|
+
props: props,
|
|
95
|
+
children: children,
|
|
96
|
+
}); };
|
|
97
|
+
function srcSet(url, additionalSizes) {
|
|
98
|
+
if (additionalSizes === void 0) { additionalSizes = ''; }
|
|
99
|
+
return ['100', '200', '400', '800', '1200', '1600', '2000']
|
|
100
|
+
.concat(additionalSizes ? additionalSizes.split(' ') : [])
|
|
101
|
+
.map(function (size) {
|
|
102
|
+
var parsedUrl = new URL(url);
|
|
103
|
+
parsedUrl.searchParams.set('width', size);
|
|
104
|
+
return "".concat(parsedUrl, " ").concat(size, "w");
|
|
105
|
+
})
|
|
106
|
+
.join(', ');
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var fs_extra_promise_1 = require("fs-extra-promise");
|
|
40
|
+
var qwik_1 = require("../generators/qwik");
|
|
41
|
+
var index_1 = require("../generators/qwik/index");
|
|
42
|
+
var src_generator_1 = require("../generators/qwik/src-generator");
|
|
43
|
+
var builder_1 = require("../parsers/builder");
|
|
44
|
+
var jsx_1 = require("../parsers/jsx");
|
|
45
|
+
var compile_away_builder_components_1 = require("../plugins/compile-away-builder-components");
|
|
46
|
+
var symbol_processor_1 = require("../symbols/symbol-processor");
|
|
47
|
+
var todo = require('../../../../examples/todo/src/components/todo.lite');
|
|
48
|
+
var todos = require('../../../../examples/todo/src/components/todos.lite');
|
|
49
|
+
var debugFiles = true;
|
|
50
|
+
var debugOutput = function (fileSet) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var testName, base, _a, _b, _i, key, file;
|
|
52
|
+
return __generator(this, function (_c) {
|
|
53
|
+
switch (_c.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
testName = expect.getState().currentTestName;
|
|
56
|
+
base = 'dist/test/' + testName.split(' ').join('/') + '/';
|
|
57
|
+
if (!debugFiles) return [3 /*break*/, 4];
|
|
58
|
+
_a = [];
|
|
59
|
+
for (_b in fileSet)
|
|
60
|
+
_a.push(_b);
|
|
61
|
+
_i = 0;
|
|
62
|
+
_c.label = 1;
|
|
63
|
+
case 1:
|
|
64
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
65
|
+
key = _a[_i];
|
|
66
|
+
file = fileSet[key];
|
|
67
|
+
return [4 /*yield*/, (0, fs_extra_promise_1.outputFileAsync)(base + file.path, file.contents)];
|
|
68
|
+
case 2:
|
|
69
|
+
_c.sent();
|
|
70
|
+
_c.label = 3;
|
|
71
|
+
case 3:
|
|
72
|
+
_i++;
|
|
73
|
+
return [3 /*break*/, 1];
|
|
74
|
+
case 4: return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); };
|
|
78
|
+
describe('qwik', function () {
|
|
79
|
+
describe('todo', function () {
|
|
80
|
+
test('Todo.tsx', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var json, fileSet;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
json = (0, jsx_1.parseJsx)(todo);
|
|
86
|
+
fileSet = (0, index_1.createFileSet)({ output: 'ts' });
|
|
87
|
+
(0, index_1.addComponent)(fileSet, json);
|
|
88
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
89
|
+
case 1:
|
|
90
|
+
_a.sent();
|
|
91
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}); });
|
|
96
|
+
test('Todo.cjs', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
var json, fileSet;
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
json = (0, jsx_1.parseJsx)(todo);
|
|
102
|
+
fileSet = (0, index_1.createFileSet)({ output: 'cjs', jsx: false });
|
|
103
|
+
(0, index_1.addComponent)(fileSet, json);
|
|
104
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); });
|
|
112
|
+
test('Todo.js', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
+
var json, fileSet;
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
switch (_a.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
json = (0, jsx_1.parseJsx)(todo);
|
|
118
|
+
fileSet = (0, index_1.createFileSet)({
|
|
119
|
+
output: 'mjs',
|
|
120
|
+
jsx: false,
|
|
121
|
+
});
|
|
122
|
+
(0, index_1.addComponent)(fileSet, json);
|
|
123
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
124
|
+
case 1:
|
|
125
|
+
_a.sent();
|
|
126
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}); });
|
|
131
|
+
});
|
|
132
|
+
describe('todos', function () {
|
|
133
|
+
test('Todo.tsx', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
134
|
+
var json, fileSet;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
json = (0, jsx_1.parseJsx)(todos);
|
|
139
|
+
fileSet = (0, index_1.createFileSet)({ output: 'ts' });
|
|
140
|
+
(0, index_1.addComponent)(fileSet, json);
|
|
141
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
142
|
+
case 1:
|
|
143
|
+
_a.sent();
|
|
144
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
145
|
+
return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}); });
|
|
149
|
+
});
|
|
150
|
+
describe('hello_world', function () {
|
|
151
|
+
test('stylesheet', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
+
var component, fileSet;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.hello_world.json'));
|
|
157
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs' });
|
|
158
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
159
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
160
|
+
case 1:
|
|
161
|
+
_a.sent();
|
|
162
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); });
|
|
167
|
+
});
|
|
168
|
+
test('page-with-symbol', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
+
var component, fileSet;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.page-with-symbol.json'));
|
|
174
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: false });
|
|
175
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
176
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
177
|
+
case 1:
|
|
178
|
+
_a.sent();
|
|
179
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); });
|
|
184
|
+
test('button', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
185
|
+
var component, fileSet;
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.button.json'));
|
|
190
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: false });
|
|
191
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
192
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
193
|
+
case 1:
|
|
194
|
+
_a.sent();
|
|
195
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
196
|
+
return [2 /*return*/];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}); });
|
|
200
|
+
test('svg', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
201
|
+
var component, fileSet;
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
switch (_a.label) {
|
|
204
|
+
case 0:
|
|
205
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.svg.json'), {
|
|
206
|
+
includeBuilderExtras: true,
|
|
207
|
+
preserveTextBlocks: true,
|
|
208
|
+
});
|
|
209
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: false });
|
|
210
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
211
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
212
|
+
case 1:
|
|
213
|
+
_a.sent();
|
|
214
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}); });
|
|
219
|
+
test('Image', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
|
+
var component, fileSet;
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.image.json'), {
|
|
225
|
+
includeBuilderExtras: true,
|
|
226
|
+
preserveTextBlocks: true,
|
|
227
|
+
});
|
|
228
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: false });
|
|
229
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
230
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
231
|
+
case 1:
|
|
232
|
+
_a.sent();
|
|
233
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
234
|
+
return [2 /*return*/];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}); });
|
|
238
|
+
test('Image.slow', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
239
|
+
var component, fileSet;
|
|
240
|
+
return __generator(this, function (_a) {
|
|
241
|
+
switch (_a.label) {
|
|
242
|
+
case 0:
|
|
243
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.image.json'), {
|
|
244
|
+
includeBuilderExtras: true,
|
|
245
|
+
preserveTextBlocks: true,
|
|
246
|
+
});
|
|
247
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: false });
|
|
248
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
249
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
250
|
+
case 1:
|
|
251
|
+
_a.sent();
|
|
252
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}); });
|
|
257
|
+
test('Accordion', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
258
|
+
var component, fileSet;
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.accordion.json'), {
|
|
263
|
+
includeBuilderExtras: true,
|
|
264
|
+
preserveTextBlocks: true,
|
|
265
|
+
});
|
|
266
|
+
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, compile_away_builder_components_1.components);
|
|
267
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: true });
|
|
268
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
269
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
270
|
+
case 1:
|
|
271
|
+
_a.sent();
|
|
272
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
273
|
+
return [2 /*return*/];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}); });
|
|
277
|
+
test('For', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
278
|
+
var component, fileSet;
|
|
279
|
+
return __generator(this, function (_a) {
|
|
280
|
+
switch (_a.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
component = (0, builder_1.builderContentToMitosisComponent)(require('./qwik.test.for-loop.json'), {
|
|
283
|
+
includeBuilderExtras: true,
|
|
284
|
+
preserveTextBlocks: true,
|
|
285
|
+
});
|
|
286
|
+
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, compile_away_builder_components_1.components);
|
|
287
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: true });
|
|
288
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
289
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
290
|
+
case 1:
|
|
291
|
+
_a.sent();
|
|
292
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
293
|
+
return [2 /*return*/];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}); });
|
|
297
|
+
describe('component', function () {
|
|
298
|
+
test('bindings', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
299
|
+
var content, state, hierarchy, fileSet, component;
|
|
300
|
+
return __generator(this, function (_a) {
|
|
301
|
+
switch (_a.label) {
|
|
302
|
+
case 0:
|
|
303
|
+
content = require('./qwik.test.component-binding.json');
|
|
304
|
+
state = {};
|
|
305
|
+
hierarchy = (0, symbol_processor_1.convertBuilderContentToSymbolHierarchy)(content, {
|
|
306
|
+
collectComponentState: state,
|
|
307
|
+
});
|
|
308
|
+
expect(state).toMatchSnapshot();
|
|
309
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: true });
|
|
310
|
+
hierarchy.depthFirstSymbols.forEach(function (builderComponent) {
|
|
311
|
+
var mitosisComponent = (0, symbol_processor_1.convertBuilderElementToMitosisComponent)(builderComponent);
|
|
312
|
+
mitosisComponent &&
|
|
313
|
+
(0, index_1.addComponent)(fileSet, mitosisComponent, { isRoot: false });
|
|
314
|
+
});
|
|
315
|
+
component = (0, builder_1.builderContentToMitosisComponent)(content, {
|
|
316
|
+
includeBuilderExtras: true,
|
|
317
|
+
preserveTextBlocks: true,
|
|
318
|
+
});
|
|
319
|
+
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, compile_away_builder_components_1.components);
|
|
320
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
321
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
322
|
+
case 1:
|
|
323
|
+
_a.sent();
|
|
324
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
325
|
+
return [2 /*return*/];
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}); });
|
|
329
|
+
test('component inputs', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
330
|
+
var content, state, fileSet, component;
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
content = require('./qwik.test.component-inputs.json');
|
|
335
|
+
state = {};
|
|
336
|
+
expect(state).toMatchSnapshot();
|
|
337
|
+
fileSet = (0, index_1.createFileSet)({ output: 'cjs', jsx: true });
|
|
338
|
+
component = (0, builder_1.builderContentToMitosisComponent)(content, {
|
|
339
|
+
includeBuilderExtras: true,
|
|
340
|
+
preserveTextBlocks: true,
|
|
341
|
+
});
|
|
342
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
343
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
344
|
+
case 1:
|
|
345
|
+
_a.sent();
|
|
346
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
347
|
+
return [2 /*return*/];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}); });
|
|
351
|
+
});
|
|
352
|
+
test('show-hide', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
353
|
+
var content, state, fileSet, component;
|
|
354
|
+
return __generator(this, function (_a) {
|
|
355
|
+
switch (_a.label) {
|
|
356
|
+
case 0:
|
|
357
|
+
content = require('./qwik.test.show-hide.json');
|
|
358
|
+
state = {};
|
|
359
|
+
expect(state).toMatchSnapshot();
|
|
360
|
+
fileSet = (0, index_1.createFileSet)({ output: 'mjs', jsx: true });
|
|
361
|
+
component = (0, builder_1.builderContentToMitosisComponent)(content, {
|
|
362
|
+
includeBuilderExtras: true,
|
|
363
|
+
preserveTextBlocks: true,
|
|
364
|
+
});
|
|
365
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
366
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
367
|
+
case 1:
|
|
368
|
+
_a.sent();
|
|
369
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
370
|
+
return [2 /*return*/];
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}); });
|
|
374
|
+
test('bindings', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
375
|
+
var content, state, fileSet, component;
|
|
376
|
+
return __generator(this, function (_a) {
|
|
377
|
+
switch (_a.label) {
|
|
378
|
+
case 0:
|
|
379
|
+
content = require('./qwik.test.bindings.json');
|
|
380
|
+
state = {};
|
|
381
|
+
expect(state).toMatchSnapshot();
|
|
382
|
+
fileSet = (0, index_1.createFileSet)({ output: 'cjs', jsx: false });
|
|
383
|
+
component = (0, builder_1.builderContentToMitosisComponent)(content, {
|
|
384
|
+
includeBuilderExtras: true,
|
|
385
|
+
preserveTextBlocks: true,
|
|
386
|
+
});
|
|
387
|
+
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, compile_away_builder_components_1.components);
|
|
388
|
+
(0, index_1.addComponent)(fileSet, component);
|
|
389
|
+
return [4 /*yield*/, debugOutput(fileSet)];
|
|
390
|
+
case 1:
|
|
391
|
+
_a.sent();
|
|
392
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
393
|
+
return [2 /*return*/];
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}); });
|
|
397
|
+
describe('src-generator', function () {
|
|
398
|
+
test('should format code', function () {
|
|
399
|
+
var file = new qwik_1.File('test.js', {
|
|
400
|
+
isPretty: true,
|
|
401
|
+
isTypeScript: false,
|
|
402
|
+
isJSX: true,
|
|
403
|
+
isModule: true,
|
|
404
|
+
}, '', '');
|
|
405
|
+
file.src.emit('const x=1');
|
|
406
|
+
expect(file.toString()).toEqual('const x = 1;\n');
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
describe('helper functions', function () {
|
|
410
|
+
describe('isStatement', function () {
|
|
411
|
+
test('is an expression', function () {
|
|
412
|
+
expect((0, src_generator_1.isStatement)('a.b')).toBe(false);
|
|
413
|
+
expect((0, src_generator_1.isStatement)('1?2:"bar"')).toBe(false);
|
|
414
|
+
expect((0, src_generator_1.isStatement)('"var x; return foo + \'\\"\';"')).toBe(false);
|
|
415
|
+
expect((0, src_generator_1.isStatement)('"foo" + `bar\nbaz`')).toBe(false);
|
|
416
|
+
expect((0, src_generator_1.isStatement)('(...)()')).toBe(false);
|
|
417
|
+
});
|
|
418
|
+
test('is a statement', function () {
|
|
419
|
+
expect((0, src_generator_1.isStatement)('var x; return x;')).toBe(true);
|
|
420
|
+
expect((0, src_generator_1.isStatement)('var x')).toBe(true);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
function toObj(fileSet) {
|
|
426
|
+
var obj = {};
|
|
427
|
+
for (var key in fileSet) {
|
|
428
|
+
if (Object.prototype.hasOwnProperty.call(fileSet, key)) {
|
|
429
|
+
var file = fileSet[key];
|
|
430
|
+
obj[file.path] = file.contents;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return obj;
|
|
434
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|