@builder.io/mitosis 0.0.56-6 → 0.0.56-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/__tests__/angular.test.js +6 -0
- package/dist/src/__tests__/data/basic-outputs.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-outputs.raw.jsx +17 -0
- package/dist/src/__tests__/data/blocks/classname-jsx.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/classname-jsx.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/slot.raw.jsx +1 -7
- package/dist/src/__tests__/solid.test.js +6 -0
- package/dist/src/generators/angular.d.ts +6 -1
- package/dist/src/generators/angular.js +85 -26
- package/dist/src/generators/solid.js +12 -3
- package/dist/src/helpers/render-imports.js +15 -10
- package/dist/src/helpers/replace-idenifiers.js +3 -2
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +2 -0
- package/dist/src/helpers/strip-state-and-props-refs.js +17 -0
- package/dist/src/types/config.d.ts +3 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -8,11 +8,17 @@ var onMount = require('./data/blocks/onMount.raw');
|
|
|
8
8
|
var onInitonMount = require('./data/blocks/onInit-onMount.raw');
|
|
9
9
|
var onInit = require('./data/blocks/onInit.raw');
|
|
10
10
|
var basicFor = require('./data/basic-for.raw');
|
|
11
|
+
var basicOutputs = require('./data/basic-outputs.raw');
|
|
11
12
|
var contentSlotHtml = require('./data/blocks/content-slot-html.raw');
|
|
12
13
|
var contentSlotJsx = require('./data/blocks/content-slot-jsx.raw');
|
|
13
14
|
var slotJsx = require('./data/blocks/slot-jsx.raw');
|
|
14
15
|
// const slotHtml = require('./data/blocks/slot-html.raw');
|
|
15
16
|
describe('Angular', function () {
|
|
17
|
+
test('basic outputs', function () {
|
|
18
|
+
var component = (0, jsx_1.parseJsx)(basicOutputs);
|
|
19
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
20
|
+
expect(output).toMatchSnapshot();
|
|
21
|
+
});
|
|
16
22
|
test('multiple onUpdate', function () {
|
|
17
23
|
var component = (0, jsx_1.parseJsx)(multipleOnUpdate);
|
|
18
24
|
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MyBasicOutputsComponent(props: any): 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
|
+
(0, mitosis_1.useMetadata)({
|
|
5
|
+
outputs: ['onMessage', 'onEvent'],
|
|
6
|
+
});
|
|
7
|
+
function MyBasicOutputsComponent(props) {
|
|
8
|
+
var state = (0, mitosis_1.useState)({
|
|
9
|
+
name: 'PatrickJS',
|
|
10
|
+
});
|
|
11
|
+
(0, mitosis_1.onMount)(function () {
|
|
12
|
+
props.onMessage(state.name);
|
|
13
|
+
props.onEvent(props.message);
|
|
14
|
+
});
|
|
15
|
+
return <div></div>;
|
|
16
|
+
}
|
|
17
|
+
exports.default = MyBasicOutputsComponent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function ClassNameCode(props) {
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
bindings: 'a binding',
|
|
7
|
+
});
|
|
8
|
+
return (<div>
|
|
9
|
+
{/*// @ts-ignore */}
|
|
10
|
+
<div className="no binding">Without Binding</div>
|
|
11
|
+
{/*// @ts-ignore */}
|
|
12
|
+
<div className={state.bindings}>With binding</div>
|
|
13
|
+
</div>);
|
|
14
|
+
}
|
|
15
|
+
exports.default = ClassNameCode;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var content_slot_raw_1 = __importDefault(require("./content-slot.raw"));
|
|
7
3
|
function SlotCode(props) {
|
|
8
|
-
return
|
|
9
|
-
<content_slot_raw_1.default slotTesting={<div>Hello</div>}/>
|
|
10
|
-
</div>);
|
|
4
|
+
return <div>{props.children}</div>;
|
|
11
5
|
}
|
|
12
6
|
exports.default = SlotCode;
|
|
@@ -18,6 +18,7 @@ var customCode = require('./data/blocks/custom-code.raw');
|
|
|
18
18
|
var embed = require('./data/blocks/embed.raw');
|
|
19
19
|
var image = require('./data/blocks/image.raw');
|
|
20
20
|
var columns = require('./data/blocks/columns.raw');
|
|
21
|
+
var show = require('./data/blocks/rootShow.raw');
|
|
21
22
|
describe('Solid', function () {
|
|
22
23
|
test('Basic', function () {
|
|
23
24
|
var component = (0, jsx_1.parseJsx)(basic);
|
|
@@ -99,4 +100,9 @@ describe('Solid', function () {
|
|
|
99
100
|
var output = (0, solid_1.componentToSolid)()({ component: component });
|
|
100
101
|
expect(output).toMatchSnapshot();
|
|
101
102
|
});
|
|
103
|
+
test('Show', function () {
|
|
104
|
+
var component = (0, jsx_1.parseJsx)(show);
|
|
105
|
+
var output = (0, solid_1.componentToSolid)()({ component: component });
|
|
106
|
+
expect(output).toMatchSnapshot();
|
|
107
|
+
});
|
|
102
108
|
});
|
|
@@ -2,5 +2,10 @@ import { MitosisNode } from '../types/mitosis-node';
|
|
|
2
2
|
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
3
3
|
export interface ToAngularOptions extends BaseTranspilerOptions {
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
interface AngularBlockOptions {
|
|
6
|
+
contextVars?: string[];
|
|
7
|
+
outputVars?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const blockToAngular: (json: MitosisNode, options?: ToAngularOptions, blockOptions?: AngularBlockOptions) => string;
|
|
6
10
|
export declare const componentToAngular: (options?: ToAngularOptions) => Transpiler;
|
|
11
|
+
export {};
|
|
@@ -26,12 +26,12 @@ var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
|
26
26
|
var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
|
|
27
27
|
var indent_1 = require("../helpers/indent");
|
|
28
28
|
var mappers = {
|
|
29
|
-
Fragment: function (json, options) {
|
|
29
|
+
Fragment: function (json, options, blockOptions) {
|
|
30
30
|
return "<div>".concat(json.children
|
|
31
|
-
.map(function (item) { return (0, exports.blockToAngular)(item, options); })
|
|
31
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
|
|
32
32
|
.join('\n'), "</div>");
|
|
33
33
|
},
|
|
34
|
-
Slot: function (json, options) {
|
|
34
|
+
Slot: function (json, options, blockOptions) {
|
|
35
35
|
return "<ng-content ".concat(Object.keys(json.bindings)
|
|
36
36
|
.map(function (binding) {
|
|
37
37
|
var _a;
|
|
@@ -44,11 +44,14 @@ var mappers = {
|
|
|
44
44
|
.join('\n'), "></ng-content>");
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
|
-
var blockToAngular = function (json, options) {
|
|
47
|
+
var blockToAngular = function (json, options, blockOptions) {
|
|
48
48
|
var _a;
|
|
49
49
|
if (options === void 0) { options = {}; }
|
|
50
|
+
if (blockOptions === void 0) { blockOptions = {}; }
|
|
51
|
+
var contextVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.contextVars) || [];
|
|
52
|
+
var outputVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.outputVars) || [];
|
|
50
53
|
if (mappers[json.name]) {
|
|
51
|
-
return mappers[json.name](json, options);
|
|
54
|
+
return mappers[json.name](json, options, blockOptions);
|
|
52
55
|
}
|
|
53
56
|
if ((0, is_children_1.default)(json)) {
|
|
54
57
|
return "<ng-content></ng-content>";
|
|
@@ -61,21 +64,27 @@ var blockToAngular = function (json, options) {
|
|
|
61
64
|
return "<ng-content select=\"[".concat(selector, "]\"></ng-content>");
|
|
62
65
|
}
|
|
63
66
|
if (json.bindings._text) {
|
|
64
|
-
return "{{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._text
|
|
67
|
+
return "{{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings._text, {
|
|
68
|
+
contextVars: contextVars,
|
|
69
|
+
outputVars: outputVars,
|
|
70
|
+
}), "}}");
|
|
65
71
|
}
|
|
66
72
|
var str = '';
|
|
67
73
|
var needsToRenderSlots = [];
|
|
68
74
|
if (json.name === 'For') {
|
|
69
|
-
str += "<ng-container *ngFor=\"let ".concat(json.properties._forName, " of ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.each
|
|
75
|
+
str += "<ng-container *ngFor=\"let ".concat(json.properties._forName, " of ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.each, {
|
|
76
|
+
contextVars: contextVars,
|
|
77
|
+
outputVars: outputVars,
|
|
78
|
+
}), "\">");
|
|
70
79
|
str += json.children
|
|
71
|
-
.map(function (item) { return (0, exports.blockToAngular)(item, options); })
|
|
80
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
|
|
72
81
|
.join('\n');
|
|
73
82
|
str += "</ng-container>";
|
|
74
83
|
}
|
|
75
84
|
else if (json.name === 'Show') {
|
|
76
|
-
str += "<ng-container *ngIf=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.when), "\">");
|
|
85
|
+
str += "<ng-container *ngIf=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.when, { contextVars: contextVars, outputVars: outputVars }), "\">");
|
|
77
86
|
str += json.children
|
|
78
|
-
.map(function (item) { return (0, exports.blockToAngular)(item, options); })
|
|
87
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
|
|
79
88
|
.join('\n');
|
|
80
89
|
str += "</ng-container>";
|
|
81
90
|
}
|
|
@@ -92,7 +101,12 @@ var blockToAngular = function (json, options) {
|
|
|
92
101
|
continue;
|
|
93
102
|
}
|
|
94
103
|
var value = json.properties[key];
|
|
95
|
-
|
|
104
|
+
if (key === 'className') {
|
|
105
|
+
str += " class=\"".concat(value, "\" ");
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
109
|
+
}
|
|
96
110
|
}
|
|
97
111
|
for (var key in json.bindings) {
|
|
98
112
|
if (key === '_spread') {
|
|
@@ -103,7 +117,10 @@ var blockToAngular = function (json, options) {
|
|
|
103
117
|
}
|
|
104
118
|
var value = json.bindings[key];
|
|
105
119
|
// TODO: proper babel transform to replace. Util for this
|
|
106
|
-
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value
|
|
120
|
+
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value, {
|
|
121
|
+
contextVars: contextVars,
|
|
122
|
+
outputVars: outputVars,
|
|
123
|
+
});
|
|
107
124
|
if (key.startsWith('on')) {
|
|
108
125
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
109
126
|
if (event_1 === 'change' &&
|
|
@@ -114,6 +131,9 @@ var blockToAngular = function (json, options) {
|
|
|
114
131
|
var finalValue = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue.replace(/event\./g, '$event.'));
|
|
115
132
|
str += " (".concat(event_1, ")=\"").concat(finalValue, "\" ");
|
|
116
133
|
}
|
|
134
|
+
else if (key === 'className') {
|
|
135
|
+
str += " [class]=\"".concat(useValue, "\" ");
|
|
136
|
+
}
|
|
117
137
|
else if (key === 'ref') {
|
|
118
138
|
str += " #".concat(useValue, " ");
|
|
119
139
|
}
|
|
@@ -135,7 +155,7 @@ var blockToAngular = function (json, options) {
|
|
|
135
155
|
}
|
|
136
156
|
if (json.children) {
|
|
137
157
|
str += json.children
|
|
138
|
-
.map(function (item) { return (0, exports.blockToAngular)(item, options); })
|
|
158
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
|
|
139
159
|
.join('\n');
|
|
140
160
|
}
|
|
141
161
|
str += "</".concat(json.name, ">");
|
|
@@ -146,15 +166,40 @@ exports.blockToAngular = blockToAngular;
|
|
|
146
166
|
var componentToAngular = function (options) {
|
|
147
167
|
if (options === void 0) { options = {}; }
|
|
148
168
|
return function (_a) {
|
|
149
|
-
var _b, _c, _d, _e, _f, _g, _h;
|
|
169
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
150
170
|
var component = _a.component;
|
|
151
171
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
152
172
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
153
173
|
if (options.plugins) {
|
|
154
174
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
155
175
|
}
|
|
176
|
+
var outputVars = ((_c = (_b = json.meta) === null || _b === void 0 ? void 0 : _b.useMetadata) === null || _c === void 0 ? void 0 : _c.outputs) || [];
|
|
177
|
+
var outputs = outputVars.map(function (variableName) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.outputs) {
|
|
180
|
+
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.outputs(json, variableName);
|
|
181
|
+
}
|
|
182
|
+
return "@Output() ".concat(variableName, " = new EventEmitter<any>()");
|
|
183
|
+
});
|
|
184
|
+
var contextVars = Object.keys(((_d = json === null || json === void 0 ? void 0 : json.context) === null || _d === void 0 ? void 0 : _d.get) || {});
|
|
185
|
+
var hasInjectable = Boolean(contextVars.length);
|
|
186
|
+
var injectables = contextVars.map(function (variableName) {
|
|
187
|
+
var _a, _b, _c, _d;
|
|
188
|
+
var variableType = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
|
|
189
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.injectables) {
|
|
190
|
+
return (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.injectables(variableName, variableType);
|
|
191
|
+
}
|
|
192
|
+
if ((_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.inject) {
|
|
193
|
+
return "@Inject(forwardRef(() => ".concat(variableType, ")) public ").concat(variableName, ": ").concat(variableType);
|
|
194
|
+
}
|
|
195
|
+
return "public ".concat(variableName, " : ").concat(variableType);
|
|
196
|
+
});
|
|
156
197
|
var props = (0, get_props_1.getProps)(component);
|
|
157
|
-
|
|
198
|
+
// remove props for outputs
|
|
199
|
+
outputVars.forEach(function (variableName) {
|
|
200
|
+
props.delete(variableName);
|
|
201
|
+
});
|
|
202
|
+
var hasOnInit = Boolean(((_e = component.hooks) === null || _e === void 0 ? void 0 : _e.onInit) || ((_f = component.hooks) === null || _f === void 0 ? void 0 : _f.onMount));
|
|
158
203
|
var refs = Array.from((0, get_refs_1.getRefs)(json));
|
|
159
204
|
(0, map_refs_1.mapRefs)(json, function (refName) { return "this.".concat(refName, ".nativeElement"); });
|
|
160
205
|
if (options.plugins) {
|
|
@@ -164,7 +209,9 @@ var componentToAngular = function (options) {
|
|
|
164
209
|
if (options.prettier !== false) {
|
|
165
210
|
css = tryFormat(css, 'css');
|
|
166
211
|
}
|
|
167
|
-
var template = json.children
|
|
212
|
+
var template = json.children
|
|
213
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, { contextVars: contextVars, outputVars: outputVars }); })
|
|
214
|
+
.join('\n');
|
|
168
215
|
if (options.prettier !== false) {
|
|
169
216
|
template = tryFormat(template, 'html');
|
|
170
217
|
}
|
|
@@ -172,38 +219,50 @@ var componentToAngular = function (options) {
|
|
|
172
219
|
var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
173
220
|
format: 'class',
|
|
174
221
|
valueMapper: function (code) {
|
|
175
|
-
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
222
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
223
|
+
replaceWith: 'this.',
|
|
224
|
+
contextVars: contextVars,
|
|
225
|
+
outputVars: outputVars,
|
|
226
|
+
});
|
|
176
227
|
},
|
|
177
228
|
});
|
|
178
|
-
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { Component ", "", " } from '@angular/core';\n ", "\n\n @Component({\n selector: '", "',\n template: `\n ", "\n `,\n ", "\n })\n export default class ", " {\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n }\n "], ["\n import { Component ", "", " } from '@angular/core';\n ", "\n\n @Component({\n selector: '", "',\n template: \\`\n ", "\n \\`,\n ", "\n })\n export default class ", " {\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n }\n "])), refs.length ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', (0, render_imports_1.renderPreComponent)(json), (0, lodash_1.kebabCase)(json.name || 'my-component'), (0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), css.length
|
|
229
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n @Component({\n selector: '", "',\n template: `\n ", "\n `,\n ", "\n })\n export default class ", " {\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n }\n "], ["\n import { ", " ", " Component ", "", " } from '@angular/core';\n ", "\n\n @Component({\n selector: '", "',\n template: \\`\n ", "\n \\`,\n ", "\n })\n export default class ", " {\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n }\n "])), outputs.length ? 'Output, EventEmitter, \n' : '', ((_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.inject) ? 'Inject, forwardRef,' : '', refs.length ? ', ViewChild, ElementRef' : '', props.size ? ', Input' : '', (0, render_imports_1.renderPreComponent)(json), (0, lodash_1.kebabCase)(json.name || 'my-component'), (0, indent_1.indent)(template, 8).replace(/`/g, '\\`').replace(/\$\{/g, '\\${'), css.length
|
|
179
230
|
? "styles: [\n `".concat((0, indent_1.indent)(css, 8), "`\n ],")
|
|
180
|
-
: '', component.name, Array.from(props)
|
|
231
|
+
: '', component.name, outputs.join('\n'), Array.from(props)
|
|
181
232
|
.filter(function (item) { return !item.startsWith('slot'); })
|
|
182
233
|
.map(function (item) { return "@Input() ".concat(item, ": any"); })
|
|
183
234
|
.join('\n'), refs
|
|
184
235
|
.map(function (refName) { return "@ViewChild('".concat(refName, "') ").concat(refName, ": ElementRef"); })
|
|
185
|
-
.join('\n'), !hasOnInit
|
|
236
|
+
.join('\n'), dataString, !hasInjectable ? '' : "constructor(\n".concat(injectables.join(',\n'), ") {}"), !hasOnInit
|
|
186
237
|
? ''
|
|
187
|
-
: "ngOnInit() {\n ".concat(!((
|
|
238
|
+
: "ngOnInit() {\n ".concat(!((_h = component.hooks) === null || _h === void 0 ? void 0 : _h.onInit)
|
|
188
239
|
? ''
|
|
189
|
-
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((
|
|
240
|
+
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_j = component.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code, {
|
|
190
241
|
replaceWith: 'this.',
|
|
191
|
-
|
|
242
|
+
contextVars: contextVars,
|
|
243
|
+
outputVars: outputVars,
|
|
244
|
+
}), "\n "), "\n ").concat(!((_k = component.hooks) === null || _k === void 0 ? void 0 : _k.onMount)
|
|
192
245
|
? ''
|
|
193
|
-
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((
|
|
246
|
+
: "\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_l = component.hooks.onMount) === null || _l === void 0 ? void 0 : _l.code, {
|
|
194
247
|
replaceWith: 'this.',
|
|
195
|
-
|
|
248
|
+
contextVars: contextVars,
|
|
249
|
+
outputVars: outputVars,
|
|
250
|
+
}), "\n "), "\n }"), !((_m = component.hooks.onUpdate) === null || _m === void 0 ? void 0 : _m.length)
|
|
196
251
|
? ''
|
|
197
252
|
: "ngAfterContentChecked() {\n ".concat(component.hooks.onUpdate.reduce(function (code, hook) {
|
|
198
253
|
code += (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.code, {
|
|
199
254
|
replaceWith: 'this.',
|
|
255
|
+
contextVars: contextVars,
|
|
256
|
+
outputVars: outputVars,
|
|
200
257
|
});
|
|
201
258
|
return code + '\n';
|
|
202
259
|
}, ''), "\n }"), !component.hooks.onUnMount
|
|
203
260
|
? ''
|
|
204
261
|
: "ngOnDestroy() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(component.hooks.onUnMount.code, {
|
|
205
262
|
replaceWith: 'this.',
|
|
206
|
-
|
|
263
|
+
contextVars: contextVars,
|
|
264
|
+
outputVars: outputVars,
|
|
265
|
+
}), "\n }"));
|
|
207
266
|
if (options.plugins) {
|
|
208
267
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
209
268
|
}
|
|
@@ -127,6 +127,9 @@ var blockToSolid = function (json, options) {
|
|
|
127
127
|
else {
|
|
128
128
|
str += "<".concat(json.name, " ");
|
|
129
129
|
}
|
|
130
|
+
if (json.name === 'Show' && json.meta.else) {
|
|
131
|
+
str += "fallback={".concat(blockToSolid(json.meta.else, options), "}");
|
|
132
|
+
}
|
|
130
133
|
var classString = collectClassString(json);
|
|
131
134
|
if (classString) {
|
|
132
135
|
str += " class=".concat(classString, " ");
|
|
@@ -238,9 +241,15 @@ var componentToSolid = function (options) {
|
|
|
238
241
|
var componentHasContext = (0, context_1.hasContext)(json);
|
|
239
242
|
var hasShowComponent = componentsUsed.has('Show');
|
|
240
243
|
var hasForComponent = componentsUsed.has('For');
|
|
241
|
-
var
|
|
242
|
-
? ''
|
|
243
|
-
|
|
244
|
+
var solidJSImports = [
|
|
245
|
+
componentHasContext ? 'useContext' : undefined,
|
|
246
|
+
hasShowComponent ? 'Show' : undefined,
|
|
247
|
+
hasForComponent ? 'For' : undefined,
|
|
248
|
+
((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ? 'onMount' : undefined,
|
|
249
|
+
].filter(Boolean);
|
|
250
|
+
var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(props) {\n ", "\n \n ", "\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(props) {\n ", "\n \n ", "\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0
|
|
251
|
+
? "import { \n ".concat(solidJSImports.map(function (item) { return item; }).join(', '), "\n } from 'solid-js';")
|
|
252
|
+
: '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", !hasState ? '' : "import { createMutable } from 'solid-js/store';", !componentHasStyles
|
|
244
253
|
? ''
|
|
245
254
|
: "import { css } from \"solid-styled-components\";", (0, render_imports_1.renderPreComponent)(json), json.name, !hasState ? '' : "const state = createMutable(".concat(stateString, ");"), getRefsString(json), getContextString(json, options), !((_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code)
|
|
246
255
|
? ''
|
|
@@ -21,22 +21,27 @@ var getDefaultImport = function (_a) {
|
|
|
21
21
|
}
|
|
22
22
|
return null;
|
|
23
23
|
};
|
|
24
|
+
var getFileExtensionForTarget = function (target) {
|
|
25
|
+
switch (target) {
|
|
26
|
+
case 'svelte':
|
|
27
|
+
return '.svelte';
|
|
28
|
+
case 'solid':
|
|
29
|
+
return '.jsx';
|
|
30
|
+
// these `.lite` extensions are handled in the `transpile` step of the CLI.
|
|
31
|
+
// TO-DO: consolidate file-extension renaming to one place.
|
|
32
|
+
default:
|
|
33
|
+
return '.lite';
|
|
34
|
+
}
|
|
35
|
+
};
|
|
24
36
|
var transformImportPath = function (theImport, target) {
|
|
25
37
|
// We need to drop the `.lite` from context files, because the context generator does so as well.
|
|
26
38
|
if (theImport.path.endsWith('.context.lite')) {
|
|
27
39
|
return theImport.path.replace('.lite', '');
|
|
28
40
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (theImport.path.endsWith('.lite'))
|
|
32
|
-
// all svelte components have `.svelte` extension
|
|
33
|
-
return theImport.path.replace('.lite', '.svelte');
|
|
34
|
-
else {
|
|
35
|
-
return theImport.path;
|
|
36
|
-
}
|
|
37
|
-
default:
|
|
38
|
-
return theImport.path;
|
|
41
|
+
if (theImport.path.endsWith('.lite')) {
|
|
42
|
+
return theImport.path.replace('.lite', getFileExtensionForTarget(target));
|
|
39
43
|
}
|
|
44
|
+
return theImport.path;
|
|
40
45
|
};
|
|
41
46
|
var renderImport = function (_a) {
|
|
42
47
|
var theImport = _a.theImport, target = _a.target;
|
|
@@ -7,8 +7,9 @@ var replaceIdentifiers = function (code, from, to) {
|
|
|
7
7
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
8
8
|
Identifier: function (path) {
|
|
9
9
|
if (
|
|
10
|
-
// This is not
|
|
11
|
-
!(core_1.types.isMemberExpression(path.parent)
|
|
10
|
+
// This is not an (optional) property access - like `foo` in `this.foo` or `this?.foo`
|
|
11
|
+
!((core_1.types.isMemberExpression(path.parent) ||
|
|
12
|
+
core_1.types.isOptionalMemberExpression(path.parent)) &&
|
|
12
13
|
path.parent.property === path.node) &&
|
|
13
14
|
// This is no the function name - like `foo` in `function foo() {}`
|
|
14
15
|
!(core_1.types.isFunctionDeclaration(path.parent) &&
|
|
@@ -2,6 +2,8 @@ export declare type StripStateAndPropsRefsOptions = {
|
|
|
2
2
|
replaceWith?: string | ((name: string) => string);
|
|
3
3
|
includeProps?: boolean;
|
|
4
4
|
includeState?: boolean;
|
|
5
|
+
contextVars?: string[];
|
|
6
|
+
outputVars?: string[];
|
|
5
7
|
};
|
|
6
8
|
/**
|
|
7
9
|
* Remove state. and props. from expressions, e.g.
|
|
@@ -13,6 +13,23 @@ var stripStateAndPropsRefs = function (code, options) {
|
|
|
13
13
|
if (options === void 0) { options = {}; }
|
|
14
14
|
var newCode = code || '';
|
|
15
15
|
var replacer = options.replaceWith || '';
|
|
16
|
+
var contextVars = (options === null || options === void 0 ? void 0 : options.contextVars) || [];
|
|
17
|
+
var outputVars = (options === null || options === void 0 ? void 0 : options.outputVars) || [];
|
|
18
|
+
if (contextVars.length) {
|
|
19
|
+
contextVars.forEach(function (_var) {
|
|
20
|
+
newCode = newCode.replace(
|
|
21
|
+
// determine expression edge cases
|
|
22
|
+
new RegExp('( |;|(\\())' + _var, 'g'), '$1this.' + _var);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (outputVars.length) {
|
|
26
|
+
outputVars.forEach(function (_var) {
|
|
27
|
+
// determine expression edge cases onMessage( to this.onMessage.emit(
|
|
28
|
+
var regexp = '( |;|\\()(props\\.?)' + _var + '\\(';
|
|
29
|
+
var replacer = '$1this.' + _var + '.emit(';
|
|
30
|
+
newCode = newCode.replace(new RegExp(regexp, 'g'), replacer);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
if (options.includeProps !== false) {
|
|
17
34
|
if (typeof replacer === 'string') {
|
|
18
35
|
newCode = newCode.replace(/props\./g, replacer);
|