@builder.io/mitosis 0.0.91 → 0.0.93

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.
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.componentToQwik = void 0;
16
+ var standalone_1 = require("prettier/standalone");
16
17
  var babel_transform_1 = require("../../helpers/babel-transform");
17
18
  var fast_clone_1 = require("../../helpers/fast-clone");
18
19
  var collect_css_1 = require("../../helpers/styles/collect-css");
@@ -84,7 +85,7 @@ var componentToQwik = function (userOptions) {
84
85
  file.exportDefault(component.name);
85
86
  emitStyles(file, css_1);
86
87
  DEBUG && file.exportConst('COMPONENT', JSON.stringify(component));
87
- var sourceFile = '// GENERATED BY MITOSIS\n\n' + file.toString();
88
+ var sourceFile = file.toString();
88
89
  if (userOptions.plugins) {
89
90
  sourceFile = (0, plugins_1.runPreCodePlugins)(sourceFile, userOptions.plugins);
90
91
  sourceFile = (0, plugins_1.runPostCodePlugins)(sourceFile, userOptions.plugins);
@@ -99,11 +100,11 @@ var componentToQwik = function (userOptions) {
99
100
  };
100
101
  exports.componentToQwik = componentToQwik;
101
102
  function emitExports(file, component) {
102
- component.exports &&
103
- Object.keys(component.exports).forEach(function (key) {
104
- var exportObj = component.exports[key];
105
- file.src.emit(exportObj.code);
106
- });
103
+ Object.keys(component.exports || {}).forEach(function (key) {
104
+ var exportObj = component.exports[key];
105
+ var code = exportObj.code.startsWith('export ') ? exportObj.code : "export ".concat(exportObj.code);
106
+ file.src.emit(code);
107
+ });
107
108
  }
108
109
  function emitTagNameHack(file, component, metadataValue) {
109
110
  if (typeof metadataValue === 'string' && metadataValue) {
@@ -154,6 +155,9 @@ function emitJSX(file, component, mutable) {
154
155
  var handlers = new Map();
155
156
  var styles = new Map();
156
157
  var parentSymbolBindings = {};
158
+ if (file.options.isPretty) {
159
+ file.src.emit('\n\n');
160
+ }
157
161
  file.src.emit('return ', (0, jsx_1.renderJSXNodes)(file, directives, handlers, component.children, styles, parentSymbolBindings));
158
162
  }
159
163
  function emitUseContextProvider(file, component) {
@@ -194,11 +198,33 @@ function emitUseStyles(file, component) {
194
198
  var css = (0, collect_css_1.collectCss)(component, { prefix: component.name });
195
199
  if (css) {
196
200
  file.src.emit(file.import(file.qwikModule, 'useStylesScoped$').localName, '(STYLES);');
201
+ if (file.options.isPretty) {
202
+ file.src.emit('\n\n');
203
+ }
197
204
  }
198
205
  return css;
199
206
  }
200
207
  function emitStyles(file, css) {
201
208
  if (css) {
209
+ if (file.options.isPretty) {
210
+ file.src.emit('\n\n');
211
+ try {
212
+ css = (0, standalone_1.format)(css, {
213
+ parser: 'css',
214
+ plugins: [
215
+ // To support running in browsers
216
+ require('prettier/parser-postcss'),
217
+ ],
218
+ });
219
+ }
220
+ catch (e) {
221
+ throw new Error(e +
222
+ '\n' +
223
+ '========================================================================\n' +
224
+ css +
225
+ '\n\n========================================================================');
226
+ }
227
+ }
202
228
  file.exportConst('STYLES', '`\n' + css.replace(/`/g, '\\`') + '`\n');
203
229
  }
204
230
  }
@@ -109,9 +109,15 @@ function addComponent(fileSet, component, opts) {
109
109
  exports.addComponent = addComponent;
110
110
  function generateStyles(fromFile, dstFile, symbol, scoped) {
111
111
  return function () {
112
+ if (this.file.options.isPretty) {
113
+ this.emit('\n\n');
114
+ }
112
115
  this.emit((0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, scoped ? 'useStylesScopedQrl' : 'useStylesQrl'), [
113
116
  generateQrl(fromFile, dstFile, symbol),
114
117
  ]), ';');
118
+ if (this.file.options.isPretty) {
119
+ this.emit('\n\n');
120
+ }
115
121
  };
116
122
  }
117
123
  function addBuilderBlockClass(children) {
@@ -47,6 +47,7 @@ export declare class SrcBuilder {
47
47
  typeParameters(typeParameters: string[] | undefined): void;
48
48
  jsxExpression(expression: EmitFn): void;
49
49
  jsxBegin(symbol: Symbol | string, props: Record<string, any>, bindings: Record<string, any>): void;
50
+ isSelfClosingTag(symbol: Symbol | string): boolean;
50
51
  jsxEnd(symbol: Symbol | string): void;
51
52
  jsxBeginFragment(symbol: Symbol): void;
52
53
  jsxEndFragment(): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.iteratorProperty = exports.lastProperty = exports.isStatement = exports.iif = exports.arrowFnValue = exports.arrowFnBlock = exports.invoke = exports.quote = exports.Block = exports.Imports = exports.Symbol = exports.SrcBuilder = exports.File = void 0;
4
4
  var standalone_1 = require("prettier/standalone");
5
+ var jsx_1 = require("../../parsers/jsx");
5
6
  var builder_1 = require("../../parsers/builder");
6
7
  var stable_serialize_1 = require("./stable-serialize");
7
8
  var File = /** @class */ (function () {
@@ -49,6 +50,9 @@ var File = /** @class */ (function () {
49
50
  this.src.const(name, value, true, locallyVisible);
50
51
  };
51
52
  File.prototype.exportDefault = function (symbolName) {
53
+ if (this.options.isPretty) {
54
+ this.src.emit('\n\n');
55
+ }
52
56
  if (this.options.isModule) {
53
57
  this.src.emit('export default ', symbolName, ';');
54
58
  }
@@ -82,6 +86,7 @@ var File = /** @class */ (function () {
82
86
  require('prettier/parser-postcss'),
83
87
  require('prettier/parser-html'),
84
88
  require('prettier/parser-babel'),
89
+ require('prettier-plugin-organize-imports'),
85
90
  ],
86
91
  htmlWhitespaceSensitivity: 'ignore',
87
92
  });
@@ -155,6 +160,9 @@ var SrcBuilder = /** @class */ (function () {
155
160
  });
156
161
  });
157
162
  }
163
+ if (this.file.options.isPretty) {
164
+ this.emit('\n\n');
165
+ }
158
166
  return this;
159
167
  };
160
168
  SrcBuilder.prototype.emit = function () {
@@ -320,7 +328,12 @@ var SrcBuilder = /** @class */ (function () {
320
328
  var key = lastProperty(rawKey);
321
329
  if (isEvent(key)) {
322
330
  key = key + '$';
323
- binding_1 = "(event)=>".concat(binding_1);
331
+ if (this_1.file.options.isJSX) {
332
+ binding_1 = "(event)=>".concat(binding_1);
333
+ }
334
+ else {
335
+ binding_1 = "".concat(this_1.file.import(this_1.file.qwikModule, '$').localName, "((event)=>").concat(binding_1, ")");
336
+ }
324
337
  }
325
338
  else if (!binding_1 && rawKey in props) {
326
339
  binding_1 = quote(props[rawKey]);
@@ -349,7 +362,9 @@ var SrcBuilder = /** @class */ (function () {
349
362
  _loop_1(rawKey);
350
363
  }
351
364
  if (this.isJSX) {
352
- this.emit('>');
365
+ if (!this.isSelfClosingTag(symbol)) {
366
+ this.emit('>');
367
+ }
353
368
  }
354
369
  else {
355
370
  this.emit('},');
@@ -377,9 +392,17 @@ var SrcBuilder = /** @class */ (function () {
377
392
  }
378
393
  }
379
394
  };
395
+ SrcBuilder.prototype.isSelfClosingTag = function (symbol) {
396
+ return jsx_1.selfClosingTags.has(String(symbol));
397
+ };
380
398
  SrcBuilder.prototype.jsxEnd = function (symbol) {
381
399
  if (this.isJSX) {
382
- this.emit('</', symbol, '>');
400
+ if (this.isSelfClosingTag(symbol)) {
401
+ this.emit(' />');
402
+ }
403
+ else {
404
+ this.emit('</', symbol, '>');
405
+ }
383
406
  }
384
407
  else {
385
408
  this.emit('),');
@@ -10,9 +10,14 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
13
16
  Object.defineProperty(exports, "__esModule", { value: true });
14
17
  exports.blockToReact = void 0;
15
18
  var lodash_1 = require("lodash");
19
+ var is_children_1 = __importDefault(require("../../helpers/is-children"));
20
+ var slots_1 = require("../../helpers/slots");
16
21
  var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
17
22
  var is_valid_attribute_name_1 = require("../../helpers/is-valid-attribute-name");
18
23
  var for_1 = require("../../helpers/nodes/for");
@@ -133,7 +138,9 @@ var blockToReact = function (json, options, component, parentSlots) {
133
138
  }
134
139
  if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
135
140
  var processed = (0, helpers_1.processBinding)(json.bindings._text.code, options);
136
- if (options.type === 'native') {
141
+ if (options.type === 'native' &&
142
+ !(0, is_children_1.default)({ node: json }) &&
143
+ !(0, slots_1.isSlotProperty)(json.bindings._text.code.split('.')[1] || '')) {
137
144
  return "<Text>{".concat(processed, "}</Text>");
138
145
  }
139
146
  return "{".concat(processed, "}");
@@ -142,7 +142,7 @@ exports.componentToPreact = componentToPreact;
142
142
  var componentToReact = function (reactOptions) {
143
143
  if (reactOptions === void 0) { reactOptions = {}; }
144
144
  return function (_a) {
145
- var component = _a.component;
145
+ var component = _a.component, path = _a.path;
146
146
  var json = (0, fast_clone_1.fastClone)(component);
147
147
  var options = (0, merge_options_1.mergeOptions)(DEFAULT_OPTIONS, reactOptions);
148
148
  if (options.plugins) {
@@ -168,7 +168,7 @@ var componentToReact = function (reactOptions) {
168
168
  .replace(/;\n\nimport\s/g, ';\nimport ');
169
169
  }
170
170
  catch (err) {
171
- console.error('Format error for file:', str, JSON.stringify(json, null, 2));
171
+ console.error('Format error for file:');
172
172
  throw err;
173
173
  }
174
174
  }
@@ -23,13 +23,14 @@ var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
23
23
  var react_1 = require("./react");
24
24
  var bindings_1 = require("../helpers/bindings");
25
25
  var merge_options_1 = require("../helpers/merge-options");
26
+ var is_children_1 = __importDefault(require("../helpers/is-children"));
26
27
  var stylePropertiesThatMustBeNumber = new Set(['lineHeight']);
27
28
  var MEDIA_QUERY_KEY_REGEX = /^@media.*/;
28
29
  var collectReactNativeStyles = function (json) {
29
30
  var styleMap = {};
30
31
  var componentIndexes = {};
31
32
  (0, traverse_1.default)(json).forEach(function (item) {
32
- var _a;
33
+ var _a, _b;
33
34
  if (!(0, is_mitosis_node_1.isMitosisNode)(item) || typeof ((_a = item.bindings.css) === null || _a === void 0 ? void 0 : _a.code) !== 'string') {
34
35
  return;
35
36
  }
@@ -62,7 +63,10 @@ var collectReactNativeStyles = function (json) {
62
63
  var componentName = (0, lodash_1.camelCase)(item.name || 'view');
63
64
  var index = (componentIndexes[componentName] = (componentIndexes[componentName] || 0) + 1);
64
65
  var className = "".concat(componentName).concat(index);
65
- item.bindings.style = (0, bindings_1.createSingleBinding)({ code: "styles.".concat(className) });
66
+ var styleSheetName = "styles.".concat(className);
67
+ item.bindings.style = (0, bindings_1.createSingleBinding)({
68
+ code: ((_b = item.bindings.style) === null || _b === void 0 ? void 0 : _b.code.replace(/}$/, ", ...".concat(styleSheetName, " }"))) || styleSheetName,
69
+ });
66
70
  styleMap[className] = value;
67
71
  });
68
72
  return styleMap;
@@ -80,10 +84,14 @@ var PROCESS_REACT_NATIVE_PLUGIN = function () { return ({
80
84
  var _a, _b, _c, _d;
81
85
  if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
82
86
  // TODO: handle TextInput, Image, etc
83
- if (node.name.toLowerCase() === node.name) {
87
+ if ((0, is_children_1.default)({ node: node })) {
88
+ node.name = '';
89
+ }
90
+ else if (node.name.toLowerCase() === node.name) {
84
91
  node.name = 'View';
85
92
  }
86
- if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) || ((_d = (_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.length)) {
93
+ else if (((_a = node.properties._text) === null || _a === void 0 ? void 0 : _a.trim().length) ||
94
+ ((_d = (_c = (_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.length)) {
87
95
  node.name = 'Text';
88
96
  }
89
97
  if (node.properties.class) {
@@ -13,6 +13,12 @@ var is_upper_case_1 = require("../../helpers/is-upper-case");
13
13
  var for_1 = require("../../helpers/nodes/for");
14
14
  var helpers_1 = require("./helpers");
15
15
  var bindings_1 = require("../../helpers/bindings");
16
+ /**
17
+ * blockToSvelte executed after stripStateAndProps,
18
+ * when stripStateAndProps is executed,
19
+ * SLOT_PREFIX from `slot` change to `$$slots.`
20
+ */
21
+ var SLOT_PREFIX = '$$slots.';
16
22
  var mappers = {
17
23
  Fragment: function (_a) {
18
24
  var _b;
@@ -71,7 +77,7 @@ var mappers = {
71
77
  }
72
78
  return "\n <span #".concat(key, ">\n ").concat((_d = json.bindings[key]) === null || _d === void 0 ? void 0 : _d.code, "\n </span>\n ");
73
79
  }
74
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
80
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName, SLOT_PREFIX).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
75
81
  },
76
82
  };
77
83
  var BINDINGS_MAPPER = {
@@ -153,8 +159,8 @@ var blockToSvelte = function (_a) {
153
159
  }
154
160
  var textCode = (_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code;
155
161
  if (textCode) {
156
- if ((0, slots_1.isSlotProperty)(textCode)) {
157
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(textCode).toLowerCase(), "\"/>");
162
+ if ((0, slots_1.isSlotProperty)(textCode, SLOT_PREFIX)) {
163
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(textCode, SLOT_PREFIX).toLowerCase(), "\"/>");
158
164
  }
159
165
  return "{".concat(textCode, "}");
160
166
  }
@@ -2,12 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripStateAndProps = void 0;
4
4
  var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
5
+ var slots_1 = require("../../helpers/slots");
5
6
  var stripStateAndProps = function (_a) {
6
7
  var options = _a.options, json = _a.json;
7
8
  return function (code) {
8
9
  return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
9
10
  includeState: options.stateType === 'variables',
10
- replaceWith: function (name) { return (name === 'children' ? '$$slots.default' : name); },
11
+ replaceWith: function (name) {
12
+ return name === 'children'
13
+ ? '$$slots.default'
14
+ : (0, slots_1.isSlotProperty)(name)
15
+ ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$$slots.".concat(x); })
16
+ : name;
17
+ },
11
18
  });
12
19
  };
13
20
  };
@@ -34,6 +34,12 @@ var SPECIAL_PROPERTIES = {
34
34
  V_ON_AT: '@',
35
35
  V_BIND: 'v-bind',
36
36
  };
37
+ /**
38
+ * blockToVue executed after processBinding,
39
+ * when processBinding is executed,
40
+ * SLOT_PREFIX from `slot` change to `$slots.`
41
+ */
42
+ var SLOT_PREFIX = '$slots.';
37
43
  // TODO: Maybe in the future allow defining `string | function` as values
38
44
  var BINDING_MAPPERS = {
39
45
  innerHTML: 'v-html',
@@ -67,7 +73,7 @@ var NODE_MAPPERS = {
67
73
  Show: function (json, options, scope) {
68
74
  var _a, _b, _c, _d, _e, _f;
69
75
  var _g, _h;
70
- var ifValue = (0, slots_1.replaceSlotsInString)(((_g = json.bindings.when) === null || _g === void 0 ? void 0 : _g.code) || '', function (slotName) { return "$slots.".concat(slotName); });
76
+ var ifValue = ((_g = json.bindings.when) === null || _g === void 0 ? void 0 : _g.code) || '';
71
77
  var defaultShowTemplate = "\n <template ".concat(SPECIAL_PROPERTIES.V_IF, "=\"").concat((0, helpers_1.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)
72
78
  ? "\n <template ".concat(SPECIAL_PROPERTIES.V_ELSE, ">\n ").concat((0, exports.blockToVue)(json.meta.else, options), "\n </template>")
73
79
  : '', "\n ");
@@ -190,7 +196,7 @@ var NODE_MAPPERS = {
190
196
  }
191
197
  return "\n <template #".concat(key, ">\n ").concat((_c = json.bindings[key]) === null || _c === void 0 ? void 0 : _c.code, "\n </template>\n ");
192
198
  }
193
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
199
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(slotName, SLOT_PREFIX).toLowerCase(), "\">").concat(renderChildren(), "</slot>");
194
200
  },
195
201
  };
196
202
  var stringifyBinding = function (node) {
@@ -292,8 +298,8 @@ var blockToVue = function (node, options, scope) {
292
298
  }
293
299
  var textCode = (_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code;
294
300
  if (textCode) {
295
- if ((0, slots_1.isSlotProperty)(textCode)) {
296
- return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(textCode).toLowerCase(), "\"/>");
301
+ if ((0, slots_1.isSlotProperty)(textCode, SLOT_PREFIX)) {
302
+ return "<slot name=\"".concat((0, slots_1.stripSlotPrefix)(textCode, SLOT_PREFIX).toLowerCase(), "\"/>");
297
303
  }
298
304
  return "{{".concat(textCode, "}}");
299
305
  }
@@ -15,8 +15,9 @@ declare type ProcessBinding = {
15
15
  json: MitosisComponent;
16
16
  preserveGetter?: boolean;
17
17
  thisPrefix?: 'this' | '_this';
18
+ codeType?: 'state' | 'hooks' | 'bindings' | 'hooks-deps' | 'properties';
18
19
  };
19
- export declare const processBinding: ({ code, options, json, preserveGetter, thisPrefix, }: ProcessBinding) => string;
20
+ export declare const processBinding: ({ code, options, json, preserveGetter, thisPrefix, codeType, }: ProcessBinding) => string;
20
21
  export declare const getContextValue: (args: Pick<ProcessBinding, 'options' | 'json' | 'thisPrefix'>) => ({ name, ref, value }: ContextSetInfo) => Nullable<string>;
21
22
  export declare const checkIfContextHasStrName: (context: ContextGetInfo | ContextSetInfo) => boolean;
22
23
  export declare const getContextKey: (context: ContextGetInfo | ContextSetInfo) => string;
@@ -29,6 +29,7 @@ var core_1 = require("@babel/core");
29
29
  var lodash_1 = require("lodash");
30
30
  var patterns_1 = require("../../helpers/patterns");
31
31
  var replace_identifiers_1 = require("../../helpers/replace-identifiers");
32
+ var slots_1 = require("../../helpers/slots");
32
33
  var html_tags_1 = require("../../constants/html_tags");
33
34
  var addPropertiesToJson = function (properties) {
34
35
  return function (json) { return (__assign(__assign({}, json), { properties: __assign(__assign({}, json.properties), properties) })); };
@@ -131,29 +132,67 @@ function prefixMethodsWithThis(input, component, options) {
131
132
  return input;
132
133
  }
133
134
  }
135
+ function optionsApiStateAndPropsReplace(name, thisPrefix, codeType) {
136
+ if (codeType === 'bindings') {
137
+ return (0, slots_1.isSlotProperty)(name) ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$slots.".concat(x); }) : name;
138
+ }
139
+ if (name === 'children' || name.startsWith('children.')) {
140
+ return "".concat(thisPrefix, ".$slots.default");
141
+ }
142
+ return (0, slots_1.isSlotProperty)(name)
143
+ ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "".concat(thisPrefix, ".$slots.").concat(x); })
144
+ : "".concat(thisPrefix, ".").concat(name);
145
+ }
134
146
  // TODO: migrate all stripStateAndPropsRefs to use this here
135
147
  // to properly replace context refs
136
148
  var processBinding = function (_a) {
137
- var code = _a.code, options = _a.options, json = _a.json, _b = _a.preserveGetter, preserveGetter = _b === void 0 ? false : _b, _c = _a.thisPrefix, thisPrefix = _c === void 0 ? 'this' : _c;
149
+ var code = _a.code, options = _a.options, json = _a.json, _b = _a.preserveGetter, preserveGetter = _b === void 0 ? false : _b, _c = _a.thisPrefix, thisPrefix = _c === void 0 ? 'this' : _c, codeType = _a.codeType;
138
150
  try {
139
- return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
140
- includeState: true,
141
- // we don't want to process `props` in the Composition API because it has a `props` ref,
142
- // therefore we can keep pointing to `props.${value}`
143
- includeProps: options.api === 'options',
151
+ return (0, function_1.pipe)(
152
+ // processed twice, once for props and once for state
153
+ (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
154
+ includeState: false,
155
+ includeProps: true,
144
156
  replaceWith: function (name) {
145
157
  switch (options.api) {
158
+ // keep pointing to `props.${value}`
146
159
  case 'composition':
147
- return name;
148
- case 'options':
160
+ if (codeType === 'bindings') {
161
+ return (0, slots_1.isSlotProperty)(name)
162
+ ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "$slots.".concat(x); })
163
+ : name;
164
+ }
149
165
  if (name === 'children' || name.startsWith('children.')) {
150
- return '${thisPrefix}.$slots.default';
166
+ return "useSlots().default";
151
167
  }
152
- return "".concat(thisPrefix, ".").concat(name);
168
+ return (0, slots_1.isSlotProperty)(name)
169
+ ? (0, slots_1.replaceSlotsInString)(name, function (x) { return "useSlots().".concat(x); })
170
+ : "props.".concat(name);
171
+ case 'options':
172
+ return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
153
173
  }
154
174
  },
155
- }), function (x) {
156
- return (0, function_1.pipe)(x, function (code) { return processRefs({ input: code, component: json, options: options, thisPrefix: thisPrefix }); }, function (code) { return prefixMethodsWithThis(code, json, options); }, function (code) { return (preserveGetter === false ? (0, patterns_1.stripGetter)(code) : code); });
175
+ }), function (code) {
176
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
177
+ includeState: true,
178
+ includeProps: false,
179
+ replaceWith: function (name) {
180
+ switch (options.api) {
181
+ case 'composition':
182
+ return name;
183
+ case 'options':
184
+ return optionsApiStateAndPropsReplace(name, thisPrefix, codeType);
185
+ }
186
+ },
187
+ });
188
+ }, function (x) {
189
+ return (0, function_1.pipe)(x,
190
+ // bindings does not need process refs and prefix this
191
+ function (code) {
192
+ return codeType === 'bindings'
193
+ ? code
194
+ : processRefs({ input: code, component: json, options: options, thisPrefix: thisPrefix });
195
+ }, function (code) { return (codeType === 'bindings' ? code : prefixMethodsWithThis(code, json, options)); }, function (code) { return (preserveGetter === false ? (0, patterns_1.stripGetter)(code) : code); });
157
196
  });
158
197
  }
159
198
  catch (e) {
@@ -112,7 +112,7 @@ var componentToVue = function (userOptions) {
112
112
  case 'state':
113
113
  return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
114
114
  case 'bindings':
115
- return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
115
+ return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); };
116
116
  case 'hooks-deps':
117
117
  return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c, { includeProps: false }); };
118
118
  case 'properties':
@@ -124,7 +124,7 @@ var componentToVue = function (userOptions) {
124
124
  case 'hooks':
125
125
  return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component }); };
126
126
  case 'bindings':
127
- return function (c) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(c); };
127
+ return function (code) { return (0, helpers_1.processBinding)({ code: code, options: options, json: component, codeType: codeType }); };
128
128
  case 'properties':
129
129
  case 'hooks-deps':
130
130
  return function (c) { return c; };
@@ -150,7 +150,9 @@ var componentToVue = function (userOptions) {
150
150
  (0, map_refs_1.mapRefs)(component, function (refName) { return "this.$refs.".concat(refName); });
151
151
  }
152
152
  // need to run this before we process the component's code
153
- var elementProps = Array.from((0, get_props_1.getProps)(component)).filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
153
+ var props = Array.from((0, get_props_1.getProps)(component));
154
+ var elementProps = props.filter(function (prop) { return !(0, slots_1.isSlotProperty)(prop); });
155
+ var slotsProps = props.filter(function (prop) { return (0, slots_1.isSlotProperty)(prop); });
154
156
  component = (0, plugins_1.runPostJsonPlugins)(component, options.plugins);
155
157
  var css = (0, collect_css_1.collectCss)(component, {
156
158
  prefix: (_c = (_b = options.cssNamespace) === null || _b === void 0 ? void 0 : _b.call(options)) !== null && _c !== void 0 ? _c : undefined,
@@ -174,6 +176,7 @@ var componentToVue = function (userOptions) {
174
176
  (0, lodash_1.size)(component.context.set) && vueImports.push('provide');
175
177
  (0, lodash_1.size)(component.context.get) && vueImports.push('inject');
176
178
  (0, lodash_1.size)(Object.keys(component.state).filter(function (key) { var _a; return ((_a = component.state[key]) === null || _a === void 0 ? void 0 : _a.type) === 'property'; })) && vueImports.push('ref');
179
+ (0, lodash_1.size)(slotsProps) && vueImports.push('useSlots');
177
180
  }
178
181
  var tsLangAttribute = options.typescript ? "lang='ts'" : '';
179
182
  var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "], ["\n ", "\n\n\n <script ", " ", ">\n ", "\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n "])), template.trim().length > 0
@@ -1,4 +1,5 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
+ export declare const getTextValue: (node: MitosisNode) => string;
2
3
  export default function isChildren({ node, extraMatches, }: {
3
4
  node: MitosisNode;
4
5
  extraMatches?: string[];
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTextValue = void 0;
4
+ var getTextValue = function (node) {
5
+ var _a;
6
+ var textValue = ((_a = node.bindings._text) === null || _a === void 0 ? void 0 : _a.code) || node.properties.__text || '';
7
+ return textValue.replace(/\s+/g, '');
8
+ };
9
+ exports.getTextValue = getTextValue;
3
10
  function isChildren(_a) {
4
- var _b;
5
- var node = _a.node, _c = _a.extraMatches, extraMatches = _c === void 0 ? [] : _c;
6
- var textValue = ((_b = node.bindings._text) === null || _b === void 0 ? void 0 : _b.code) || node.properties.__text || '';
7
- var trimmedTextValue = textValue.replace(/\s+/g, '');
8
- return ['props.children', 'children'].concat(extraMatches).includes(trimmedTextValue);
11
+ var node = _a.node, _b = _a.extraMatches, extraMatches = _b === void 0 ? [] : _b;
12
+ var textValue = (0, exports.getTextValue)(node);
13
+ return ['props.children', 'children'].concat(extraMatches).includes(textValue);
9
14
  }
10
15
  exports.default = isChildren;
@@ -85,14 +85,14 @@ var _replaceIdentifiers = function (path, _a) {
85
85
  path.replaceWith(newMemberExpression);
86
86
  }
87
87
  catch (err) {
88
- console.debug('Could not replace', path.node, 'with', to.toString());
88
+ console.debug('Could not replace node.');
89
89
  // throw err;
90
90
  }
91
91
  }
92
92
  }
93
93
  else {
94
94
  if (core_1.types.isIdentifier(path.node)) {
95
- console.debug("Could not replace Identifier '".concat(from.toString(), "' with nothing."));
95
+ console.debug("Could not replace Identifier with nothing.");
96
96
  }
97
97
  else {
98
98
  // if we're looking at a member expression, e.g. `props.foo` and no `to` was provided, then we want to strip out
@@ -1,4 +1,4 @@
1
1
  export declare type SlotMapper = (slotName: string) => string;
2
- export declare const isSlotProperty: (key: string) => boolean;
3
- export declare const stripSlotPrefix: (key: string) => string;
2
+ export declare const isSlotProperty: (key: string, slotPrefix?: string) => boolean;
3
+ export declare const stripSlotPrefix: (key: string, slotPrefix?: string) => string;
4
4
  export declare function replaceSlotsInString(code: string, mapper: SlotMapper): string;
@@ -4,10 +4,14 @@ exports.replaceSlotsInString = exports.stripSlotPrefix = exports.isSlotProperty
4
4
  var core_1 = require("@babel/core");
5
5
  var babel_transform_1 = require("./babel-transform");
6
6
  var SLOT_PREFIX = 'slot';
7
- var isSlotProperty = function (key) { return key.startsWith(SLOT_PREFIX); };
7
+ var isSlotProperty = function (key, slotPrefix) {
8
+ if (slotPrefix === void 0) { slotPrefix = SLOT_PREFIX; }
9
+ return key.startsWith(slotPrefix);
10
+ };
8
11
  exports.isSlotProperty = isSlotProperty;
9
- var stripSlotPrefix = function (key) {
10
- return (0, exports.isSlotProperty)(key) ? key.substring(SLOT_PREFIX.length) : key;
12
+ var stripSlotPrefix = function (key, slotPrefix) {
13
+ if (slotPrefix === void 0) { slotPrefix = SLOT_PREFIX; }
14
+ return (0, exports.isSlotProperty)(key, slotPrefix) ? key.substring(slotPrefix.length) : key;
11
15
  };
12
16
  exports.stripSlotPrefix = stripSlotPrefix;
13
17
  function replaceSlotsInString(code, mapper) {
@@ -53,7 +53,7 @@ var traverse_1 = __importDefault(require("traverse"));
53
53
  var create_mitosis_node_1 = require("../helpers/create-mitosis-node");
54
54
  var filter_empty_text_nodes_1 = require("../helpers/filter-empty-text-nodes");
55
55
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
56
- var JSON5 = __importStar(require("json5"));
56
+ var json5_1 = __importStar(require("json5")), JSON5 = json5_1;
57
57
  var builder_1 = require("../parsers/builder");
58
58
  var bindings_1 = require("../helpers/bindings");
59
59
  function getComponentInputNames(componentName) {
@@ -72,6 +72,12 @@ exports.components = {
72
72
  CoreButton: function (node, context, components) {
73
73
  var properties = {};
74
74
  var bindings = {};
75
+ if (!node.properties.href && node.bindings.css) {
76
+ var css = json5_1.default.parse(node.bindings.css.code);
77
+ // When using button tag ensure we have all: unset and
78
+ // be sure that is the first style in the list
79
+ node.bindings.css.code = json5_1.default.stringify(__assign({ all: 'unset' }, css));
80
+ }
75
81
  if ('link' in node.properties) {
76
82
  properties.href = node.properties.link;
77
83
  }
@@ -79,10 +85,22 @@ exports.components = {
79
85
  bindings.href = node.properties.link;
80
86
  }
81
87
  if ('text' in node.properties) {
82
- properties.innerHTML = node.properties.text;
88
+ node.children = [
89
+ (0, create_mitosis_node_1.createMitosisNode)({
90
+ properties: {
91
+ _text: node.properties.text,
92
+ },
93
+ }),
94
+ ];
83
95
  }
84
96
  if ('text' in node.bindings) {
85
- bindings.innerHTML = node.properties.text;
97
+ node.children = [
98
+ (0, create_mitosis_node_1.createMitosisNode)({
99
+ bindings: {
100
+ _text: node.bindings.text,
101
+ },
102
+ }),
103
+ ];
86
104
  }
87
105
  if ('openInNewTab' in node.bindings) {
88
106
  bindings.target = "".concat(node.bindings.openInNewTab, " ? '_blank' : '_self'");
@@ -91,7 +109,7 @@ exports.components = {
91
109
  var hasLink = node.properties.link || node.bindings.link;
92
110
  return (0, create_mitosis_node_1.createMitosisNode)(__assign(__assign({}, node), {
93
111
  // TODO: use 'button' tag for no link, and add `all: unset` to CSS string only then
94
- name: hasLink ? 'a' : node.properties.$tagName || 'span', properties: __assign(__assign({}, (0, lodash_1.omit)(node.properties, omitFields)), properties), bindings: __assign(__assign({}, (0, lodash_1.omit)(node.bindings, omitFields)), bindings) }));
112
+ name: hasLink ? 'a' : 'button', properties: __assign(__assign({}, (0, lodash_1.omit)(node.properties, omitFields)), properties), bindings: __assign(__assign({}, (0, lodash_1.omit)(node.bindings, omitFields)), bindings) }));
95
113
  },
96
114
  Embed: function (node, context, components) {
97
115
  return wrapOutput(node, (0, create_mitosis_node_1.createMitosisNode)({