@builder.io/mitosis 0.0.56-99 → 0.0.58

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.
Files changed (254) hide show
  1. package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +4 -1
  2. package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
  3. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +5 -1
  4. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +3 -3
  5. package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
  6. package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
  7. package/dist/src/__tests__/shared.d.ts +7 -2
  8. package/dist/src/__tests__/shared.js +66 -9
  9. package/dist/src/constants/method-literal-prefix.d.ts +0 -1
  10. package/dist/src/constants/method-literal-prefix.js +0 -3
  11. package/dist/src/generators/angular.d.ts +2 -2
  12. package/dist/src/generators/angular.js +14 -6
  13. package/dist/src/generators/builder.d.ts +4 -11
  14. package/dist/src/generators/builder.js +3 -2
  15. package/dist/src/generators/context/qwik.js +1 -1
  16. package/dist/src/generators/context/svelte.d.ts +3 -0
  17. package/dist/src/generators/context/svelte.js +3 -0
  18. package/dist/src/generators/helpers/functions.d.ts +2 -0
  19. package/dist/src/generators/helpers/functions.js +28 -0
  20. package/dist/src/generators/html.d.ts +3 -3
  21. package/dist/src/generators/html.js +9 -7
  22. package/dist/src/generators/liquid.d.ts +2 -2
  23. package/dist/src/generators/liquid.js +4 -4
  24. package/dist/src/generators/lit/generate.d.ts +2 -2
  25. package/dist/src/generators/lit/generate.js +3 -2
  26. package/dist/src/generators/marko/generate.d.ts +2 -2
  27. package/dist/src/generators/marko/generate.js +10 -8
  28. package/dist/src/generators/mitosis.d.ts +3 -4
  29. package/dist/src/generators/mitosis.js +3 -2
  30. package/dist/src/generators/qwik/component-generator.d.ts +2 -2
  31. package/dist/src/generators/qwik/component-generator.js +68 -64
  32. package/dist/src/generators/qwik/component.d.ts +0 -1
  33. package/dist/src/generators/qwik/component.js +22 -19
  34. package/dist/src/generators/qwik/directives.d.ts +1 -0
  35. package/dist/src/generators/qwik/directives.js +11 -14
  36. package/dist/src/generators/qwik/jsx.d.ts +1 -1
  37. package/dist/src/generators/qwik/jsx.js +9 -5
  38. package/dist/src/generators/qwik/src-generator.js +11 -3
  39. package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
  40. package/dist/src/generators/qwik/stable-serialize.js +51 -0
  41. package/dist/src/generators/react/generator.d.ts +6 -0
  42. package/dist/src/generators/{react.js → react/generator.js} +58 -150
  43. package/dist/src/generators/react/helpers.d.ts +2 -0
  44. package/dist/src/generators/react/helpers.js +14 -0
  45. package/dist/src/generators/react/index.d.ts +2 -0
  46. package/dist/src/generators/react/index.js +18 -0
  47. package/dist/src/generators/react/state.d.ts +9 -0
  48. package/dist/src/generators/react/state.js +107 -0
  49. package/dist/src/generators/react/types.d.ts +10 -0
  50. package/dist/src/{types/string-map.js → generators/react/types.js} +0 -0
  51. package/dist/src/generators/react-native.d.ts +2 -2
  52. package/dist/src/generators/solid/index.d.ts +3 -0
  53. package/dist/src/generators/{solid.js → solid/index.js} +80 -40
  54. package/dist/src/generators/solid/state.d.ts +19 -0
  55. package/dist/src/generators/solid/state.js +144 -0
  56. package/dist/src/generators/solid/types.d.ts +6 -0
  57. package/dist/src/generators/solid/types.js +2 -0
  58. package/dist/src/generators/stencil/generate.d.ts +2 -2
  59. package/dist/src/generators/stencil/generate.js +5 -2
  60. package/dist/src/generators/svelte.d.ts +6 -7
  61. package/dist/src/generators/svelte.js +43 -40
  62. package/dist/src/generators/swift-ui.d.ts +3 -5
  63. package/dist/src/generators/swift-ui.js +3 -2
  64. package/dist/src/generators/template.d.ts +2 -2
  65. package/dist/src/generators/template.js +3 -2
  66. package/dist/src/generators/vue.d.ts +5 -3
  67. package/dist/src/generators/vue.js +256 -113
  68. package/dist/src/helpers/babel-transform.d.ts +3 -1
  69. package/dist/src/helpers/babel-transform.js +52 -56
  70. package/dist/src/helpers/get-bindings.js +3 -5
  71. package/dist/src/helpers/get-props.js +14 -1
  72. package/dist/src/helpers/get-state-object-string.js +24 -21
  73. package/dist/src/helpers/getters-to-functions.js +1 -11
  74. package/dist/src/helpers/map-refs.js +25 -25
  75. package/dist/src/helpers/nodes/for.d.ts +4 -0
  76. package/dist/src/helpers/nodes/for.js +13 -0
  77. package/dist/src/helpers/nullable.d.ts +2 -0
  78. package/dist/src/helpers/nullable.js +7 -0
  79. package/dist/src/helpers/patterns.d.ts +2 -0
  80. package/dist/src/helpers/patterns.js +5 -1
  81. package/dist/src/helpers/render-imports.js +3 -3
  82. package/dist/src/helpers/replace-identifiers.d.ts +5 -0
  83. package/dist/src/helpers/{replace-idenifiers.js → replace-identifiers.js} +2 -1
  84. package/dist/src/helpers/slots.d.ts +2 -0
  85. package/dist/src/helpers/slots.js +15 -1
  86. package/dist/src/helpers/state.d.ts +0 -2
  87. package/dist/src/helpers/state.js +1 -10
  88. package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -1
  89. package/dist/src/helpers/strip-state-and-props-refs.js +43 -31
  90. package/dist/src/helpers/styles/helpers.d.ts +3 -2
  91. package/dist/src/index.d.ts +0 -2
  92. package/dist/src/index.js +0 -2
  93. package/dist/src/parsers/angular.js +2 -2
  94. package/dist/src/parsers/builder.d.ts +2 -2
  95. package/dist/src/parsers/builder.js +61 -43
  96. package/dist/src/parsers/constants/outdated-prefixes.d.ts +10 -0
  97. package/dist/src/parsers/constants/outdated-prefixes.js +13 -0
  98. package/dist/src/parsers/context.js +2 -2
  99. package/dist/src/parsers/helpers/state.d.ts +3 -0
  100. package/dist/src/parsers/helpers/state.js +30 -0
  101. package/dist/src/parsers/jsx/component-types.d.ts +1 -1
  102. package/dist/src/parsers/jsx/component-types.js +15 -2
  103. package/dist/src/parsers/jsx/context.js +1 -1
  104. package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
  105. package/dist/src/parsers/jsx/element-parser.js +243 -0
  106. package/dist/src/parsers/jsx/exports.d.ts +3 -0
  107. package/dist/src/parsers/jsx/exports.js +78 -0
  108. package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
  109. package/dist/src/parsers/jsx/function-parser.js +291 -0
  110. package/dist/src/parsers/jsx/helpers.d.ts +2 -0
  111. package/dist/src/parsers/jsx/helpers.js +30 -1
  112. package/dist/src/parsers/jsx/imports.d.ts +7 -0
  113. package/dist/src/parsers/jsx/imports.js +65 -0
  114. package/dist/src/parsers/jsx/index.d.ts +1 -1
  115. package/dist/src/parsers/jsx/index.js +1 -2
  116. package/dist/src/parsers/jsx/jsx.js +29 -516
  117. package/dist/src/parsers/jsx/state.d.ts +2 -3
  118. package/dist/src/parsers/jsx/state.js +15 -22
  119. package/dist/src/plugins/compile-away-builder-components.js +6 -0
  120. package/dist/src/symbols/symbol-processor.js +3 -0
  121. package/dist/src/targets.d.ts +21 -28
  122. package/dist/src/targets.js +2 -2
  123. package/dist/src/types/config.d.ts +11 -1
  124. package/dist/src/types/mitosis-component.d.ts +12 -6
  125. package/dist/src/types/mitosis-component.js +11 -0
  126. package/dist/src/types/mitosis-context.d.ts +2 -2
  127. package/dist/src/types/mitosis-node.d.ts +14 -5
  128. package/dist/src/types/mitosis-node.js +3 -0
  129. package/dist/src/types/transpiler.d.ts +6 -1
  130. package/dist/tsconfig.build.tsbuildinfo +1 -1
  131. package/package.json +9 -9
  132. package/dist/src/__tests__/angular.test.d.ts +0 -1
  133. package/dist/src/__tests__/angular.test.js +0 -10
  134. package/dist/src/__tests__/builder.test.d.ts +0 -1
  135. package/dist/src/__tests__/builder.test.js +0 -235
  136. package/dist/src/__tests__/context.test.d.ts +0 -1
  137. package/dist/src/__tests__/context.test.js +0 -35
  138. package/dist/src/__tests__/hash-code.test.d.ts +0 -1
  139. package/dist/src/__tests__/hash-code.test.js +0 -11
  140. package/dist/src/__tests__/html.test.d.ts +0 -1
  141. package/dist/src/__tests__/html.test.js +0 -7
  142. package/dist/src/__tests__/liquid.test.d.ts +0 -1
  143. package/dist/src/__tests__/liquid.test.js +0 -7
  144. package/dist/src/__tests__/lit.test.d.ts +0 -1
  145. package/dist/src/__tests__/lit.test.js +0 -7
  146. package/dist/src/__tests__/marko.test.d.ts +0 -1
  147. package/dist/src/__tests__/marko.test.js +0 -14
  148. package/dist/src/__tests__/parse-jsx.test.d.ts +0 -1
  149. package/dist/src/__tests__/parse-jsx.test.js +0 -37
  150. package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +0 -1
  151. package/dist/src/__tests__/qwik/convert-method-to-function.test.js +0 -37
  152. package/dist/src/__tests__/qwik/src-generator.test.d.ts +0 -1
  153. package/dist/src/__tests__/qwik/src-generator.test.js +0 -65
  154. package/dist/src/__tests__/qwik.directive.test.d.ts +0 -1
  155. package/dist/src/__tests__/qwik.directive.test.js +0 -108
  156. package/dist/src/__tests__/qwik.test.d.ts +0 -1
  157. package/dist/src/__tests__/qwik.test.js +0 -465
  158. package/dist/src/__tests__/react-native.test.d.ts +0 -1
  159. package/dist/src/__tests__/react-native.test.js +0 -7
  160. package/dist/src/__tests__/react.test.d.ts +0 -1
  161. package/dist/src/__tests__/react.test.js +0 -20
  162. package/dist/src/__tests__/solid.test.d.ts +0 -1
  163. package/dist/src/__tests__/solid.test.js +0 -10
  164. package/dist/src/__tests__/stencil.test.d.ts +0 -1
  165. package/dist/src/__tests__/stencil.test.js +0 -7
  166. package/dist/src/__tests__/styles.test.d.ts +0 -1
  167. package/dist/src/__tests__/styles.test.js +0 -23
  168. package/dist/src/__tests__/svelte.test.d.ts +0 -1
  169. package/dist/src/__tests__/svelte.test.js +0 -7
  170. package/dist/src/__tests__/vue.test.d.ts +0 -1
  171. package/dist/src/__tests__/vue.test.js +0 -7
  172. package/dist/src/__tests__/webcomponent.test.d.ts +0 -1
  173. package/dist/src/__tests__/webcomponent.test.js +0 -15
  174. package/dist/src/constants/function-literal-prefix.d.ts +0 -1
  175. package/dist/src/constants/function-literal-prefix.js +0 -4
  176. package/dist/src/generators/react.d.ts +0 -14
  177. package/dist/src/generators/solid.d.ts +0 -5
  178. package/dist/src/helpers/babel-transform.test.d.ts +0 -1
  179. package/dist/src/helpers/babel-transform.test.js +0 -7
  180. package/dist/src/helpers/generic-format.test.d.ts +0 -1
  181. package/dist/src/helpers/generic-format.test.js +0 -8
  182. package/dist/src/helpers/map-to-attributes.d.ts +0 -2
  183. package/dist/src/helpers/map-to-attributes.js +0 -19
  184. package/dist/src/helpers/map-to-css.d.ts +0 -2
  185. package/dist/src/helpers/map-to-css.js +0 -16
  186. package/dist/src/helpers/parse-reactive-script.d.ts +0 -7
  187. package/dist/src/helpers/parse-reactive-script.js +0 -87
  188. package/dist/src/helpers/remove-surrounding-block.test.d.ts +0 -1
  189. package/dist/src/helpers/remove-surrounding-block.test.js +0 -9
  190. package/dist/src/helpers/render-imports.test.d.ts +0 -1
  191. package/dist/src/helpers/render-imports.test.js +0 -33
  192. package/dist/src/helpers/replace-idenifiers.d.ts +0 -1
  193. package/dist/src/helpers/styles/collect-css.test.d.ts +0 -1
  194. package/dist/src/helpers/styles/collect-css.test.js +0 -18
  195. package/dist/src/parsers/html.d.ts +0 -0
  196. package/dist/src/parsers/html.js +0 -2
  197. package/dist/src/parsers/liquid.d.ts +0 -70
  198. package/dist/src/parsers/liquid.js +0 -2538
  199. package/dist/src/types/string-map.d.ts +0 -3
  200. package/dist/test/qwik/Accordion/high.jsx +0 -0
  201. package/dist/test/qwik/Accordion/low.jsx +0 -240
  202. package/dist/test/qwik/Accordion/med.jsx +0 -4
  203. package/dist/test/qwik/For/high.jsx +0 -0
  204. package/dist/test/qwik/For/low.jsx +0 -52
  205. package/dist/test/qwik/For/med.jsx +0 -4
  206. package/dist/test/qwik/Image/high.js +0 -9
  207. package/dist/test/qwik/Image/low.js +0 -0
  208. package/dist/test/qwik/Image/med.js +0 -155
  209. package/dist/test/qwik/Image.slow/high.js +0 -9
  210. package/dist/test/qwik/Image.slow/low.js +0 -0
  211. package/dist/test/qwik/Image.slow/med.js +0 -155
  212. package/dist/test/qwik/bindings/high.cjs +0 -0
  213. package/dist/test/qwik/bindings/low.cjs +0 -45
  214. package/dist/test/qwik/bindings/med.cjs +0 -3
  215. package/dist/test/qwik/button/high.js +0 -3
  216. package/dist/test/qwik/button/low.js +0 -25
  217. package/dist/test/qwik/button/med.js +0 -31
  218. package/dist/test/qwik/component/bindings/high.jsx +0 -0
  219. package/dist/test/qwik/component/bindings/low.jsx +0 -104
  220. package/dist/test/qwik/component/bindings/med.jsx +0 -7
  221. package/dist/test/qwik/component/component/inputs/high.cjsx +0 -9
  222. package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
  223. package/dist/test/qwik/component/component/inputs/med.cjsx +0 -68
  224. package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
  225. package/dist/test/qwik/for-loop.bindings/low.cjs +0 -56
  226. package/dist/test/qwik/for-loop.bindings/med.cjs +0 -5
  227. package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -0
  228. package/dist/test/qwik/hello_world/stylesheet/low.jsx +0 -26
  229. package/dist/test/qwik/hello_world/stylesheet/med.jsx +0 -4
  230. package/dist/test/qwik/mount/high.cjs +0 -0
  231. package/dist/test/qwik/mount/low.cjs +0 -47
  232. package/dist/test/qwik/mount/med.cjs +0 -3
  233. package/dist/test/qwik/page-with-symbol/high.js +0 -0
  234. package/dist/test/qwik/page-with-symbol/low.js +0 -33
  235. package/dist/test/qwik/page-with-symbol/med.js +0 -4
  236. package/dist/test/qwik/show-hide/high.jsx +0 -9
  237. package/dist/test/qwik/show-hide/low.jsx +0 -0
  238. package/dist/test/qwik/show-hide/med.jsx +0 -181
  239. package/dist/test/qwik/svg/high.js +0 -0
  240. package/dist/test/qwik/svg/low.js +0 -30
  241. package/dist/test/qwik/svg/med.js +0 -4
  242. package/dist/test/qwik/todo/Todo.cjs/high.cjs +0 -19
  243. package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -0
  244. package/dist/test/qwik/todo/Todo.cjs/med.cjs +0 -51
  245. package/dist/test/qwik/todo/Todo.js/high.js +0 -19
  246. package/dist/test/qwik/todo/Todo.js/low.js +0 -0
  247. package/dist/test/qwik/todo/Todo.js/med.js +0 -47
  248. package/dist/test/qwik/todo/Todo.tsx/high.tsx +0 -19
  249. package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -0
  250. package/dist/test/qwik/todo/Todo.tsx/med.tsx +0 -43
  251. package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -7
  252. package/dist/test/qwik/todos/Todo.tsx/low.tsx +0 -32
  253. package/dist/test/qwik/todos/Todo.tsx/med.tsx +0 -4
  254. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -34,10 +34,43 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.babelTransformExpression = exports.babelTransformCode = exports.babelTransform = void 0;
