@builder.io/mitosis 0.0.56-2 → 0.0.56-5
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 +24 -0
- package/dist/src/__tests__/data/basic-for.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-for.raw.jsx +24 -0
- package/dist/src/__tests__/data/blocks/img-state.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/img-state.raw.jsx +17 -0
- package/dist/src/__tests__/data/blocks/onInit-onMount.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/onInit-onMount.raw.jsx +13 -0
- package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/onInit.raw.jsx +10 -0
- package/dist/src/__tests__/data/blocks/section-state.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/section-state.raw.jsx +17 -0
- package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +3 -1
- package/dist/src/__tests__/data/context/component-with-context.lite.jsx +7 -2
- package/dist/src/__tests__/html.test.js +126 -0
- package/dist/src/__tests__/react.test.js +12 -0
- package/dist/src/__tests__/svelte.test.js +40 -6
- package/dist/src/__tests__/webcomponent.test.js +144 -0
- package/dist/src/generators/angular.js +12 -5
- package/dist/src/generators/html.js +167 -67
- package/dist/src/generators/react.js +10 -6
- package/dist/src/generators/svelte.js +10 -2
- package/dist/src/generators/vue.js +2 -2
- package/dist/src/helpers/render-imports.d.ts +1 -1
- package/dist/src/parsers/builder.d.ts +2 -0
- package/dist/src/parsers/jsx.js +26 -2
- package/dist/src/symbols/symbol-processor.js +3 -3
- package/dist/src/types/config.d.ts +7 -1
- package/dist/src/types/mitosis-component.d.ts +1 -0
- package/dist/src/types/mitosis-node.d.ts +8 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var angular_1 = require("../generators/angular");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
5
|
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
6
|
+
var onMount = require('./data/blocks/onMount.raw');
|
|
7
|
+
var onInitonMount = require('./data/blocks/onInit-onMount.raw');
|
|
8
|
+
var onInit = require('./data/blocks/onInit.raw');
|
|
9
|
+
var basicFor = require('./data/basic-for.raw');
|
|
6
10
|
var slot = require('./data/blocks/slot.raw');
|
|
7
11
|
describe('Angular', function () {
|
|
8
12
|
test('onUpdate', function () {
|
|
@@ -10,6 +14,26 @@ describe('Angular', function () {
|
|
|
10
14
|
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
11
15
|
expect(output).toMatchSnapshot();
|
|
12
16
|
});
|
|
17
|
+
test('onMount', function () {
|
|
18
|
+
var component = (0, jsx_1.parseJsx)(onMount);
|
|
19
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
20
|
+
expect(output).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
test('onInit and onMount', function () {
|
|
23
|
+
var component = (0, jsx_1.parseJsx)(onInitonMount);
|
|
24
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
25
|
+
expect(output).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
test('onInit', function () {
|
|
28
|
+
var component = (0, jsx_1.parseJsx)(onInit);
|
|
29
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
30
|
+
expect(output).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
test('BasicFor', function () {
|
|
33
|
+
var component = (0, jsx_1.parseJsx)(basicFor);
|
|
34
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
35
|
+
expect(output).toMatchSnapshot();
|
|
36
|
+
});
|
|
13
37
|
test('ng-content', function () {
|
|
14
38
|
var component = (0, jsx_1.parseJsx)(slot);
|
|
15
39
|
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MyBasicForComponent(): JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MyBasicForComponent() {
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
name: 'PatrickJS',
|
|
7
|
+
names: ['Steve', 'PatrickJS'],
|
|
8
|
+
});
|
|
9
|
+
(0, mitosis_1.onMount)(function () {
|
|
10
|
+
console.log('onMount code');
|
|
11
|
+
});
|
|
12
|
+
return (<div>
|
|
13
|
+
<mitosis_1.For each={state.names}>
|
|
14
|
+
{function (person) { return (<>
|
|
15
|
+
<input value={state.name} onChange={function (event) {
|
|
16
|
+
state.name = event.target.value + ' and ' + person;
|
|
17
|
+
}}/>
|
|
18
|
+
Hello {person}! I can run in Qwik, Web Component, React, Vue, Solid,
|
|
19
|
+
or Liquid!
|
|
20
|
+
</>); }}
|
|
21
|
+
</mitosis_1.For>
|
|
22
|
+
</div>);
|
|
23
|
+
}
|
|
24
|
+
exports.default = MyBasicForComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ImgStateComponent(): JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function ImgStateComponent() {
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
canShow: true,
|
|
7
|
+
images: ['http://example.com/qwik.png'],
|
|
8
|
+
});
|
|
9
|
+
return (<div>
|
|
10
|
+
<mitosis_1.For each={state.images}>
|
|
11
|
+
{function (item, itemIndex) { return (<>
|
|
12
|
+
<img class={'custom-class'} src={item} key={itemIndex}/>
|
|
13
|
+
</>); }}
|
|
14
|
+
</mitosis_1.For>
|
|
15
|
+
</div>);
|
|
16
|
+
}
|
|
17
|
+
exports.default = ImgStateComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function OnInit(): JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function OnInit() {
|
|
5
|
+
(0, mitosis_1.onInit)(function () {
|
|
6
|
+
console.log('onInit');
|
|
7
|
+
});
|
|
8
|
+
(0, mitosis_1.onMount)(function () {
|
|
9
|
+
console.log('onMount');
|
|
10
|
+
});
|
|
11
|
+
return <div />;
|
|
12
|
+
}
|
|
13
|
+
exports.default = OnInit;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function OnInit(): JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function OnInit() {
|
|
5
|
+
(0, mitosis_1.onInit)(function () {
|
|
6
|
+
console.log('Runs once every update/rerender');
|
|
7
|
+
});
|
|
8
|
+
return <div />;
|
|
9
|
+
}
|
|
10
|
+
exports.default = OnInit;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function SectionStateComponent(props) {
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
max: 42,
|
|
7
|
+
items: [42],
|
|
8
|
+
});
|
|
9
|
+
return (<mitosis_1.Show when={state.max}>
|
|
10
|
+
<mitosis_1.For each={state.items}>
|
|
11
|
+
{function (item) { return (<section {...props.attributes} style={{ maxWidth: item + state.max }}>
|
|
12
|
+
{props.children}
|
|
13
|
+
</section>); }}
|
|
14
|
+
</mitosis_1.For>
|
|
15
|
+
</mitosis_1.Show>);
|
|
16
|
+
}
|
|
17
|
+
exports.default = SectionStateComponent;
|
|
@@ -6,9 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
var _1_1 = __importDefault(require("@dummy/1"));
|
|
7
7
|
var _2_1 = __importDefault(require("@dummy/2"));
|
|
8
8
|
var mitosis_1 = require("@builder.io/mitosis");
|
|
9
|
-
function ComponentWithContext() {
|
|
9
|
+
function ComponentWithContext(props) {
|
|
10
10
|
var foo = (0, mitosis_1.useContext)(_1_1.default);
|
|
11
|
-
(0, mitosis_1.setContext)(_1_1.default, {
|
|
11
|
+
(0, mitosis_1.setContext)(_1_1.default, {
|
|
12
|
+
foo: 'bar',
|
|
13
|
+
content: function () {
|
|
14
|
+
return props.content;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
12
17
|
return (<_2_1.default.Provider value={{ bar: 'baz' }}>
|
|
13
18
|
<>{foo.value}</>
|
|
14
19
|
</_2_1.default.Provider>);
|
|
@@ -2,9 +2,135 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var html_1 = require("../generators/html");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
|
+
var basic = require('./data/basic.raw');
|
|
6
|
+
var basicFor = require('./data/basic-for.raw');
|
|
7
|
+
var submitButtonBlock = require('./data/blocks/submit-button.raw');
|
|
8
|
+
var inputBlock = require('./data/blocks/input.raw');
|
|
9
|
+
var selectBlock = require('./data/blocks/select.raw');
|
|
10
|
+
// const formBlock = require('./data/blocks/form.raw');
|
|
11
|
+
var button = require('./data/blocks/button.raw');
|
|
12
|
+
var textarea = require('./data/blocks/textarea.raw');
|
|
13
|
+
var img = require('./data/blocks/img.raw');
|
|
14
|
+
var video = require('./data/blocks/video.raw');
|
|
15
|
+
var section = require('./data/blocks/section.raw');
|
|
16
|
+
var sectionState = require('./data/blocks/section-state.raw');
|
|
17
|
+
var text = require('./data/blocks/text.raw');
|
|
18
|
+
var image = require('./data/blocks/image.raw');
|
|
19
|
+
var imageState = require('./data/blocks/img-state.raw');
|
|
20
|
+
var columns = require('./data/blocks/columns.raw');
|
|
21
|
+
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
22
|
+
var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
|
|
23
|
+
var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
|
|
24
|
+
var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
|
|
25
|
+
var onMount = require('./data/blocks/onMount.raw');
|
|
5
26
|
var stamped = require('./data/blocks/stamped-io.raw');
|
|
6
27
|
var shadowDom = require('./data/blocks/shadow-dom.raw');
|
|
7
28
|
describe('Html', function () {
|
|
29
|
+
test('Basic', function () {
|
|
30
|
+
var component = (0, jsx_1.parseJsx)(basic);
|
|
31
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
32
|
+
expect(output).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
test('BasicFor', function () {
|
|
35
|
+
var component = (0, jsx_1.parseJsx)(basicFor);
|
|
36
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
37
|
+
expect(output).toMatchSnapshot();
|
|
38
|
+
});
|
|
39
|
+
test('Input block', function () {
|
|
40
|
+
var component = (0, jsx_1.parseJsx)(inputBlock);
|
|
41
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
42
|
+
expect(output).toMatchSnapshot();
|
|
43
|
+
});
|
|
44
|
+
test('Submit button block', function () {
|
|
45
|
+
var component = (0, jsx_1.parseJsx)(submitButtonBlock);
|
|
46
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
47
|
+
expect(output).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
test('Select block', function () {
|
|
50
|
+
var component = (0, jsx_1.parseJsx)(selectBlock);
|
|
51
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
52
|
+
expect(output).toMatchSnapshot();
|
|
53
|
+
});
|
|
54
|
+
// test('Form block', () => {
|
|
55
|
+
// const component = parseJsx(formBlock);
|
|
56
|
+
// const output = componentToHtml()({ component });
|
|
57
|
+
// expect(output).toMatchSnapshot();
|
|
58
|
+
// });
|
|
59
|
+
test('Button', function () {
|
|
60
|
+
var component = (0, jsx_1.parseJsx)(button);
|
|
61
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
62
|
+
expect(output).toMatchSnapshot();
|
|
63
|
+
});
|
|
64
|
+
test('Textarea', function () {
|
|
65
|
+
var component = (0, jsx_1.parseJsx)(textarea);
|
|
66
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
67
|
+
expect(output).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
test('Img', function () {
|
|
70
|
+
var component = (0, jsx_1.parseJsx)(img);
|
|
71
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
72
|
+
expect(output).toMatchSnapshot();
|
|
73
|
+
});
|
|
74
|
+
test('ImageState', function () {
|
|
75
|
+
var component = (0, jsx_1.parseJsx)(imageState);
|
|
76
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
77
|
+
expect(output).toMatchSnapshot();
|
|
78
|
+
});
|
|
79
|
+
test('Video', function () {
|
|
80
|
+
var component = (0, jsx_1.parseJsx)(video);
|
|
81
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
82
|
+
expect(output).toMatchSnapshot();
|
|
83
|
+
});
|
|
84
|
+
test('Section', function () {
|
|
85
|
+
var component = (0, jsx_1.parseJsx)(section);
|
|
86
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
87
|
+
expect(output).toMatchSnapshot();
|
|
88
|
+
});
|
|
89
|
+
test('SectionState', function () {
|
|
90
|
+
var component = (0, jsx_1.parseJsx)(sectionState);
|
|
91
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
92
|
+
expect(output).toMatchSnapshot();
|
|
93
|
+
});
|
|
94
|
+
test('Text', function () {
|
|
95
|
+
var component = (0, jsx_1.parseJsx)(text);
|
|
96
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
97
|
+
expect(output).toMatchSnapshot();
|
|
98
|
+
});
|
|
99
|
+
test('Image', function () {
|
|
100
|
+
var component = (0, jsx_1.parseJsx)(image);
|
|
101
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
102
|
+
expect(output).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
test('Columns', function () {
|
|
105
|
+
var component = (0, jsx_1.parseJsx)(columns);
|
|
106
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
107
|
+
expect(output).toMatchSnapshot();
|
|
108
|
+
});
|
|
109
|
+
test('onUpdate', function () {
|
|
110
|
+
var component = (0, jsx_1.parseJsx)(onUpdate);
|
|
111
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
112
|
+
expect(output).toMatchSnapshot();
|
|
113
|
+
});
|
|
114
|
+
test('onUpdateWithDeps', function () {
|
|
115
|
+
var component = (0, jsx_1.parseJsx)(onUpdateWithDeps);
|
|
116
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
117
|
+
expect(output).toMatchSnapshot();
|
|
118
|
+
});
|
|
119
|
+
test('multipleOnUpdate', function () {
|
|
120
|
+
var component = (0, jsx_1.parseJsx)(multipleOnUpdate);
|
|
121
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
122
|
+
expect(output).toMatchSnapshot();
|
|
123
|
+
});
|
|
124
|
+
test('multipleOnnUpdateWithDeps', function () {
|
|
125
|
+
var component = (0, jsx_1.parseJsx)(multipleOnUpdateWithDeps);
|
|
126
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
127
|
+
expect(output).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
test('onMount & onUnMount', function () {
|
|
130
|
+
var component = (0, jsx_1.parseJsx)(onMount);
|
|
131
|
+
var output = (0, html_1.componentToHtml)()({ component: component });
|
|
132
|
+
expect(output).toMatchSnapshot();
|
|
133
|
+
});
|
|
8
134
|
test('Stamped', function () {
|
|
9
135
|
var component = (0, jsx_1.parseJsx)(stamped);
|
|
10
136
|
var html = (0, html_1.componentToHtml)()({ component: component });
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var react_1 = require("../generators/react");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
5
|
var basic = require('./data/basic.raw');
|
|
6
|
+
var basicFor = require('./data/basic-for.raw');
|
|
6
7
|
var submitButtonBlock = require('./data/blocks/submit-button.raw');
|
|
7
8
|
var inputBlock = require('./data/blocks/input.raw');
|
|
8
9
|
var selectBlock = require('./data/blocks/select.raw');
|
|
@@ -20,6 +21,7 @@ var embed = require('./data/blocks/embed.raw');
|
|
|
20
21
|
var image = require('./data/blocks/image.raw');
|
|
21
22
|
var columns = require('./data/blocks/columns.raw');
|
|
22
23
|
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
24
|
+
var onInit = require('./data/blocks/onInit.raw');
|
|
23
25
|
var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
|
|
24
26
|
var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
|
|
25
27
|
var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
|
|
@@ -31,6 +33,11 @@ describe('React', function () {
|
|
|
31
33
|
var output = (0, react_1.componentToReact)()({ component: component });
|
|
32
34
|
expect(output).toMatchSnapshot();
|
|
33
35
|
});
|
|
36
|
+
test('BasicFor', function () {
|
|
37
|
+
var component = (0, jsx_1.parseJsx)(basicFor);
|
|
38
|
+
var output = (0, react_1.componentToReact)()({ component: component });
|
|
39
|
+
expect(output).toMatchSnapshot();
|
|
40
|
+
});
|
|
34
41
|
test('Input block', function () {
|
|
35
42
|
var component = (0, jsx_1.parseJsx)(inputBlock);
|
|
36
43
|
var output = (0, react_1.componentToReact)()({ component: component });
|
|
@@ -119,6 +126,11 @@ describe('React', function () {
|
|
|
119
126
|
var output = (0, react_1.componentToReact)()({ component: component });
|
|
120
127
|
expect(output).toMatchSnapshot();
|
|
121
128
|
});
|
|
129
|
+
test('onInit', function () {
|
|
130
|
+
var component = (0, jsx_1.parseJsx)(onInit);
|
|
131
|
+
var output = (0, react_1.componentToReact)()({ component: component });
|
|
132
|
+
expect(output).toMatchSnapshot();
|
|
133
|
+
});
|
|
122
134
|
test('onUpdateWithDeps', function () {
|
|
123
135
|
var component = (0, jsx_1.parseJsx)(onUpdateWithDeps);
|
|
124
136
|
var output = (0, react_1.componentToReact)()({ component: component });
|
|
@@ -1,36 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var svelte_1 = require("../generators/svelte");
|
|
3
|
+
var svelte_1 = require("../generators/context/svelte");
|
|
4
|
+
var context_1 = require("../parsers/context");
|
|
5
|
+
var svelte_2 = require("../generators/svelte");
|
|
4
6
|
var jsx_1 = require("../parsers/jsx");
|
|
5
7
|
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
6
8
|
var multipleOUpdate = require('./data/blocks/multiple-onUpdate.raw');
|
|
7
9
|
var selfReferencingComponent = require('./data/blocks/self-referencing-component.raw');
|
|
8
10
|
var selfReferencingComponentWithChildren = require('./data/blocks/self-referencing-component-with-children.raw');
|
|
9
11
|
var builderRenderBlock = require('./data/blocks/builder-render-block.raw');
|
|
12
|
+
var rootShow = require('./data/blocks/rootShow.raw');
|
|
13
|
+
var simpleExample = require('./data/context/simple.context.lite');
|
|
14
|
+
var componentWithContext = require('./data/context/component-with-context.lite');
|
|
15
|
+
var renderBlock = require('./data/blocks/builder-render-block.raw');
|
|
10
16
|
describe('Svelte', function () {
|
|
11
17
|
test('onUpdate', function () {
|
|
12
18
|
var component = (0, jsx_1.parseJsx)(onUpdate);
|
|
13
|
-
var output = (0,
|
|
19
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
14
20
|
expect(output).toMatchSnapshot();
|
|
15
21
|
});
|
|
16
22
|
test('multipleOnUpdate', function () {
|
|
17
23
|
var component = (0, jsx_1.parseJsx)(multipleOUpdate);
|
|
18
|
-
var output = (0,
|
|
24
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
19
25
|
expect(output).toMatchSnapshot();
|
|
20
26
|
});
|
|
21
27
|
test('selfReferencingComponent', function () {
|
|
22
28
|
var component = (0, jsx_1.parseJsx)(selfReferencingComponent);
|
|
23
|
-
var output = (0,
|
|
29
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
24
30
|
expect(output).toMatchSnapshot();
|
|
25
31
|
});
|
|
26
32
|
test('selfReferencingComponentWithChildren', function () {
|
|
27
33
|
var component = (0, jsx_1.parseJsx)(selfReferencingComponentWithChildren);
|
|
28
|
-
var output = (0,
|
|
34
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
29
35
|
expect(output).toMatchSnapshot();
|
|
30
36
|
});
|
|
31
37
|
test('BuilderRenderBlock', function () {
|
|
32
38
|
var component = (0, jsx_1.parseJsx)(builderRenderBlock);
|
|
33
|
-
var output = (0,
|
|
39
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
34
40
|
expect(output).toMatchSnapshot();
|
|
35
41
|
});
|
|
42
|
+
test('rootShow', function () {
|
|
43
|
+
var component = (0, jsx_1.parseJsx)(rootShow);
|
|
44
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
45
|
+
expect(output).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
describe('Context', function () {
|
|
48
|
+
test('Parse context', function () {
|
|
49
|
+
var component = (0, context_1.parseContext)(simpleExample, { name: 'SimpleExample' });
|
|
50
|
+
if (!component) {
|
|
51
|
+
throw new Error('No parseable context found for simple.context.lite.ts');
|
|
52
|
+
}
|
|
53
|
+
expect(component).toMatchSnapshot();
|
|
54
|
+
var context = (0, svelte_1.contextToSvelte)()({ context: component });
|
|
55
|
+
expect(context).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
test('Use and set context in components', function () {
|
|
58
|
+
var component = (0, jsx_1.parseJsx)(componentWithContext);
|
|
59
|
+
expect(component).toMatchSnapshot();
|
|
60
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
61
|
+
expect(output).toMatchSnapshot();
|
|
62
|
+
});
|
|
63
|
+
test('Use and set context in complex components', function () {
|
|
64
|
+
var component = (0, jsx_1.parseJsx)(renderBlock);
|
|
65
|
+
expect(component).toMatchSnapshot();
|
|
66
|
+
var output = (0, svelte_2.componentToSvelte)()({ component: component });
|
|
67
|
+
expect(output).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
36
70
|
});
|
|
@@ -2,11 +2,155 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var html_1 = require("../generators/html");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
|
+
var basic = require('./data/basic.raw');
|
|
6
|
+
var basicFor = require('./data/basic-for.raw');
|
|
7
|
+
var submitButtonBlock = require('./data/blocks/submit-button.raw');
|
|
8
|
+
var inputBlock = require('./data/blocks/input.raw');
|
|
9
|
+
var selectBlock = require('./data/blocks/select.raw');
|
|
10
|
+
// const formBlock = require('./data/blocks/form.raw');
|
|
11
|
+
var button = require('./data/blocks/button.raw');
|
|
12
|
+
var textarea = require('./data/blocks/textarea.raw');
|
|
13
|
+
var img = require('./data/blocks/img.raw');
|
|
14
|
+
var video = require('./data/blocks/video.raw');
|
|
15
|
+
var section = require('./data/blocks/section.raw');
|
|
16
|
+
var sectionState = require('./data/blocks/section-state.raw');
|
|
17
|
+
var text = require('./data/blocks/text.raw');
|
|
18
|
+
var image = require('./data/blocks/image.raw');
|
|
19
|
+
var imageState = require('./data/blocks/img-state.raw');
|
|
20
|
+
var columns = require('./data/blocks/columns.raw');
|
|
21
|
+
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
22
|
+
var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
|
|
23
|
+
var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
|
|
24
|
+
var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
|
|
25
|
+
var onMount = require('./data/blocks/onMount.raw');
|
|
26
|
+
var onInit = require('./data/blocks/onInit.raw');
|
|
27
|
+
var onInitonMount = require('./data/blocks/onInit-onMount.raw');
|
|
5
28
|
var stamped = require('./data/blocks/stamped-io.raw');
|
|
29
|
+
var shadowDom = require('./data/blocks/shadow-dom.raw');
|
|
6
30
|
describe('webcomponent', function () {
|
|
31
|
+
test('Basic', function () {
|
|
32
|
+
var component = (0, jsx_1.parseJsx)(basic);
|
|
33
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
34
|
+
expect(output).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
test('BasicFor', function () {
|
|
37
|
+
var component = (0, jsx_1.parseJsx)(basicFor);
|
|
38
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
39
|
+
expect(output).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
test('Input block', function () {
|
|
42
|
+
var component = (0, jsx_1.parseJsx)(inputBlock);
|
|
43
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
44
|
+
expect(output).toMatchSnapshot();
|
|
45
|
+
});
|
|
46
|
+
test('Submit button block', function () {
|
|
47
|
+
var component = (0, jsx_1.parseJsx)(submitButtonBlock);
|
|
48
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
49
|
+
expect(output).toMatchSnapshot();
|
|
50
|
+
});
|
|
51
|
+
test('Select block', function () {
|
|
52
|
+
var component = (0, jsx_1.parseJsx)(selectBlock);
|
|
53
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
54
|
+
expect(output).toMatchSnapshot();
|
|
55
|
+
});
|
|
56
|
+
// test('Form block', () => {
|
|
57
|
+
// const component = parseJsx(formBlock);
|
|
58
|
+
// const output = componentToCustomElement()({ component });
|
|
59
|
+
// expect(output).toMatchSnapshot();
|
|
60
|
+
// });
|
|
61
|
+
test('Button', function () {
|
|
62
|
+
var component = (0, jsx_1.parseJsx)(button);
|
|
63
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
64
|
+
expect(output).toMatchSnapshot();
|
|
65
|
+
});
|
|
66
|
+
test('Textarea', function () {
|
|
67
|
+
var component = (0, jsx_1.parseJsx)(textarea);
|
|
68
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
69
|
+
expect(output).toMatchSnapshot();
|
|
70
|
+
});
|
|
71
|
+
test('Img', function () {
|
|
72
|
+
var component = (0, jsx_1.parseJsx)(img);
|
|
73
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
74
|
+
expect(output).toMatchSnapshot();
|
|
75
|
+
});
|
|
76
|
+
test('Video', function () {
|
|
77
|
+
var component = (0, jsx_1.parseJsx)(video);
|
|
78
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
79
|
+
expect(output).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
test('Section', function () {
|
|
82
|
+
var component = (0, jsx_1.parseJsx)(section);
|
|
83
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
84
|
+
expect(output).toMatchSnapshot();
|
|
85
|
+
});
|
|
86
|
+
test('SectionState', function () {
|
|
87
|
+
var component = (0, jsx_1.parseJsx)(sectionState);
|
|
88
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
89
|
+
expect(output).toMatchSnapshot();
|
|
90
|
+
});
|
|
91
|
+
test('Text', function () {
|
|
92
|
+
var component = (0, jsx_1.parseJsx)(text);
|
|
93
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
94
|
+
expect(output).toMatchSnapshot();
|
|
95
|
+
});
|
|
96
|
+
test('Image', function () {
|
|
97
|
+
var component = (0, jsx_1.parseJsx)(image);
|
|
98
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
99
|
+
expect(output).toMatchSnapshot();
|
|
100
|
+
});
|
|
101
|
+
test('ImageState', function () {
|
|
102
|
+
var component = (0, jsx_1.parseJsx)(imageState);
|
|
103
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
104
|
+
expect(output).toMatchSnapshot();
|
|
105
|
+
});
|
|
106
|
+
test('Columns', function () {
|
|
107
|
+
var component = (0, jsx_1.parseJsx)(columns);
|
|
108
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
109
|
+
expect(output).toMatchSnapshot();
|
|
110
|
+
});
|
|
111
|
+
test('onUpdate', function () {
|
|
112
|
+
var component = (0, jsx_1.parseJsx)(onUpdate);
|
|
113
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
114
|
+
expect(output).toMatchSnapshot();
|
|
115
|
+
});
|
|
116
|
+
test('onUpdateWithDeps', function () {
|
|
117
|
+
var component = (0, jsx_1.parseJsx)(onUpdateWithDeps);
|
|
118
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
119
|
+
expect(output).toMatchSnapshot();
|
|
120
|
+
});
|
|
121
|
+
test('multipleOnUpdate', function () {
|
|
122
|
+
var component = (0, jsx_1.parseJsx)(multipleOnUpdate);
|
|
123
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
124
|
+
expect(output).toMatchSnapshot();
|
|
125
|
+
});
|
|
126
|
+
test('multipleOnnUpdateWithDeps', function () {
|
|
127
|
+
var component = (0, jsx_1.parseJsx)(multipleOnUpdateWithDeps);
|
|
128
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
129
|
+
expect(output).toMatchSnapshot();
|
|
130
|
+
});
|
|
131
|
+
test('onMount & onUnMount', function () {
|
|
132
|
+
var component = (0, jsx_1.parseJsx)(onMount);
|
|
133
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
134
|
+
expect(output).toMatchSnapshot();
|
|
135
|
+
});
|
|
136
|
+
test('onInit', function () {
|
|
137
|
+
var component = (0, jsx_1.parseJsx)(onInit);
|
|
138
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
139
|
+
expect(output).toMatchSnapshot();
|
|
140
|
+
});
|
|
141
|
+
test('onInit & onMount', function () {
|
|
142
|
+
var component = (0, jsx_1.parseJsx)(onInitonMount);
|
|
143
|
+
var output = (0, html_1.componentToCustomElement)()({ component: component });
|
|
144
|
+
expect(output).toMatchSnapshot();
|
|
145
|
+
});
|
|
7
146
|
test('Stamped', function () {
|
|
8
147
|
var component = (0, jsx_1.parseJsx)(stamped);
|
|
9
148
|
var html = (0, html_1.componentToCustomElement)()({ component: component });
|
|
10
149
|
expect(html).toMatchSnapshot();
|
|
11
150
|
});
|
|
151
|
+
test('Shadow DOM', function () {
|
|
152
|
+
var component = (0, jsx_1.parseJsx)(shadowDom);
|
|
153
|
+
var html = (0, html_1.componentToCustomElement)()({ component: component });
|
|
154
|
+
expect(html).toMatchSnapshot();
|
|
155
|
+
});
|
|
12
156
|
});
|
|
@@ -120,7 +120,7 @@ exports.blockToAngular = blockToAngular;
|
|
|
120
120
|
var componentToAngular = function (options) {
|
|
121
121
|
if (options === void 0) { options = {}; }
|
|
122
122
|
return function (_a) {
|
|
123
|
-
var _b;
|
|
123
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
124
124
|
var component = _a.component;
|
|
125
125
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
126
126
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
@@ -128,6 +128,7 @@ var componentToAngular = function (options) {
|
|
|
128
128
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
129
129
|
}
|
|
130
130
|
var props = (0, get_props_1.getProps)(component);
|
|
131
|
+
var hasOnInit = Boolean(((_b = component.hooks) === null || _b === void 0 ? void 0 : _b.onInit) || ((_c = component.hooks) === null || _c === void 0 ? void 0 : _c.onMount));
|
|
131
132
|
var refs = Array.from((0, get_refs_1.getRefs)(json));
|
|
132
133
|
(0, map_refs_1.mapRefs)(json, function (refName) { return "this.".concat(refName, ".nativeElement"); });
|
|
133
134
|
if (options.plugins) {
|
|
@@ -154,11 +155,17 @@ var componentToAngular = function (options) {
|
|
|
154
155
|
.map(function (item) { return "@Input() ".concat(item, ": any"); })
|
|
155
156
|
.join('\n'), refs
|
|
156
157
|
.map(function (refName) { return "@ViewChild('".concat(refName, "') ").concat(refName, ": ElementRef"); })
|
|
157
|
-
.join('\n'), !
|
|
158
|
+
.join('\n'), !hasOnInit
|
|
158
159
|
? ''
|
|
159
|
-
: "ngOnInit() {\n ".concat((
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
: "ngOnInit() {\n ".concat(!((_d = component.hooks) === null || _d === void 0 ? void 0 : _d.onInit)
|
|
161
|
+
? ''
|
|
162
|
+
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_e = component.hooks.onInit) === null || _e === void 0 ? void 0 : _e.code, {
|
|
163
|
+
replaceWith: 'this.',
|
|
164
|
+
}), "\n "), "\n ").concat(!((_f = component.hooks) === null || _f === void 0 ? void 0 : _f.onMount)
|
|
165
|
+
? ''
|
|
166
|
+
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_g = component.hooks.onMount) === null || _g === void 0 ? void 0 : _g.code, {
|
|
167
|
+
replaceWith: 'this.',
|
|
168
|
+
}), "\n "), "\n }"), !((_h = component.hooks.onUpdate) === null || _h === void 0 ? void 0 : _h.length)
|
|
162
169
|
? ''
|
|
163
170
|
: "ngAfterContentChecked() {\n ".concat(component.hooks.onUpdate.map(function (hook) {
|
|
164
171
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.code, {
|