@builder.io/mitosis 0.0.45-4 → 0.0.47

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 (218) hide show
  1. package/dist/src/__tests__/builder.test.js +73 -65
  2. package/dist/src/__tests__/context.test.js +13 -10
  3. package/dist/src/__tests__/data/basic.raw.jsx +1 -1
  4. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +1 -1
  5. package/dist/src/__tests__/data/blocks/columns.raw.jsx +2 -2
  6. package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -3
  7. package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -3
  8. package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
  9. package/dist/src/__tests__/data/blocks/image.raw.jsx +4 -4
  10. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -4
  11. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +2 -2
  12. package/dist/src/__tests__/data/context/simple.context.lite.js +1 -1
  13. package/dist/src/__tests__/html.test.js +2 -2
  14. package/dist/src/__tests__/liquid.test.js +34 -34
  15. package/dist/src/__tests__/parse-jsx.test.js +1 -1
  16. package/dist/src/__tests__/qwik.test.js +197 -50
  17. package/dist/src/__tests__/react-native.test.js +35 -35
  18. package/dist/src/__tests__/react.test.js +35 -35
  19. package/dist/src/__tests__/solid.test.js +32 -32
  20. package/dist/src/__tests__/vue.test.js +35 -34
  21. package/dist/src/generators/angular.d.ts +4 -7
  22. package/dist/src/generators/angular.js +77 -81
  23. package/dist/src/generators/builder.d.ts +4 -4
  24. package/dist/src/generators/builder.js +57 -57
  25. package/dist/src/generators/context/react.d.ts +3 -1
  26. package/dist/src/generators/context/react.js +20 -17
  27. package/dist/src/generators/html.d.ts +5 -9
  28. package/dist/src/generators/html.js +205 -199
  29. package/dist/src/generators/liquid.d.ts +5 -9
  30. package/dist/src/generators/liquid.js +62 -59
  31. package/dist/src/generators/mitosis.d.ts +6 -7
  32. package/dist/src/generators/mitosis.js +61 -63
  33. package/dist/src/generators/qwik/component.d.ts +20 -0
  34. package/dist/src/generators/qwik/component.js +117 -0
  35. package/dist/src/generators/qwik/directives.d.ts +2 -0
  36. package/dist/src/generators/qwik/directives.js +27 -0
  37. package/dist/src/generators/qwik/handlers.d.ts +4 -0
  38. package/dist/src/generators/qwik/handlers.js +80 -0
  39. package/dist/src/generators/qwik/index.d.ts +2 -0
  40. package/dist/src/generators/qwik/index.js +9 -0
  41. package/dist/src/generators/qwik/jsx.d.ts +4 -0
  42. package/dist/src/generators/qwik/jsx.js +124 -0
  43. package/dist/src/generators/qwik/src-generator.d.ts +79 -0
  44. package/dist/src/generators/qwik/src-generator.js +427 -0
  45. package/dist/src/generators/qwik/styles.d.ts +7 -0
  46. package/dist/src/generators/qwik/styles.js +94 -0
  47. package/dist/src/generators/react-native.d.ts +4 -7
  48. package/dist/src/generators/react-native.js +25 -22
  49. package/dist/src/generators/react.d.ts +4 -8
  50. package/dist/src/generators/react.js +118 -114
  51. package/dist/src/generators/solid.d.ts +4 -8
  52. package/dist/src/generators/solid.js +55 -54
  53. package/dist/src/generators/svelte.d.ts +4 -7
  54. package/dist/src/generators/svelte.js +120 -123
  55. package/dist/src/generators/swift-ui.d.ts +2 -2
  56. package/dist/src/generators/swift-ui.js +62 -62
  57. package/dist/src/generators/template.d.ts +4 -8
  58. package/dist/src/generators/template.js +48 -45
  59. package/dist/src/generators/vue.d.ts +9 -9
  60. package/dist/src/generators/vue.js +170 -169
  61. package/dist/src/helpers/babel-transform.js +9 -9
  62. package/dist/src/helpers/camel-case.d.ts +8 -0
  63. package/dist/src/helpers/camel-case.js +18 -0
  64. package/dist/src/helpers/collect-styles.js +39 -37
  65. package/dist/src/helpers/dash-case.js +1 -1
  66. package/dist/src/helpers/generic-format.test.js +2 -2
  67. package/dist/src/helpers/get-components-used.js +2 -2
  68. package/dist/src/helpers/get-components.js +3 -3
  69. package/dist/src/helpers/get-props.js +1 -1
  70. package/dist/src/helpers/get-refs.js +2 -2
  71. package/dist/src/helpers/get-state-object-string.js +52 -39
  72. package/dist/src/helpers/get-state-used.js +1 -1
  73. package/dist/src/helpers/get-styles.js +1 -1
  74. package/dist/src/helpers/getters-to-functions.js +4 -4
  75. package/dist/src/helpers/handle-missing-state.js +1 -1
  76. package/dist/src/helpers/has-component.js +2 -2
  77. package/dist/src/helpers/has-props.js +1 -1
  78. package/dist/src/helpers/is-children.js +1 -1
  79. package/dist/src/helpers/json.d.ts +1 -0
  80. package/dist/src/helpers/json.js +17 -0
  81. package/dist/src/helpers/map-refs.js +7 -6
  82. package/dist/src/helpers/map-to-attributes.js +4 -4
  83. package/dist/src/helpers/map-to-css.js +2 -2
  84. package/dist/src/helpers/parse-node.js +2 -2
  85. package/dist/src/helpers/parse-reactive-script.js +4 -4
  86. package/dist/src/helpers/patterns.d.ts +2 -0
  87. package/dist/src/helpers/patterns.js +5 -0
  88. package/dist/src/helpers/process-http-requests.js +1 -1
  89. package/dist/src/helpers/process-tag-references.js +4 -4
  90. package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
  91. package/dist/src/helpers/render-imports.js +7 -7
  92. package/dist/src/helpers/replace-idenifiers.js +1 -1
  93. package/dist/src/helpers/strip-meta-properties.js +2 -2
  94. package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
  95. package/dist/src/helpers/traverse-nodes.js +2 -2
  96. package/dist/src/helpers/try-prettier-format.js +1 -1
  97. package/dist/src/index.d.ts +3 -1
  98. package/dist/src/index.js +3 -1
  99. package/dist/src/modules/plugins.d.ts +2 -10
  100. package/dist/src/parsers/angular.js +13 -13
  101. package/dist/src/parsers/builder.d.ts +1 -1
  102. package/dist/src/parsers/builder.js +56 -59
  103. package/dist/src/parsers/context.js +2 -2
  104. package/dist/src/parsers/jsx.js +59 -87
  105. package/dist/src/parsers/liquid.js +193 -195
  106. package/dist/src/plugins/compile-away-builder-components.d.ts +1 -1
  107. package/dist/src/plugins/compile-away-builder-components.js +337 -92
  108. package/dist/src/plugins/compile-away-components.js +3 -3
  109. package/dist/src/plugins/map-styles.js +3 -3
  110. package/dist/src/targets.d.ts +24 -0
  111. package/dist/src/targets.js +30 -0
  112. package/dist/src/types/config.d.ts +31 -0
  113. package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
  114. package/dist/src/types/generators.d.ts +0 -0
  115. package/dist/src/types/generators.js +1 -0
  116. package/dist/src/types/plugins.d.ts +11 -0
  117. package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
  118. package/dist/test/qwik/Accordion/high.jsx +1 -0
  119. package/dist/test/qwik/Accordion/low.jsx +92 -0
  120. package/dist/test/qwik/Accordion/med.jsx +9 -0
  121. package/dist/test/qwik/For/high.jsx +1 -0
  122. package/dist/test/qwik/For/low.jsx +55 -0
  123. package/dist/test/qwik/For/med.jsx +9 -0
  124. package/dist/test/qwik/Image/high.js +1 -0
  125. package/dist/test/qwik/Image/low.js +68 -0
  126. package/dist/test/qwik/Image/med.js +9 -0
  127. package/dist/test/qwik/Image.slow/high.js +1 -0
  128. package/dist/test/qwik/Image.slow/low.js +68 -0
  129. package/dist/test/qwik/Image.slow/med.js +9 -0
  130. package/dist/test/qwik/button/high.js +8 -0
  131. package/dist/test/qwik/button/low.js +34 -0
  132. package/dist/test/qwik/button/med.js +9 -0
  133. package/dist/test/qwik/hello_world/stylesheet/high.jsx +1 -0
  134. package/dist/test/qwik/hello_world/stylesheet/low.jsx +24 -0
  135. package/dist/test/qwik/hello_world/stylesheet/med.jsx +9 -0
  136. package/dist/test/qwik/page-with-symbol/high.js +1 -0
  137. package/dist/test/qwik/page-with-symbol/low.js +49 -0
  138. package/dist/test/qwik/page-with-symbol/med.js +9 -0
  139. package/dist/test/qwik/svg/high.js +1 -0
  140. package/dist/test/qwik/svg/low.js +30 -0
  141. package/dist/test/qwik/svg/med.js +9 -0
  142. package/dist/test/qwik/todo/Todo.cjs/high.cjs +31 -0
  143. package/dist/test/qwik/todo/Todo.cjs/low.cjs +1 -0
  144. package/dist/test/qwik/todo/Todo.cjs/med.cjs +59 -0
  145. package/dist/test/qwik/todo/Todo.js/high.js +5 -0
  146. package/dist/test/qwik/todo/Todo.js/low.js +0 -0
  147. package/dist/test/qwik/todo/Todo.js/med.js +1 -0
  148. package/dist/test/qwik/todo/Todo.tsx/high.tsx +30 -0
  149. package/dist/test/qwik/todo/Todo.tsx/low.tsx +1 -0
  150. package/dist/test/qwik/todo/Todo.tsx/med.tsx +34 -0
  151. package/dist/test/qwik/todos/Todo.tsx/high.tsx +12 -0
  152. package/dist/test/qwik/todos/Todo.tsx/low.tsx +25 -0
  153. package/dist/test/qwik/todos/Todo.tsx/med.tsx +8 -0
  154. package/dist/tsconfig.tsbuildinfo +1 -1
  155. package/package.json +5 -4
  156. package/CHANGELOG.md +0 -4
  157. package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
  158. package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
  159. package/dist/src/__tests__/qoot.test.d.ts +0 -1
  160. package/dist/src/__tests__/qoot.test.js +0 -115
  161. package/dist/src/generators/jsx-lite.d.ts +0 -10
  162. package/dist/src/generators/jsx-lite.js +0 -176
  163. package/dist/src/generators/qoot.d.ts +0 -21
  164. package/dist/src/generators/qoot.js +0 -442
  165. package/dist/src/generators/qwik.d.ts +0 -21
  166. package/dist/src/generators/qwik.js +0 -458
  167. package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
  168. package/dist/src/helpers/create-jsx-lite-component.js +0 -16
  169. package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
  170. package/dist/src/helpers/create-jsx-lite-context.js +0 -18
  171. package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
  172. package/dist/src/helpers/create-jsx-lite-node.js +0 -16
  173. package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
  174. package/dist/src/helpers/is-jsx-lite-node.js +0 -7
  175. package/dist/src/types/jsx-lite-component.d.ts +0 -63
  176. package/dist/src/types/jsx-lite-context.d.ts +0 -6
  177. package/dist/src/types/jsx-lite-node.d.ts +0 -13
  178. package/dist/src/types/jsx-lite-node.js +0 -2
  179. package/dist/src/types/jsx-lite-styles.d.ts +0 -1
  180. package/dist/src/types/jsx-lite-styles.js +0 -2
  181. package/dist/test/qoot/Todo/bundle.js +0 -88
  182. package/dist/test/qoot/Todo/component.ts +0 -17
  183. package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
  184. package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
  185. package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
  186. package/dist/test/qoot/Todo/onInputClick.ts +0 -10
  187. package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
  188. package/dist/test/qoot/Todo/public.ts +0 -4
  189. package/dist/test/qoot/Todo/template.tsx +0 -46
  190. package/dist/test/qoot/Todos/component.ts +0 -9
  191. package/dist/test/qoot/Todos/onInputClick.ts +0 -14
  192. package/dist/test/qoot/Todos/public.ts +0 -3
  193. package/dist/test/qoot/Todos/template.tsx +0 -30
  194. package/dist/test/qwik/Todo/bundle.js +0 -46
  195. package/dist/test/qwik/Todo/component.ts +0 -17
  196. package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
  197. package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
  198. package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
  199. package/dist/test/qwik/Todo/onInputClick.ts +0 -13
  200. package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
  201. package/dist/test/qwik/Todo/public.ts +0 -3
  202. package/dist/test/qwik/Todo/template.tsx +0 -46
  203. package/dist/test/qwik/Todo.ts +0 -4
  204. package/dist/test/qwik/Todo_component.ts +0 -14
  205. package/dist/test/qwik/Todo_onButtonClick.ts +0 -10
  206. package/dist/test/qwik/Todo_onInput2Blur.ts +0 -11
  207. package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
  208. package/dist/test/qwik/Todo_onInputClick.ts +0 -10
  209. package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -11
  210. package/dist/test/qwik/Todo_template.tsx +0 -46
  211. package/dist/test/qwik/Todos/component.ts +0 -9
  212. package/dist/test/qwik/Todos/onInputClick.ts +0 -14
  213. package/dist/test/qwik/Todos/public.ts +0 -3
  214. package/dist/test/qwik/Todos/template.tsx +0 -30
  215. package/dist/test/qwik/Todos.ts +0 -3
  216. package/dist/test/qwik/Todos_component.ts +0 -9
  217. package/dist/test/qwik/Todos_onInputClick.ts +0 -14
  218. package/dist/test/qwik/Todos_template.tsx +0 -30
