@builder.io/mitosis 0.0.57 → 0.0.59

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.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var mitosis_1 = require("@builder.io/mitosis");
4
4
  function Button(props) {
5
- return (<>
5
+ return (<div>
6
6
  <mitosis_1.Show when={props.link}>
7
7
  <a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
8
8
  {props.text}
@@ -13,6 +13,6 @@ function Button(props) {
13
13
  {props.text}
14
14
  </button>
15
15
  </mitosis_1.Show>
16
- </>);
16
+ </div>);
17
17
  }
18
18
  exports.default = Button;
@@ -45,7 +45,7 @@ function Image(props) {
45
45
  window.removeEventListener('scroll', state.scrollListener);
46
46
  }
47
47
  });
48
- return (<>
48
+ return (<div>
49
49
  <picture ref={pictureRef}>
50
50
  <mitosis_1.Show when={!state.useLazyLoading() || load}>
51
51
  <img alt={props.altText} aria-role={props.altText ? 'presentation' : undefined} css={{
@@ -60,6 +60,6 @@ function Image(props) {
60
60
  <source srcset={props.srcset}/>
61
61
  </picture>
62
62
  {props.children}
63
- </>);
63
+ </div>);
64
64
  }
65
65
  exports.default = Image;
@@ -0,0 +1,7 @@
1
+ export interface ButtonProps {
2
+ attributes?: any;
3
+ text?: string;
4
+ link?: string;
5
+ openLinkInNewTab?: boolean;
6
+ }
7
+ export default function Button(props: ButtonProps): import("@builder.io/mitosis/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mitosis_1 = require("@builder.io/mitosis");
4
+ function Button(props) {
5
+ return (<>
6
+ <mitosis_1.Show when={props.link}>
7
+ <a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
8
+ {props.text}
9
+ </a>
10
+ </mitosis_1.Show>
11
+ <mitosis_1.Show when={!props.link}>
12
+ <button {...props.attributes} type="button">
13
+ {props.text}
14
+ </button>
15
+ </mitosis_1.Show>
16
+ </>);
17
+ }
18
+ exports.default = Button;
@@ -7,7 +7,7 @@ function Button(props) {
7
7
  link: 'https://builder.io/',
8
8
  openLinkInNewTab: false,
9
9
  });
10
- return (<>
10
+ return (<div>
11
11
  <mitosis_1.Show when={props.link}>
12
12
  <a {...props.attributes} href={props.link} target={props.openLinkInNewTab ? '_blank' : undefined}>
13
13
  {props.text}
@@ -18,6 +18,6 @@ function Button(props) {
18
18
  {props.text}
19
19
  </button>
20
20
  </mitosis_1.Show>
21
- </>);
21
+ </div>);
22
22
  }
23
23
  exports.default = Button;
@@ -1,7 +1,7 @@
1
- import { TranspilerGenerator } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  import { Target } from '../types/config';
3
3
  export declare const runTestsForJsx: () => void;
4
- export declare const runTestsForTarget: <X>({ target, generator, options, }: {
4
+ export declare const runTestsForTarget: <X extends BaseTranspilerOptions>({ target, generator, options, }: {
5
5
  target: Target;
6
6
  generator: TranspilerGenerator<X, string>;
7
7
  options: X;
@@ -13,65 +13,67 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.runTestsForTarget = exports.runTestsForJsx = void 0;
15
15
  var jsx_1 = require("../parsers/jsx");
16
- var basicForShow = require('./data/basic-for-show.raw');
17
- var basicOnMountUpdate = require('./data/basic-onMount-update.raw');
18
- var basicContext = require('./data/basic-context.raw');
19
- var basicOutputsMeta = require('./data/basic-outputs-meta.raw');
20
- var basicOutputs = require('./data/basic-outputs.raw');
21
- var subComponent = require('./data/sub-component.lite.jsx');
22
- var basic = require('./data/basic.raw');
23
- var basicMitosis = require('./data/basic-custom-mitosis-package.raw');
24
- var basicChildComponent = require('./data/basic-child-component.raw');
25
- var basicFor = require('./data/basic-for.raw');
26
- var basicRef = require('./data/basic-ref.raw');
27
- var basicForwardRef = require('./data/basic-forwardRef.raw');
28
- var basicForwardRefMetadata = require('./data/basic-forwardRef-metadata.raw');
29
- var basicRefPrevious = require('./data/basic-ref-usePrevious.raw');
30
- var basicRefAssignment = require('./data/basic-ref-assignment.raw');
31
- var propsDestructure = require('./data/basic-props-destructure.raw');
32
- var nestedStyles = require('./data/nested-styles.lite');
33
- var preserveExportOrLocalStatement = require('./data/basic-preserve-export-or-local-statement.raw');
34
- var propsType = require('./data/types/component-props-type.raw');
35
- var propsInterface = require('./data/types/component-props-interface.raw');
36
- var preserveTyping = require('./data/types/preserve-typing.raw');
37
- var typeDependency = require('./data/types/type-dependency.raw');
38
- var defaultProps = require('./data/default-props/default-props.raw');
39
- var classRaw = require('./data/styles/class.raw');
40
- var className = require('./data/styles/className.raw');
41
- var classAndClassName = require('./data/styles/class-and-className.raw');
42
- var classState = require('./data/styles/classState.raw');
43
- var button = require('./data/blocks/button.raw');
44
- var classNameJsx = require('./data/blocks/classname-jsx.raw');
45
- var columns = require('./data/blocks/columns.raw');
46
- var contentSlotHtml = require('./data/blocks/content-slot-html.raw');
47
- var contentSlotJsx = require('./data/blocks/content-slot-jsx.raw');
48
- var customCode = require('./data/blocks/custom-code.raw');
49
- var formBlock = require('./data/blocks/form.raw');
50
- var image = require('./data/blocks/image.raw');
51
- var imageState = require('./data/blocks/img-state.raw');
52
- var img = require('./data/blocks/img.raw');
53
- var inputBlock = require('./data/blocks/input.raw');
54
- var multipleOnUpdate = require('./data/blocks/multiple-onUpdate.raw');
55
- var multipleOnUpdateWithDeps = require('./data/blocks/multiple-onUpdateWithDeps.raw');
56
- var onInit = require('./data/blocks/onInit.raw');
57
- var onInitonMount = require('./data/blocks/onInit-onMount.raw');
58
- var onMount = require('./data/blocks/onMount.raw');
59
- var onUpdate = require('./data/blocks/onUpdate.raw');
60
- var onUpdateWithDeps = require('./data/blocks/onUpdateWithDeps.raw');
61
- var rawText = require('./data/blocks/raw-text.raw');
62
- var section = require('./data/blocks/section.raw');
63
- var sectionState = require('./data/blocks/section-state.raw');
64
- var selectBlock = require('./data/blocks/select.raw');
65
- var selfRefCompWChildren = require('./data/blocks/self-referencing-component-with-children.raw');
66
- var selfRefComp = require('./data/blocks/self-referencing-component.raw');
67
- var slotHtml = require('./data/blocks/slot-html.raw');
68
- var slotJsx = require('./data/blocks/slot-jsx.raw');
69
- var stamped = require('./data/blocks/stamped-io.raw');
70
- var submitButtonBlock = require('./data/blocks/submit-button.raw');
71
- var text = require('./data/blocks/text.raw');
72
- var textarea = require('./data/blocks/textarea.raw');
73
- var video = require('./data/blocks/video.raw');
74
- var builderRenderContent = require('./data/blocks/builder-render-content.raw');
16
+ var getRawFile = function (path) { return require(path); };
17
+ var basicForShow = getRawFile('./data/basic-for-show.raw');
18
+ var basicOnMountUpdate = getRawFile('./data/basic-onMount-update.raw');
19
+ var basicContext = getRawFile('./data/basic-context.raw');
20
+ var basicOutputsMeta = getRawFile('./data/basic-outputs-meta.raw');
21
+ var basicOutputs = getRawFile('./data/basic-outputs.raw');
22
+ var subComponent = getRawFile('./data/sub-component.lite.jsx');
23
+ var basic = getRawFile('./data/basic.raw');
24
+ var basicMitosis = getRawFile('./data/basic-custom-mitosis-package.raw');
25
+ var basicChildComponent = getRawFile('./data/basic-child-component.raw');
26
+ var basicFor = getRawFile('./data/basic-for.raw');
27
+ var basicRef = getRawFile('./data/basic-ref.raw');
28
+ var basicForwardRef = getRawFile('./data/basic-forwardRef.raw');
29
+ var basicForwardRefMetadata = getRawFile('./data/basic-forwardRef-metadata.raw');
30
+ var basicRefPrevious = getRawFile('./data/basic-ref-usePrevious.raw');
31
+ var basicRefAssignment = getRawFile('./data/basic-ref-assignment.raw');
32
+ var propsDestructure = getRawFile('./data/basic-props-destructure.raw');
33
+ var nestedStyles = getRawFile('./data/nested-styles.lite');
34
+ var preserveExportOrLocalStatement = getRawFile('./data/basic-preserve-export-or-local-statement.raw');
35
+ var propsType = getRawFile('./data/types/component-props-type.raw');
36
+ var propsInterface = getRawFile('./data/types/component-props-interface.raw');
37
+ var preserveTyping = getRawFile('./data/types/preserve-typing.raw');
38
+ var typeDependency = getRawFile('./data/types/type-dependency.raw');
39
+ var defaultProps = getRawFile('./data/default-props/default-props.raw');
40
+ var classRaw = getRawFile('./data/styles/class.raw');
41
+ var className = getRawFile('./data/styles/className.raw');
42
+ var classAndClassName = getRawFile('./data/styles/class-and-className.raw');
43
+ var classState = getRawFile('./data/styles/classState.raw');
44
+ var button = getRawFile('./data/blocks/button.raw');
45
+ var classNameJsx = getRawFile('./data/blocks/classname-jsx.raw');
46
+ var columns = getRawFile('./data/blocks/columns.raw');
47
+ var contentSlotHtml = getRawFile('./data/blocks/content-slot-html.raw');
48
+ var contentSlotJsx = getRawFile('./data/blocks/content-slot-jsx.raw');
49
+ var customCode = getRawFile('./data/blocks/custom-code.raw');
50
+ var formBlock = getRawFile('./data/blocks/form.raw');
51
+ var image = getRawFile('./data/blocks/image.raw');
52
+ var imageState = getRawFile('./data/blocks/img-state.raw');
53
+ var img = getRawFile('./data/blocks/img.raw');
54
+ var inputBlock = getRawFile('./data/blocks/input.raw');
55
+ var multipleOnUpdate = getRawFile('./data/blocks/multiple-onUpdate.raw');
56
+ var multipleOnUpdateWithDeps = getRawFile('./data/blocks/multiple-onUpdateWithDeps.raw');
57
+ var onInit = getRawFile('./data/blocks/onInit.raw');
58
+ var onInitonMount = getRawFile('./data/blocks/onInit-onMount.raw');
59
+ var onMount = getRawFile('./data/blocks/onMount.raw');
60
+ var onUpdate = getRawFile('./data/blocks/onUpdate.raw');
61
+ var onUpdateWithDeps = getRawFile('./data/blocks/onUpdateWithDeps.raw');
62
+ var rawText = getRawFile('./data/blocks/raw-text.raw');
63
+ var section = getRawFile('./data/blocks/section.raw');
64
+ var sectionState = getRawFile('./data/blocks/section-state.raw');
65
+ var selectBlock = getRawFile('./data/blocks/select.raw');
66
+ var selfRefCompWChildren = getRawFile('./data/blocks/self-referencing-component-with-children.raw');
67
+ var selfRefComp = getRawFile('./data/blocks/self-referencing-component.raw');
68
+ var slotHtml = getRawFile('./data/blocks/slot-html.raw');
69
+ var slotJsx = getRawFile('./data/blocks/slot-jsx.raw');
70
+ var stamped = getRawFile('./data/blocks/stamped-io.raw');
71
+ var submitButtonBlock = getRawFile('./data/blocks/submit-button.raw');
72
+ var text = getRawFile('./data/blocks/text.raw');
73
+ var textarea = getRawFile('./data/blocks/textarea.raw');
74
+ var video = getRawFile('./data/blocks/video.raw');
75
+ var builderRenderContent = getRawFile('./data/blocks/builder-render-content.raw');
76
+ var rootFragmentMultiNode = getRawFile('./data/blocks/root-fragment-multi-node.raw');
75
77
  var path = 'test-path';
76
78
  var BASIC_TESTS = {
77
79
  Basic: basic,
@@ -104,7 +106,7 @@ var BASIC_TESTS = {
104
106
  defaultProps: defaultProps,
105
107
  preserveTyping: preserveTyping,
106
108
  typeDependency: typeDependency,
107
- defaultValsWithTypes: require('./data/types/component-with-default-values-types.raw'),
109
+ defaultValsWithTypes: getRawFile('./data/types/component-with-default-values-types.raw'),
108
110
  'import types': builderRenderContent,
109
111
  subComponent: subComponent,
110
112
  nestedStyles: nestedStyles,
@@ -122,6 +124,7 @@ var BASIC_TESTS = {
122
124
  'class + ClassName + css': classAndClassName,
123
125
  'self-referencing component with children': selfRefCompWChildren,
124
126
  'self-referencing component': selfRefComp,
127
+ rootFragmentMultiNode: rootFragmentMultiNode,
125
128
  };
126
129
  var SLOTS_TESTS = {
127
130
  ContentSlotJSX: contentSlotJsx,
@@ -146,15 +149,15 @@ var FORWARD_REF_TESTS = {
146
149
  basicForwardRefMetadata: basicForwardRefMetadata,
147
150
  };
148
151
  var SHOW_TESTS = {
149
- rootShow: require('./data/blocks/rootShow.raw'),
150
- nestedShow: require('./data/show/nested-show.raw'),
151
- showWithFor: require('./data/show/show-with-for.raw'),
152
+ rootShow: getRawFile('./data/blocks/rootShow.raw'),
153
+ nestedShow: getRawFile('./data/show/nested-show.raw'),
154
+ showWithFor: getRawFile('./data/show/show-with-for.raw'),
152
155
  };
153
156
  var ADVANCED_REF = {
154
- AdvancedRef: require('./data/advanced-ref.raw'),
157
+ AdvancedRef: getRawFile('./data/advanced-ref.raw'),
155
158
  };
156
159
  var ON_UPDATE_RETURN = {
157
- basicOnUpdateReturn: require('./data/basic-onUpdate-return.raw'),
160
+ basicOnUpdateReturn: getRawFile('./data/basic-onUpdate-return.raw'),
158
161
  };
159
162
  var JSX_TESTS = [
160
163
  BASIC_TESTS,
@@ -346,14 +349,13 @@ var runTestsForTarget = function (_a) {
346
349
  testsArray.forEach(function (tests) {
347
350
  Object.keys(tests).forEach(function (key) {
348
351
  test(key, function () {
352
+ var component = (0, jsx_1.parseJsx)(tests[key], { typescript: options.typescript });
353
+ var getOutput = function () { return generator(options)({ component: component, path: path }); };
349
354
  try {
350
- var component = (0, jsx_1.parseJsx)(tests[key]);
351
- var output = generator(options)({ component: component, path: path });
352
- expect(output).toMatchSnapshot();
355
+ expect(getOutput()).toMatchSnapshot();
353
356
  }
354
357
  catch (error) {
355
- console.log('failed to parse', error);
356
- throw error;
358
+ expect(getOutput).toThrowErrorMatchingSnapshot();
357
359
  }
358
360
  });
359
361
  });
@@ -52,14 +52,20 @@ var mappers = {
52
52
  Slot: function (json, options, blockOptions) {
53
53
  return "<ng-content ".concat(Object.keys(json.bindings)
54
54
  .map(function (binding) {
55
- var _a, _b, _c;
55
+ var _a, _b;
56
56
  if (binding === 'name') {
57
57
  var selector = (0, lodash_1.kebabCase)((_b = (_a = json.bindings.name) === null || _a === void 0 ? void 0 : _a.code) === null || _b === void 0 ? void 0 : _b.replace('props.slot', ''));
58
58
  return "select=\"[".concat(selector, "]\"");
59
59
  }
60
- return "".concat((_c = json.bindings[binding]) === null || _c === void 0 ? void 0 : _c.code);
61
60
  })
62
- .join('\n'), "></ng-content>");
61
+ .join('\n'), ">").concat(Object.keys(json.bindings)
62
+ .map(function (binding) {
63
+ var _a;
64
+ if (binding !== 'name') {
65
+ return "".concat((_a = json.bindings[binding]) === null || _a === void 0 ? void 0 : _a.code);
66
+ }
67
+ })
68
+ .join('\n'), "</ng-content>");
63
69
  },
64
70
  };
65
71
  // TODO: Maybe in the future allow defining `string | function` as values
@@ -6,7 +6,7 @@ var contextToQwik = function (options) {
6
6
  if (options === void 0) { options = {}; }
7
7
  return function (_a) {
8
8
  var context = _a.context;
9
- var str = "\n import { createContext } from '@builder.io/qwik';\n\n export default createContext(\"".concat(context.name, "\")\n ");
9
+ var str = "\n import { createContext } from '@builder.io/qwik';\n\n export default createContext<any>(\"".concat(context.name, "\")\n ");
10
10
  if (options.format !== false) {
11
11
  try {
12
12
  str = (0, standalone_1.format)(str, {
@@ -42,10 +42,11 @@ var componentToQwik = function (userOptions) {
42
42
  if (userOptions.plugins) {
43
43
  component = (0, plugins_1.runPostJsonPlugins)(component, userOptions.plugins);
44
44
  }
45
- var file = new src_generator_1.File(component.name + '.js', {
45
+ var isTypeScript = !!userOptions.typescript;
46
+ var file = new src_generator_1.File(component.name + (isTypeScript ? '.ts' : '.js'), {
46
47
  isPretty: true,
47
48
  isJSX: true,
48
- isTypeScript: false,
49
+ isTypeScript: isTypeScript,
49
50
  isModule: true,
50
51
  isBuilder: false,
51
52
  }, '@builder.io/qwik', '');
@@ -60,7 +61,7 @@ var componentToQwik = function (userOptions) {
60
61
  var state_2 = emitStateMethodsAndRewriteBindings(file, component, metadata);
61
62
  var hasState_1 = (0, state_1.checkHasState)(component);
62
63
  var css_1 = null;
63
- var componentBody = (0, src_generator_1.arrowFnBlock)(['props'], [
64
+ var componentFn = (0, src_generator_1.arrowFnBlock)(['props'], [
64
65
  function () {
65
66
  css_1 = emitUseStyles(file, component);
66
67
  emitUseContext(file, component);
@@ -73,14 +74,19 @@ var componentToQwik = function (userOptions) {
73
74
  emitTagNameHack(file, component);
74
75
  emitJSX(file, component, mutable_1);
75
76
  },
76
- ], [component.propsTypeRef || 'any']);
77
+ ], [component.propsTypeRef + (isLightComponent ? '&{key?:any}' : '') || 'any']);
77
78
  file.src.const(component.name, isLightComponent
78
- ? componentBody
79
- : (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentBody]), true, true);
79
+ ? componentFn
80
+ : (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentFn]), true, true);
80
81
  file.exportDefault(component.name);
81
82
  emitStyles(file, css_1);
82
83
  DEBUG && file.exportConst('COMPONENT', (0, stable_serialize_1.stableJSONserialize)(component));
83
- return '// GENERATED BY MITOSIS\n\n' + file.toString();
84
+ var sourceFile = '// GENERATED BY MITOSIS\n\n' + file.toString();
85
+ if (userOptions.plugins) {
86
+ sourceFile = (0, plugins_1.runPreCodePlugins)(sourceFile, userOptions.plugins);
87
+ sourceFile = (0, plugins_1.runPostCodePlugins)(sourceFile, userOptions.plugins);
88
+ }
89
+ return sourceFile;
84
90
  }
85
91
  catch (e) {
86
92
  console.error(e);
@@ -199,13 +205,17 @@ function emitUseStore(file, stateInit) {
199
205
  var state = stateInit[0];
200
206
  var hasState = state && Object.keys(state).length > 0;
201
207
  if (hasState) {
202
- file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName, '(');
208
+ file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName);
209
+ if (file.options.isTypeScript) {
210
+ file.src.emit('<any>');
211
+ }
212
+ file.src.emit('(');
203
213
  file.src.emit((0, stable_serialize_1.stableJSONserialize)(state));
204
214
  file.src.emit(');');
205
215
  }
206
216
  else {
207
217
  // TODO hack for now so that `state` variable is defined, even though it is never read.
208
- file.src.emit('const state={};');
218
+ file.src.emit('const state={tagName:""' + (file.options.isTypeScript ? 'as any' : '') + '};');
209
219
  }
210
220
  }
211
221
  function emitTypes(file, component) {
@@ -358,6 +358,8 @@ var SrcBuilder = /** @class */ (function () {
358
358
  if (value) {
359
359
  if (key === 'innerHTML')
360
360
  key = 'dangerouslySetInnerHTML';
361
+ if (key === 'dataSet')
362
+ return; // ignore
361
363
  if (self.isJSX) {
362
364
  self.emit(' ', key, '=');
363
365
  if (typeof value == 'string' && value.startsWith('"') && value.endsWith('"')) {
@@ -108,7 +108,10 @@ function processBinding(code, _options, json, includeProps) {
108
108
  });
109
109
  }
110
110
  var NODE_MAPPERS = {
111
- Fragment: function (json, options) {
111
+ Fragment: function (json, options, scope) {
112
+ if (options.vueVersion === 2 && (scope === null || scope === void 0 ? void 0 : scope.isRootNode)) {
113
+ throw new Error('Vue 2 template should have a single root element');
114
+ }
112
115
  return json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n');
113
116
  },
114
117
  For: function (_json, options) {
@@ -133,12 +136,18 @@ var NODE_MAPPERS = {
133
136
  var _a, _b, _c, _d, _e;
134
137
  var _f, _g;
135
138
  var ifValue = (0, slots_1.replaceSlotsInString)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code), function (slotName) { return "$slots.".concat(slotName); });
139
+ var defaultShowTemplate = "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat(encodeQuotes(ifValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat((0, is_mitosis_node_1.isMitosisNode)(json.meta.else)
140
+ ? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
141
+ : '', "\n ");
136
142
  switch (options.vueVersion) {
137
143
  case 3:
138
- return "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat(encodeQuotes(ifValue), "\">\n ").concat(json.children.map(function (item) { return (0, exports.blockToVue)(item, options); }).join('\n'), "\n </template>\n ").concat((0, is_mitosis_node_1.isMitosisNode)(json.meta.else)
139
- ? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
140
- : '', "\n ");
144
+ return defaultShowTemplate;
141
145
  case 2:
146
+ // if it is not the root node, the default show template can be used
147
+ // as Vue 2 only has this limitation at root level
148
+ if (!(scope === null || scope === void 0 ? void 0 : scope.isRootNode)) {
149
+ return defaultShowTemplate;
150
+ }
142
151
  // Vue 2 can only handle one root element, so we just take the first one.
143
152
  // TO-DO: warn user of multi-children Show.
144
153
  var firstChild = json.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)[0];
@@ -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, "').then(x => x.default)");
113
+ return "const ".concat(importValue, " = () => import('").concat(path, "')\n .then(x => x.default)\n .catch(err => { \n console.error('Error while attempting to dynamically import component ").concat(importValue, " at ").concat(path, "', err);\n throw err;\n });");
114
114
  }
115
115
  }
116
116
  return importValue ? "import ".concat(importValue, " from '").concat(path, "';") : "import '".concat(path, "';");
package/dist/src/index.js CHANGED
@@ -17,7 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.useDefaultProps = exports.useMetadata = exports.onError = exports.useDynamicTag = exports.onUnMount = exports.onInit = exports.onCreate = exports.onUpdate = exports.onMount = exports.setContext = exports.createContext = exports.useContext = exports.useRef = exports.useState = exports.useStore = void 0;
18
18
  __exportStar(require("./flow"), exports);
19
19
  // These compile away
20
- var useStore = function (obj) { return obj; };
20
+ var useStore = function (obj) {
21
+ throw new Error('useStore: Mitosis hook should have been compiled away');
22
+ return obj;
23
+ };
21
24
  exports.useStore = useStore;
22
25
  var useState = function (obj) {
23
26
  throw new Error('useState: Mitosis hook should have been compiled away');
@@ -7,4 +7,4 @@ import { ParseMitosisOptions } from './types';
7
7
  * @param jsx string representation of the Mitosis component
8
8
  * @returns A JSON representation of the Mitosis component
9
9
  */
10
- export declare function parseJsx(jsx: string, options?: Partial<ParseMitosisOptions>): MitosisComponent;
10
+ export declare function parseJsx(jsx: string, _options?: Partial<ParseMitosisOptions>): MitosisComponent;
@@ -72,10 +72,10 @@ var beforeParse = function (path) {
72
72
  * @param jsx string representation of the Mitosis component
73
73
  * @returns A JSON representation of the Mitosis component
74
74
  */
75
- function parseJsx(jsx, options) {
76
- if (options === void 0) { options = {}; }
77
- var useOptions = __assign({ format: 'react' }, options);
75
+ function parseJsx(jsx, _options) {
76
+ if (_options === void 0) { _options = {}; }
78
77
  var subComponentFunctions = [];
78
+ var options = __assign({ typescript: false }, _options);
79
79
  var output = babel.transform(jsx, {
80
80
  configFile: false,
81
81
  babelrc: false,
@@ -89,7 +89,8 @@ function parseJsx(jsx, options) {
89
89
  // If left to its default `false`, then this will strip away:
90
90
  // - unused JS imports
91
91
  // - types imports within regular JS import syntax
92
- onlyRemoveTypeImports: true,
92
+ // When outputting to TS, we must set it to `true` to preserve these imports.
93
+ onlyRemoveTypeImports: options.typescript,
93
94
  },
94
95
  ],
95
96
  ],
@@ -118,7 +119,7 @@ function parseJsx(jsx, options) {
118
119
  return !types.isExportDefaultDeclaration(node) && types.isFunctionDeclaration(node);
119
120
  })
120
121
  .map(function (node) { return "export default ".concat((0, generator_1.default)(node).code); });
121
- var preComponentCode = (0, function_1.pipe)(path.node.body.filter(function (statement) { return !(0, helpers_1.isImportOrDefaultExport)(statement); }), function (statements) { return (0, metadata_1.collectMetadata)(statements, context.builder.component, useOptions); }, types.program, generator_1.default, function (generatorResult) { return generatorResult.code; });
122
+ var preComponentCode = (0, function_1.pipe)(path.node.body.filter(function (statement) { return !(0, helpers_1.isImportOrDefaultExport)(statement); }), function (statements) { return (0, metadata_1.collectMetadata)(statements, context.builder.component, options); }, types.program, generator_1.default, function (generatorResult) { return generatorResult.code; });
122
123
  // TODO: support multiple? e.g. for others to add imports?
123
124
  context.builder.component.hooks.preComponent = { code: preComponentCode };
124
125
  path.replaceWith(types.program(keepStatements));
@@ -171,7 +172,7 @@ function parseJsx(jsx, options) {
171
172
  var parsed = (0, json_1.tryParseJson)(toParse);
172
173
  (0, state_1.mapStateIdentifiers)(parsed);
173
174
  (0, context_1.extractContextComponents)(parsed);
174
- parsed.subComponents = subComponentFunctions.map(function (item) { return parseJsx(item, useOptions); });
175
+ parsed.subComponents = subComponentFunctions.map(function (item) { return parseJsx(item, options); });
175
176
  return parsed;
176
177
  }
177
178
  exports.parseJsx = parseJsx;
@@ -1,8 +1,8 @@
1
1
  import { MitosisComponent } from '../../types/mitosis-component';
2
2
  export declare type ParseMitosisOptions = {
3
- format: 'react' | 'simple';
4
3
  jsonHookNames?: string[];
5
4
  compileAwayPackages?: string[];
5
+ typescript: boolean;
6
6
  };
7
7
  export declare type Context = {
8
8
  builder: {
@@ -59,6 +59,11 @@ export declare type MitosisConfig = {
59
59
  * Configure a custom parser function which takes a string and returns MitosisJSON
60
60
  * Defaults to the JSXParser of this project (src/parsers/jsx)
61
61
  */
62
- parser?: (code: string) => MitosisComponent;
62
+ parser?: (code: string, path?: string) => MitosisComponent;
63
+ /**
64
+ * Configure a custom function that provides the output path for each target.
65
+ * If you provide this function, you must provide a value for every target yourself.
66
+ */
67
+ getTargetPath?: (target: Target) => string;
63
68
  };
64
69
  export {};