@builder.io/mitosis 0.4.0 → 0.4.2
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/constants/media-sizes.js +4 -5
- package/dist/src/generators/alpine/generate.js +114 -132
- package/dist/src/generators/alpine/render-mount-hook.js +8 -5
- package/dist/src/generators/alpine/render-update-hooks.js +13 -13
- package/dist/src/generators/angular/helpers.js +19 -9
- package/dist/src/generators/angular/index.js +599 -584
- package/dist/src/generators/builder.js +200 -165
- package/dist/src/generators/context/angular.js +32 -26
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +25 -21
- package/dist/src/generators/context/qwik.js +21 -21
- package/dist/src/generators/context/react.js +22 -22
- package/dist/src/generators/context/rsc.js +20 -22
- package/dist/src/generators/context/solid.js +22 -22
- package/dist/src/generators/context/svelte.js +33 -28
- package/dist/src/generators/context/vue.js +1 -1
- package/dist/src/generators/helpers/context.js +6 -13
- package/dist/src/generators/helpers/functions.js +8 -8
- package/dist/src/generators/helpers/on-mount.js +9 -5
- package/dist/src/generators/helpers/rsc.js +7 -9
- package/dist/src/generators/html.js +995 -534
- package/dist/src/generators/liquid.js +81 -79
- package/dist/src/generators/lit/collect-class-string.js +10 -12
- package/dist/src/generators/lit/generate.js +204 -159
- package/dist/src/generators/marko/generate.js +193 -183
- package/dist/src/generators/minify.js +5 -9
- package/dist/src/generators/mitosis.js +135 -134
- package/dist/src/generators/qwik/component-generator.js +159 -154
- package/dist/src/generators/qwik/component.js +51 -81
- package/dist/src/generators/qwik/directives.js +68 -84
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +6 -7
- package/dist/src/generators/qwik/helpers/convert-method-to-function.js +38 -38
- package/dist/src/generators/qwik/helpers/handlers.js +16 -25
- package/dist/src/generators/qwik/helpers/stable-inject.js +7 -8
- package/dist/src/generators/qwik/helpers/stable-serialize.js +7 -8
- package/dist/src/generators/qwik/helpers/state.js +36 -43
- package/dist/src/generators/qwik/helpers/styles.js +19 -40
- package/dist/src/generators/qwik/jsx.js +63 -75
- package/dist/src/generators/qwik/src-generator.js +134 -167
- package/dist/src/generators/react/blocks.js +122 -127
- package/dist/src/generators/react/generator.js +314 -259
- package/dist/src/generators/react/helpers.js +23 -28
- package/dist/src/generators/react/state.js +34 -51
- package/dist/src/generators/react-native/index.js +72 -84
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +14 -26
- package/dist/src/generators/rsc.js +30 -36
- package/dist/src/generators/solid/blocks.js +46 -43
- package/dist/src/generators/solid/helpers/styles.js +11 -11
- package/dist/src/generators/solid/index.js +199 -190
- package/dist/src/generators/solid/state/helpers.js +76 -90
- package/dist/src/generators/solid/state/signals.js +30 -37
- package/dist/src/generators/solid/state/state.js +35 -48
- package/dist/src/generators/solid/state/store.js +40 -46
- package/dist/src/generators/stencil/collect-class-string.js +10 -12
- package/dist/src/generators/stencil/generate.js +158 -145
- package/dist/src/generators/svelte/blocks.js +146 -144
- package/dist/src/generators/svelte/helpers.js +10 -17
- package/dist/src/generators/svelte/svelte.js +321 -287
- package/dist/src/generators/swift-ui.js +162 -101
- package/dist/src/generators/taro.js +32 -36
- package/dist/src/generators/template.js +71 -74
- package/dist/src/generators/vue/blocks.js +116 -107
- package/dist/src/generators/vue/compositionApi.js +67 -50
- package/dist/src/generators/vue/helpers.js +71 -96
- package/dist/src/generators/vue/optionsApi.js +134 -105
- package/dist/src/generators/vue/vue.js +210 -207
- package/dist/src/helpers/babel-transform.js +40 -63
- package/dist/src/helpers/bindings.js +4 -12
- package/dist/src/helpers/camel-case.js +4 -5
- package/dist/src/helpers/capitalize.js +1 -1
- package/dist/src/helpers/component-file-extensions.js +23 -35
- package/dist/src/helpers/create-mitosis-component.js +22 -26
- package/dist/src/helpers/create-mitosis-context.js +5 -12
- package/dist/src/helpers/create-mitosis-node.js +10 -12
- package/dist/src/helpers/dash-case.js +2 -2
- package/dist/src/helpers/dedent.js +18 -22
- package/dist/src/helpers/event-handlers.js +1 -1
- package/dist/src/helpers/fast-clone.js +1 -1
- package/dist/src/helpers/filter-empty-text-nodes.js +2 -2
- package/dist/src/helpers/generic-format.js +7 -8
- package/dist/src/helpers/get-bindings.js +4 -4
- package/dist/src/helpers/get-components-used.js +3 -3
- package/dist/src/helpers/get-components.js +4 -4
- package/dist/src/helpers/get-custom-imports.js +10 -12
- package/dist/src/helpers/get-prop-functions.js +7 -8
- package/dist/src/helpers/get-props-ref.js +8 -8
- package/dist/src/helpers/get-props.js +12 -13
- package/dist/src/helpers/get-refs.js +4 -4
- package/dist/src/helpers/get-state-object-string.js +42 -61
- package/dist/src/helpers/get-state-used.js +7 -8
- package/dist/src/helpers/get-styles.js +6 -6
- package/dist/src/helpers/getters-to-functions.js +8 -12
- package/dist/src/helpers/handle-missing-state.js +3 -3
- package/dist/src/helpers/has-bindings-text.js +6 -6
- package/dist/src/helpers/has-component.js +4 -4
- package/dist/src/helpers/has-props.js +3 -3
- package/dist/src/helpers/has-stateful-dom.js +4 -4
- package/dist/src/helpers/has.js +3 -3
- package/dist/src/helpers/indent.js +2 -3
- package/dist/src/helpers/is-children.js +4 -5
- package/dist/src/helpers/is-component.js +1 -1
- package/dist/src/helpers/is-html-attribute.js +2 -11
- package/dist/src/helpers/is-mitosis-node.js +1 -1
- package/dist/src/helpers/is-root-text-node.js +1 -1
- package/dist/src/helpers/is-upper-case.js +1 -1
- package/dist/src/helpers/is-valid-attribute-name.js +1 -1
- package/dist/src/helpers/json.js +2 -2
- package/dist/src/helpers/map-refs.js +29 -40
- package/dist/src/helpers/merge-options.js +20 -31
- package/dist/src/helpers/mitosis-imports.js +5 -6
- package/dist/src/helpers/nodes/for.js +2 -3
- package/dist/src/helpers/nullable.js +1 -3
- package/dist/src/helpers/on-event.js +32 -36
- package/dist/src/helpers/output.js +4 -5
- package/dist/src/helpers/parse-node.js +13 -5
- package/dist/src/helpers/parsers.js +10 -14
- package/dist/src/helpers/patterns.js +6 -8
- package/dist/src/helpers/plugins/process-code/index.js +114 -120
- package/dist/src/helpers/plugins/process-signals.js +114 -125
- package/dist/src/helpers/plugins/process-target-blocks.js +18 -20
- package/dist/src/helpers/process-http-requests.js +8 -4
- package/dist/src/helpers/remove-surrounding-block.js +2 -2
- package/dist/src/helpers/render-imports.js +99 -111
- package/dist/src/helpers/replace-identifiers.js +40 -49
- package/dist/src/helpers/replace-new-lines-in-strings.js +3 -3
- package/dist/src/helpers/signals/signals.js +27 -35
- package/dist/src/helpers/slots.js +11 -20
- package/dist/src/helpers/state.js +1 -3
- package/dist/src/helpers/strip-meta-properties.js +6 -6
- package/dist/src/helpers/strip-state-and-props-refs.js +21 -32
- package/dist/src/helpers/styles/collect-css.js +39 -44
- package/dist/src/helpers/styles/collect-styled-components.js +30 -28
- package/dist/src/helpers/styles/helpers.js +23 -29
- package/dist/src/helpers/trace-reference-to-module-path.js +3 -4
- package/dist/src/helpers/transform-state-setters.js +16 -19
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +3 -3
- package/dist/src/helpers/typescript-project.js +25 -25
- package/dist/src/helpers/typescript.js +1 -3
- package/dist/src/modules/plugins.js +20 -28
- package/dist/src/parsers/angular.js +49 -57
- package/dist/src/parsers/builder/builder.js +448 -343
- package/dist/src/parsers/builder/helpers.js +10 -10
- package/dist/src/parsers/context.js +15 -17
- package/dist/src/parsers/jsx/ast.js +11 -11
- package/dist/src/parsers/jsx/component-types.js +22 -32
- package/dist/src/parsers/jsx/context.js +12 -12
- package/dist/src/parsers/jsx/element-parser.js +43 -54
- package/dist/src/parsers/jsx/exports.js +12 -14
- package/dist/src/parsers/jsx/function-parser.js +108 -119
- package/dist/src/parsers/jsx/helpers.js +11 -13
- package/dist/src/parsers/jsx/hooks/helpers.js +14 -16
- package/dist/src/parsers/jsx/hooks/index.js +34 -44
- package/dist/src/parsers/jsx/hooks/use-target.js +27 -27
- package/dist/src/parsers/jsx/imports.js +7 -17
- package/dist/src/parsers/jsx/jsx.js +92 -91
- package/dist/src/parsers/jsx/props-types.js +8 -10
- package/dist/src/parsers/jsx/props.js +15 -23
- package/dist/src/parsers/jsx/signals.js +28 -29
- package/dist/src/parsers/jsx/state.d.ts +2 -4
- package/dist/src/parsers/jsx/state.js +59 -93
- package/dist/src/parsers/svelte/css/index.js +1 -1
- package/dist/src/parsers/svelte/helpers/bindings.js +18 -19
- package/dist/src/parsers/svelte/helpers/children.js +5 -6
- package/dist/src/parsers/svelte/helpers/expressions.js +7 -9
- package/dist/src/parsers/svelte/helpers/hooks.js +2 -2
- package/dist/src/parsers/svelte/helpers/post-process.js +49 -70
- package/dist/src/parsers/svelte/helpers/string.js +5 -5
- package/dist/src/parsers/svelte/html/actions.js +17 -10
- package/dist/src/parsers/svelte/html/each.js +11 -16
- package/dist/src/parsers/svelte/html/element.js +68 -78
- package/dist/src/parsers/svelte/html/fragment.js +3 -3
- package/dist/src/parsers/svelte/html/if-else.js +11 -18
- package/dist/src/parsers/svelte/html/index.js +14 -14
- package/dist/src/parsers/svelte/html/mustache-tag.js +5 -5
- package/dist/src/parsers/svelte/html/slot.js +5 -5
- package/dist/src/parsers/svelte/html/text.js +7 -14
- package/dist/src/parsers/svelte/index.js +23 -72
- package/dist/src/parsers/svelte/instance/context.js +17 -17
- package/dist/src/parsers/svelte/instance/expressions.js +2 -2
- package/dist/src/parsers/svelte/instance/functions.js +35 -30
- package/dist/src/parsers/svelte/instance/hooks.js +4 -5
- package/dist/src/parsers/svelte/instance/imports.js +11 -21
- package/dist/src/parsers/svelte/instance/index.js +22 -22
- package/dist/src/parsers/svelte/instance/properties.js +11 -23
- package/dist/src/parsers/svelte/instance/reactive.js +11 -11
- package/dist/src/parsers/svelte/instance/references.js +13 -13
- package/dist/src/parsers/svelte/instance/statements.js +3 -3
- package/dist/src/parsers/svelte/module/index.js +14 -26
- package/dist/src/parsers/svelte/typescript/index.js +27 -36
- package/dist/src/plugins/compile-away-builder-components.js +223 -156
- package/dist/src/plugins/compile-away-components.js +13 -21
- package/dist/src/plugins/map-styles.js +7 -7
- package/dist/src/symbols/symbol-processor.js +44 -62
- package/dist/src/targets.js +19 -19
- package/dist/src/types/mitosis-node.js +1 -1
- package/package.json +1 -1
|
@@ -1,177 +1,165 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderPreComponent = exports.renderImport = exports.transformImportPath = exports.checkIsComponentImport = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var value = theImport.imports[key];
|
|
4
|
+
const component_file_extensions_1 = require("./component-file-extensions");
|
|
5
|
+
const DEFAULT_IMPORT = 'default';
|
|
6
|
+
const STAR_IMPORT = '*';
|
|
7
|
+
const getStarImport = ({ theImport }) => {
|
|
8
|
+
for (const key in theImport.imports) {
|
|
9
|
+
const value = theImport.imports[key];
|
|
11
10
|
if (value === STAR_IMPORT) {
|
|
12
11
|
return key;
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
return null;
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var value = theImport.imports[key];
|
|
16
|
+
const getDefaultImport = ({ theImport }) => {
|
|
17
|
+
for (const key in theImport.imports) {
|
|
18
|
+
const value = theImport.imports[key];
|
|
21
19
|
if (value === DEFAULT_IMPORT) {
|
|
22
20
|
return key;
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
return null;
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var checkIsComponentImport = function (theImport) {
|
|
32
|
-
return !checkIsContextImport(theImport) &&
|
|
33
|
-
component_file_extensions_1.COMPONENT_IMPORT_EXTENSIONS.some(function (contextPath) { return theImport.path.endsWith(contextPath); });
|
|
34
|
-
};
|
|
25
|
+
const CONTEXT_IMPORTS = ['context.lite', 'context.lite.ts', 'context.lite.js'];
|
|
26
|
+
const checkIsContextImport = (theImport) => CONTEXT_IMPORTS.some((contextPath) => theImport.path.endsWith(contextPath));
|
|
27
|
+
const checkIsComponentImport = (theImport) => !checkIsContextImport(theImport) &&
|
|
28
|
+
component_file_extensions_1.COMPONENT_IMPORT_EXTENSIONS.some((contextPath) => theImport.path.endsWith(contextPath));
|
|
35
29
|
exports.checkIsComponentImport = checkIsComponentImport;
|
|
36
|
-
|
|
37
|
-
var theImport = _a.theImport, target = _a.target, preserveFileExtensions = _a.preserveFileExtensions, explicitImportFileExtension = _a.explicitImportFileExtension;
|
|
30
|
+
const transformImportPath = ({ theImport, target, preserveFileExtensions, explicitImportFileExtension, }) => {
|
|
38
31
|
// We need to drop the `.lite` from context files, because the context generator does so as well.
|
|
39
32
|
if (checkIsContextImport(theImport)) {
|
|
40
|
-
|
|
41
|
-
CONTEXT_IMPORTS.forEach(
|
|
42
|
-
if (
|
|
43
|
-
|
|
33
|
+
let path = theImport.path;
|
|
34
|
+
CONTEXT_IMPORTS.forEach((contextPath) => {
|
|
35
|
+
if (path.endsWith(contextPath)) {
|
|
36
|
+
path = path.replace(contextPath, 'context.js');
|
|
44
37
|
}
|
|
45
38
|
});
|
|
46
|
-
return
|
|
39
|
+
return path;
|
|
47
40
|
}
|
|
48
41
|
if (preserveFileExtensions)
|
|
49
42
|
return theImport.path;
|
|
50
43
|
if ((0, exports.checkIsComponentImport)(theImport)) {
|
|
51
|
-
return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target
|
|
44
|
+
return theImport.path.replace(component_file_extensions_1.INPUT_EXTENSION_REGEX, (0, component_file_extensions_1.getComponentFileExtensionForTarget)({ target, type: 'import', explicitImportFileExtension }));
|
|
52
45
|
}
|
|
53
46
|
return theImport.path;
|
|
54
47
|
};
|
|
55
48
|
exports.transformImportPath = transformImportPath;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
return ![DEFAULT_IMPORT, STAR_IMPORT].includes(value);
|
|
62
|
-
})
|
|
63
|
-
.map(function (_a) {
|
|
64
|
-
var key = _a[0], value = _a[1];
|
|
65
|
-
return key !== value ? "".concat(value, " as ").concat(key) : value;
|
|
49
|
+
const getNamedImports = ({ theImport }) => {
|
|
50
|
+
const namedImports = Object.entries(theImport.imports)
|
|
51
|
+
.filter(([, value]) => ![DEFAULT_IMPORT, STAR_IMPORT].includes(value))
|
|
52
|
+
.map(([key, value]) => {
|
|
53
|
+
return key !== value ? `${value} as ${key}` : value;
|
|
66
54
|
});
|
|
67
55
|
if (namedImports.length > 0) {
|
|
68
|
-
return
|
|
56
|
+
return `{ ${namedImports.join(', ')} }`;
|
|
69
57
|
}
|
|
70
58
|
else {
|
|
71
59
|
return null;
|
|
72
60
|
}
|
|
73
61
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return { starImport: starImport, defaultImport: defaultImport, namedImports: namedImports };
|
|
62
|
+
const getImportedValues = ({ theImport }) => {
|
|
63
|
+
const starImport = getStarImport({ theImport });
|
|
64
|
+
const defaultImport = getDefaultImport({ theImport });
|
|
65
|
+
const namedImports = getNamedImports({ theImport });
|
|
66
|
+
return { starImport, defaultImport, namedImports };
|
|
80
67
|
};
|
|
81
|
-
|
|
82
|
-
var defaultImport = _a.defaultImport, namedImports = _a.namedImports, starImport = _a.starImport;
|
|
68
|
+
const getImportValue = ({ defaultImport, namedImports, starImport }) => {
|
|
83
69
|
if (starImport) {
|
|
84
|
-
return
|
|
70
|
+
return ` * as ${starImport} `;
|
|
85
71
|
}
|
|
86
72
|
else {
|
|
87
73
|
return [defaultImport, namedImports].filter(Boolean).join(', ');
|
|
88
74
|
}
|
|
89
75
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
explicitImportFileExtension: explicitImportFileExtension,
|
|
76
|
+
const renderImport = ({ theImport, target, asyncComponentImports, preserveFileExtensions = false, component = undefined, componentsUsed = [], importMapper, explicitImportFileExtension = false, }) => {
|
|
77
|
+
const importedValues = getImportedValues({ theImport });
|
|
78
|
+
const path = (0, exports.transformImportPath)({
|
|
79
|
+
theImport,
|
|
80
|
+
target,
|
|
81
|
+
preserveFileExtensions,
|
|
82
|
+
explicitImportFileExtension,
|
|
98
83
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
84
|
+
const importValue = getImportValue(importedValues);
|
|
85
|
+
const isComponentImport = (0, exports.checkIsComponentImport)(theImport);
|
|
86
|
+
const shouldBeAsyncImport = asyncComponentImports && isComponentImport;
|
|
87
|
+
const isTypeImport = theImport.importKind === 'type';
|
|
103
88
|
// For lit (components) we just want to do a plain import
|
|
104
89
|
// https://lit.dev/docs/components/rendering/#composing-templates
|
|
105
90
|
if (isComponentImport && target === 'lit') {
|
|
106
|
-
return
|
|
91
|
+
return `import '${path}';`;
|
|
107
92
|
}
|
|
108
93
|
if (shouldBeAsyncImport) {
|
|
109
|
-
|
|
94
|
+
const isVueImport = target === 'vue';
|
|
110
95
|
if (isVueImport && importedValues.namedImports) {
|
|
111
96
|
console.warn('Vue: Async Component imports cannot include named imports. Dropping async import. This might break your code.');
|
|
112
97
|
}
|
|
113
98
|
else {
|
|
114
|
-
return
|
|
99
|
+
return `const ${importValue} = () => import('${path}')
|
|
100
|
+
.then(x => x.default)
|
|
101
|
+
.catch(err => {
|
|
102
|
+
console.error('Error while attempting to dynamically import component ${importValue} at ${path}', err);
|
|
103
|
+
throw err;
|
|
104
|
+
});`;
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
if (importMapper) {
|
|
118
108
|
return importMapper(component, theImport, importedValues, componentsUsed);
|
|
119
109
|
}
|
|
120
110
|
return importValue
|
|
121
|
-
?
|
|
122
|
-
:
|
|
111
|
+
? `import ${isTypeImport ? 'type' : ''} ${importValue} from '${path}';`
|
|
112
|
+
: `import '${path}';`;
|
|
123
113
|
};
|
|
124
114
|
exports.renderImport = renderImport;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
//
|
|
131
|
-
theImport.path
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
-
var renderPreComponent = function (_a) {
|
|
158
|
-
var _b;
|
|
159
|
-
var component = _a.component, target = _a.target, excludeMitosisComponents = _a.excludeMitosisComponents, _c = _a.asyncComponentImports, asyncComponentImports = _c === void 0 ? false : _c, _d = _a.preserveFileExtensions, preserveFileExtensions = _d === void 0 ? false : _d, _e = _a.componentsUsed, componentsUsed = _e === void 0 ? [] : _e, importMapper = _a.importMapper, _f = _a.explicitImportFileExtension, explicitImportFileExtension = _f === void 0 ? false : _f;
|
|
160
|
-
return "\n ".concat(renderImports({
|
|
115
|
+
const renderImports = ({ imports, target, asyncComponentImports, excludeMitosisComponents, preserveFileExtensions = false, component, componentsUsed, importMapper, explicitImportFileExtension, }) => imports
|
|
116
|
+
.filter((theImport) => {
|
|
117
|
+
if (
|
|
118
|
+
// Remove compile away components
|
|
119
|
+
theImport.path === '@builder.io/components' ||
|
|
120
|
+
// TODO: Mitosis output needs this
|
|
121
|
+
theImport.path.startsWith('@builder.io/mitosis')) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
else if (excludeMitosisComponents && theImport.path.includes('.lite')) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.map((theImport) => (0, exports.renderImport)({
|
|
132
|
+
theImport,
|
|
133
|
+
target,
|
|
134
|
+
asyncComponentImports,
|
|
135
|
+
preserveFileExtensions,
|
|
136
|
+
component,
|
|
137
|
+
componentsUsed,
|
|
138
|
+
importMapper,
|
|
139
|
+
explicitImportFileExtension,
|
|
140
|
+
}))
|
|
141
|
+
.join('\n');
|
|
142
|
+
const renderPreComponent = ({ component, target, excludeMitosisComponents, asyncComponentImports = false, preserveFileExtensions = false, componentsUsed = [], importMapper, explicitImportFileExtension = false, }) => {
|
|
143
|
+
var _a;
|
|
144
|
+
return `
|
|
145
|
+
${renderImports({
|
|
161
146
|
imports: component.imports,
|
|
162
|
-
target
|
|
163
|
-
asyncComponentImports
|
|
164
|
-
excludeMitosisComponents
|
|
165
|
-
preserveFileExtensions
|
|
166
|
-
component
|
|
167
|
-
componentsUsed
|
|
168
|
-
importMapper
|
|
169
|
-
explicitImportFileExtension
|
|
170
|
-
})
|
|
147
|
+
target,
|
|
148
|
+
asyncComponentImports,
|
|
149
|
+
excludeMitosisComponents,
|
|
150
|
+
preserveFileExtensions,
|
|
151
|
+
component,
|
|
152
|
+
componentsUsed,
|
|
153
|
+
importMapper,
|
|
154
|
+
explicitImportFileExtension,
|
|
155
|
+
})}
|
|
156
|
+
${renderExportAndLocal(component)}
|
|
157
|
+
${((_a = component.hooks.preComponent) === null || _a === void 0 ? void 0 : _a.code) || ''}
|
|
158
|
+
`;
|
|
171
159
|
};
|
|
172
160
|
exports.renderPreComponent = renderPreComponent;
|
|
173
|
-
|
|
161
|
+
const renderExportAndLocal = (component) => {
|
|
174
162
|
return Object.keys(component.exports || {})
|
|
175
|
-
.map(
|
|
163
|
+
.map((key) => component.exports[key].code)
|
|
176
164
|
.join('\n');
|
|
177
165
|
};
|
|
@@ -4,48 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.replaceNodes = exports.replacePropsIdentifier = exports.replaceStateIdentifier = exports.replaceIdentifiers = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const core_1 = require("@babel/core");
|
|
8
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
9
|
+
const function_1 = require("fp-ts/lib/function");
|
|
10
|
+
const babel_transform_1 = require("./babel-transform");
|
|
11
11
|
/**
|
|
12
12
|
* Given a `to` function given by the user, figure out the best argument to provide to the `to` function.
|
|
13
13
|
* This function makes a best guess based on the AST structure it's dealing with.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
const getToParam = (path) => {
|
|
16
16
|
if (core_1.types.isMemberExpression(path.node) || core_1.types.isOptionalMemberExpression(path.node)) {
|
|
17
17
|
if (core_1.types.isIdentifier(path.node.property)) {
|
|
18
18
|
// if simple member expression e.g. `props.foo`, returns `foo`
|
|
19
|
-
|
|
19
|
+
const propertyName = path.node.property.name;
|
|
20
20
|
return propertyName;
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
// if nested member expression e.g. `props.foo.bar.baz`, returns `foo.bar.baz`
|
|
24
|
-
|
|
24
|
+
const x = (0, generator_1.default)(path.node.property).code;
|
|
25
25
|
return x;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
// if naked identifier e.g. `foo`, returns `foo`
|
|
30
|
-
|
|
30
|
+
const nodeName = path.node.name;
|
|
31
31
|
return nodeName;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var normalizedFrom = Array.isArray(from) ? from : [from];
|
|
34
|
+
const _replaceIdentifiers = (path, { from, to }) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const memberExpressionObject = core_1.types.isIdentifier(path.node) ? path.node : path.node.object;
|
|
37
|
+
const normalizedFrom = Array.isArray(from) ? from : [from];
|
|
39
38
|
if (!core_1.types.isIdentifier(memberExpressionObject) ||
|
|
40
|
-
((
|
|
39
|
+
((_b = (_a = path.node) === null || _a === void 0 ? void 0 : _a._builder_meta) === null || _b === void 0 ? void 0 : _b.newlyGenerated)) {
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
const matchesFrom = normalizedFrom.includes(memberExpressionObject.name);
|
|
44
43
|
if (matchesFrom) {
|
|
45
44
|
if (to) {
|
|
46
45
|
// `props.foo` to `state`, e.g. `state.foo`
|
|
47
46
|
if (typeof to === 'string') {
|
|
48
|
-
|
|
47
|
+
const cleanedIdentifier = (0, function_1.pipe)(
|
|
49
48
|
// Remove trailing `.` if it exists in the user-provided string, as the dot is generated
|
|
50
49
|
// by babel from the AST
|
|
51
50
|
to.endsWith('.') ? to.substring(0, to.length - 1) : to, core_1.types.identifier);
|
|
@@ -59,12 +58,11 @@ var _replaceIdentifiers = function (path, _a) {
|
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const newMemberExpression = (0, function_1.pipe)(getToParam(path), (x) => to(x, memberExpressionObject.name), (expression) => {
|
|
62
|
+
const [head, ...tail] = expression.split('.');
|
|
64
63
|
return [head, tail.join('.')];
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
var objIdentifier = core_1.types.identifier(obj);
|
|
64
|
+
}, ([obj, prop]) => {
|
|
65
|
+
const objIdentifier = core_1.types.identifier(obj);
|
|
68
66
|
if (prop === '') {
|
|
69
67
|
return objIdentifier;
|
|
70
68
|
}
|
|
@@ -92,7 +90,7 @@ var _replaceIdentifiers = function (path, _a) {
|
|
|
92
90
|
}
|
|
93
91
|
else {
|
|
94
92
|
if (core_1.types.isIdentifier(path.node)) {
|
|
95
|
-
console.debug(
|
|
93
|
+
console.debug(`Could not replace Identifier with nothing.`);
|
|
96
94
|
}
|
|
97
95
|
else {
|
|
98
96
|
// if we're looking at a member expression, e.g. `props.foo` and no `to` was provided, then we want to strip out
|
|
@@ -105,17 +103,16 @@ var _replaceIdentifiers = function (path, _a) {
|
|
|
105
103
|
/**
|
|
106
104
|
* @deprecated Use `replaceNodes` instead.
|
|
107
105
|
*/
|
|
108
|
-
|
|
109
|
-
var code = _a.code, from = _a.from, to = _a.to;
|
|
106
|
+
const replaceIdentifiers = ({ code, from, to }) => {
|
|
110
107
|
try {
|
|
111
108
|
return (0, function_1.pipe)((0, babel_transform_1.babelTransformExpression)(code, {
|
|
112
|
-
MemberExpression
|
|
113
|
-
_replaceIdentifiers(path, { from
|
|
109
|
+
MemberExpression(path) {
|
|
110
|
+
_replaceIdentifiers(path, { from, to });
|
|
114
111
|
},
|
|
115
|
-
OptionalMemberExpression
|
|
116
|
-
_replaceIdentifiers(path, { from
|
|
112
|
+
OptionalMemberExpression(path) {
|
|
113
|
+
_replaceIdentifiers(path, { from, to });
|
|
117
114
|
},
|
|
118
|
-
Identifier
|
|
115
|
+
Identifier(path) {
|
|
119
116
|
// we only want to ignore certain identifiers:
|
|
120
117
|
if (
|
|
121
118
|
// (optional) member expressions are already handled in other visitors
|
|
@@ -127,52 +124,46 @@ var replaceIdentifiers = function (_a) {
|
|
|
127
124
|
// !(types.isVariableDeclarator(path.parent) && path.parent.id === path.node)
|
|
128
125
|
// object -> { detail: { state: 'something' } } shouldn't be transformed to { detail: { this: 'something' } }
|
|
129
126
|
!core_1.types.isObjectProperty(path.parent)) {
|
|
130
|
-
_replaceIdentifiers(path, { from
|
|
127
|
+
_replaceIdentifiers(path, { from, to });
|
|
131
128
|
}
|
|
132
129
|
},
|
|
133
130
|
}),
|
|
134
131
|
// merely running `babel.transform` will add spaces around the code, even if we don't end up replacing anything.
|
|
135
132
|
// we have some other code downstream that cannot have untrimmed spaces, so we need to trim the output.
|
|
136
|
-
|
|
133
|
+
(code) => code.trim());
|
|
137
134
|
}
|
|
138
135
|
catch (err) {
|
|
139
136
|
throw err;
|
|
140
137
|
}
|
|
141
138
|
};
|
|
142
139
|
exports.replaceIdentifiers = replaceIdentifiers;
|
|
143
|
-
|
|
144
|
-
return (0, exports.replaceIdentifiers)({ code: code, from: 'state', to: to });
|
|
145
|
-
}; };
|
|
140
|
+
const replaceStateIdentifier = (to) => (code) => (0, exports.replaceIdentifiers)({ code, from: 'state', to });
|
|
146
141
|
exports.replaceStateIdentifier = replaceStateIdentifier;
|
|
147
|
-
|
|
148
|
-
return (0, exports.replaceIdentifiers)({ code: code, from: 'props', to: to });
|
|
149
|
-
}; };
|
|
142
|
+
const replacePropsIdentifier = (to) => (code) => (0, exports.replaceIdentifiers)({ code, from: 'props', to });
|
|
150
143
|
exports.replacePropsIdentifier = replacePropsIdentifier;
|
|
151
|
-
|
|
144
|
+
const isNewlyGenerated = (node) => { var _a; return (_a = node === null || node === void 0 ? void 0 : node._builder_meta) === null || _a === void 0 ? void 0 : _a.newlyGenerated; };
|
|
152
145
|
/**
|
|
153
146
|
* Replaces all instances of a Babel AST Node with a new Node within a code string.
|
|
154
147
|
* Uses `generate()` to convert the Node to a string and compare them.
|
|
155
148
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var searchAndReplace = function (path) {
|
|
149
|
+
const replaceNodes = ({ code, nodeMaps, }) => {
|
|
150
|
+
const searchAndReplace = (path) => {
|
|
159
151
|
if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
|
|
160
152
|
return;
|
|
161
|
-
for (
|
|
162
|
-
var _a = nodeMaps_1[_i], from = _a.from, to = _a.to, condition = _a.condition;
|
|
153
|
+
for (const { from, to, condition } of nodeMaps) {
|
|
163
154
|
if (isNewlyGenerated(path.node) || isNewlyGenerated(path.parent))
|
|
164
155
|
return;
|
|
165
156
|
// if (path.node.type !== from.type) return;
|
|
166
|
-
|
|
157
|
+
const matchesCondition = condition ? condition(path) : true;
|
|
167
158
|
if ((0, generator_1.default)(path.node).code === (0, generator_1.default)(from).code && matchesCondition) {
|
|
168
|
-
|
|
159
|
+
const x = core_1.types.cloneNode(to);
|
|
169
160
|
x._builder_meta = { newlyGenerated: true };
|
|
170
161
|
try {
|
|
171
162
|
path.replaceWith(x);
|
|
172
163
|
}
|
|
173
164
|
catch (err) {
|
|
174
165
|
console.log('error replacing', {
|
|
175
|
-
code
|
|
166
|
+
code,
|
|
176
167
|
orig: (0, generator_1.default)(path.node).code,
|
|
177
168
|
to: (0, generator_1.default)(x).code,
|
|
178
169
|
});
|
|
@@ -182,13 +173,13 @@ var replaceNodes = function (_a) {
|
|
|
182
173
|
}
|
|
183
174
|
};
|
|
184
175
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
185
|
-
MemberExpression
|
|
176
|
+
MemberExpression(path) {
|
|
186
177
|
searchAndReplace(path);
|
|
187
178
|
},
|
|
188
|
-
Identifier
|
|
179
|
+
Identifier(path) {
|
|
189
180
|
searchAndReplace(path);
|
|
190
181
|
},
|
|
191
|
-
OptionalMemberExpression
|
|
182
|
+
OptionalMemberExpression(path) {
|
|
192
183
|
searchAndReplace(path);
|
|
193
184
|
},
|
|
194
185
|
});
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripNewlinesInStrings = void 0;
|
|
4
4
|
function stripNewlinesInStrings(string) {
|
|
5
|
-
|
|
5
|
+
let inString = null;
|
|
6
6
|
return string
|
|
7
7
|
.split('')
|
|
8
|
-
.map(
|
|
8
|
+
.map((char, index) => {
|
|
9
9
|
if (inString) {
|
|
10
10
|
if (char === '\n') {
|
|
11
11
|
return ' ';
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
// Prior char is escape char and the char before that is not escaping it
|
|
15
|
-
|
|
15
|
+
const isEscaped = string[index - 1] === '\\' && string[index - 2] !== '\\';
|
|
16
16
|
if (!inString && (char === '"' || char === "'") && !isEscaped) {
|
|
17
17
|
inString = char;
|
|
18
18
|
}
|
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mapSignalTypeInTSFile = exports.mapSignalType = exports.getSignalImportName = exports.getSignalMitosisImportForTarget = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
const function_1 = require("fp-ts/lib/function");
|
|
6
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
7
|
+
const mitosis_imports_1 = require("../mitosis-imports");
|
|
8
|
+
const getSignalMappingForTarget = (target) => {
|
|
9
9
|
switch (target) {
|
|
10
10
|
case 'svelte':
|
|
11
|
-
|
|
11
|
+
const importDeclaration = core_1.types.importDeclaration([core_1.types.importSpecifier(core_1.types.identifier('Writable'), core_1.types.identifier('Writable'))], core_1.types.stringLiteral('svelte/store'));
|
|
12
12
|
importDeclaration.importKind = 'type';
|
|
13
13
|
return {
|
|
14
|
-
getTypeReference:
|
|
15
|
-
|
|
16
|
-
return core_1.types.tsTypeReference(core_1.types.identifier('Writable'), core_1.types.tsTypeParameterInstantiation(generics));
|
|
17
|
-
},
|
|
18
|
-
importDeclaration: importDeclaration,
|
|
14
|
+
getTypeReference: (generics = []) => core_1.types.tsTypeReference(core_1.types.identifier('Writable'), core_1.types.tsTypeParameterInstantiation(generics)),
|
|
15
|
+
importDeclaration,
|
|
19
16
|
};
|
|
20
17
|
default:
|
|
21
18
|
return undefined;
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const getSignalMitosisImportForTarget = (target) => {
|
|
22
|
+
const signalType = getSignalMappingForTarget(target);
|
|
26
23
|
if (!signalType) {
|
|
27
24
|
return undefined;
|
|
28
25
|
}
|
|
29
26
|
return (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(signalType.importDeclaration);
|
|
30
27
|
};
|
|
31
28
|
exports.getSignalMitosisImportForTarget = getSignalMitosisImportForTarget;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const getSignalImportName = (code) => {
|
|
30
|
+
let foundSignalUsage = false;
|
|
31
|
+
let signalImportName = undefined;
|
|
35
32
|
(0, babel_transform_1.babelTransformExpression)(code, {
|
|
36
|
-
ImportSpecifier
|
|
33
|
+
ImportSpecifier(path) {
|
|
37
34
|
if (core_1.types.isIdentifier(path.node.imported) && path.node.imported.name === 'Signal') {
|
|
38
35
|
if (path.parentPath.isImportDeclaration() &&
|
|
39
36
|
path.parentPath.node.source.value === '@builder.io/mitosis') {
|
|
@@ -51,7 +48,7 @@ var getSignalImportName = function (code) {
|
|
|
51
48
|
return undefined;
|
|
52
49
|
}
|
|
53
50
|
(0, babel_transform_1.babelTransformExpression)(code, {
|
|
54
|
-
TSTypeReference
|
|
51
|
+
TSTypeReference(path) {
|
|
55
52
|
if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
|
|
56
53
|
foundSignalUsage = true;
|
|
57
54
|
path.stop();
|
|
@@ -61,14 +58,13 @@ var getSignalImportName = function (code) {
|
|
|
61
58
|
return foundSignalUsage ? signalImportName : undefined;
|
|
62
59
|
};
|
|
63
60
|
exports.getSignalImportName = getSignalImportName;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var signalType = getSignalMappingForTarget(target);
|
|
61
|
+
const addSignalImport = ({ code, target }) => {
|
|
62
|
+
const signalType = getSignalMappingForTarget(target);
|
|
67
63
|
if (!signalType) {
|
|
68
64
|
return code;
|
|
69
65
|
}
|
|
70
66
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
71
|
-
Program
|
|
67
|
+
Program(path) {
|
|
72
68
|
path.node.body.unshift(signalType.importDeclaration);
|
|
73
69
|
},
|
|
74
70
|
});
|
|
@@ -77,14 +73,13 @@ var addSignalImport = function (_a) {
|
|
|
77
73
|
* Finds all `Signal` types and replaces them with the correct type for the given target.
|
|
78
74
|
* e.g. `Signal<string>` becomes `Writable<string>` for Svelte.
|
|
79
75
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
var map = function (path) {
|
|
76
|
+
const mapSignalType = ({ code, target, signalImportName = (0, exports.getSignalImportName)(code), }) => {
|
|
77
|
+
const signalType = getSignalMappingForTarget(target);
|
|
78
|
+
const map = (path) => {
|
|
84
79
|
var _a;
|
|
85
80
|
if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const params = ((_a = path.node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) || [];
|
|
82
|
+
const newType = (signalType === null || signalType === void 0 ? void 0 : signalType.getTypeReference)
|
|
88
83
|
? signalType.getTypeReference(params)
|
|
89
84
|
: // if no mapping exists, drop `Signal` and just use the generic type passed to `Signal` as-is.
|
|
90
85
|
params[0];
|
|
@@ -92,7 +87,7 @@ var mapSignalType = function (_a) {
|
|
|
92
87
|
}
|
|
93
88
|
};
|
|
94
89
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
95
|
-
TSTypeReference
|
|
90
|
+
TSTypeReference(path) {
|
|
96
91
|
map(path);
|
|
97
92
|
},
|
|
98
93
|
});
|
|
@@ -104,14 +99,11 @@ exports.mapSignalType = mapSignalType;
|
|
|
104
99
|
* - Maps the `Signal` type to the target's equivalent
|
|
105
100
|
* - Adds the equivalent of the `Signal` import to the file
|
|
106
101
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var signalImportName = (0, exports.getSignalImportName)(code);
|
|
102
|
+
const mapSignalTypeInTSFile = ({ code, target }) => {
|
|
103
|
+
const signalImportName = (0, exports.getSignalImportName)(code);
|
|
110
104
|
if (!signalImportName) {
|
|
111
105
|
return code;
|
|
112
106
|
}
|
|
113
|
-
return (0, function_1.pipe)((0, exports.mapSignalType)({ target
|
|
114
|
-
return addSignalImport({ code: code, target: target });
|
|
115
|
-
});
|
|
107
|
+
return (0, function_1.pipe)((0, exports.mapSignalType)({ target, code, signalImportName }), (code) => addSignalImport({ code, target }));
|
|
116
108
|
};
|
|
117
109
|
exports.mapSignalTypeInTSFile = mapSignalTypeInTSFile;
|