@@ -30,28 +30,29 @@ var replace_idenifiers_1 = require("../helpers/replace-idenifiers");
30
30
  var filter_empty_text_nodes_1 = require("../helpers/filter-empty-text-nodes");
31
31
  var json5_1 = __importDefault(require("json5"));
32
32
  var process_http_requests_1 = require("../helpers/process-http-requests");
33
+ var patterns_1 = require("../helpers/patterns");
33
34
  function getContextNames(json) {
34
35
  return Object.keys(json.context.get);
35
36
  }
36
37
  // TODO: migrate all stripStateAndPropsRefs to use this here
37
38
  // to properly replace context refs
38
39
  function processBinding(code, _options, json) {
39
- return replace_idenifiers_1.replaceIdentifiers(strip_state_and_props_refs_1.stripStateAndPropsRefs(code, {
40
+ return (0, replace_idenifiers_1.replaceIdentifiers)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
40
41
  includeState: true,
41
42
  includeProps: true,
42
43
  replaceWith: 'this.',
43
- }), getContextNames(json), function (name) { return "this." + name; });
44
+ }), getContextNames(json), function (name) { return "this.".concat(name); });
44
45
  }
45
46
  var NODE_MAPPERS = {
46
47
  Fragment: function (json, options) {
47
- return json.children.map(function (item) { return exports.blockToVue(item, options); }).join('\n');
48
+ return json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
48
49
  },
49
50
  For: function (json, options) {
50
51
  var keyValue = json.bindings.key || 'index';
51
- var forValue = "(" + json.properties._forName + ", index) in " + strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings.each);
52
+ var forValue = "(".concat(json.properties._forName, ", index) in ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.each));
52
53
  if (options.vueVersion >= 3) {
53
54
  // TODO: tmk key goes on different element (parent vs child) based on Vue 2 vs Vue 3
54
- return "<template :key=\"" + keyValue + "\" v-for=\"" + forValue + "\">\n " + json.children.map(function (item) { return exports.blockToVue(item, options); }).join('\n') + "\n </template>";
55
+ return "<template :key=\"".concat(keyValue, "\" v-for=\"").concat(forValue, "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>");
55
56
  }
56
57
  // Vue 2 can only handle one root element
57
58
  var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
@@ -60,29 +61,29 @@ var NODE_MAPPERS = {
60
61
  }
61
62
  firstChild.bindings.key = keyValue;
62
63
  firstChild.properties['v-for'] = forValue;
63
- return exports.blockToVue(firstChild, options);
64
+ return (0, exports.blockToVue)(firstChild, options);
64
65
  },
65
66
  Show: function (json, options) {
66
- var ifValue = strip_state_and_props_refs_1.stripStateAndPropsRefs(json.bindings.when);
67
+ var ifValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(json.bindings.when);
67
68
  if (options.vueVersion >= 3) {
68
- return "\n <template v-if=\"" + ifValue + "\">\n " + json.children.map(function (item) { return exports.blockToVue(item, options); }).join('\n') + "\n </template>\n " + (!json.meta.else
69
+ return "\n <template v-if=\"".concat(ifValue, "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat(!json.meta.else
69
70
  ? ''
70
- : "\n <template v-else>\n " + exports.blockToVue(json.meta.else, options) + "\n </template>\n ") + "\n ";
71
+ : "\n <template v-else>\n ".concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>\n "), "\n ");
71
72
  }
72
73
  var ifString = '';
73
74
  // Vue 2 can only handle one root element
74
75
  var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
75
76
  if (firstChild) {
76
77
  firstChild.properties['v-if'] = ifValue;
77
- ifString = exports.blockToVue(firstChild, options);
78
+ ifString = (0, exports.blockToVue)(firstChild, options);
78
79
  }
79
80
  var elseString = '';
80
81
  var elseBlock = json.meta.else;
81
- if (is_mitosis_node_1.isMitosisNode(elseBlock)) {
82
+ if ((0, is_mitosis_node_1.isMitosisNode)(elseBlock)) {
82
83
  elseBlock.properties['v-else'] = '';
83
- elseString = exports.blockToVue(elseBlock, options);
84
+ elseString = (0, exports.blockToVue)(elseBlock, options);
84
85
  }
85
- return "\n " + ifString + "\n " + elseString + "\n ";
86
+ return "\n ".concat(ifString, "\n ").concat(elseString, "\n ");
86
87
  },
87
88
  };
88
89
  // TODO: Maybe in the future allow defining `string | function` as values
@@ -90,9 +91,9 @@ var BINDING_MAPPERS = {
90
91
  innerHTML: 'v-html',
91
92
  };
92
93
  // Transform <foo.bar key="value" /> to <component :is="foo.bar" key="value" />
93
- function processDynamicComponents(json, options) {
94
- traverse_1.default(json).forEach(function (node) {
95
- if (is_mitosis_node_1.isMitosisNode(node)) {
94
+ function processDynamicComponents(json, _options) {
95
+ (0, traverse_1.default)(json).forEach(function (node) {
96
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
96
97
  if (node.name.includes('.')) {
97
98
  node.bindings.is = node.name;
98
99
  node.name = 'component';
@@ -100,9 +101,9 @@ function processDynamicComponents(json, options) {
100
101
  }
101
102
  });
102
103
  }
103
- function processForKeys(json, options) {
104
- traverse_1.default(json).forEach(function (node) {
105
- if (is_mitosis_node_1.isMitosisNode(node)) {
104
+ function processForKeys(json, _options) {
105
+ (0, traverse_1.default)(json).forEach(function (node) {
106
+ if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
106
107
  if (node.name === 'For') {
107
108
  var firstChild = node.children[0];
108
109
  if (firstChild && firstChild.bindings.key) {
@@ -118,7 +119,7 @@ var blockToVue = function (node, options) {
118
119
  if (nodeMapper) {
119
120
  return nodeMapper(node, options);
120
121
  }
121
- if (is_children_1.default(node)) {
122
+ if ((0, is_children_1.default)(node)) {
122
123
  return "<slot></slot>";
123
124
  }
124
125
  if (node.name === 'style') {
@@ -128,19 +129,19 @@ var blockToVue = function (node, options) {
128
129
  node.properties.is = 'style';
129
130
  }
130
131
  if (node.properties._text) {
131
- return "" + node.properties._text;
132
+ return "".concat(node.properties._text);
132
133
  }
133
134
  if (node.bindings._text) {
134
- return "{{" + strip_state_and_props_refs_1.stripStateAndPropsRefs(node.bindings._text) + "}}";
135
+ return "{{".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._text), "}}");
135
136
  }
136
137
  var str = '';
137
- str += "<" + node.name + " ";
138
+ str += "<".concat(node.name, " ");
138
139
  if (node.bindings._spread) {
139
- str += "v-bind=\"" + strip_state_and_props_refs_1.stripStateAndPropsRefs(node.bindings._spread) + "\"";
140
+ str += "v-bind=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(node.bindings._spread), "\"");
140
141
  }
141
142
  for (var key in node.properties) {
142
143
  var value = node.properties[key];
143
- str += " " + key + "=\"" + value + "\" ";
144
+ str += " ".concat(key, "=\"").concat(value, "\" ");
144
145
  }
145
146
  for (var key in node.bindings) {
146
147
  if (key === '_spread') {
@@ -148,33 +149,33 @@ var blockToVue = function (node, options) {
148
149
  }
149
150
  var value = node.bindings[key];
150
151
  if (key === 'class') {
151
- str += " :class=\"_classStringToObject(" + strip_state_and_props_refs_1.stripStateAndPropsRefs(value, {
152
+ str += " :class=\"_classStringToObject(".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value, {
152
153
  replaceWith: 'this.',
153
- }) + ")\" ";
154
+ }), ")\" ");
154
155
  // TODO: support dynamic classes as objects somehow like Vue requires
155
156
  // https://vuejs.org/v2/guide/class-and-style.html
156
157
  continue;
157
158
  }
158
159
  // TODO: proper babel transform to replace. Util for this
159
- var useValue = strip_state_and_props_refs_1.stripStateAndPropsRefs(value);
160
+ var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(value);
160
161
  if (key.startsWith('on')) {
161
162
  var event_1 = key.replace('on', '').toLowerCase();
162
163
  if (event_1 === 'change' && node.name === 'input') {
163
164
  event_1 = 'input';
164
165
  }
165
166
  // TODO: proper babel transform to replace. Util for this
166
- str += " @" + event_1 + "=\"" + remove_surrounding_block_1.removeSurroundingBlock(useValue
167
+ str += " @".concat(event_1, "=\"").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue
167
168
  // TODO: proper reference parse and replacing
168
- .replace(/event\./g, '$event.')) + "\" ";
169
+ .replace(/event\./g, '$event.')), "\" ");
169
170
  }
170
171
  else if (key === 'ref') {
171
- str += " ref=\"" + useValue + "\" ";
172
+ str += " ref=\"".concat(useValue, "\" ");
172
173
  }
173
174
  else if (BINDING_MAPPERS[key]) {
174
- str += " " + BINDING_MAPPERS[key] + "=\"" + useValue + "\" ";
175
+ str += " ".concat(BINDING_MAPPERS[key], "=\"").concat(useValue, "\" ");
175
176
  }
176
177
  else {
177
- str += " :" + key + "=\"" + useValue + "\" ";
178
+ str += " :".concat(key, "=\"").concat(useValue, "\" ");
178
179
  }
179
180
  }
180
181
  if (jsx_1.selfClosingTags.has(node.name)) {
@@ -182,15 +183,15 @@ var blockToVue = function (node, options) {
182
183
  }
183
184
  str += '>';
184
185
  if (node.children) {
185
- str += node.children.map(function (item) { return exports.blockToVue(item, options); }).join('');
186
+ str += node.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('');
186
187
  }
187
- return str + ("</" + node.name + ">");
188
+ return str + "</".concat(node.name, ">");
188
189
  };
189
190
  exports.blockToVue = blockToVue;
190
191
  function getContextInjectString(component, options) {
191
192
  var str = '{';
192
193
  for (var key in component.context.get) {
193
- str += "\n " + key + ": \"" + component.context.get[key].name + "\",\n ";
194
+ str += "\n ".concat(key, ": \"").concat(component.context.get[key].name, "\",\n ");
194
195
  }
195
196
  str += '}';
196
197
  return str;
@@ -199,150 +200,150 @@ function getContextProvideString(component, options) {
199
200
  var str = '{';
200
201
  for (var key in component.context.set) {
201
202
  var _a = component.context.set[key], value = _a.value, name_1 = _a.name;
202
- str += "\n " + name_1 + ": " + (value
203
- ? get_state_object_string_1.getMemberObjectString(value, {
203
+ str += "\n ".concat(name_1, ": ").concat(value
204
+ ? (0, get_state_object_string_1.getMemberObjectString)(value, {
204
205
  valueMapper: function (code) {
205
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(code, { replaceWith: '_this.' });
206
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, { replaceWith: '_this.' });
206
207
  },
207
208
  })
208
- : null) + ",\n ";
209
+ : null, ",\n ");
209
210
  }
210
211
  str += '}';
211
212
  return str;
212
213
  }
213
- var componentToVue = function (component, options) {
214
+ var componentToVue = function (options) {
214
215
  if (options === void 0) { options = {}; }
215
- // Make a copy we can safely mutate, similar to babel's toolchain can be used
216
- component = fast_clone_1.fastClone(component);
217
- process_http_requests_1.processHttpRequests(component);
218
- processDynamicComponents(component, options);
219
- processForKeys(component, options);
220
- if (options.plugins) {
221
- component = plugins_1.runPreJsonPlugins(component, options.plugins);
222
- }
223
- map_refs_1.mapRefs(component, function (refName) { return "this.$refs." + refName; });
224
- if (options.plugins) {
225
- component = plugins_1.runPostJsonPlugins(component, options.plugins);
226
- }
227
- var css = collect_styles_1.collectCss(component, {
228
- prefix: options.cssNamespace,
229
- });
230
- var dataString = get_state_object_string_1.getStateObjectStringFromComponent(component, {
231
- data: true,
232
- functions: false,
233
- getters: false,
234
- });
235
- var getterString = get_state_object_string_1.getStateObjectStringFromComponent(component, {
236
- data: false,
237
- getters: true,
238
- functions: false,
239
- valueMapper: function (code) {
240
- return processBinding(code.replace(/^get /, ''), options, component);
241
- },
242
- });
243
- var functionsString = get_state_object_string_1.getStateObjectStringFromComponent(component, {
244
- data: false,
245
- getters: false,
246
- functions: true,
247
- valueMapper: function (code) { return processBinding(code, options, component); },
248
- });
249
- var blocksString = JSON.stringify(component.children);
250
- // Component references to include in `component: { YourComponent, ... }
251
- var componentsUsed = Array.from(get_components_used_1.getComponentsUsed(component))
252
- .filter(function (name) {
253
- return name.length && !name.includes('.') && name[0].toUpperCase() === name[0];
254
- })
255
- // Strip out components that compile away
256
- .filter(function (name) { return !['For', 'Show', 'Fragment', component.name].includes(name); });
257
- // Append refs to data as { foo, bar, etc }
258
- dataString = dataString.replace(/}$/, component.imports
259
- .map(function (thisImport) { return Object.keys(thisImport.imports).join(','); })
260
- // Make sure actually used in template
261
- .filter(function (key) { return Boolean(key && blocksString.includes(key)); })
262
- // Don't include component imports
263
- .filter(function (key) { return !componentsUsed.includes(key); })
264
- .join(',') + "}");
265
- var elementProps = get_props_1.getProps(component);
266
- strip_meta_properties_1.stripMetaProperties(component);
267
- var template = component.children
268
- .map(function (item) { return exports.blockToVue(item, options); })
269
- .join('\n');
270
- var includeClassMapHelper = template.includes('_classStringToObject');
271
- if (includeClassMapHelper) {
272
- functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/); \n for (const name of classNames) {\n obj[name] = true;\n } \n return obj;\n } }");
273
- }
274
- var builderRegister = Boolean(options.builderRegister && component.meta.registerComponent);
275
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n <script>\n ", "\n ", "\n\n export default ", "{\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n }", "\n </script>\n ", "\n "], ["\n <template>\n ", "\n </template>\n <script>\n ", "\n ",
276
- "\n\n export default ", "{\n ",
277
- "\n ",
278
- "\n ",
279
- "\n ",
280
- "\n\n ",
281
- "\n ",
282
- "\n\n ",
283
- "\n ",
284
- "\n\n ",
285
- "\n ",
286
- "\n }",
287
- "\n </script>\n ",
288
- "\n "])), template, render_imports_1.renderPreComponent(component), !builderRegister
289
- ? ''
290
- : "import { registerComponent } from '@builder.io/sdk-vue'", !builderRegister ? '' : 'registerComponent(', !component.name
291
- ? ''
292
- : "name: '" + (options.namePrefix ? options.namePrefix + '-' : '') + lodash_1.kebabCase(component.name) + "',", !componentsUsed.length
293
- ? ''
294
- : "components: { " + componentsUsed
295
- .map(function (componentName) {
296
- return "'" + lodash_1.kebabCase(componentName) + "': async () => " + componentName;
216
+ // hack while we migrate all other transpilers to receive/handle path
217
+ // TO-DO: use `Transpiler` once possible
218
+ return function (_a) {
219
+ var _b, _c, _d, _e, _f;
220
+ var component = _a.component, path = _a.path;
221
+ // Make a copy we can safely mutate, similar to babel's toolchain can be used
222
+ component = (0, fast_clone_1.fastClone)(component);
223
+ (0, process_http_requests_1.processHttpRequests)(component);
224
+ processDynamicComponents(component, options);
225
+ processForKeys(component, options);
226
+ if (options.plugins) {
227
+ component = (0, plugins_1.runPreJsonPlugins)(component, options.plugins);
228
+ }
229
+ (0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
230
+ if (options.plugins) {
231
+ component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
232
+ }
233
+ var css = (0, collect_styles_1.collectCss)(component, {
234
+ prefix: (_c = (_b = options.cssNamespace) === null || _b === void 0 ? void 0 : _b.call(options)) !== null && _c !== void 0 ? _c : undefined,
235
+ });
236
+ var dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
237
+ data: true,
238
+ functions: false,
239
+ getters: false,
240
+ });
241
+ var getterString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
242
+ data: false,
243
+ getters: true,
244
+ functions: false,
245
+ valueMapper: function (code) {
246
+ return processBinding(code.replace(patterns_1.GETTER, ''), options, component);
247
+ },
248
+ });
249
+ var functionsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(component, {
250
+ data: false,
251
+ getters: false,
252
+ functions: true,
253
+ valueMapper: function (code) { return processBinding(code, options, component); },
254
+ });
255
+ var blocksString = JSON.stringify(component.children);
256
+ // Component references to include in `component: { YourComponent, ... }
257
+ var componentsUsed = Array.from((0, get_components_used_1.getComponentsUsed)(component))
258
+ .filter(function (name) {
259
+ return name.length &&
260
+ !name.includes('.') &&
261
+ name[0].toUpperCase() === name[0];
297
262
  })
298
- .join(',') + " },", elementProps.size
299
- ? "props: " + JSON.stringify(Array.from(elementProps).filter(function (prop) { return prop !== 'children' && prop !== 'class'; })) + ","
300
- : '', dataString.length < 4
301
- ? ''
302
- : "\n data: () => (" + dataString + "),\n ", lodash_1.size(component.context.set)
303
- ? "provide() {\n const _this = this;\n return " + getContextProvideString(component, options) + "\n },"
304
- : '', lodash_1.size(component.context.get)
305
- ? "inject: " + getContextInjectString(component, options) + ","
306
- : '', component.hooks.onMount
307
- ? "mounted() {\n " + processBinding(component.hooks.onMount, options, component) + "\n },"
308
- : '', component.hooks.onUnMount
309
- ? "unmounted() {\n " + processBinding(component.hooks.onUnMount, options, component) + "\n },"
310
- : '', getterString.length < 4
311
- ? ''
312
- : "\n computed: " + getterString + ",\n ", functionsString.length < 4
313
- ? ''
314
- : "\n methods: " + functionsString + ",\n ", !builderRegister
315
- ? ''
316
- : ", " + json5_1.default.stringify(component.meta.registerComponent || {}) + ")", !css.trim().length
317
- ? ''
318
- : "<style scoped>\n " + css + "\n </style>");
319
- if (options.plugins) {
320
- str = plugins_1.runPreCodePlugins(str, options.plugins);
321
- }
322
- if (true || options.prettier !== false) {
323
- try {
324
- str = standalone_1.format(str, {
325
- parser: 'vue',
326
- plugins: [
327
- // To support running in browsers
328
- require('prettier/parser-html'),
329
- require('prettier/parser-postcss'),
330
- require('prettier/parser-babel'),
331
- ],
332
- });
263
+ // Strip out components that compile away
264
+ .filter(function (name) { return !['For', 'Show', 'Fragment', component.name].includes(name); });
265
+ // Append refs to data as { foo, bar, etc }
266
+ dataString = dataString.replace(/}$/, "".concat(component.imports
267
+ .map(function (thisImport) { return Object.keys(thisImport.imports).join(','); })
268
+ // Make sure actually used in template
269
+ .filter(function (key) { return Boolean(key && blocksString.includes(key)); })
270
+ // Don't include component imports
271
+ .filter(function (key) { return !componentsUsed.includes(key); })
272
+ .join(','), "}"));
273
+ var elementProps = (0, get_props_1.getProps)(component);
274
+ (0, strip_meta_properties_1.stripMetaProperties)(component);
275
+ var template = component.children
276
+ .map(function (item) { return (0, exports.blockToVue)(item, options); })
277
+ .join('\n');
278
+ var includeClassMapHelper = template.includes('_classStringToObject');
279
+ if (includeClassMapHelper) {
280
+ functionsString = functionsString.replace(/}\s*$/, "_classStringToObject(str) {\n const obj = {};\n if (typeof str !== 'string') { return obj }\n const classNames = str.trim().split(/\\s+/); \n for (const name of classNames) {\n obj[name] = true;\n } \n return obj;\n } }");
333
281
  }
334
- catch (err) {
335
- console.warn('Could not prettify', { string: str }, err);
282
+ var builderRegister = Boolean(options.builderRegister && component.meta.registerComponent);
283
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <template>\n ", "\n </template>\n <script>\n ", "\n ", "\n\n export default ", "{\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n }", "\n </script>\n ", "\n "], ["\n <template>\n ", "\n </template>\n <script>\n ", "\n ", "\n\n export default ", "{\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n }", "\n </script>\n ", "\n "])), template, (0, render_imports_1.renderPreComponent)(component), component.meta.registerComponent
284
+ ? (_d = options.registerComponentPrepend) !== null && _d !== void 0 ? _d : ''
285
+ : '', !builderRegister ? '' : 'registerComponent(', !component.name
286
+ ? ''
287
+ : "name: '".concat(((_e = options.namePrefix) === null || _e === void 0 ? void 0 : _e.call(options, path))
288
+ ? ((_f = options.namePrefix) === null || _f === void 0 ? void 0 : _f.call(options, path)) + '-'
289
+ : '').concat((0, lodash_1.kebabCase)(component.name), "',"), !componentsUsed.length
290
+ ? ''
291
+ : "components: { ".concat(componentsUsed
292
+ .map(function (componentName) {
293
+ return "'".concat((0, lodash_1.kebabCase)(componentName), "': async () => ").concat(componentName);
294
+ })
295
+ .join(','), " },"), elementProps.size
296
+ ? "props: ".concat(JSON.stringify(Array.from(elementProps).filter(function (prop) { return prop !== 'children' && prop !== 'class'; })), ",")
297
+ : '', dataString.length < 4
298
+ ? ''
299
+ : "\n data: () => (".concat(dataString, "),\n "), (0, lodash_1.size)(component.context.set)
300
+ ? "provide() {\n const _this = this;\n return ".concat(getContextProvideString(component, options), "\n },")
301
+ : '', (0, lodash_1.size)(component.context.get)
302
+ ? "inject: ".concat(getContextInjectString(component, options), ",")
303
+ : '', component.hooks.onMount
304
+ ? "mounted() {\n ".concat(processBinding(component.hooks.onMount, options, component), "\n },")
305
+ : '', component.hooks.onUnMount
306
+ ? "unmounted() {\n ".concat(processBinding(component.hooks.onUnMount, options, component), "\n },")
307
+ : '', getterString.length < 4
308
+ ? ''
309
+ : "\n computed: ".concat(getterString, ",\n "), functionsString.length < 4
310
+ ? ''
311
+ : "\n methods: ".concat(functionsString, ",\n "), !builderRegister
312
+ ? ''
313
+ : ", ".concat(json5_1.default.stringify(component.meta.registerComponent || {}), ")"), !css.trim().length
314
+ ? ''
315
+ : "<style scoped>\n ".concat(css, "\n </style>"));
316
+ if (options.plugins) {
317
+ str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
336
318
  }
337
- }
338
- if (options.plugins) {
339
- str = plugins_1.runPostCodePlugins(str, options.plugins);
340
- }
341
- for (var _i = 0, removePatterns_1 = removePatterns; _i < removePatterns_1.length; _i++) {
342
- var pattern = removePatterns_1[_i];
343
- str = str.replace(pattern, '');
344
- }
345
- return str;
319
+ if (true || options.prettier !== false) {
320
+ try {
321
+ str = (0, standalone_1.format)(str, {
322
+ parser: 'vue',
323
+ plugins: [
324
+ // To support running in browsers
325
+ require('prettier/parser-html'),
326
+ require('prettier/parser-postcss'),
327
+ require('prettier/parser-babel'),
328
+ ],
329
+ });
330
+ }
331
+ catch (err) {
332
+ console.warn('Could not prettify', { string: str }, err);
333
+ }
334
+ }
335
+ if (options.plugins) {
336
+ str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
337
+ }
338
+ for (var _i = 0, removePatterns_1 = removePatterns; _i < removePatterns_1.length; _i++) {
339
+ var pattern = removePatterns_1[_i];
340
+ str = str.replace(pattern, '');
341
+ }
342
+ // Transform <FooBar> to <foo-bar> as Vue2 needs
343
+ return str.replace(/<\/?\w+/g, function (match) {
344
+ return match.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
345
+ });
346
+ };
346
347
  };
347
348
  exports.componentToVue = componentToVue;
348
349
  // Remove unused artifacts like empty script or style tags
@@ -37,7 +37,7 @@ var babelTransform = function (code, visitor) {
37
37
  exports.babelTransform = babelTransform;
38
38
  var babelTransformCode = function (code, visitor) {
39
39
  var _a;
40
- return ((_a = exports.babelTransform(code, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
40
+ return ((_a = (0, exports.babelTransform)(code, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
41
41
  };
42
42
  exports.babelTransformCode = babelTransformCode;
43
43
  var babelTransformExpression = function (code, visitor, type) {
@@ -59,13 +59,13 @@ var babelTransformExpression = function (code, visitor, type) {
59
59
  }
60
60
  var useCode = code;
61
61
  if (type === 'functionBody') {
62
- useCode = "function(){" + useCode + "}";
62
+ useCode = "function(){".concat(useCode, "}");
63
63
  }
64
64
  var result = type === 'expression'
65
65
  ? null
66
- : lodash_1.attempt(function () {
66
+ : (0, lodash_1.attempt)(function () {
67
67
  var _a;
68
- var result = ((_a = exports.babelTransform(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
68
+ var result = ((_a = (0, exports.babelTransform)(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '';
69
69
  if (type === 'functionBody') {
70
70
  return result.replace(/^function\(\)\{/, '').replace(/\};$/, '');
71
71
  }
@@ -76,7 +76,7 @@ var babelTransformExpression = function (code, visitor, type) {
76
76
  return result.replace(/;$/, '');
77
77
  }
78
78
  });
79
- if (lodash_1.isError(result) || type === 'expression') {
79
+ if ((0, lodash_1.isError)(result) || type === 'expression') {
80
80
  try {
81
81
  // If it can't, e.g. this is an expression or code fragment, modify the code below and try again
82
82
  // Detect method fragments. These get passed sometimes and otherwise
@@ -84,13 +84,13 @@ var babelTransformExpression = function (code, visitor, type) {
84
84
  var isMethod = Boolean(!code.startsWith('function') &&
85
85
  code.match(/^[a-z0-9]+\s*\([^\)]*\)\s*[\{:]/i));
86
86
  if (isMethod) {
87
- useCode = "function " + useCode;
87
+ useCode = "function ".concat(useCode);
88
88
  }
89
89
  // Parse the code as an expression (instead of the default, a block) by giving it a fake variable assignment
90
90
  // e.g. if the code parsed is { ... } babel will treat that as a block by deafult, unless processed as an expression
91
91
  // that is an object
92
- useCode = "let _ = " + useCode;
93
- result = (((_a = exports.babelTransform(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '')
92
+ useCode = "let _ = ".concat(useCode);
93
+ result = (((_a = (0, exports.babelTransform)(useCode, visitor)) === null || _a === void 0 ? void 0 : _a.code) || '')
94
94
  // Babel addes trailing semicolons, but for expressions we need those gone
95
95
  .replace(/;$/, '')
96
96
  // Remove our fake variable assignment
@@ -102,7 +102,7 @@ var babelTransformExpression = function (code, visitor, type) {
102
102
  catch (err) {
103
103
  console.error('Error parsing code:\n', code, '\n', result);
104
104
  try {
105
- return exports.babelTransformExpression(code, visitor, 'functionBody');
105
+ return (0, exports.babelTransformExpression)(code, visitor, 'functionBody');
106
106
  }
107
107
  catch (err) {
108
108
  throw err;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This is a function similar to loadash `camelCase`, but it does not mess with capitalization.
3
+ *
4
+ * loadash: `camelCase('A-BC')` => "ABc"
5
+ * this fn: `camelCase('A-BC')` => "ABC"
6
+ *
7
+ */
8
+ export declare function camelCase(text?: string): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelCase = void 0;
4
+ var capitalize_1 = require("./capitalize");
5
+ /**
6
+ * This is a function similar to loadash `camelCase`, but it does not mess with capitalization.
7
+ *
8
+ * loadash: `camelCase('A-BC')` => "ABc"
9
+ * this fn: `camelCase('A-BC')` => "ABC"
10
+ *
11
+ */
12
+ function camelCase(text) {
13
+ if (text === void 0) { text = ''; }
14
+ var parts = text.split('-');
15
+ var first = parts.shift();
16
+ return first + parts.map(capitalize_1.capitalize).join('');
17
+ }
18
+ exports.camelCase = camelCase;