@builder.io/mitosis 0.6.7 → 0.7.0

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.
@@ -461,7 +461,7 @@ function isGlobalStyle(key) {
461
461
  key.startsWith('@'));
462
462
  }
463
463
  const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
464
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
464
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
465
465
  const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
466
466
  if (mapper) {
467
467
  const element = mapper(json, options);
@@ -562,13 +562,6 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
562
562
  }
563
563
  delete json.bindings.css;
564
564
  }
565
- if (thisIsComponent) {
566
- for (const key in json.bindings) {
567
- if (!((_o = json.slots) === null || _o === void 0 ? void 0 : _o[key])) {
568
- builderBindings[`component.options.${key}`] = json.bindings[key].code;
569
- }
570
- }
571
- }
572
565
  const element = el({
573
566
  tagName: thisIsComponent ? undefined : json.name,
574
567
  ...(hasCss && {
@@ -6,6 +6,7 @@ const helpers_1 = require("../../generators/stencil/helpers");
6
6
  const collect_class_string_1 = require("../../generators/stencil/helpers/collect-class-string");
7
7
  const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
8
8
  const for_1 = require("../../helpers/nodes/for");
9
+ const transform_to_jsx_1 = require("../../helpers/transform-to-jsx");
9
10
  const mitosis_node_1 = require("../../types/mitosis-node");
10
11
  const blockToStencil = ({ json, options = {}, insideJsx, rootRef, childComponents, }) => {
11
12
  var _a, _b, _c, _d, _e, _f, _g;
@@ -78,7 +79,8 @@ const blockToStencil = ({ json, options = {}, insideJsx, rootRef, childComponent
78
79
  }
79
80
  for (const key in json.properties) {
80
81
  const value = json.properties[key];
81
- str += ` ${key}="${value}" `;
82
+ // Stencil uses ´htmlFor´ (JSX) instead of ´for´ (HTML)
83
+ str += ` ${(0, transform_to_jsx_1.transformAttributeToJSX)(key)}="${value}" `;
82
84
  }
83
85
  for (const key in json.bindings) {
84
86
  const { code, arguments: cusArgs = [], type } = json.bindings[key];
@@ -7,6 +7,7 @@ const helpers_1 = require("../../generators/stencil/helpers");
7
7
  const get_code_processor_plugins_1 = require("../../generators/stencil/plugins/get-code-processor-plugins");
8
8
  const dash_case_1 = require("../../helpers/dash-case");
9
9
  const dedent_1 = require("../../helpers/dedent");
10
+ const event_handlers_1 = require("../../helpers/event-handlers");
10
11
  const fast_clone_1 = require("../../helpers/fast-clone");
11
12
  const get_child_components_1 = require("../../helpers/get-child-components");
12
13
  const get_props_1 = require("../../helpers/get-props");
@@ -21,168 +22,187 @@ const plugins_1 = require("../../modules/plugins");
21
22
  const standalone_1 = require("prettier/standalone");
22
23
  const componentToStencil = (_options = {
23
24
  typescript: true, // Stencil is uses .tsx always
24
- }) => ({ component }) => {
25
- var _a, _b, _c, _d, _e, _f, _g, _h;
26
- let json = (0, fast_clone_1.fastClone)(component);
27
- const options = (0, merge_options_1.initializeOptions)({
28
- target: 'stencil',
29
- component,
30
- defaults: _options,
31
- });
32
- if (options.plugins) {
33
- json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
34
- }
35
- (0, map_refs_1.mapRefs)(json, (refName) => `this.${refName}`);
36
- let css = (0, collect_css_1.collectCss)(json);
37
- const props = Array.from((0, get_props_1.getProps)(json));
38
- const events = props.filter((prop) => (0, helpers_1.isEvent)(prop));
39
- const defaultProps = json.defaultProps;
40
- const childComponents = (0, get_child_components_1.getChildComponents)(json);
41
- const processBindingOptions = { events };
42
- options.plugins = (0, get_code_processor_plugins_1.getCodeProcessorPlugins)(json, options, processBindingOptions);
43
- if (options.plugins) {
44
- json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
45
- }
46
- (0, strip_meta_properties_1.stripMetaProperties)(json);
47
- const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
48
- format: 'class',
49
- data: true,
50
- functions: false,
51
- getters: false,
52
- keyPrefix: '@State() ',
53
- });
54
- const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
55
- format: 'class',
56
- data: false,
57
- functions: true,
58
- getters: true,
59
- });
60
- let refs = json.refs
61
- ? Object.entries(json.refs)
62
- .map(([key, value]) => { var _a; return `private ${key}!: ${(_a = value.typeParameter) !== null && _a !== void 0 ? _a : 'HTMLElement'};`; })
63
- .join('\n')
64
- : '';
65
- const wrap = (0, helpers_1.needsWrap)(json.children);
66
- const withAttributePassing = !wrap && (0, attribute_passing_1.shouldAddAttributePassing)(json, options);
67
- const rootRef = (0, attribute_passing_1.getAddAttributePassingRef)(json, options);
68
- if (withAttributePassing && !refs.includes(rootRef)) {
69
- refs += `\nprivate ${rootRef}!: HTMLElement;`;
70
- }
71
- if (options.prettier !== false) {
72
- try {
73
- css = (0, standalone_1.format)(css, {
74
- parser: 'css',
75
- plugins: [require('prettier/parser-postcss')],
76
- });
25
+ }) => {
26
+ return ({ component }) => {
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
28
+ let json = (0, fast_clone_1.fastClone)(component);
29
+ const options = (0, merge_options_1.initializeOptions)({
30
+ target: 'stencil',
31
+ component,
32
+ defaults: _options,
33
+ });
34
+ if (options.plugins) {
35
+ json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
77
36
  }
78
- catch (err) {
79
- console.warn('Could not format css', err);
37
+ (0, map_refs_1.mapRefs)(json, (refName) => `this.${refName}`);
38
+ let css = (0, collect_css_1.collectCss)(json);
39
+ let props = Array.from((0, get_props_1.getProps)(json));
40
+ const events = props.filter((prop) => (0, helpers_1.isEvent)(prop));
41
+ const defaultProps = json.defaultProps;
42
+ const childComponents = (0, get_child_components_1.getChildComponents)(json);
43
+ const processBindingOptions = { events };
44
+ props = props
45
+ .map((prop) => {
46
+ // Stencil adds "on" to every `@Event` so we need to remove "on" from event props
47
+ // https://stenciljs.com/docs/events#using-events-in-jsx
48
+ if ((0, helpers_1.isEvent)(prop)) {
49
+ return (0, event_handlers_1.getEventNameWithoutOn)(prop);
50
+ }
51
+ return prop;
52
+ })
53
+ .filter((prop) => {
54
+ // Stencil doesn't need children as a prop
55
+ return prop !== 'children';
56
+ });
57
+ options.plugins = (0, get_code_processor_plugins_1.getCodeProcessorPlugins)(json, options, processBindingOptions);
58
+ if (options.plugins) {
59
+ json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
80
60
  }
81
- }
82
- let tagName = (0, helpers_1.getTagName)(json.name, options);
83
- if ((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.tagName) {
84
- // Deprecated option, we shouldn't use this, instead change the name of your Mitosis component
85
- tagName = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName;
86
- }
87
- const noDependencyOnUpdateHooks = (_d = (_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.filter((hook) => !hook.deps)) !== null && _d !== void 0 ? _d : [];
88
- /*
89
- * We want to create a function for every onUpdate hook that has dependencies.
90
- * We call the function once in "componentDidLoad"
91
- * And we create "Watch" decorators for every dependency
92
- */
93
- const dependencyOnUpdateHooks = (_f = (_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter((hook) => hook.deps)) !== null && _f !== void 0 ? _f : [];
94
- const coreImports = (0, helpers_1.getStencilCoreImportsAsString)({
95
- wrap,
96
- events,
97
- props,
98
- dataString,
99
- watch: Boolean(dependencyOnUpdateHooks === null || dependencyOnUpdateHooks === void 0 ? void 0 : dependencyOnUpdateHooks.length),
100
- });
101
- let str = (0, dedent_1.dedent) `
102
- ${(0, helpers_1.getImports)(json, options, childComponents)}
103
-
104
- import { ${coreImports} } from '@stencil/core';
105
-
106
- @Component({
107
- tag: '${tagName}',
108
- ${((_g = json.meta.useMetadata) === null || _g === void 0 ? void 0 : _g.isAttachedToShadowDom) ? 'shadow: true,' : ''}
109
- ${css.length
110
- ? `styles: \`
111
- ${(0, indent_1.indent)(css, 8)}\`,`
112
- : ''}
113
- })
114
- export class ${json.name} {
115
- ${refs}
116
- ${(0, helpers_1.getPropsAsCode)(props, json, defaultProps)}
117
- ${dataString}
118
- ${methodsString}
119
- ${(0, helpers_1.getExportsAndLocal)(json)}
120
- ${withAttributePassing ? (0, attribute_passing_1.getAttributePassingString)(true) : ''}
121
-
122
- ${dependencyOnUpdateHooks
123
- .map((hook, index) => {
124
- return `
125
- watch${index}Fn() {
126
- ${hook.code}
127
- }
61
+ (0, strip_meta_properties_1.stripMetaProperties)(json);
62
+ const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
63
+ format: 'class',
64
+ data: true,
65
+ functions: false,
66
+ getters: false,
67
+ keyPrefix: '@State() ',
68
+ });
69
+ const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
70
+ format: 'class',
71
+ data: false,
72
+ functions: true,
73
+ getters: true,
74
+ });
75
+ let refs = json.refs
76
+ ? Object.entries(json.refs)
77
+ .map(([key, value]) => { var _a; return `private ${key}!: ${(_a = value.typeParameter) !== null && _a !== void 0 ? _a : 'HTMLElement'};`; })
78
+ .join('\n')
79
+ : '';
80
+ const wrap = (0, helpers_1.needsWrap)(json.children);
81
+ const withAttributePassing = !wrap && (0, attribute_passing_1.shouldAddAttributePassing)(json, options);
82
+ const rootRef = (0, attribute_passing_1.getAddAttributePassingRef)(json, options);
83
+ if (withAttributePassing && !refs.includes(rootRef)) {
84
+ refs += `\nprivate ${rootRef}!: HTMLElement;`;
85
+ }
86
+ if (options.prettier !== false) {
87
+ try {
88
+ css = (0, standalone_1.format)(css, {
89
+ parser: 'css',
90
+ plugins: [require('prettier/parser-postcss')],
91
+ });
92
+ }
93
+ catch (err) {
94
+ console.warn('Could not format css', err);
95
+ }
96
+ }
97
+ let tagName = (0, helpers_1.getTagName)(json.name, options);
98
+ if ((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.tagName) {
99
+ // Deprecated option, we shouldn't use this, instead change the name of your Mitosis component
100
+ tagName = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName;
101
+ }
102
+ const noDependencyOnUpdateHooks = (_d = (_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.filter((hook) => !hook.deps)) !== null && _d !== void 0 ? _d : [];
103
+ /*
104
+ * We want to create a function for every onUpdate hook that has dependencies.
105
+ * We call the function once in "componentDidLoad"
106
+ * And we create "Watch" decorators for every dependency
107
+ */
108
+ const dependencyOnUpdateHooks = (_f = (_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter((hook) => hook.deps)) !== null && _f !== void 0 ? _f : [];
109
+ const coreImports = (0, helpers_1.getStencilCoreImportsAsString)({
110
+ wrap,
111
+ events,
112
+ props,
113
+ dataString,
114
+ watch: Boolean(dependencyOnUpdateHooks === null || dependencyOnUpdateHooks === void 0 ? void 0 : dependencyOnUpdateHooks.length),
115
+ });
116
+ const propOptions = {
117
+ ...options.propOptions,
118
+ ...(_h = (_g = json.meta.useMetadata) === null || _g === void 0 ? void 0 : _g.stencil) === null || _h === void 0 ? void 0 : _h.propOptions,
119
+ };
120
+ let str = (0, dedent_1.dedent) `
121
+ ${(0, helpers_1.getImports)(json, options, childComponents)}
122
+
123
+ import { ${coreImports} } from '@stencil/core';
124
+
125
+ @Component({
126
+ tag: '${tagName}',
127
+ ${((_j = json.meta.useMetadata) === null || _j === void 0 ? void 0 : _j.isAttachedToShadowDom) ? 'shadow: true,' : ''}
128
+ ${css.length
129
+ ? `styles: \`
130
+ ${(0, indent_1.indent)(css, 8)}\`,`
131
+ : ''}
132
+ })
133
+ export class ${json.name} {
134
+ ${refs}
135
+ ${(0, helpers_1.getPropsAsCode)({ props, json, defaultProps, propOptions })}
136
+ ${dataString}
137
+ ${methodsString}
138
+ ${(0, helpers_1.getExportsAndLocal)(json)}
139
+ ${withAttributePassing ? (0, attribute_passing_1.getAttributePassingString)(true) : ''}
128
140
 
129
- ${(0, helpers_1.getDepsAsArray)(hook.deps)
130
- .map((dep) => `@Watch("${dep}")`)
141
+ ${dependencyOnUpdateHooks
142
+ .map((hook, index) => {
143
+ return `
144
+ watch${index}Fn() {
145
+ ${hook.code}
146
+ }
147
+
148
+ ${(0, helpers_1.getDepsAsArray)(hook.deps)
149
+ .map((dep) => `@Watch("${dep}")`)
150
+ .join('\n')}
151
+ watch${index}(){
152
+ this.watch${index}Fn();
153
+ }
154
+ `;
155
+ })
131
156
  .join('\n')}
132
- watch${index}(){
133
- this.watch${index}Fn();
134
- }
135
- `;
136
- })
137
- .join('\n')}
138
-
139
- ${`componentDidLoad() {
140
- ${withAttributePassing
141
- ? `this.enableAttributePassing(this.${rootRef}, "${(0, dash_case_1.dashCase)(json.name)}");`
142
- : ''}
143
- ${json.hooks.onMount.length ? (0, on_mount_1.stringifySingleScopeOnMount)(json) : ''}
144
- ${dependencyOnUpdateHooks
145
- .map((_, index) => `this.watch${index}Fn();`)
146
- .join('\n')}
147
- }`}
148
- ${!((_h = json.hooks.onUnMount) === null || _h === void 0 ? void 0 : _h.code)
149
- ? ''
150
- : `disconnectedCallback() { ${json.hooks.onUnMount.code} }`}
151
- ${noDependencyOnUpdateHooks.length
152
- ? `componentDidUpdate() { ${noDependencyOnUpdateHooks
153
- .map((hook) => hook.code)
154
- .join('\n')} }`
155
- : ''}
156
-
157
- render() {
158
- return (${wrap ? '<Host>' : ''}
159
-
160
- ${json.children
161
- .map((item) => (0, blocks_1.blockToStencil)({
162
- json: item,
163
- options,
164
- insideJsx: true,
165
- childComponents,
166
- rootRef: withAttributePassing && rootRef === attribute_passing_1.ROOT_REF ? rootRef : undefined, // only pass rootRef if it's not the default
167
- }))
168
- .join('\n')}
169
-
170
- ${wrap ? '</Host>' : ''})
157
+
158
+ ${`componentDidLoad() {
159
+ ${withAttributePassing
160
+ ? `this.enableAttributePassing(this.${rootRef}, "${(0, dash_case_1.dashCase)(json.name)}");`
161
+ : ''}
162
+ ${json.hooks.onMount.length ? (0, on_mount_1.stringifySingleScopeOnMount)(json) : ''}
163
+ ${dependencyOnUpdateHooks
164
+ .map((_, index) => `this.watch${index}Fn();`)
165
+ .join('\n')}
166
+ }`}
167
+ ${!((_k = json.hooks.onUnMount) === null || _k === void 0 ? void 0 : _k.code)
168
+ ? ''
169
+ : `disconnectedCallback() { ${json.hooks.onUnMount.code} }`}
170
+ ${noDependencyOnUpdateHooks.length
171
+ ? `componentDidUpdate() { ${noDependencyOnUpdateHooks
172
+ .map((hook) => hook.code)
173
+ .join('\n')} }`
174
+ : ''}
175
+
176
+ render() {
177
+ return (${wrap ? '<Host>' : ''}
178
+
179
+ ${json.children
180
+ .map((item) => (0, blocks_1.blockToStencil)({
181
+ json: item,
182
+ options,
183
+ insideJsx: true,
184
+ childComponents,
185
+ rootRef: withAttributePassing && rootRef === attribute_passing_1.ROOT_REF ? rootRef : undefined, // only pass rootRef if it's not the default
186
+ }))
187
+ .join('\n')}
188
+
189
+ ${wrap ? '</Host>' : ''})
190
+ }
171
191
  }
172
- }
173
- `;
174
- if (options.plugins) {
175
- str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
176
- }
177
- if (options.prettier !== false) {
178
- str = (0, standalone_1.format)(str, {
179
- parser: 'typescript',
180
- plugins: [require('prettier/parser-typescript')],
181
- });
182
- }
183
- if (options.plugins) {
184
- str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
185
- }
186
- return str;
192
+ `;
193
+ if (options.plugins) {
194
+ str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
195
+ }
196
+ if (options.prettier !== false) {
197
+ str = (0, standalone_1.format)(str, {
198
+ parser: 'typescript',
199
+ plugins: [require('prettier/parser-typescript')],
200
+ });
201
+ }
202
+ if (options.plugins) {
203
+ str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
204
+ }
205
+ return str;
206
+ };
187
207
  };
188
208
  exports.componentToStencil = componentToStencil;
@@ -1,4 +1,4 @@
1
- import { ToStencilOptions } from '../../../generators/stencil/types';
1
+ import { StencilPropOption, ToStencilOptions } from '../../../generators/stencil/types';
2
2
  import { MitosisComponent, MitosisState } from '../../../types/mitosis-component';
3
3
  import { MitosisNode } from '../../../types/mitosis-node';
4
4
  export declare const isEvent: (key: string) => boolean;
@@ -7,7 +7,12 @@ export type ProcessBindingOptions = {
7
7
  };
8
8
  export declare const processBinding: (json: MitosisComponent, code: string, { events }: ProcessBindingOptions) => string;
9
9
  export declare const getTagName: (name: string, { prefix }: ToStencilOptions) => string;
10
- export declare const getPropsAsCode: (props: string[], json: MitosisComponent, defaultProps?: MitosisState | undefined) => string;
10
+ export declare const getPropsAsCode: ({ props, propOptions, defaultProps, json, }: {
11
+ props: string[];
12
+ json: MitosisComponent;
13
+ defaultProps?: MitosisState | undefined;
14
+ propOptions: Record<string, StencilPropOption>;
15
+ }) => string;
11
16
  /**
12
17
  * Check for root element if it needs a wrapping <Host>
13
18
  * @param children
@@ -14,7 +14,7 @@ const appendEmits = (str, events) => {
14
14
  let code = str;
15
15
  if (events.length) {
16
16
  for (const event of events) {
17
- code = code.replaceAll(`props.${event}(`, `props.${event}.emit(`);
17
+ code = code.replaceAll(`props.${event}(`, `props.${(0, event_handlers_1.getEventNameWithoutOn)(event)}.emit(`);
18
18
  }
19
19
  }
20
20
  return code;
@@ -43,7 +43,7 @@ const getTagName = (name, { prefix }) => {
43
43
  return dashName;
44
44
  };
45
45
  exports.getTagName = getTagName;
46
- const getPropsAsCode = (props, json, defaultProps) => {
46
+ const getPropsAsCode = ({ props, propOptions, defaultProps, json, }) => {
47
47
  const propsTypeRef = json.propsTypeRef;
48
48
  const internalTypes = json.types;
49
49
  const isInternalType = propsTypeRef && internalTypes && internalTypes.find((iType) => iType.includes(propsTypeRef));
@@ -52,6 +52,7 @@ const getPropsAsCode = (props, json, defaultProps) => {
52
52
  var _a;
53
53
  const defaultProp = defaultProps ? (_a = defaultProps[item]) === null || _a === void 0 ? void 0 : _a.code : undefined;
54
54
  const defaultPropString = defaultProp ? ` = ${defaultProp}` : '';
55
+ const propOption = propOptions[item];
55
56
  if ((0, exports.isEvent)(item)) {
56
57
  return `@Event() ${item}: any${defaultPropString}`;
57
58
  }
@@ -62,7 +63,7 @@ const getPropsAsCode = (props, json, defaultProps) => {
62
63
  !isInternalType
63
64
  ? `${propsTypeRef}["${item}"]`
64
65
  : 'any';
65
- return `@Prop() ${item}: ${type}${defaultPropString}`;
66
+ return `@Prop(${propOption ? JSON.stringify(propOption) : ''}) ${item}: ${type}${defaultPropString}`;
66
67
  })
67
68
  .join(';\n');
68
69
  };
@@ -1,5 +1,28 @@
1
1
  import { BaseTranspilerOptions } from '../../types/transpiler';
2
- export interface ToStencilOptions extends BaseTranspilerOptions {
2
+ export interface StencilPropOption {
3
+ attribute?: string;
4
+ mutable?: boolean;
5
+ reflect?: boolean;
6
+ }
7
+ export interface StencilPropOptions {
8
+ /**
9
+ * Add additional options for Stencil properties: https://stenciljs.com/docs/properties#prop-options.
10
+ * You need to map your properties you provide to the component.
11
+ *
12
+ * Example:
13
+ * ```tsx
14
+ * propOptions: {
15
+ * className: {
16
+ * attribute: 'classname',
17
+ * mutable: false,
18
+ * reflect: false,
19
+ * },
20
+ * }
21
+ * ```
22
+ */
23
+ propOptions?: Record<string, StencilPropOption>;
24
+ }
25
+ export interface ToStencilOptions extends BaseTranspilerOptions, StencilPropOptions {
3
26
  /**
4
27
  * Add a prefix for every component like `my`.
5
28
  * A Stencil component needs a prefix with a dash.
@@ -11,4 +34,4 @@ export interface ToStencilOptions extends BaseTranspilerOptions {
11
34
  */
12
35
  prefix?: string;
13
36
  }
14
- export type StencilMetadata = {};
37
+ export type StencilMetadata = {} & StencilPropOptions;
@@ -1,2 +1,3 @@
1
1
  export declare const checkIsEvent: (code: string) => boolean;
2
+ export declare const getEventNameWithoutOn: (code: string) => string;
2
3
  export declare const checkIsBindingNativeEvent: (code: string) => boolean;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkIsBindingNativeEvent = exports.checkIsEvent = void 0;
3
+ exports.checkIsBindingNativeEvent = exports.getEventNameWithoutOn = exports.checkIsEvent = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const checkIsEvent = (code) => code.startsWith('on');
5
6
  exports.checkIsEvent = checkIsEvent;
7
+ const getEventNameWithoutOn = (code) => (0, lodash_1.camelCase)(code.replace('on', ''));
8
+ exports.getEventNameWithoutOn = getEventNameWithoutOn;
6
9
  const nativeEvents = [
7
10
  'abort',
8
11
  'animationcancel',
@@ -0,0 +1,4 @@
1
+ export declare const JSX_TO_HTML_ATTR: {
2
+ for: string;
3
+ };
4
+ export declare const transformAttributeToJSX: (key: string) => string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformAttributeToJSX = exports.JSX_TO_HTML_ATTR = void 0;
4
+ const typescript_1 = require("../helpers/typescript");
5
+ exports.JSX_TO_HTML_ATTR = {
6
+ for: 'htmlFor',
7
+ };
8
+ const transformAttributeToJSX = (key) => {
9
+ if ((0, typescript_1.objectHasKey)(exports.JSX_TO_HTML_ATTR, key))
10
+ return exports.JSX_TO_HTML_ATTR[key];
11
+ return key;
12
+ };
13
+ exports.transformAttributeToJSX = transformAttributeToJSX;
@@ -103,7 +103,7 @@ const jsxElementToJson = (node) => {
103
103
  }),
104
104
  },
105
105
  scope: forArguments,
106
- children: [(0, exports.jsxElementToJson)(bodyExpression)],
106
+ children: [(0, exports.jsxElementToJson)(bodyExpression)].filter(nullable_1.checkIsDefined),
107
107
  });
108
108
  }
109
109
  }
@@ -144,7 +144,7 @@ const jsxElementToJson = (node) => {
144
144
  }).code,
145
145
  }),
146
146
  },
147
- children: [(0, exports.jsxElementToJson)(node.right)],
147
+ children: [(0, exports.jsxElementToJson)(node.right)].filter(nullable_1.checkIsDefined),
148
148
  });
149
149
  }
150
150
  else {
@@ -154,10 +154,11 @@ const jsxElementToJson = (node) => {
154
154
  else if (types.isConditionalExpression(node)) {
155
155
  // {foo ? <div /> : <span />} -> <Show when={foo} else={<span />}>...</Show>
156
156
  const child = (0, exports.jsxElementToJson)(node.consequent);
157
+ const elseCase = (0, exports.jsxElementToJson)(node.alternate);
157
158
  return (0, create_mitosis_node_1.createMitosisNode)({
158
159
  name: 'Show',
159
160
  meta: {
160
- else: (0, exports.jsxElementToJson)(node.alternate),
161
+ ...((0, nullable_1.checkIsDefined)(elseCase) ? { else: elseCase } : undefined),
161
162
  },
162
163
  bindings: {
163
164
  when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.test, { compact: true }).code }),
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.6.7",
25
+ "version": "0.7.0",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {