@builder.io/mitosis 0.0.45 → 0.0.46

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 (206) hide show
  1. package/dist/src/__tests__/builder.test.js +71 -68
  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 +36 -36
  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.js +13 -13
  34. package/dist/src/generators/qwik/handlers.js +12 -8
  35. package/dist/src/generators/qwik/jsx.js +13 -9
  36. package/dist/src/generators/qwik/styles.js +11 -7
  37. package/dist/src/generators/react-native.d.ts +4 -7
  38. package/dist/src/generators/react-native.js +25 -22
  39. package/dist/src/generators/react.d.ts +4 -8
  40. package/dist/src/generators/react.js +103 -112
  41. package/dist/src/generators/solid.d.ts +4 -8
  42. package/dist/src/generators/solid.js +55 -54
  43. package/dist/src/generators/svelte.d.ts +4 -7
  44. package/dist/src/generators/svelte.js +120 -123
  45. package/dist/src/generators/swift-ui.d.ts +2 -2
  46. package/dist/src/generators/swift-ui.js +62 -62
  47. package/dist/src/generators/template.d.ts +4 -8
  48. package/dist/src/generators/template.js +48 -45
  49. package/dist/src/generators/vue.d.ts +9 -9
  50. package/dist/src/generators/vue.js +169 -169
  51. package/dist/src/helpers/babel-transform.js +9 -9
  52. package/dist/src/helpers/collect-styles.js +39 -39
  53. package/dist/src/helpers/dash-case.js +1 -1
  54. package/dist/src/helpers/generic-format.test.js +2 -2
  55. package/dist/src/helpers/get-components-used.js +2 -2
  56. package/dist/src/helpers/get-components.js +3 -3
  57. package/dist/src/helpers/get-props.js +1 -1
  58. package/dist/src/helpers/get-refs.js +2 -2
  59. package/dist/src/helpers/get-state-object-string.js +5 -5
  60. package/dist/src/helpers/get-state-used.js +1 -1
  61. package/dist/src/helpers/get-styles.js +1 -1
  62. package/dist/src/helpers/getters-to-functions.js +4 -4
  63. package/dist/src/helpers/handle-missing-state.js +1 -1
  64. package/dist/src/helpers/has-component.js +2 -2
  65. package/dist/src/helpers/has-props.js +1 -1
  66. package/dist/src/helpers/is-children.js +1 -1
  67. package/dist/src/helpers/json.d.ts +1 -0
  68. package/dist/src/helpers/json.js +17 -0
  69. package/dist/src/helpers/map-refs.js +4 -4
  70. package/dist/src/helpers/map-to-attributes.js +4 -4
  71. package/dist/src/helpers/map-to-css.js +2 -2
  72. package/dist/src/helpers/parse-node.js +2 -2
  73. package/dist/src/helpers/parse-reactive-script.js +4 -4
  74. package/dist/src/helpers/process-http-requests.js +1 -1
  75. package/dist/src/helpers/process-tag-references.js +4 -4
  76. package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
  77. package/dist/src/helpers/render-imports.js +7 -7
  78. package/dist/src/helpers/replace-idenifiers.js +1 -1
  79. package/dist/src/helpers/strip-meta-properties.js +2 -2
  80. package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
  81. package/dist/src/helpers/traverse-nodes.js +2 -2
  82. package/dist/src/helpers/try-prettier-format.js +1 -1
  83. package/dist/src/index.d.ts +2 -0
  84. package/dist/src/index.js +2 -0
  85. package/dist/src/modules/plugins.d.ts +2 -10
  86. package/dist/src/parsers/angular.js +13 -13
  87. package/dist/src/parsers/builder.js +54 -58
  88. package/dist/src/parsers/context.js +2 -2
  89. package/dist/src/parsers/jsx.js +59 -87
  90. package/dist/src/parsers/liquid.js +191 -194
  91. package/dist/src/plugins/compile-away-builder-components.js +49 -45
  92. package/dist/src/plugins/compile-away-components.js +3 -3
  93. package/dist/src/plugins/map-styles.js +3 -3
  94. package/dist/src/targets.d.ts +24 -0
  95. package/dist/src/targets.js +30 -0
  96. package/dist/src/types/config.d.ts +31 -0
  97. package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
  98. package/dist/{test/qwik/Todo/Todo.js/low.js → src/types/generators.d.ts} +0 -0
  99. package/dist/src/types/generators.js +1 -0
  100. package/dist/src/types/plugins.d.ts +11 -0
  101. package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
  102. package/dist/test/qwik/{Todo → todo}/Todo.cjs/high.cjs +0 -0
  103. package/dist/test/qwik/{Todo → todo}/Todo.cjs/low.cjs +0 -0
  104. package/dist/test/qwik/{Todo → todo}/Todo.cjs/med.cjs +0 -0
  105. package/dist/test/qwik/{Todo → todo}/Todo.js/high.js +0 -0
  106. package/dist/test/qwik/{qwik/todo → todo}/Todo.js/low.js +0 -0
  107. package/dist/test/qwik/{Todo → todo}/Todo.js/med.js +0 -0
  108. package/dist/test/qwik/{Todo → todo}/Todo.tsx/high.tsx +0 -0
  109. package/dist/test/qwik/{Todo → todo}/Todo.tsx/low.tsx +0 -0
  110. package/dist/test/qwik/{Todo → todo}/Todo.tsx/med.tsx +0 -0
  111. package/dist/test/qwik/{Todos → todos}/Todo.tsx/high.tsx +0 -0
  112. package/dist/test/qwik/{Todos → todos}/Todo.tsx/low.tsx +0 -0
  113. package/dist/test/qwik/{Todos → todos}/Todo.tsx/med.tsx +0 -0
  114. package/dist/tsconfig.tsbuildinfo +1 -1
  115. package/package.json +2 -2
  116. package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
  117. package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
  118. package/dist/src/__tests__/qoot.test.d.ts +0 -1
  119. package/dist/src/__tests__/qoot.test.js +0 -115
  120. package/dist/src/generators/jsx-lite.d.ts +0 -10
  121. package/dist/src/generators/jsx-lite.js +0 -176
  122. package/dist/src/generators/qoot.d.ts +0 -21
  123. package/dist/src/generators/qoot.js +0 -442
  124. package/dist/src/generators/qwik.d.ts +0 -21
  125. package/dist/src/generators/qwik.js +0 -458
  126. package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
  127. package/dist/src/helpers/create-jsx-lite-component.js +0 -16
  128. package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
  129. package/dist/src/helpers/create-jsx-lite-context.js +0 -18
  130. package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
  131. package/dist/src/helpers/create-jsx-lite-node.js +0 -16
  132. package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
  133. package/dist/src/helpers/is-jsx-lite-node.js +0 -7
  134. package/dist/src/types/jsx-lite-component.d.ts +0 -63
  135. package/dist/src/types/jsx-lite-context.d.ts +0 -6
  136. package/dist/src/types/jsx-lite-node.d.ts +0 -13
  137. package/dist/src/types/jsx-lite-node.js +0 -2
  138. package/dist/src/types/jsx-lite-styles.d.ts +0 -1
  139. package/dist/src/types/jsx-lite-styles.js +0 -2
  140. package/dist/test/qoot/Todo/bundle.js +0 -88
  141. package/dist/test/qoot/Todo/component.ts +0 -17
  142. package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
  143. package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
  144. package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
  145. package/dist/test/qoot/Todo/onInputClick.ts +0 -10
  146. package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
  147. package/dist/test/qoot/Todo/public.ts +0 -4
  148. package/dist/test/qoot/Todo/template.tsx +0 -46
  149. package/dist/test/qoot/Todos/component.ts +0 -9
  150. package/dist/test/qoot/Todos/onInputClick.ts +0 -14
  151. package/dist/test/qoot/Todos/public.ts +0 -3
  152. package/dist/test/qoot/Todos/template.tsx +0 -30
  153. package/dist/test/qwik/Todo/bundle.js +0 -46
  154. package/dist/test/qwik/Todo/component.ts +0 -17
  155. package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
  156. package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
  157. package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
  158. package/dist/test/qwik/Todo/onInputClick.ts +0 -13
  159. package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
  160. package/dist/test/qwik/Todo/public.ts +0 -3
  161. package/dist/test/qwik/Todo/template.tsx +0 -46
  162. package/dist/test/qwik/Todo.ts +0 -4
  163. package/dist/test/qwik/Todo_component.ts +0 -17
  164. package/dist/test/qwik/Todo_onButtonClick.ts +0 -13
  165. package/dist/test/qwik/Todo_onInput2Blur.ts +0 -14
  166. package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
  167. package/dist/test/qwik/Todo_onInputClick.ts +0 -13
  168. package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -14
  169. package/dist/test/qwik/Todo_template.tsx +0 -46
  170. package/dist/test/qwik/Todos/component.ts +0 -9
  171. package/dist/test/qwik/Todos/onInputClick.ts +0 -14
  172. package/dist/test/qwik/Todos/public.ts +0 -3
  173. package/dist/test/qwik/Todos/template.tsx +0 -30
  174. package/dist/test/qwik/Todos.ts +0 -3
  175. package/dist/test/qwik/Todos_component.ts +0 -9
  176. package/dist/test/qwik/Todos_onInputClick.ts +0 -14
  177. package/dist/test/qwik/Todos_template.tsx +0 -30
  178. package/dist/test/qwik/qwik/Image/high.js +0 -1
  179. package/dist/test/qwik/qwik/Image/low.js +0 -75
  180. package/dist/test/qwik/qwik/Image/med.js +0 -9
  181. package/dist/test/qwik/qwik/Image.slow/high.js +0 -1
  182. package/dist/test/qwik/qwik/Image.slow/low.js +0 -75
  183. package/dist/test/qwik/qwik/Image.slow/med.js +0 -9
  184. package/dist/test/qwik/qwik/button/high.js +0 -8
  185. package/dist/test/qwik/qwik/button/low.js +0 -34
  186. package/dist/test/qwik/qwik/button/med.js +0 -9
  187. package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +0 -1
  188. package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +0 -24
  189. package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +0 -9
  190. package/dist/test/qwik/qwik/page-with-symbol/high.js +0 -1
  191. package/dist/test/qwik/qwik/page-with-symbol/low.js +0 -49
  192. package/dist/test/qwik/qwik/page-with-symbol/med.js +0 -9
  193. package/dist/test/qwik/qwik/svg/high.js +0 -1
  194. package/dist/test/qwik/qwik/svg/low.js +0 -30
  195. package/dist/test/qwik/qwik/svg/med.js +0 -9
  196. package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +0 -31
  197. package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +0 -1
  198. package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +0 -59
  199. package/dist/test/qwik/qwik/todo/Todo.js/high.js +0 -5
  200. package/dist/test/qwik/qwik/todo/Todo.js/med.js +0 -1
  201. package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +0 -30
  202. package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +0 -1
  203. package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +0 -34
  204. package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +0 -12
  205. package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +0 -24
  206. package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +0 -8
@@ -3,23 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contextToReact = void 0;
4
4
  var standalone_1 = require("prettier/standalone");
5
5
  var get_state_object_string_1 = require("../../helpers/get-state-object-string");
6
- function contextToReact(context, options) {
6
+ var contextToReact = function (options) {
7
7
  if (options === void 0) { options = {}; }
8
- var str = "\n import { createContext } from 'react';\n\n export default createContext(" + get_state_object_string_1.getMemberObjectString(context.value) + ")\n ";
9
- if (options.format !== false) {
10
- try {
11
- str = standalone_1.format(str, {
12
- parser: 'typescript',
13
- plugins: [
14
- require('prettier/parser-typescript'), // To support running in browsers
15
- ],
16
- });
8
+ return function (_a) {
9
+ var context = _a.context;
10
+ var str = "\n import { createContext } from 'react';\n\n export default createContext(".concat((0, get_state_object_string_1.getMemberObjectString)(context.value), ")\n ");
11
+ if (options.format !== false) {
12
+ try {
13
+ str = (0, standalone_1.format)(str, {
14
+ parser: 'typescript',
15
+ plugins: [
16
+ require('prettier/parser-typescript'), // To support running in browsers
17
+ ],
18
+ });
19
+ }
20
+ catch (err) {
21
+ console.error('Format error for file:', str);
22
+ throw err;
23
+ }
17
24
  }
18
- catch (err) {
19
- console.error('Format error for file:', str);
20
- throw err;
21
- }
22
- }
23
- return str;
24
- }
25
+ return str;
26
+ };
27
+ };
25
28
  exports.contextToReact = contextToReact;
@@ -1,11 +1,7 @@
1
- import { MitosisComponent } from '../types/mitosis-component';
2
- import { Plugin } from '../modules/plugins';
3
- declare type ToHtmlOptions = {
4
- prettier?: boolean;
1
+ import { BaseTranspilerOptions, Transpiler } from '../types/config';
2
+ export interface ToHtmlOptions extends BaseTranspilerOptions {
5
3
  format?: 'class' | 'script';
6
- plugins?: Plugin[];
7
4
  prefix?: string;
8
- };
9
- export declare const componentToHtml: (componentJson: MitosisComponent, options?: ToHtmlOptions) => string;
10
- export declare const componentToCustomElement: (componentJson: MitosisComponent, options?: ToHtmlOptions) => string;
11
- export {};
5
+ }
6
+ export declare const componentToHtml: (options?: ToHtmlOptions) => Transpiler;
7
+ export declare const componentToCustomElement: (options?: ToHtmlOptions) => Transpiler;
@@ -36,8 +36,8 @@ var is_children_1 = __importDefault(require("../helpers/is-children"));
36
36
  var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
37
37
  var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
38
38
  var addUpdateAfterSet = function (json, options) {
39
- traverse_1.default(json).forEach(function (item) {
40
- if (is_mitosis_node_1.isMitosisNode(item)) {
39
+ (0, traverse_1.default)(json).forEach(function (item) {
40
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
41
41
  for (var key in item.bindings) {
42
42
  var value = item.bindings[key];
43
43
  var newValue = addUpdateAfterSetInCode(value, options);
@@ -50,8 +50,8 @@ var addUpdateAfterSet = function (json, options) {
50
50
  };
51
51
  var getForNames = function (json) {
52
52
  var names = [];
53
- traverse_1.default(json).forEach(function (item) {
54
- if (is_mitosis_node_1.isMitosisNode(item)) {
53
+ (0, traverse_1.default)(json).forEach(function (item) {
54
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
55
55
  if (item.name === 'For') {
56
56
  names.push(item.properties._forName);
57
57
  }
@@ -62,16 +62,16 @@ var getForNames = function (json) {
62
62
  var replaceForNameIdentifiers = function (json, options) {
63
63
  // TODO: cache this. by reference? lru?
64
64
  var forNames = getForNames(json);
65
- traverse_1.default(json).forEach(function (item) {
66
- if (is_mitosis_node_1.isMitosisNode(item)) {
65
+ (0, traverse_1.default)(json).forEach(function (item) {
66
+ if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
67
67
  for (var key in item.bindings) {
68
68
  if (key === 'css' || key === '_forName') {
69
69
  continue;
70
70
  }
71
71
  var value = item.bindings[key];
72
72
  if (typeof value === 'string') {
73
- item.bindings[key] = replace_idenifiers_1.replaceIdentifiers(value, forNames, function (name) {
74
- return (options.format === 'class' ? 'this.' : '') + "getContext(el, \"" + name + "\")";
73
+ item.bindings[key] = (0, replace_idenifiers_1.replaceIdentifiers)(value, forNames, function (name) {
74
+ return "".concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(name, "\")");
75
75
  });
76
76
  }
77
77
  }
@@ -85,17 +85,17 @@ var mappers = {
85
85
  };
86
86
  var getId = function (json, options) {
87
87
  var name = json.properties.$name
88
- ? dash_case_1.dashCase(json.properties.$name)
88
+ ? (0, dash_case_1.dashCase)(json.properties.$name)
89
89
  : /^h\d$/.test(json.name || '') // don't dashcase h1 into h-1
90
90
  ? json.name
91
- : dash_case_1.dashCase(json.name || 'div');
91
+ : (0, dash_case_1.dashCase)(json.name || 'div');
92
92
  var newNameNum = (options.namesMap[name] || 0) + 1;
93
93
  options.namesMap[name] = newNameNum;
94
- return "" + name + (options.prefix ? "-" + options.prefix : '') + (name !== json.name && newNameNum === 1 ? '' : "-" + newNameNum);
94
+ return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '').concat(name !== json.name && newNameNum === 1 ? '' : "-".concat(newNameNum));
95
95
  };
96
96
  var updateReferencesInCode = function (code, options) {
97
97
  if (options.format === 'class') {
98
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(strip_state_and_props_refs_1.stripStateAndPropsRefs(code, {
98
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
99
99
  includeProps: false,
100
100
  includeState: true,
101
101
  replaceWith: 'this.state.',
@@ -125,16 +125,16 @@ var blockToHtml = function (json, options) {
125
125
  if (mappers[json.name]) {
126
126
  return mappers[json.name](json, options);
127
127
  }
128
- if (is_children_1.default(json)) {
128
+ if ((0, is_children_1.default)(json)) {
129
129
  return "<slot></slot>";
130
130
  }
131
131
  if (json.properties._text) {
132
132
  return json.properties._text;
133
133
  }
134
134
  if (json.bindings._text) {
135
- addOnChangeJs(elId, options, "el.innerText = " + json.bindings._text + ";");
136
- return "<span data-name=\"" + elId + "\"><!-- " + json.bindings
137
- ._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1') + " --></span>";
135
+ addOnChangeJs(elId, options, "el.innerText = ".concat(json.bindings._text, ";"));
136
+ return "<span data-name=\"".concat(elId, "\"><!-- ").concat(json.bindings
137
+ ._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1'), " --></span>");
138
138
  }
139
139
  var str = '';
140
140
  if (json.name === 'For') {
@@ -142,24 +142,24 @@ var blockToHtml = function (json, options) {
142
142
  addOnChangeJs(elId, options,
143
143
  // TODO: be smarter about rendering, deleting old items and adding new ones by
144
144
  // querying dom potentially
145
- "\n let array = " + json.bindings.each + ";\n let template = " + (options.format === 'class' ? 'this' : 'document') + ".querySelector('[data-template-for=\"" + elId + "\"]');\n " + (options.format === 'class' ? 'this.' : '') + "renderLoop(el, array, template, \"" + itemName + "\");\n ");
145
+ "\n let array = ".concat(json.bindings.each, ";\n let template = ").concat(options.format === 'class' ? 'this' : 'document', ".querySelector('[data-template-for=\"").concat(elId, "\"]');\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, template, \"").concat(itemName, "\");\n "));
146
146
  // TODO: decide on how to handle this...
147
- str += "\n <span data-name=\"" + elId + "\"></span>\n <template data-template-for=\"" + elId + "\">";
147
+ str += "\n <span data-name=\"".concat(elId, "\"></span>\n <template data-template-for=\"").concat(elId, "\">");
148
148
  if (json.children) {
149
149
  str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
150
150
  }
151
151
  str += '</template>';
152
152
  }
153
153
  else if (json.name === 'Show') {
154
- addOnChangeJs(elId, options, "el.style.display = " + json.bindings.when.replace(/;$/, '') + " ? 'inline' : 'none'");
155
- str += "<span data-name=\"" + elId + "\">";
154
+ addOnChangeJs(elId, options, "el.style.display = ".concat(json.bindings.when.replace(/;$/, ''), " ? 'inline' : 'none'"));
155
+ str += "<span data-name=\"".concat(elId, "\">");
156
156
  if (json.children) {
157
157
  str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
158
158
  }
159
159
  str += '</span>';
160
160
  }
161
161
  else {
162
- str += "<" + json.name + " ";
162
+ str += "<".concat(json.name, " ");
163
163
  // For now, spread is not supported
164
164
  // if (json.bindings._spread === '_spread') {
165
165
  // str += `
@@ -178,7 +178,7 @@ var blockToHtml = function (json, options) {
178
178
  var value = (json.properties[key] || '')
179
179
  .replace(/"/g, '&quot;')
180
180
  .replace(/\n/g, '\\n');
181
- str += " " + key + "=\"" + value + "\" ";
181
+ str += " ".concat(key, "=\"").concat(value, "\" ");
182
182
  }
183
183
  for (var key in json.bindings) {
184
184
  if (key === '_spread' || key === 'ref' || key === 'css') {
@@ -189,25 +189,25 @@ var blockToHtml = function (json, options) {
189
189
  var useValue = value;
190
190
  if (key.startsWith('on')) {
191
191
  var event_1 = key.replace('on', '').toLowerCase();
192
- if (!is_component_1.isComponent(json) && event_1 === 'change') {
192
+ if (!(0, is_component_1.isComponent)(json) && event_1 === 'change') {
193
193
  event_1 = 'input';
194
194
  }
195
- var fnName = lodash_1.camelCase("on-" + elId + "-" + event_1);
196
- options.js += "\n // Event handler for '" + event_1 + "' event on " + elId + "\n " + (options.format === 'class'
197
- ? "this." + fnName + " = (event) => {"
198
- : "function " + fnName + " (event) {") + "\n " + remove_surrounding_block_1.removeSurroundingBlock(updateReferencesInCode(useValue, options)) + "\n }\n ";
199
- var fnIdentifier = "" + (options.format === 'class' ? 'this.' : '') + fnName;
200
- addOnChangeJs(elId, options, "\n ;el.removeEventListener('" + event_1 + "', " + fnIdentifier + ");\n ;el.addEventListener('" + event_1 + "', " + fnIdentifier + ");\n ");
195
+ var fnName = (0, lodash_1.camelCase)("on-".concat(elId, "-").concat(event_1));
196
+ options.js += "\n // Event handler for '".concat(event_1, "' event on ").concat(elId, "\n ").concat(options.format === 'class'
197
+ ? "this.".concat(fnName, " = (event) => {")
198
+ : "function ".concat(fnName, " (event) {"), "\n ").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options)), "\n }\n ");
199
+ var fnIdentifier = "".concat(options.format === 'class' ? 'this.' : '').concat(fnName);
200
+ addOnChangeJs(elId, options, "\n ;el.removeEventListener('".concat(event_1, "', ").concat(fnIdentifier, ");\n ;el.addEventListener('").concat(event_1, "', ").concat(fnIdentifier, ");\n "));
201
201
  }
202
202
  else {
203
203
  if (key === 'style') {
204
- addOnChangeJs(elId, options, ";Object.assign(el.style, " + useValue + ");");
204
+ addOnChangeJs(elId, options, ";Object.assign(el.style, ".concat(useValue, ");"));
205
205
  }
206
206
  else {
207
207
  var useAttribute = key.includes('-');
208
208
  addOnChangeJs(elId, options, useAttribute
209
- ? ";el.setAttribute(" + key + ", " + useValue + ");"
210
- : ";el." + key + " = " + useValue);
209
+ ? ";el.setAttribute(".concat(key, ", ").concat(useValue, ");")
210
+ : ";el.".concat(key, " = ").concat(useValue));
211
211
  }
212
212
  }
213
213
  }
@@ -222,14 +222,14 @@ var blockToHtml = function (json, options) {
222
222
  // Maybe put some kind of safety here for broken HTML such as no close tag
223
223
  str += htmlDecode(json.properties.innerHTML);
224
224
  }
225
- str += "</" + json.name + ">";
225
+ str += "</".concat(json.name, ">");
226
226
  }
227
227
  return str;
228
228
  };
229
229
  function addUpdateAfterSetInCode(code, options, useString) {
230
230
  if (useString === void 0) { useString = options.format === 'class' ? 'this.update' : 'update'; }
231
231
  var updates = 0;
232
- return babel_transform_1.babelTransformExpression(code, {
232
+ return (0, babel_transform_1.babelTransformExpression)(code, {
233
233
  AssignmentExpression: function (path) {
234
234
  var node = path.node;
235
235
  if (core_1.types.isMemberExpression(node.left)) {
@@ -263,182 +263,188 @@ function addUpdateAfterSetInCode(code, options, useString) {
263
263
  }
264
264
  var htmlDecode = function (html) { return html.replace(/&quot;/gi, '"'); };
265
265
  // TODO: props support via custom elements
266
- var componentToHtml = function (componentJson, options) {
266
+ var componentToHtml = function (options) {
267
267
  if (options === void 0) { options = {}; }
268
- var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'script' });
269
- var json = fast_clone_1.fastClone(componentJson);
270
- if (options.plugins) {
271
- json = plugins_1.runPreJsonPlugins(json, options.plugins);
272
- }
273
- replaceForNameIdentifiers(json, useOptions);
274
- addUpdateAfterSet(json, useOptions);
275
- var componentHasProps = has_props_1.hasProps(json);
276
- var hasLoop = has_component_1.hasComponent('For', json);
277
- if (options.plugins) {
278
- json = plugins_1.runPostJsonPlugins(json, options.plugins);
279
- }
280
- var css = collect_styles_1.collectCss(json, {
281
- prefix: options.prefix,
282
- });
283
- var str = json.children
284
- .map(function (item) { return blockToHtml(item, useOptions); })
285
- .join('\n');
286
- if (css.trim().length) {
287
- str += "<style>" + css + "</style>";
288
- }
289
- var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
290
- var hasGeneratedJs = Boolean(useOptions.js.trim().length);
291
- if (hasChangeListeners || hasGeneratedJs || json.hooks.onMount || hasLoop) {
292
- // TODO: collectJs helper for here and liquid
293
- str += "\n <script>\n (() => {\n const state = " + get_state_object_string_1.getStateObjectStringFromComponent(json, {
294
- valueMapper: function (value) {
295
- return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
296
- },
297
- }) + ";\n " + (componentHasProps ? "let props = {};" : '') + "\n\n " + (!hasChangeListeners
298
- ? ''
299
- : "\n \n // Function to update data bindings and loops\n // call update() when you mutate state and need the updates to reflect\n // in the dom\n function update() {\n " + Object.keys(useOptions.onChangeJsById)
300
- .map(function (key) {
301
- var value = useOptions.onChangeJsById[key];
302
- if (!value) {
303
- return '';
304
- }
305
- return "\n document.querySelectorAll(\"[data-name='" + key + "']\").forEach((el) => {\n " + value + "\n })\n ";
306
- })
307
- .join('\n\n') + "\n }\n\n " + useOptions.js + "\n\n // Update with initial state on first load\n update();\n ") + "\n\n " + (!json.hooks.onMount
308
- ? ''
309
- : // TODO: make prettier by grabbing only the function body
310
- "\n // onMount\n " + updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions) + " \n ") + "\n\n " + (!hasLoop
311
- ? ''
312
- : "\n\n // Helper to render loops\n function renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach(function (child) {\n contextMap.set(child, {\n ...contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n // Helper to pass context down for loops\n let contextMap = new WeakMap();\n function getContext(el, name) {\n let parent = el;\n do {\n let context = contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ") + "\n })()\n </script>\n ";
313
- }
314
- if (options.plugins) {
315
- str = plugins_1.runPreCodePlugins(str, options.plugins);
316
- }
317
- if (options.prettier !== false) {
318
- try {
319
- str = standalone_1.format(str, {
320
- parser: 'html',
321
- htmlWhitespaceSensitivity: 'ignore',
322
- plugins: [
323
- // To support running in browsers
324
- require('prettier/parser-html'),
325
- require('prettier/parser-postcss'),
326
- require('prettier/parser-babel'),
327
- ],
328
- });
268
+ return function (_a) {
269
+ var component = _a.component;
270
+ var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'script' });
271
+ var json = (0, fast_clone_1.fastClone)(component);
272
+ if (options.plugins) {
273
+ json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
329
274
  }
330
- catch (err) {
331
- console.warn('Could not prettify', { string: str }, err);
275
+ replaceForNameIdentifiers(json, useOptions);
276
+ addUpdateAfterSet(json, useOptions);
277
+ var componentHasProps = (0, has_props_1.hasProps)(json);
278
+ var hasLoop = (0, has_component_1.hasComponent)('For', json);
279
+ if (options.plugins) {
280
+ json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
332
281
  }
333
- }
334
- if (options.plugins) {
335
- str = plugins_1.runPostCodePlugins(str, options.plugins);
336
- }
337
- return str;
282
+ var css = (0, collect_styles_1.collectCss)(json, {
283
+ prefix: options.prefix,
284
+ });
285
+ var str = json.children
286
+ .map(function (item) { return blockToHtml(item, useOptions); })
287
+ .join('\n');
288
+ if (css.trim().length) {
289
+ str += "<style>".concat(css, "</style>");
290
+ }
291
+ var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
292
+ var hasGeneratedJs = Boolean(useOptions.js.trim().length);
293
+ if (hasChangeListeners || hasGeneratedJs || json.hooks.onMount || hasLoop) {
294
+ // TODO: collectJs helper for here and liquid
295
+ str += "\n <script>\n (() => {\n const state = ".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
296
+ valueMapper: function (value) {
297
+ return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
298
+ },
299
+ }), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n\n ").concat(!hasChangeListeners
300
+ ? ''
301
+ : "\n \n // Function to update data bindings and loops\n // call update() when you mutate state and need the updates to reflect\n // in the dom\n function update() {\n ".concat(Object.keys(useOptions.onChangeJsById)
302
+ .map(function (key) {
303
+ var value = useOptions.onChangeJsById[key];
304
+ if (!value) {
305
+ return '';
306
+ }
307
+ return "\n document.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(value, "\n })\n ");
308
+ })
309
+ .join('\n\n'), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!json.hooks.onMount
310
+ ? ''
311
+ : // TODO: make prettier by grabbing only the function body
312
+ "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions), " \n "), "\n\n ").concat(!hasLoop
313
+ ? ''
314
+ : "\n\n // Helper to render loops\n function renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach(function (child) {\n contextMap.set(child, {\n ...contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n // Helper to pass context down for loops\n let contextMap = new WeakMap();\n function getContext(el, name) {\n let parent = el;\n do {\n let context = contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ", "\n })()\n </script>\n ");
315
+ }
316
+ if (options.plugins) {
317
+ str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
318
+ }
319
+ if (options.prettier !== false) {
320
+ try {
321
+ str = (0, standalone_1.format)(str, {
322
+ parser: 'html',
323
+ htmlWhitespaceSensitivity: 'ignore',
324
+ plugins: [
325
+ // To support running in browsers
326
+ require('prettier/parser-html'),
327
+ require('prettier/parser-postcss'),
328
+ require('prettier/parser-babel'),
329
+ ],
330
+ });
331
+ }
332
+ catch (err) {
333
+ console.warn('Could not prettify', { string: str }, err);
334
+ }
335
+ }
336
+ if (options.plugins) {
337
+ str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
338
+ }
339
+ return str;
340
+ };
338
341
  };
339
342
  exports.componentToHtml = componentToHtml;
340
343
  // TODO: props support via custom elements
341
- var componentToCustomElement = function (componentJson, options) {
344
+ var componentToCustomElement = function (options) {
342
345
  if (options === void 0) { options = {}; }
343
- var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
344
- var json = fast_clone_1.fastClone(componentJson);
345
- if (options.plugins) {
346
- json = plugins_1.runPreJsonPlugins(json, options.plugins);
347
- }
348
- var componentHasProps = has_props_1.hasProps(json);
349
- replaceForNameIdentifiers(json, useOptions);
350
- addUpdateAfterSet(json, useOptions);
351
- var hasLoop = has_component_1.hasComponent('For', json);
352
- if (options.plugins) {
353
- json = plugins_1.runPostJsonPlugins(json, options.plugins);
354
- }
355
- var css = collect_styles_1.collectCss(json, {
356
- prefix: options.prefix,
357
- });
358
- strip_meta_properties_1.stripMetaProperties(json);
359
- var html = json.children
360
- .map(function (item) { return blockToHtml(item, useOptions); })
361
- .join('\n');
362
- html += "<style>" + css + "</style>";
363
- if (options.prettier !== false) {
364
- try {
365
- html = standalone_1.format(html, {
366
- parser: 'html',
367
- htmlWhitespaceSensitivity: 'ignore',
368
- plugins: [
369
- // To support running in browsers
370
- require('prettier/parser-html'),
371
- require('prettier/parser-postcss'),
372
- require('prettier/parser-babel'),
373
- require('prettier/parser-typescript'),
374
- ],
375
- });
376
- html = html.trim().replace(/\n/g, '\n ');
346
+ return function (_a) {
347
+ var component = _a.component;
348
+ var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
349
+ var json = (0, fast_clone_1.fastClone)(component);
350
+ if (options.plugins) {
351
+ json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
377
352
  }
378
- catch (err) {
379
- console.warn('Could not prettify', { string: html }, err);
353
+ var componentHasProps = (0, has_props_1.hasProps)(json);
354
+ replaceForNameIdentifiers(json, useOptions);
355
+ addUpdateAfterSet(json, useOptions);
356
+ var hasLoop = (0, has_component_1.hasComponent)('For', json);
357
+ if (options.plugins) {
358
+ json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
380
359
  }
381
- }
382
- var kebabName = componentJson.name
383
- .replace(/([a-z])([A-Z])/g, '$1-$2')
384
- .toLowerCase();
385
- var str = "\n /**\n * Usage:\n * \n * <" + kebabName + "></" + kebabName + ">\n * \n */\n class " + componentJson.name + " extends HTMLElement {\n constructor() {\n super();\n\n const self = this;\n this.state = " + get_state_object_string_1.getStateObjectStringFromComponent(json, {
386
- valueMapper: function (value) {
387
- return strip_state_and_props_refs_1.stripStateAndPropsRefs(strip_state_and_props_refs_1.stripStateAndPropsRefs(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
388
- includeProps: false,
389
- includeState: true,
390
- // TODO: if it's an arrow function it's this.state.
391
- replaceWith: 'self.state.',
392
- }), {
393
- // TODO: replace with `this.` and add setters that call this.update()
394
- includeProps: true,
395
- includeState: false,
396
- replaceWith: 'self.props.',
397
- });
398
- },
399
- }) + ";\n " + (componentHasProps /* TODO: accept these as attributes/properties on the custom element */
400
- ? "this.props = {};"
401
- : '') + "\n\n " + (!hasLoop
402
- ? ''
403
- : "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ") + "\n\n " + useOptions.js + "\n }\n\n " + (!json.hooks.onUnMount
404
- ? ''
405
- : "\n disconnectedCallback() {\n // onUnMount\n " + updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount, useOptions), useOptions) + "\n }\n ") + "\n\n connectedCallback() {\n this.innerHTML = `\n " + html + "`;\n this.update();\n\n " + (!json.hooks.onMount
406
- ? ''
407
- : // TODO: make prettier by grabbing only the function body
408
- "\n // onMount\n " + updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions) + "\n ") + "\n }\n\n update() {\n " + Object.keys(useOptions.onChangeJsById)
409
- .map(function (key) {
410
- var value = useOptions.onChangeJsById[key];
411
- if (!value) {
412
- return '';
360
+ var css = (0, collect_styles_1.collectCss)(json, {
361
+ prefix: options.prefix,
362
+ });
363
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
364
+ var html = json.children
365
+ .map(function (item) { return blockToHtml(item, useOptions); })
366
+ .join('\n');
367
+ html += "<style>".concat(css, "</style>");
368
+ if (options.prettier !== false) {
369
+ try {
370
+ html = (0, standalone_1.format)(html, {
371
+ parser: 'html',
372
+ htmlWhitespaceSensitivity: 'ignore',
373
+ plugins: [
374
+ // To support running in browsers
375
+ require('prettier/parser-html'),
376
+ require('prettier/parser-postcss'),
377
+ require('prettier/parser-babel'),
378
+ require('prettier/parser-typescript'),
379
+ ],
380
+ });
381
+ html = html.trim().replace(/\n/g, '\n ');
382
+ }
383
+ catch (err) {
384
+ console.warn('Could not prettify', { string: html }, err);
385
+ }
413
386
  }
414
- return "\n this.querySelectorAll(\"[data-name='" + key + "']\").forEach((el) => {\n " + updateReferencesInCode(value, useOptions) + "\n })\n ";
415
- })
416
- .join('\n\n') + "\n }\n\n " + (!hasLoop
417
- ? ''
418
- : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n this.contextMap.set(child, {\n ...this.contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n getContext(el, name) {\n let parent = el;\n do {\n let context = this.contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ") + "\n }\n\n customElements.define('" + kebabName + "', " + componentJson.name + ");\n ";
419
- if (options.plugins) {
420
- str = plugins_1.runPreCodePlugins(str, options.plugins);
421
- }
422
- if (options.prettier !== false) {
423
- try {
424
- str = standalone_1.format(str, {
425
- parser: 'typescript',
426
- plugins: [
427
- // To support running in browsers
428
- require('prettier/parser-html'),
429
- require('prettier/parser-postcss'),
430
- require('prettier/parser-babel'),
431
- require('prettier/parser-typescript'),
432
- ],
433
- });
387
+ var kebabName = component.name
388
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
389
+ .toLowerCase();
390
+ var str = "\n /**\n * Usage:\n * \n * <".concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(component.name, " extends HTMLElement {\n constructor() {\n super();\n\n const self = this;\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
391
+ valueMapper: function (value) {
392
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
393
+ includeProps: false,
394
+ includeState: true,
395
+ // TODO: if it's an arrow function it's this.state.
396
+ replaceWith: 'self.state.',
397
+ }), {
398
+ // TODO: replace with `this.` and add setters that call this.update()
399
+ includeProps: true,
400
+ includeState: false,
401
+ replaceWith: 'self.props.',
402
+ });
403
+ },
404
+ }), ";\n ").concat(componentHasProps /* TODO: accept these as attributes/properties on the custom element */
405
+ ? "this.props = {};"
406
+ : '', "\n\n ").concat(!hasLoop
407
+ ? ''
408
+ : "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ", "\n\n ").concat(useOptions.js, "\n }\n\n ").concat(!json.hooks.onUnMount
409
+ ? ''
410
+ : "\n disconnectedCallback() {\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount, useOptions), useOptions), "\n }\n "), "\n\n connectedCallback() {\n this.innerHTML = `\n ").concat(html, "`;\n this.update();\n\n ").concat(!json.hooks.onMount
411
+ ? ''
412
+ : // TODO: make prettier by grabbing only the function body
413
+ "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions), "\n "), "\n }\n\n update() {\n ").concat(Object.keys(useOptions.onChangeJsById)
414
+ .map(function (key) {
415
+ var value = useOptions.onChangeJsById[key];
416
+ if (!value) {
417
+ return '';
418
+ }
419
+ return "\n this.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(updateReferencesInCode(value, useOptions), "\n })\n ");
420
+ })
421
+ .join('\n\n'), "\n }\n\n ").concat(!hasLoop
422
+ ? ''
423
+ : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n this.contextMap.set(child, {\n ...this.contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n getContext(el, name) {\n let parent = el;\n do {\n let context = this.contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ", "\n }\n\n customElements.define('").concat(kebabName, "', ").concat(component.name, ");\n ");
424
+ if (options.plugins) {
425
+ str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
426
+ }
427
+ if (options.prettier !== false) {
428
+ try {
429
+ str = (0, standalone_1.format)(str, {
430
+ parser: 'typescript',
431
+ plugins: [
432
+ // To support running in browsers
433
+ require('prettier/parser-html'),
434
+ require('prettier/parser-postcss'),
435
+ require('prettier/parser-babel'),
436
+ require('prettier/parser-typescript'),
437
+ ],
438
+ });
439
+ }
440
+ catch (err) {
441
+ console.warn('Could not prettify', { string: str }, err);
442
+ }
434
443
  }
435
- catch (err) {
436
- console.warn('Could not prettify', { string: str }, err);
444
+ if (options.plugins) {
445
+ str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
437
446
  }
438
- }
439
- if (options.plugins) {
440
- str = plugins_1.runPostCodePlugins(str, options.plugins);
441
- }
442
- return str;
447
+ return str;
448
+ };
443
449
  };
444
450
  exports.componentToCustomElement = componentToCustomElement;
@@ -1,15 +1,11 @@
1
- import { MitosisComponent } from '../types/mitosis-component';
2
- import { Plugin } from '../modules/plugins';
1
+ import { BaseTranspilerOptions, Transpiler } from '../types/config';
2
+ export interface ToLiquidOptions extends BaseTranspilerOptions {
3
+ reactive?: boolean;
4
+ }
3
5
  /**
4
6
  * Test if the binding expression would be likely to generate
5
7
  * valid or invalid liquid. If we generate invalid liquid tags
6
8
  * Shopify will reject our PUT to update the template
7
9
  */
8
10
  export declare const isValidLiquidBinding: (str?: string) => boolean;
9
- declare type ToLiquidOptions = {
10
- prettier?: boolean;
11
- plugins?: Plugin[];
12
- reactive?: boolean;
13
- };
14
- export declare const componentToLiquid: (componentJson: MitosisComponent, options?: ToLiquidOptions) => string;
15
- export {};
11
+ export declare const componentToLiquid: (options?: ToLiquidOptions) => Transpiler;