@builder.io/mitosis 0.0.115-7 → 0.0.115

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.
@@ -82,7 +82,14 @@ var checkIsObjectWithCodeBlock = function (obj) {
82
82
  return typeof obj == 'object' && (obj === null || obj === void 0 ? void 0 : obj.code) && typeof obj.code === 'string';
83
83
  };
84
84
  function getLexicalScopeVars(component) {
85
- return __spreadArray(__spreadArray(['props', 'state'], Object.keys(component.refs), true), Object.keys(component.context.get), true);
85
+ return __spreadArray(__spreadArray(__spreadArray([
86
+ 'props',
87
+ 'state'
88
+ ], Object.keys(component.refs), true), Object.keys(component.context.get), true), Object.keys(component.state).filter(function (key) {
89
+ var _a;
90
+ var stateType = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.type;
91
+ return stateType === 'getter' || stateType === 'function';
92
+ }), true);
86
93
  }
87
94
  exports.getLexicalScopeVars = getLexicalScopeVars;
88
95
  function rewriteCodeExpr(component, methodMap, lexicalArgs, replace) {
@@ -89,7 +89,6 @@ var componentToRsc = function (_options) {
89
89
  var component = _a.component, path = _a.path;
90
90
  if (!(0, nullable_1.checkIsDefined)((_c = (_b = component.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.rsc) === null || _c === void 0 ? void 0 : _c.componentType) &&
91
91
  checkIfIsRsc(component)) {
92
- console.log('comp type is not defined. setting as RSC: ', component.name);
93
92
  component.meta.useMetadata = __assign(__assign({}, component.meta.useMetadata), { rsc: __assign(__assign({}, (_d = component.meta.useMetadata) === null || _d === void 0 ? void 0 : _d.rsc), { componentType: 'server' }) });
94
93
  }
95
94
  var isRSC = ((_f = (_e = component.meta.useMetadata) === null || _e === void 0 ? void 0 : _e.rsc) === null || _f === void 0 ? void 0 : _f.componentType) === 'server';
@@ -125,18 +125,20 @@ var getTagName = function (_a) {
125
125
  }
126
126
  return json.name;
127
127
  };
128
- var stringifyBinding = function (options) {
128
+ var stringifyBinding = function (node, options) {
129
129
  return function (_a) {
130
130
  var key = _a[0], binding = _a[1];
131
131
  if (key === 'innerHTML' || !binding) {
132
132
  return '';
133
133
  }
134
134
  var code = binding.code, _b = binding.arguments, cusArgs = _b === void 0 ? ['event'] : _b, type = binding.type;
135
+ var isValidHtmlTag = html_tags_2.VALID_HTML_TAGS.includes(node.name);
135
136
  if (type === 'spread') {
136
137
  var spreadValue = key === 'props' ? '$$props' : code;
137
138
  return " {...".concat(spreadValue, "} ");
138
139
  }
139
- else if (key.startsWith('on')) {
140
+ else if (key.startsWith('on') && isValidHtmlTag) {
141
+ // handle html native on[event] props
140
142
  var event_1 = key.replace('on', '').toLowerCase();
141
143
  // TODO: handle quotes in event handler values
142
144
  var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
@@ -147,6 +149,16 @@ var stringifyBinding = function (options) {
147
149
  return " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
148
150
  }
149
151
  }
152
+ else if (key.startsWith('on')) {
153
+ // handle on[custom event] props
154
+ var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(code);
155
+ if (valueWithoutBlock === key) {
156
+ return " ".concat(key, "={").concat(valueWithoutBlock, "} ");
157
+ }
158
+ else {
159
+ return " ".concat(key, "={(").concat(cusArgs.join(','), ") => ").concat(valueWithoutBlock, "}");
160
+ }
161
+ }
150
162
  else if (key === 'ref') {
151
163
  return " bind:this={".concat(code, "} ");
152
164
  }
@@ -192,7 +204,9 @@ var blockToSvelte = function (_a) {
192
204
  var value = json.properties[key];
193
205
  str += " ".concat(key, "=\"").concat(value, "\" ");
194
206
  }
195
- var stringifiedBindings = Object.entries(json.bindings).map(stringifyBinding(options)).join('');
207
+ var stringifiedBindings = Object.entries(json.bindings)
208
+ .map(stringifyBinding(json, options))
209
+ .join('');
196
210
  str += stringifiedBindings;
197
211
  // if we have innerHTML, it doesn't matter whether we have closing tags or not, or children or not.
198
212
  // we use the innerHTML content as children and don't render the self-closing tag.
@@ -211,6 +211,7 @@ var SPECIAL_HTML_TAGS = ['style', 'script'];
211
211
  var stringifyBinding = function (node) {
212
212
  return function (_a) {
213
213
  var key = _a[0], value = _a[1];
214
+ var isValidHtmlTag = html_tags_1.VALID_HTML_TAGS.includes(node.name);
214
215
  if (value.type === 'spread') {
215
216
  return ''; // we handle this after
216
217
  }
@@ -222,7 +223,8 @@ var stringifyBinding = function (node) {
222
223
  else {
223
224
  // TODO: proper babel transform to replace. Util for this
224
225
  var useValue = (value === null || value === void 0 ? void 0 : value.code) || '';
225
- if (key.startsWith('on')) {
226
+ if (key.startsWith('on') && isValidHtmlTag) {
227
+ // handle html native on[event] props
226
228
  var _b = value.arguments, cusArgs = _b === void 0 ? ['event'] : _b;
227
229
  var event_1 = key.replace('on', '').toLowerCase();
228
230
  if (event_1 === 'change' && node.name === 'input') {
@@ -237,6 +239,11 @@ var stringifyBinding = function (node) {
237
239
  var eventHandlerKey = "".concat(SPECIAL_PROPERTIES.V_ON_AT).concat(event_1);
238
240
  return "".concat(eventHandlerKey, "=\"").concat(eventHandlerValue, "\"");
239
241
  }
242
+ else if (key.startsWith('on')) {
243
+ // handle on[custom event] props
244
+ var _c = node.bindings[key].arguments, cusArgs = _c === void 0 ? ['event'] : _c;
245
+ return ":".concat(key, "=\"(").concat(cusArgs.join(','), ") => ").concat((0, helpers_1.encodeQuotes)(useValue), "\"");
246
+ }
240
247
  else if (key === 'ref') {
241
248
  return "ref=\"".concat((0, helpers_1.encodeQuotes)(useValue), "\"");
242
249
  }
@@ -0,0 +1,5 @@
1
+ import * as babel from '@babel/core';
2
+ import { MitosisImport } from '../types/mitosis-component';
3
+ declare const types: typeof babel.types;
4
+ export declare const mapImportDeclarationToMitosisImport: (node: babel.types.ImportDeclaration) => MitosisImport;
5
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.mapImportDeclarationToMitosisImport = void 0;
27
+ var babel = __importStar(require("@babel/core"));
28
+ var types = babel.types;
29
+ var mapImportDeclarationToMitosisImport = function (node) {
30
+ var importObject = {
31
+ imports: {},
32
+ path: node.source.value,
33
+ importKind: node.importKind,
34
+ };
35
+ for (var _i = 0, _a = node.specifiers; _i < _a.length; _i++) {
36
+ var specifier = _a[_i];
37
+ if (types.isImportSpecifier(specifier)) {
38
+ importObject.imports[specifier.local.name] = specifier.imported.name;
39
+ }
40
+ else if (types.isImportDefaultSpecifier(specifier)) {
41
+ importObject.imports[specifier.local.name] = 'default';
42
+ }
43
+ else if (types.isImportNamespaceSpecifier(specifier)) {
44
+ importObject.imports[specifier.local.name] = '*';
45
+ }
46
+ }
47
+ return importObject;
48
+ };
49
+ exports.mapImportDeclarationToMitosisImport = mapImportDeclarationToMitosisImport;
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getSignalAccessPlugin = exports.getSignalTypePlugin = exports.replaceSignalSetters = void 0;
7
7
  var core_1 = require("@babel/core");
8
8
  var generator_1 = __importDefault(require("@babel/generator"));
9
- var types_identification_1 = require("../../parsers/jsx/types-identification");
10
9
  var babel_transform_1 = require("../babel-transform");
11
10
  var capitalize_1 = require("../capitalize");
12
11
  var nullable_1 = require("../nullable");
13
12
  var replace_identifiers_1 = require("../replace-identifiers");
13
+ var signals_1 = require("../signals");
14
14
  var process_code_1 = require("./process-code");
15
15
  var replaceSignalSetters = function (_a) {
16
16
  var code = _a.code, nodeMaps = _a.nodeMaps;
@@ -75,7 +75,7 @@ var getSignalTypePlugin = function (_a) {
75
75
  return function (code) {
76
76
  var _a;
77
77
  if ((_a = json.signals) === null || _a === void 0 ? void 0 : _a.signalTypeImportName) {
78
- return (0, types_identification_1.mapSignalType)({
78
+ return (0, signals_1.mapSignalType)({
79
79
  code: code,
80
80
  signalImportName: json.signals.signalTypeImportName,
81
81
  target: target,
@@ -87,7 +87,7 @@ var getSignalTypePlugin = function (_a) {
87
87
  })(json);
88
88
  if ((_a = json.signals) === null || _a === void 0 ? void 0 : _a.signalTypeImportName) {
89
89
  json.imports = json.imports || [];
90
- var signalMappedImport = (0, types_identification_1.getSignalMitosisImportForTarget)(target);
90
+ var signalMappedImport = (0, signals_1.getSignalMitosisImportForTarget)(target);
91
91
  if (signalMappedImport) {
92
92
  json.imports.push(signalMappedImport);
93
93
  }
@@ -175,7 +175,6 @@ var replaceNodes = function (_a) {
175
175
  orig: (0, generator_1.default)(path.node).code,
176
176
  to: (0, generator_1.default)(x).code,
177
177
  });
178
- console.log({ parent: path.parent });
179
178
  // throw err;
180
179
  }
181
180
  }
@@ -0,0 +1 @@
1
+ export * from './signals';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./signals"), exports);
@@ -1,5 +1,9 @@
1
- import { Project, Symbol } from 'ts-morph';
1
+ import { types } from '@babel/core';
2
2
  import { Target } from '../../types/config';
3
+ export declare const getSignalMappingForTarget: (target: Target) => {
4
+ getTypeReference: (generics?: types.TSType[]) => types.TSTypeReference;
5
+ importDeclaration: types.ImportDeclaration;
6
+ } | undefined;
3
7
  export declare const getSignalMitosisImportForTarget: (target: Target) => import("../..").MitosisImport | undefined;
4
8
  export declare const getSignalImportName: (code: string) => string | undefined;
5
9
  /**
@@ -13,25 +17,11 @@ export declare const mapSignalType: ({ code, target, signalImportName, }: {
13
17
  }) => string;
14
18
  /**
15
19
  * Processes the `Signal` type usage in a plain TS file:
16
- * - Finds the Signal import name
17
- * - Maps the Signal type to the target's equivalent
18
- * - Adds the equivalent of the Signal import to the file
20
+ * - Finds the `Signal` import name
21
+ * - Maps the `Signal` type to the target's equivalent
22
+ * - Adds the equivalent of the `Signal` import to the file
19
23
  */
20
24
  export declare const mapSignalTypeInTSFile: ({ code, target }: {
21
25
  code: string;
22
26
  target: Target;
23
27
  }) => string;
24
- export declare const createTypescriptProject: (tsConfigFilePath: string) => {
25
- project: Project;
26
- signalSymbol: Symbol;
27
- };
28
- export declare const findSignals: (args: {
29
- project: Project;
30
- signalSymbol: Symbol;
31
- code?: string | undefined;
32
- filePath?: string | undefined;
33
- }) => {
34
- props: Set<string>;
35
- state: Set<string>;
36
- context: Set<string>;
37
- };
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapSignalTypeInTSFile = exports.mapSignalType = exports.getSignalImportName = exports.getSignalMitosisImportForTarget = exports.getSignalMappingForTarget = void 0;
4
+ var core_1 = require("@babel/core");
5
+ var function_1 = require("fp-ts/lib/function");
6
+ var babel_transform_1 = require("../../helpers/babel-transform");
7
+ var mitosis_imports_1 = require("../mitosis-imports");
8
+ var getSignalMappingForTarget = function (target) {
9
+ switch (target) {
10
+ case 'svelte':
11
+ var 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
+ importDeclaration.importKind = 'type';
13
+ return {
14
+ getTypeReference: function (generics) {
15
+ if (generics === void 0) { generics = []; }
16
+ return core_1.types.tsTypeReference(core_1.types.identifier('Writable'), core_1.types.tsTypeParameterInstantiation(generics));
17
+ },
18
+ importDeclaration: importDeclaration,
19
+ };
20
+ default:
21
+ return undefined;
22
+ }
23
+ };
24
+ exports.getSignalMappingForTarget = getSignalMappingForTarget;
25
+ var getSignalMitosisImportForTarget = function (target) {
26
+ var signalType = (0, exports.getSignalMappingForTarget)(target);
27
+ if (!signalType) {
28
+ return undefined;
29
+ }
30
+ return (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(signalType.importDeclaration);
31
+ };
32
+ exports.getSignalMitosisImportForTarget = getSignalMitosisImportForTarget;
33
+ var getSignalImportName = function (code) {
34
+ var foundSignalUsage = false;
35
+ var signalImportName = undefined;
36
+ (0, babel_transform_1.babelTransformExpression)(code, {
37
+ ImportSpecifier: function (path) {
38
+ if (core_1.types.isIdentifier(path.node.imported) && path.node.imported.name === 'Signal') {
39
+ if (path.parentPath.isImportDeclaration() &&
40
+ path.parentPath.node.source.value === '@builder.io/mitosis') {
41
+ /**
42
+ * in case the import is aliased, we need to use the local name,
43
+ * e.g. `import { Signal as MySignal } from '@builder.io/mitosis'`
44
+ */
45
+ signalImportName = path.node.local.name;
46
+ path.stop();
47
+ }
48
+ }
49
+ },
50
+ });
51
+ if (!signalImportName) {
52
+ return undefined;
53
+ }
54
+ (0, babel_transform_1.babelTransformExpression)(code, {
55
+ TSTypeReference: function (path) {
56
+ if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
57
+ foundSignalUsage = true;
58
+ path.stop();
59
+ }
60
+ },
61
+ });
62
+ return foundSignalUsage ? signalImportName : undefined;
63
+ };
64
+ exports.getSignalImportName = getSignalImportName;
65
+ var addSignalImport = function (_a) {
66
+ var code = _a.code, target = _a.target;
67
+ var signalType = (0, exports.getSignalMappingForTarget)(target);
68
+ if (!signalType) {
69
+ return code;
70
+ }
71
+ return (0, babel_transform_1.babelTransformExpression)(code, {
72
+ Program: function (path) {
73
+ path.node.body.unshift(signalType.importDeclaration);
74
+ },
75
+ });
76
+ };
77
+ /**
78
+ * Finds all `Signal` types and replaces them with the correct type for the given target.
79
+ * e.g. `Signal<string>` becomes `Writable<string>` for Svelte.
80
+ */
81
+ var mapSignalType = function (_a) {
82
+ var code = _a.code, target = _a.target, _b = _a.signalImportName, signalImportName = _b === void 0 ? (0, exports.getSignalImportName)(code) : _b;
83
+ var signalType = (0, exports.getSignalMappingForTarget)(target);
84
+ return (0, babel_transform_1.babelTransformExpression)(code, {
85
+ TSTypeReference: function (path) {
86
+ var _a;
87
+ if (core_1.types.isIdentifier(path.node.typeName) && path.node.typeName.name === signalImportName) {
88
+ var params = ((_a = path.node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) || [];
89
+ var newType = (signalType === null || signalType === void 0 ? void 0 : signalType.getTypeReference)
90
+ ? signalType.getTypeReference(params)
91
+ : // if no mapping exists, drop `Signal` and just use the generic type passed to `Signal` as-is.
92
+ params[0];
93
+ path.replaceWith(newType);
94
+ }
95
+ },
96
+ });
97
+ };
98
+ exports.mapSignalType = mapSignalType;
99
+ /**
100
+ * Processes the `Signal` type usage in a plain TS file:
101
+ * - Finds the `Signal` import name
102
+ * - Maps the `Signal` type to the target's equivalent
103
+ * - Adds the equivalent of the `Signal` import to the file
104
+ */
105
+ var mapSignalTypeInTSFile = function (_a) {
106
+ var code = _a.code, target = _a.target;
107
+ var signalImportName = (0, exports.getSignalImportName)(code);
108
+ if (!signalImportName) {
109
+ return code;
110
+ }
111
+ return (0, function_1.pipe)((0, exports.mapSignalType)({ target: target, code: code, signalImportName: signalImportName }), function (code) {
112
+ return addSignalImport({ code: code, target: target });
113
+ });
114
+ };
115
+ exports.mapSignalTypeInTSFile = mapSignalTypeInTSFile;
@@ -0,0 +1,8 @@
1
+ import { Project, SourceFile, Symbol } from 'ts-morph';
2
+ export declare const removeMitosisImport: (code: string) => string;
3
+ export declare const getPropsSymbol: (ast: SourceFile) => Symbol | undefined;
4
+ export declare const getContextSymbols: (ast: SourceFile) => Set<Symbol>;
5
+ export declare const createTypescriptProject: (tsConfigFilePath: string) => {
6
+ project: Project;
7
+ signalSymbol: Symbol;
8
+ };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTypescriptProject = exports.getContextSymbols = exports.getPropsSymbol = exports.removeMitosisImport = void 0;
4
+ var ts_morph_1 = require("ts-morph");
5
+ var babel_transform_1 = require("./babel-transform");
6
+ var removeMitosisImport = function (code) {
7
+ return (0, babel_transform_1.babelTransformExpression)(code, {
8
+ ImportDeclaration: function (path) {
9
+ if (path.node.source.value === '@builder.io/mitosis') {
10
+ path.remove();
11
+ }
12
+ },
13
+ });
14
+ };
15
+ exports.removeMitosisImport = removeMitosisImport;
16
+ var getPropsSymbol = function (ast) {
17
+ var propsSymbol = undefined;
18
+ ast.forEachChild(function (node) {
19
+ var _a;
20
+ if (propsSymbol !== undefined)
21
+ return;
22
+ if (ts_morph_1.Node.isArrowFunction(node) || ts_morph_1.Node.isFunctionDeclaration(node)) {
23
+ if (node.hasModifier(ts_morph_1.SyntaxKind.ExportKeyword) &&
24
+ node.hasModifier(ts_morph_1.SyntaxKind.DefaultKeyword)) {
25
+ propsSymbol = (_a = node.getParameters()[0]) === null || _a === void 0 ? void 0 : _a.getSymbol();
26
+ }
27
+ }
28
+ });
29
+ return propsSymbol;
30
+ };
31
+ exports.getPropsSymbol = getPropsSymbol;
32
+ var getContextSymbols = function (ast) {
33
+ var contextSymbols = new Set();
34
+ ast.forEachDescendant(function (node) {
35
+ if (!ts_morph_1.Node.isVariableDeclaration(node))
36
+ return;
37
+ var initializer = node.getInitializer();
38
+ if (!ts_morph_1.Node.isCallExpression(initializer))
39
+ return;
40
+ if (initializer.getExpression().getText() !== 'useContext')
41
+ return;
42
+ var contextSymbol = node.getNameNode().getSymbol();
43
+ if (contextSymbol === undefined)
44
+ return;
45
+ contextSymbols.add(contextSymbol);
46
+ });
47
+ return contextSymbols;
48
+ };
49
+ exports.getContextSymbols = getContextSymbols;
50
+ var getSignalSymbol = function (project) {
51
+ var symbolExport = project.createSourceFile('homepage3.lite.tsx', "import { Signal } from '@builder.io/mitosis';");
52
+ // Find the original Signal symbol
53
+ var signalSymbol = undefined;
54
+ symbolExport.forEachDescendant(function (node) {
55
+ var _a;
56
+ if (ts_morph_1.Node.isImportSpecifier(node)) {
57
+ signalSymbol = (_a = node.getSymbol()) === null || _a === void 0 ? void 0 : _a.getAliasedSymbol();
58
+ }
59
+ });
60
+ if (signalSymbol === undefined) {
61
+ throw new Error('Could not find the Mitosis Signal symbol in your TS project. Is `@builder.io/mitosis` installed correctly?');
62
+ }
63
+ return signalSymbol;
64
+ };
65
+ var getProject = function (tsConfigFilePath) {
66
+ try {
67
+ return new ts_morph_1.Project({ tsConfigFilePath: tsConfigFilePath });
68
+ }
69
+ catch (err) {
70
+ throw new Error('Error creating Typescript Project. Make sure `tsConfigFilePath` points to a valid tsconfig.json file');
71
+ }
72
+ };
73
+ var createTypescriptProject = function (tsConfigFilePath) {
74
+ var project = getProject(tsConfigFilePath);
75
+ var signalSymbol = getSignalSymbol(project);
76
+ return { project: project, signalSymbol: signalSymbol };
77
+ };
78
+ exports.createTypescriptProject = createTypescriptProject;
@@ -29,6 +29,8 @@ export * from './generators/taro';
29
29
  export * from './generators/template';
30
30
  export * from './generators/vue';
31
31
  export * from './helpers/is-mitosis-node';
32
+ export * from './helpers/signals';
33
+ export * from './helpers/typescript-project';
32
34
  export * from './parsers/angular';
33
35
  export * from './parsers/builder';
34
36
  export * from './parsers/context';
package/dist/src/index.js CHANGED
@@ -41,6 +41,8 @@ __exportStar(require("./generators/taro"), exports);
41
41
  __exportStar(require("./generators/template"), exports);
42
42
  __exportStar(require("./generators/vue"), exports);
43
43
  __exportStar(require("./helpers/is-mitosis-node"), exports);
44
+ __exportStar(require("./helpers/signals"), exports);
45
+ __exportStar(require("./helpers/typescript-project"), exports);
44
46
  __exportStar(require("./parsers/angular"), exports);
45
47
  __exportStar(require("./parsers/builder"), exports);
46
48
  __exportStar(require("./parsers/context"), exports);
@@ -79,6 +79,7 @@ var getUseTargetStatements = function (path) {
79
79
  if (!Object.keys(targets_1.targets).concat('default').includes(prop.key.name)) {
80
80
  throw new Error('ERROR Parsing `useTarget()`: Invalid target: ' + prop.key.name);
81
81
  }
82
+ var keyName = prop.key.name;
82
83
  var targetCode = prop.value;
83
84
  if (isInlinedCodeInsideFunctionBody) {
84
85
  if (!(types.isArrowFunctionExpression(targetCode) || types.isFunctionExpression(targetCode)))
@@ -86,12 +87,15 @@ var getUseTargetStatements = function (path) {
86
87
  var body = targetCode.body;
87
88
  if (types.isBlockStatement(body)) {
88
89
  var code_1 = '';
89
- body.body.map(function (statement) {
90
+ body.body.forEach(function (statement) {
90
91
  code_1 += (0, generator_1.default)(statement).code + '\n';
91
92
  });
93
+ targetBlock[keyName] = {
94
+ code: code_1,
95
+ };
92
96
  }
93
97
  else {
94
- targetBlock[prop.key.name] = {
98
+ targetBlock[keyName] = {
95
99
  code: (0, generator_1.default)(body).code,
96
100
  };
97
101
  }
@@ -99,7 +103,7 @@ var getUseTargetStatements = function (path) {
99
103
  else {
100
104
  if (!types.isExpression(targetCode))
101
105
  return undefined;
102
- targetBlock[prop.key.name] = {
106
+ targetBlock[keyName] = {
103
107
  code: (0, generator_1.default)(targetCode).code,
104
108
  };
105
109
  }
@@ -1,8 +1,6 @@
1
1
  import * as babel from '@babel/core';
2
- import { MitosisImport } from '../../types/mitosis-component';
3
2
  import { Context, ParseMitosisOptions } from './types';
4
3
  declare const types: typeof babel.types;
5
- export declare const mapImportDeclarationToMitosisImport: (node: babel.types.ImportDeclaration) => MitosisImport;
6
4
  export declare const handleImportDeclaration: ({ options, path, context, }: {
7
5
  options: Partial<ParseMitosisOptions>;
8
6
  path: babel.NodePath<babel.types.ImportDeclaration>;
@@ -32,30 +32,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
32
32
  return to.concat(ar || Array.prototype.slice.call(from));
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.handleImportDeclaration = exports.mapImportDeclarationToMitosisImport = void 0;
35
+ exports.handleImportDeclaration = void 0;
36
36
  var babel = __importStar(require("@babel/core"));
37
+ var mitosis_imports_1 = require("../../helpers/mitosis-imports");
37
38
  var types = babel.types;
38
- var mapImportDeclarationToMitosisImport = function (node) {
39
- var importObject = {
40
- imports: {},
41
- path: node.source.value,
42
- importKind: node.importKind,
43
- };
44
- for (var _i = 0, _a = node.specifiers; _i < _a.length; _i++) {
45
- var specifier = _a[_i];
46
- if (types.isImportSpecifier(specifier)) {
47
- importObject.imports[specifier.local.name] = specifier.imported.name;
48
- }
49
- else if (types.isImportDefaultSpecifier(specifier)) {
50
- importObject.imports[specifier.local.name] = 'default';
51
- }
52
- else if (types.isImportNamespaceSpecifier(specifier)) {
53
- importObject.imports[specifier.local.name] = '*';
54
- }
55
- }
56
- return importObject;
57
- };
58
- exports.mapImportDeclarationToMitosisImport = mapImportDeclarationToMitosisImport;
59
39
  var handleImportDeclaration = function (_a) {
60
40
  var options = _a.options, path = _a.path, context = _a.context;
61
41
  // @builder.io/mitosis or React imports compile away
@@ -64,7 +44,7 @@ var handleImportDeclaration = function (_a) {
64
44
  path.remove();
65
45
  return;
66
46
  }
67
- var importObject = (0, exports.mapImportDeclarationToMitosisImport)(path.node);
47
+ var importObject = (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(path.node);
68
48
  context.builder.component.imports.push(importObject);
69
49
  path.remove();
70
50
  };
@@ -1,2 +1 @@
1
1
  export { parseJsx } from './jsx';
2
- export { createTypescriptProject, mapSignalTypeInTSFile } from './types-identification';
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapSignalTypeInTSFile = exports.createTypescriptProject = exports.parseJsx = void 0;
3
+ exports.parseJsx = void 0;
4
4
  var jsx_1 = require("./jsx");
5
5
  Object.defineProperty(exports, "parseJsx", { enumerable: true, get: function () { return jsx_1.parseJsx; } });
6
- var types_identification_1 = require("./types-identification");
7
- Object.defineProperty(exports, "createTypescriptProject", { enumerable: true, get: function () { return types_identification_1.createTypescriptProject; } });
8
- Object.defineProperty(exports, "mapSignalTypeInTSFile", { enumerable: true, get: function () { return types_identification_1.mapSignalTypeInTSFile; } });
@@ -47,6 +47,7 @@ var hooks_1 = require("../../constants/hooks");
47
47
  var create_mitosis_component_1 = require("../../helpers/create-mitosis-component");
48
48
  var json_1 = require("../../helpers/json");
49
49
  var replace_new_lines_in_strings_1 = require("../../helpers/replace-new-lines-in-strings");
50
+ var signals_1 = require("../../helpers/signals");
50
51
  var ast_1 = require("./ast");
51
52
  var component_types_1 = require("./component-types");
52
53
  var context_1 = require("./context");
@@ -58,8 +59,8 @@ var hooks_2 = require("./hooks");
58
59
  var use_target_1 = require("./hooks/use-target");
59
60
  var imports_1 = require("./imports");
60
61
  var props_1 = require("./props");
62
+ var signals_2 = require("./signals");
61
63
  var state_1 = require("./state");
62
- var types_identification_1 = require("./types-identification");
63
64
  var types = babel.types;
64
65
  var typescriptBabelPreset = [preset_typescript_1.default, { isTSX: true, allExtensions: true }];
65
66
  var beforeParse = function (path) {
@@ -197,12 +198,12 @@ function parseJsx(jsx, _options) {
197
198
  (0, state_1.mapStateIdentifiers)(mitosisComponent);
198
199
  (0, context_1.extractContextComponents)(mitosisComponent);
199
200
  mitosisComponent.subComponents = subComponentFunctions.map(function (item) { return parseJsx(item, options); });
200
- var signalTypeImportName = (0, types_identification_1.getSignalImportName)(jsxToUse);
201
+ var signalTypeImportName = (0, signals_1.getSignalImportName)(jsxToUse);
201
202
  if (signalTypeImportName) {
202
203
  mitosisComponent.signals = { signalTypeImportName: signalTypeImportName };
203
204
  }
204
205
  if (options.tsProject && options.filePath) {
205
- var reactiveValues = (0, types_identification_1.findSignals)({
206
+ var reactiveValues = (0, signals_2.findSignals)({
206
207
  filePath: options.filePath,
207
208
  project: options.tsProject.project,
208
209
  signalSymbol: options.tsProject.signalSymbol,
@@ -0,0 +1,11 @@
1
+ import { Project, Symbol } from 'ts-morph';
2
+ export declare const findSignals: (args: {
3
+ project: Project;
4
+ signalSymbol: Symbol;
5
+ code?: string | undefined;
6
+ filePath?: string | undefined;
7
+ }) => {
8
+ props: Set<string>;
9
+ state: Set<string>;
10
+ context: Set<string>;
11
+ };