36
36
  var babel = __importStar(require("@babel/core"));
37
- var lodash_1 = require("lodash");
38
37
  var jsxPlugin = require('@babel/plugin-syntax-jsx');
39
38
  var tsPreset = require('@babel/preset-typescript');
40
39
  var decorators = require('@babel/plugin-syntax-decorators');
40
+ var function_1 = require("fp-ts/lib/function");
41
+ var handleErrorOrExpression = function (_a) {
42
+ var code = _a.code, useCode = _a.useCode, result = _a.result, visitor = _a.visitor;
43
+ try {
44
+ // If it can't, e.g. this is an expression or code fragment, modify the code below and try again
45
+ // Detect method fragments. These get passed sometimes and otherwise
46
+ // generate compile errors. They are of the form `foo() { ... }`
47
+ var isMethod = Boolean(!code.startsWith('function') && code.match(/^[a-z0-9_]+\s*\([^\)]*\)\s*[\{:]/i));
48
+ if (isMethod) {
49
+ useCode = "function ".concat(useCode);
50
+ }
51
+ // Parse the code as an expression (instead of the default, a block) by giving it a fake variable assignment
52
+ // e.g. if the code parsed is { ... } babel will treat that as a block by deafult, unless processed as an expression
53
+ // that is an object
54
+ useCode = "let _ = ".concat(useCode);
55
+ result = (0, function_1.pipe)((0, exports.babelTransformCode)(useCode, visitor), trimSemicolons, function (str) {
56
+ // Remove our fake variable assignment
57
+ return str.replace(/let _ =\s/, '');
58
+ });
59
+ if (isMethod) {
60
+ return result.replace('function', '');
61
+ }
62
+ return result;
63
+ }
64
+ catch (err) {
65
+ console.error('Error parsing code:\n', code, '\n', result);
66
+ try {
67
+ return (0, exports.babelTransformExpression)(code, visitor, 'functionBody');
68
+ }
69
+ catch (err) {
70
+ throw err;
71
+ }
72
+ }
73
+ };
41
74
  var babelTransform = function (code, visitor) {
42
75
  return babel.transform(code, {
43
76
  sourceFileName: 'file.tsx',
@@ -49,13 +82,21 @@ var babelTransform = function (code, visitor) {
49
82
  });
50
83
  };
51
84
  exports.babelTransform = babelTransform;
52
- var babelTransformCode = function (code, visitor) {
53
- var _a;
54
- return ((_a = (0, exports.babelTransform)(code, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
55
- };
85
+ var babelTransformCode = function (code, visitor) { var _a; return ((_a = (0, exports.babelTransform)(code, visitor)) === null || _a === void 0 ? void 0 : _a.code) || ''; };
56
86
  exports.babelTransformCode = babelTransformCode;
87
+ // Babel adds trailing semicolons, but for expressions we need those gone
88
+ // TODO: maybe detect if the original code ended with one, and keep it if so, for the case
89
+ // of appending several fragements
90
+ var trimSemicolons = function (code) { return code.replace(/;$/, ''); };
91
+ var trimExpression = function (type) { return function (code) {
92
+ switch (type) {
93
+ case 'functionBody':
94
+ return code.replace(/^function\s*\(\)\s*\{/, '').replace(/\};?$/, '');
95
+ default:
96
+ return trimSemicolons(code);
97
+ }
98
+ }; };
57
99
  var babelTransformExpression = function (code, visitor, type) {
58
- var _a;
59
100
  if (type === void 0) { type = 'unknown'; }
60
101
  if (!code) {
61
102
  return '';
@@ -74,61 +115,16 @@ var babelTransformExpression = function (code, visitor, type) {
74
115
  if (type === 'functionBody') {
75
116
  useCode = "function(){".concat(useCode, "}");
76
117
  }
77
- var result = type === 'expression'
78
- ? null
79
- : (0, lodash_1.attempt)(function () {
80
- var _a;
81
- var result = ((_a = (0, exports.babelTransform)(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
82
- if (type === 'functionBody') {
83
- return result.replace(/^function\(\)\{/, '').replace(/\};$/, '');
84
- }
85
- else {
86
- // Babel addes trailing semicolons, but for expressions we need those gone
87
- // TODO: maybe detect if the original code ended with one, and keep it if so, for the case
88
- // of appending several fragements
89
- return result.replace(/;$/, '');
90
- }
91
- });
92
- if ((0, lodash_1.isError)(result) || type === 'expression') {
118
+ if (type !== 'expression') {
93
119
  try {
94
- // If it can't, e.g. this is an expression or code fragment, modify the code below and try again
95
- // Detect method fragments. These get passed sometimes and otherwise
96
- // generate compile errors. They are of the form `foo() { ... }`
97
- var isMethod = Boolean(!code.startsWith('function') && code.match(/^[a-z0-9_]+\s*\([^\)]*\)\s*[\{:]/i));
98
- if (isMethod) {
99
- useCode = "function ".concat(useCode);
100
- }
101
- // Parse the code as an expression (instead of the default, a block) by giving it a fake variable assignment
102
- // e.g. if the code parsed is { ... } babel will treat that as a block by deafult, unless processed as an expression
103
- // that is an object
104
- useCode = "let _ = ".concat(useCode);
105
- result = (((_a = (0, exports.babelTransform)(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '')
106
- // Babel adds trailing semicolons, but for expressions we need those gone
107
- .replace(/;$/, '')
108
- // Remove our fake variable assignment
109
- .replace(/let _ =\s/, '');
110
- if (isMethod) {
111
- result = result.replace('function', '');
112
- }
120
+ return (0, function_1.pipe)((0, exports.babelTransformCode)(useCode, visitor), trimExpression(type));
113
121
  }
114
- catch (err) {
115
- console.error('Error parsing code:\n', code, '\n', result);
116
- try {
117
- return (0, exports.babelTransformExpression)(code, visitor, 'functionBody');
118
- }
119
- catch (err) {
120
- throw err;
121
- }
122
+ catch (error) {
123
+ return handleErrorOrExpression({ code: code, useCode: useCode, result: null, visitor: visitor });
122
124
  }
123
125
  }
124
- if (type === 'functionBody') {
125
- return result.replace(/^function\s*\(\)\s*\{/, '').replace(/\};?$/, '');
126
- }
127
126
  else {
128
- // Babel adds trailing semicolons, but for expressions we need those gone
129
- // TODO: maybe detect if the original code ended with one, and keep it if so, for the case
130
- // of appending several fragements
131
- return result.replace(/;$/, '');
127
+ return handleErrorOrExpression({ code: code, useCode: useCode, result: null, visitor: visitor });
132
128
  }
133
129
  };
134
130
  exports.babelTransformExpression = babelTransformExpression;
@@ -4,11 +4,9 @@ exports.getBindingsCode = void 0;
4
4
  function getBindingsCode(children) {
5
5
  var bindings = [];
6
6
  children.forEach(function (child) {
7
- if (child.bindings) {
8
- Object.keys(child.bindings).forEach(function (key) {
9
- bindings.push(child.bindings[key].code);
10
- });
11
- }
7
+ Object.values(child.bindings || []).forEach(function (binding) {
8
+ bindings.push(binding.code);
9
+ });
12
10
  if (child.children) {
13
11
  bindings.push.apply(bindings, getBindingsCode(child.children));
14
12
  }
@@ -7,6 +7,15 @@ exports.getProps = void 0;
7
7
  var traverse_1 = __importDefault(require("traverse"));
8
8
  var propsRegex = /props\s*\.\s*([a-zA-Z0-9_\$]+)/;
9
9
  var allPropsMatchesRegex = new RegExp(propsRegex, 'g');
10
+ // copied from https://github.com/vuejs/core/blob/fa6556a0d56eeff1fec4f948460351ccf8f99f35/packages/compiler-core/src/validateExpression.ts
11
+ // typeof, instanceof and in are allowed
12
+ var prohibitedKeywordRE = new RegExp('\\b' +
13
+ ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
14
+ 'super,throw,while,yield,delete,export,import,return,switch,default,' +
15
+ 'extends,finally,continue,debugger,function,arguments,typeof,void')
16
+ .split(',')
17
+ .join('\\b|\\b') +
18
+ '\\b');
10
19
  /**
11
20
  * Get props used in the components by reference
12
21
  */
@@ -19,7 +28,11 @@ var getProps = function (json) {
19
28
  if (matches) {
20
29
  for (var _i = 0, matches_1 = matches; _i < matches_1.length; _i++) {
21
30
  var match = matches_1[_i];
22
- props.add(match.match(propsRegex)[1]);
31
+ var prop = match.match(propsRegex)[1];
32
+ if (prop.match(prohibitedKeywordRE)) {
33
+ throw new Error("avoid using JavaScript keyword as property name: \"".concat(prop, "\""));
34
+ }
35
+ props.add(prop);
23
36
  }
24
37
  }
25
38
  }
@@ -16,10 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.getStateObjectStringFromComponent = exports.stringifyContextValue = exports.getMemberObjectString = void 0;
18
18
  var json5_1 = __importDefault(require("json5"));
19
- var function_literal_prefix_1 = require("../constants/function-literal-prefix");
20
- var method_literal_prefix_1 = require("../constants/method-literal-prefix");
21
- var patterns_1 = require("./patterns");
22
- var state_1 = require("./state");
23
19
  var DEFAULT_OPTIONS = {
24
20
  format: 'object',
25
21
  keyPrefix: '',
@@ -33,31 +29,38 @@ var convertStateMemberToString = function (_a) {
33
29
  return function (_a) {
34
30
  var key = _a[0], state = _a[1];
35
31
  var keyValueDelimiter = format === 'object' ? ':' : '=';
36
- var code = state === null || state === void 0 ? void 0 : state.code;
37
- if (typeof code === 'string') {
38
- if (code.startsWith(function_literal_prefix_1.functionLiteralPrefix)) {
39
- if (functions === false) {
32
+ if (!state) {
33
+ return undefined;
34
+ }
35
+ var code = state.code;
36
+ switch (state.type) {
37
+ case 'function': {
38
+ if (functions === false || typeof code !== 'string') {
40
39
  return undefined;
41
40
  }
42
- var functionValue = code.replace(function_literal_prefix_1.functionLiteralPrefix, '');
43
- return "".concat(keyPrefix, " ").concat(key, " ").concat(keyValueDelimiter, " ").concat(valueMapper(functionValue, 'function'));
41
+ return "".concat(keyPrefix, " ").concat(key, " ").concat(keyValueDelimiter, " ").concat(valueMapper(code, 'function'));
44
42
  }
45
- else if (code.startsWith(method_literal_prefix_1.methodLiteralPrefix)) {
46
- var methodValue = code.replace(method_literal_prefix_1.methodLiteralPrefix, '');
47
- var isGet = Boolean(methodValue.match(patterns_1.GETTER));
48
- if (isGet && getters === false) {
43
+ case 'method': {
44
+ if (functions === false || typeof code !== 'string') {
49
45
  return undefined;
50
46
  }
51
- if (!isGet && functions === false) {
47
+ return "".concat(keyPrefix, " ").concat(valueMapper(code, 'function'));
48
+ }
49
+ case 'getter': {
50
+ if (getters === false || typeof code !== 'string') {
52
51
  return undefined;
53
52
  }
54
- return "".concat(keyPrefix, " ").concat(valueMapper(methodValue, isGet ? 'getter' : 'function'));
53
+ return "".concat(keyPrefix, " ").concat(valueMapper(code, 'getter'));
55
54
  }
55
+ case 'property': {
56
+ if (data === false) {
57
+ return undefined;
58
+ }
59
+ return "".concat(keyPrefix, " ").concat(key).concat(keyValueDelimiter, " ").concat(valueMapper(json5_1.default.stringify(code), 'data'));
60
+ }
61
+ default:
62
+ break;
56
63
  }
57
- if (data === false) {
58
- return undefined;
59
- }
60
- return "".concat(keyPrefix, " ").concat(key).concat(keyValueDelimiter, " ").concat(valueMapper(json5_1.default.stringify(code), 'data'));
61
64
  };
62
65
  };
63
66
  var getMemberObjectString = function (object, userOptions) {
@@ -80,7 +83,7 @@ var getMemberObjectString = function (object, userOptions) {
80
83
  exports.getMemberObjectString = getMemberObjectString;
81
84
  var stringifyContextValue = function (object, userOptions) {
82
85
  if (userOptions === void 0) { userOptions = {}; }
83
- return (0, exports.getMemberObjectString)((0, state_1.mapJsonObjectToStateValue)(object), userOptions);
86
+ return (0, exports.getMemberObjectString)(object, userOptions);
84
87
  };
85
88
  exports.stringifyContextValue = stringifyContextValue;
86
89
  var getStateObjectStringFromComponent = function (component, options) { return (0, exports.getMemberObjectString)(component.state, options); };
@@ -4,22 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.gettersToFunctions = void 0;
7
- var method_literal_prefix_1 = require("../constants/method-literal-prefix");
8
7
  var traverse_1 = __importDefault(require("traverse"));
9
8
  /**
10
9
  * Map getters like `useStore({ get foo() { ... }})` from `state.foo` to `foo()`
11
10
  */
12
11
  var gettersToFunctions = function (json) {
13
- var getterKeys = Object.keys(json.state).filter(function (item) {
14
- var _a;
15
- var value = (_a = json.state[item]) === null || _a === void 0 ? void 0 : _a.code;
16
- if (typeof value === 'string' &&
17
- value.startsWith(method_literal_prefix_1.methodLiteralPrefix) &&
18
- value.replace(method_literal_prefix_1.methodLiteralPrefix, '').startsWith('get ')) {
19
- return true;
20
- }
21
- return false;
22
- });
12
+ var getterKeys = Object.keys(json.state).filter(function (item) { var _a; return ((_a = json.state[item]) === null || _a === void 0 ? void 0 : _a.type) === 'getter'; });
23
13
  (0, traverse_1.default)(json).forEach(function (item) {
24
14
  // TODO: not all strings are expressions!
25
15
  if (typeof item === 'string') {
@@ -42,8 +42,6 @@ var traverse_1 = __importDefault(require("traverse"));
42
42
  var babel = __importStar(require("@babel/core"));
43
43
  var get_refs_1 = require("./get-refs");
44
44
  var is_mitosis_node_1 = require("./is-mitosis-node");
45
- var method_literal_prefix_1 = require("../constants/method-literal-prefix");
46
- var function_literal_prefix_1 = require("../constants/function-literal-prefix");
47
45
  var babel_transform_1 = require("./babel-transform");
48
46
  var patterns_1 = require("./patterns");
49
47
  var tsPreset = require('@babel/preset-typescript');
@@ -59,31 +57,33 @@ var replaceRefsInString = function (code, refs, mapper) {
59
57
  });
60
58
  };
61
59
  var mapRefs = function (component, mapper) {
62
- var _a;
63
60
  var refSet = (0, get_refs_1.getRefs)(component);
64
61
  // grab refs not used for bindings
65
62
  Object.keys(component.refs).forEach(function (ref) { return refSet.add(ref); });
66
63
  var refs = Array.from(refSet);
67
- for (var _i = 0, _b = Object.keys(component.state); _i < _b.length; _i++) {
68
- var key = _b[_i];
69
- var value = (_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.code;
70
- if (typeof value === 'string') {
71
- if (value.startsWith(method_literal_prefix_1.methodLiteralPrefix)) {
72
- var methodValue = value.replace(method_literal_prefix_1.methodLiteralPrefix, '');
73
- var isGet = Boolean(methodValue.match(patterns_1.GETTER));
74
- var isSet = Boolean(methodValue.match(patterns_1.SETTER));
75
- component.state[key] = {
76
- code: method_literal_prefix_1.methodLiteralPrefix +
77
- replaceRefsInString(methodValue.replace(/^(get |set )?/, 'function '), refs, mapper).replace(/^function /, isGet ? 'get ' : isSet ? 'set ' : ''),
78
- type: isGet ? 'getter' : 'method',
79
- };
80
- }
81
- else if (value.startsWith(function_literal_prefix_1.functionLiteralPrefix)) {
82
- component.state[key] = {
83
- code: function_literal_prefix_1.functionLiteralPrefix +
84
- replaceRefsInString(value.replace(function_literal_prefix_1.functionLiteralPrefix, ''), refs, mapper),
85
- type: 'function',
86
- };
64
+ for (var _i = 0, _a = Object.keys(component.state); _i < _a.length; _i++) {
65
+ var key = _a[_i];
66
+ var stateVal = component.state[key];
67
+ if (typeof (stateVal === null || stateVal === void 0 ? void 0 : stateVal.code) === 'string') {
68
+ var value = stateVal.code;
69
+ switch (stateVal.type) {
70
+ case 'method':
71
+ case 'getter':
72
+ var isGet = stateVal.type === 'getter';
73
+ var isSet = Boolean(value.match(patterns_1.SETTER));
74
+ component.state[key] = {
75
+ code: replaceRefsInString(value.replace(/^(get |set )?/, 'function '), refs, mapper).replace(/^function /, isGet ? 'get ' : isSet ? 'set ' : ''),
76
+ type: stateVal.type,
77
+ };
78
+ break;
79
+ case 'function':
80
+ component.state[key] = {
81
+ code: replaceRefsInString(value, refs, mapper),
82
+ type: 'function',
83
+ };
84
+ break;
85
+ default:
86
+ break;
87
87
  }
88
88
  }
89
89
  }
@@ -98,8 +98,8 @@ var mapRefs = function (component, mapper) {
98
98
  }
99
99
  }
100
100
  });
101
- for (var _c = 0, _d = Object.keys(component.hooks); _c < _d.length; _c++) {
102
- var key = _d[_c];
101
+ for (var _b = 0, _c = Object.keys(component.hooks); _b < _c.length; _b++) {
102
+ var key = _c[_b];
103
103
  var hooks = component.hooks[key];
104
104
  if (Array.isArray(hooks)) {
105
105
  hooks.forEach(function (hook) {
@@ -0,0 +1,4 @@
1
+ import { ForNode } from '../../types/mitosis-node';
2
+ export declare const getForArguments: (node: ForNode, { excludeCollectionName }?: {
3
+ excludeCollectionName: boolean;
4
+ }) => string[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getForArguments = void 0;
4
+ var nullable_1 = require("../nullable");
5
+ var getForArguments = function (node, _a) {
6
+ var _b = _a === void 0 ? { excludeCollectionName: false } : _a, excludeCollectionName = _b.excludeCollectionName;
7
+ return [
8
+ node.scope.forName || 'item',
9
+ node.scope.indexName,
10
+ excludeCollectionName ? undefined : node.scope.collectionName,
11
+ ].filter(nullable_1.checkIsDefined);
12
+ };
13
+ exports.getForArguments = getForArguments;
@@ -0,0 +1,2 @@
1
+ export declare type Nullable<X> = X | null | undefined;
2
+ export declare const checkIsDefined: <T>(value: Nullable<T>) => value is NonNullable<T>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIsDefined = void 0;
4
+ var checkIsDefined = function (value) {
5
+ return value !== null && value !== undefined;
6
+ };
7
+ exports.checkIsDefined = checkIsDefined;
@@ -1,2 +1,4 @@
1
1
  export declare const GETTER: RegExp;
2
2
  export declare const SETTER: RegExp;
3
+ export declare const replaceGetterWithFunction: (str: string) => string;
4
+ export declare const prefixWithFunction: (str: string) => string;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SETTER = exports.GETTER = void 0;
3
+ exports.prefixWithFunction = exports.replaceGetterWithFunction = exports.SETTER = exports.GETTER = void 0;
4
4
  exports.GETTER = /^get /;
5
5
  exports.SETTER = /^set /;
6
+ var replaceGetterWithFunction = function (str) { return str.replace(/^(get )?/, 'function '); };
7
+ exports.replaceGetterWithFunction = replaceGetterWithFunction;
8
+ var prefixWithFunction = function (str) { return "function ".concat(str); };
9
+ exports.prefixWithFunction = prefixWithFunction;
@@ -40,7 +40,7 @@ var getFileExtensionForTarget = function (target) {
40
40
  case 'angular':
41
41
  return '';
42
42
  // these `.lite` extensions are handled in the `transpile` step of the CLI.
43
- // TO-DO: consolidate file-extension renaming to one place.
43
+ // TO-DO: consolidate file-extension renaming to this file, and remove `.lite` replaces from the CLI `transpile`.
44
44
  default:
45
45
  return '.lite';
46
46
  }
@@ -51,7 +51,7 @@ var checkIsComponentImport = function (theImport) {
51
51
  var transformImportPath = function (theImport, target) {
52
52
  // We need to drop the `.lite` from context files, because the context generator does so as well.
53
53
  if (theImport.path.endsWith('.context.lite')) {
54
- return theImport.path.replace('.lite', '');
54
+ return theImport.path.replace('.lite', '.js');
55
55
  }
56
56
  if (checkIsComponentImport(theImport)) {
57
57
  return theImport.path.replace('.lite', getFileExtensionForTarget(target));
@@ -110,7 +110,7 @@ var renderImport = function (_a) {
110
110
  console.warn('Vue: Async Component imports cannot include named imports. Dropping async import. This might break your code.');
111
111
  }
112
112
  else {
113
- return "const ".concat(importValue, " = () => import('").concat(path, "')");
113
+ return "const ".concat(importValue, " = () => import('").concat(path, "').then(x => x.default)");
114
114
  }
115
115
  }
116
116
  return importValue ? "import ".concat(importValue, " from '").concat(path, "';") : "import '".concat(path, "';");
@@ -0,0 +1,5 @@
1
+ export declare const replaceIdentifiers: ({ code, from, to, }: {
2
+ code: string;
3
+ from: string | string[];
4
+ to: string | ((identifier: string) => string);
5
+ }) => string;
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceIdentifiers = void 0;
4
4
  var core_1 = require("@babel/core");
5
5
  var babel_transform_1 = require("./babel-transform");
6
- var replaceIdentifiers = function (code, from, to) {
6
+ var replaceIdentifiers = function (_a) {
7
+ var code = _a.code, from = _a.from, to = _a.to;
7
8
  return (0, babel_transform_1.babelTransformExpression)(code, {
8
9
  Identifier: function (path) {
9
10
  if (
@@ -1,2 +1,4 @@
1
+ export declare type SlotMapper = (slotName: string) => string;
1
2
  export declare const isSlotProperty: (key: string) => boolean;
2
3
  export declare const stripSlotPrefix: (key: string) => string;
4
+ export declare function replaceSlotsInString(code: string, mapper: SlotMapper): string;
@@ -1,8 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripSlotPrefix = exports.isSlotProperty = void 0;
3
+ exports.replaceSlotsInString = exports.stripSlotPrefix = exports.isSlotProperty = void 0;
4
+ var core_1 = require("@babel/core");
5
+ var babel_transform_1 = require("./babel-transform");
4
6
  var SLOT_PREFIX = 'slot';
5
7
  var isSlotProperty = function (key) { return key.startsWith(SLOT_PREFIX); };
6
8
  exports.isSlotProperty = isSlotProperty;
7
9
  var stripSlotPrefix = function (key) { return key.substring(SLOT_PREFIX.length); };
8
10
  exports.stripSlotPrefix = stripSlotPrefix;
11
+ function replaceSlotsInString(code, mapper) {
12
+ return (0, babel_transform_1.babelTransformExpression)(code, {
13
+ Identifier: function (path) {
14
+ var name = path.node.name;
15
+ var isSlot = (0, exports.isSlotProperty)(name);
16
+ if (isSlot) {
17
+ path.replaceWith(core_1.types.identifier(mapper((0, exports.stripSlotPrefix)(name).toLowerCase())));
18
+ }
19
+ },
20
+ });
21
+ }
22
+ exports.replaceSlotsInString = replaceSlotsInString;
@@ -1,4 +1,2 @@
1
- import { JSONObject } from '../types/json';
2
1
  import { MitosisComponent } from '../types/mitosis-component';
3
2
  export declare const checkHasState: (component: MitosisComponent) => boolean;
4
- export declare const mapJsonObjectToStateValue: (value: JSONObject) => MitosisComponent['state'];
@@ -1,16 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapJsonObjectToStateValue = exports.checkHasState = void 0;
4
- var lodash_1 = require("lodash");
3
+ exports.checkHasState = void 0;
5
4
  var checkHasState = function (component) {
6
5
  return Boolean(Object.keys(component.state).length);
7
6
  };
8
7
  exports.checkHasState = checkHasState;
9
- var mapJsonToStateValue = function (value) { return ({
10
- code: value,
11
- type: 'property',
12
- }); };
13
- var mapJsonObjectToStateValue = function (value) {
14
- return (0, lodash_1.mapValues)(value, mapJsonToStateValue);
15
- };
16
- exports.mapJsonObjectToStateValue = mapJsonObjectToStateValue;
@@ -16,4 +16,4 @@ export declare type StripStateAndPropsRefsOptions = {
16
16
  *
17
17
  * @todo proper ref replacement with babel
18
18
  */
19
- export declare const stripStateAndPropsRefs: (code?: string, options?: StripStateAndPropsRefsOptions) => string;
19
+ export declare const stripStateAndPropsRefs: (code?: string, _options?: StripStateAndPropsRefsOptions) => string;
@@ -1,6 +1,27 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.stripStateAndPropsRefs = void 0;
15
+ var DEFAULT_OPTIONS = {
16
+ replaceWith: '',
17
+ contextVars: [],
18
+ outputVars: [],
19
+ stateVars: [],
20
+ context: 'this.',
21
+ domRefs: [],
22
+ includeProps: true,
23
+ includeState: true,
24
+ };
4
25
  /**
5
26
  * Remove state. and props. from expressions, e.g.
6
27
  * state.foo -> foo
@@ -9,48 +30,39 @@ exports.stripStateAndPropsRefs = void 0;
9
30
  *
10
31
  * @todo proper ref replacement with babel
11
32
  */
12
- var stripStateAndPropsRefs = function (code, options) {
13
- if (options === void 0) { options = {}; }
33
+ var stripStateAndPropsRefs = function (code, _options) {
34
+ if (_options === void 0) { _options = {}; }
14
35
  var newCode = code || '';
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
- var context = (options === null || options === void 0 ? void 0 : options.context) || 'this.';
19
- var domRefs = (options === null || options === void 0 ? void 0 : options.domRefs) || [];
20
- var stateVars = (options === null || options === void 0 ? void 0 : options.stateVars) || [];
21
- if (contextVars.length) {
22
- contextVars.forEach(function (_var) {
23
- newCode = newCode.replace(
24
- // determine expression edge cases - https://regex101.com/r/iNcTSM/1
25
- new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + _var + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g'), '$1' + context + _var + '$2');
26
- });
27
- }
28
- if (outputVars.length) {
29
- outputVars.forEach(function (_var) {
30
- // determine expression edge cases onMessage( to this.onMessage.emit(
31
- var regexp = '(^|\\s|;|\\()(props\\.?)' + _var + '\\(';
32
- var replacer = '$1' + context + _var + '.emit(';
33
- newCode = newCode.replace(new RegExp(regexp, 'g'), replacer);
34
- });
35
- }
36
- if (options.includeProps !== false) {
37
- if (typeof replacer === 'string') {
38
- newCode = newCode.replace(/props\./g, replacer);
36
+ var _a = __assign(__assign({}, DEFAULT_OPTIONS), _options), replaceWith = _a.replaceWith, contextVars = _a.contextVars, outputVars = _a.outputVars, context = _a.context, domRefs = _a.domRefs, includeProps = _a.includeProps, includeState = _a.includeState, stateVars = _a.stateVars;
37
+ contextVars.forEach(function (_var) {
38
+ newCode = newCode.replace(
39
+ // determine expression edge cases - https://regex101.com/r/iNcTSM/1
40
+ new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + _var + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g'), '$1' + context + _var + '$2');
41
+ });
42
+ outputVars.forEach(function (_var) {
43
+ // determine expression edge cases onMessage( to this.onMessage.emit(
44
+ var regexp = '(^|\\s|;|\\()(props\\.?)' + _var + '\\(';
45
+ var replacer = '$1' + context + _var + '.emit(';
46
+ newCode = newCode.replace(new RegExp(regexp, 'g'), replacer);
47
+ });
48
+ if (includeProps !== false) {
49
+ if (typeof replaceWith === 'string') {
50
+ newCode = newCode.replace(/props\./g, replaceWith);
39
51
  }
40
52
  else {
41
- newCode = newCode.replace(/props\.([\$a-z0-9_]+)/gi, function (memo, name) { return replacer(name); });
53
+ newCode = newCode.replace(/props\.([\$a-z0-9_]+)/gi, function (memo, name) { return replaceWith(name); });
42
54
  }
43
55
  // TODO: webcomponent edge-case
44
56
  if (/el\.this\.props/.test(newCode)) {
45
57
  newCode = newCode.replace(/el\.this\.props/g, 'el.props');
46
58
  }
47
59
  }
48
- if (options.includeState !== false) {
49
- if (typeof replacer === 'string') {
50
- newCode = newCode.replace(/state\./g, replacer);
60
+ if (includeState !== false) {
61
+ if (typeof replaceWith === 'string') {
62
+ newCode = newCode.replace(/state\./g, replaceWith);
51
63
  }
52
64
  else {
53
- newCode = newCode.replace(/state\.([\$a-z0-9_]+)/gi, function (memo, name) { return replacer(name); });
65
+ newCode = newCode.replace(/state\.([\$a-z0-9_]+)/gi, function (memo, name) { return replaceWith(name); });
54
66
  }
55
67
  }
56
68
  var matchPropertyAccessorsArguments = '\\?\\.|,|\\.|\\(| |;|\\)|\\]|$'; // foo?.stuff | foo) | foo | foo] etc.
@@ -1,3 +1,4 @@
1
+ /// <reference types="lodash" />
1
2
  import * as CSS from 'csstype';
2
3
  import { MitosisNode } from '../../types/mitosis-node';
3
4
  import { MitosisComponent } from '../../types/mitosis-component';
@@ -19,8 +20,8 @@ export declare const hasStyle: (component: MitosisComponent) => boolean;
19
20
  export declare type StyleMap = {
20
21
  [className: string]: CSS.Properties | StyleMap;
21
22
  };
22
- export declare const getNestedSelectors: (map: StyleMap) => import("lodash").Dictionary<StyleMap | CSS.Properties<0 | (string & {}), string & {}>>;
23
- export declare const getStylesOnly: (map: StyleMap) => import("lodash").Dictionary<StyleMap | CSS.Properties<0 | (string & {}), string & {}>>;
23
+ export declare const getNestedSelectors: (map: StyleMap) => import("lodash").Dictionary<CSS.Properties<0 | (string & {}), string & {}> | StyleMap>;
24
+ export declare const getStylesOnly: (map: StyleMap) => import("lodash").Dictionary<CSS.Properties<0 | (string & {}), string & {}> | StyleMap>;
24
25
  /**
25
26
  * { 'my-class': { display: 'block', '&.foo': { display: 'none' } }}
26
27
  */