@builder.io/mitosis 0.0.56-104 → 0.0.56-107

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 (49) hide show
  1. package/dist/src/__tests__/shared.d.ts +6 -2
  2. package/dist/src/__tests__/shared.js +43 -14
  3. package/dist/src/generators/angular.d.ts +2 -2
  4. package/dist/src/generators/builder.d.ts +4 -11
  5. package/dist/src/generators/helpers/functions.d.ts +2 -0
  6. package/dist/src/generators/helpers/functions.js +28 -0
  7. package/dist/src/generators/html.d.ts +3 -3
  8. package/dist/src/generators/liquid.d.ts +2 -2
  9. package/dist/src/generators/lit/generate.d.ts +2 -2
  10. package/dist/src/generators/marko/generate.d.ts +2 -2
  11. package/dist/src/generators/mitosis.d.ts +3 -4
  12. package/dist/src/generators/qwik/component-generator.d.ts +2 -2
  13. package/dist/src/generators/qwik/component-generator.js +4 -3
  14. package/dist/src/generators/qwik/component.js +3 -2
  15. package/dist/src/generators/qwik/src-generator.js +2 -1
  16. package/dist/src/generators/qwik/stable-serialize.d.ts +6 -0
  17. package/dist/src/generators/qwik/stable-serialize.js +51 -0
  18. package/dist/src/generators/react/generator.d.ts +3 -3
  19. package/dist/src/generators/react-native.d.ts +2 -2
  20. package/dist/src/generators/solid/index.d.ts +2 -2
  21. package/dist/src/generators/stencil/generate.d.ts +2 -2
  22. package/dist/src/generators/svelte.d.ts +2 -2
  23. package/dist/src/generators/svelte.js +33 -31
  24. package/dist/src/generators/swift-ui.d.ts +3 -5
  25. package/dist/src/generators/template.d.ts +2 -2
  26. package/dist/src/generators/vue.d.ts +5 -3
  27. package/dist/src/generators/vue.js +213 -102
  28. package/dist/src/helpers/nullable.d.ts +1 -2
  29. package/dist/src/parsers/jsx/component-types.d.ts +1 -1
  30. package/dist/src/parsers/jsx/component-types.js +15 -2
  31. package/dist/src/parsers/jsx/element-parser.d.ts +6 -0
  32. package/dist/src/parsers/jsx/element-parser.js +232 -0
  33. package/dist/src/parsers/jsx/exports.d.ts +3 -0
  34. package/dist/src/parsers/jsx/exports.js +78 -0
  35. package/dist/src/parsers/jsx/function-parser.d.ts +7 -0
  36. package/dist/src/parsers/jsx/function-parser.js +291 -0
  37. package/dist/src/parsers/jsx/helpers.d.ts +2 -0
  38. package/dist/src/parsers/jsx/helpers.js +30 -1
  39. package/dist/src/parsers/jsx/imports.d.ts +7 -0
  40. package/dist/src/parsers/jsx/imports.js +65 -0
  41. package/dist/src/parsers/jsx/jsx.js +29 -515
  42. package/dist/src/parsers/jsx/state.d.ts +1 -1
  43. package/dist/src/parsers/jsx/state.js +6 -6
  44. package/dist/src/targets.d.ts +21 -28
  45. package/dist/src/targets.js +2 -2
  46. package/dist/src/types/config.d.ts +0 -1
  47. package/dist/src/types/transpiler.d.ts +6 -1
  48. package/dist/tsconfig.build.tsbuildinfo +1 -1
  49. package/package.json +4 -3
@@ -1,4 +1,8 @@
1
- import { Transpiler } from '../types/transpiler';
1
+ import { TranspilerGenerator } from '../types/transpiler';
2
2
  import { Target } from '../types/config';
3
3
  export declare const runTestsForJsx: () => void;
4
- export declare const runTestsForTarget: (target: Target, generator: Transpiler) => void;
4
+ export declare const runTestsForTarget: <X>({ target, generator, options, }: {
5
+ target: Target;
6
+ generator: TranspilerGenerator<X, string>;
7
+ options: X;
8
+ }) => void;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.runTestsForTarget = exports.runTestsForJsx = void 0;
4
15
  var jsx_1 = require("../parsers/jsx");
@@ -60,6 +71,7 @@ var submitButtonBlock = require('./data/blocks/submit-button.raw');
60
71
  var text = require('./data/blocks/text.raw');
61
72
  var textarea = require('./data/blocks/textarea.raw');
62
73
  var video = require('./data/blocks/video.raw');
74
+ var builderRenderContent = require('./data/blocks/builder-render-content.raw');
63
75
  var path = 'test-path';
64
76
  var BASIC_TESTS = {
65
77
  Basic: basic,
@@ -93,6 +105,7 @@ var BASIC_TESTS = {
93
105
  preserveTyping: preserveTyping,
94
106
  typeDependency: typeDependency,
95
107
  defaultValsWithTypes: require('./data/types/component-with-default-values-types.raw'),
108
+ 'import types': builderRenderContent,
96
109
  subComponent: subComponent,
97
110
  nestedStyles: nestedStyles,
98
111
  propsDestructure: propsDestructure,
@@ -296,6 +309,12 @@ var TESTS_FOR_TARGET = {
296
309
  ],
297
310
  };
298
311
  var runTestsForJsx = function () {
312
+ test('Remove Internal mitosis package', function () {
313
+ var component = (0, jsx_1.parseJsx)(basicMitosis, {
314
+ compileAwayPackages: ['@dummy/custom-mitosis'],
315
+ });
316
+ expect(component).toMatchSnapshot();
317
+ });
299
318
  JSX_TESTS.forEach(function (tests) {
300
319
  Object.keys(tests).forEach(function (key) {
301
320
  test(key, function () {
@@ -306,28 +325,38 @@ var runTestsForJsx = function () {
306
325
  });
307
326
  };
308
327
  exports.runTestsForJsx = runTestsForJsx;
309
- var runTestsForTarget = function (target, generator) {
328
+ var runTestsForTarget = function (_a) {
329
+ var target = _a.target, generator = _a.generator, options = _a.options;
310
330
  var testsArray = TESTS_FOR_TARGET[target];
311
331
  test('Remove Internal mitosis package', function () {
312
332
  var component = (0, jsx_1.parseJsx)(basicMitosis, {
313
333
  compileAwayPackages: ['@dummy/custom-mitosis'],
314
334
  });
315
- var output = generator({ component: component, path: path });
335
+ var output = generator(options)({ component: component, path: path });
316
336
  expect(output).toMatchSnapshot();
317
337
  });
338
+ var configurations = [
339
+ { options: __assign(__assign({}, options), { typescript: false }), testName: 'Javascript Test' },
340
+ { options: __assign(__assign({}, options), { typescript: true }), testName: 'Typescript Test' },
341
+ ];
318
342
  if (testsArray) {
319
- testsArray.forEach(function (tests) {
320
- Object.keys(tests).forEach(function (key) {
321
- test(key, function () {
322
- try {
323
- var component = (0, jsx_1.parseJsx)(tests[key]);
324
- var output = generator({ component: component, path: path });
325
- expect(output).toMatchSnapshot();
326
- }
327
- catch (error) {
328
- console.log('failed to parse', error);
329
- throw error;
330
- }
343
+ configurations.forEach(function (_a) {
344
+ var options = _a.options, testName = _a.testName;
345
+ describe(testName, function () {
346
+ testsArray.forEach(function (tests) {
347
+ Object.keys(tests).forEach(function (key) {
348
+ test(key, function () {
349
+ try {
350
+ var component = (0, jsx_1.parseJsx)(tests[key]);
351
+ var output = generator(options)({ component: component, path: path });
352
+ expect(output).toMatchSnapshot();
353
+ }
354
+ catch (error) {
355
+ console.log('failed to parse', error);
356
+ throw error;
357
+ }
358
+ });
359
+ });
331
360
  });
332
361
  });
333
362
  });
@@ -1,5 +1,5 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
2
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
3
3
  export interface ToAngularOptions extends BaseTranspilerOptions {
4
4
  standalone?: boolean;
5
5
  }
@@ -10,5 +10,5 @@ interface AngularBlockOptions {
10
10
  domRefs?: string[];
11
11
  }
12
12
  export declare const blockToAngular: (json: MitosisNode, options?: ToAngularOptions, blockOptions?: AngularBlockOptions) => string;
13
- export declare const componentToAngular: (options?: ToAngularOptions) => Transpiler;
13
+ export declare const componentToAngular: TranspilerGenerator<ToAngularOptions>;
14
14
  export {};
@@ -1,19 +1,12 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
- import { BuilderElement } from '@builder.io/sdk';
3
- import { TranspilerArgs } from '../types/transpiler';
4
- export interface ToBuilderOptions {
2
+ import { BuilderContent, BuilderElement } from '@builder.io/sdk';
3
+ import { BaseTranspilerOptions, TranspilerArgs } from '../types/transpiler';
4
+ export interface ToBuilderOptions extends BaseTranspilerOptions {
5
5
  includeIds?: boolean;
6
6
  }
7
7
  declare type InternalOptions = {
8
8
  skipMapper?: boolean;
9
9
  };
10
10
  export declare const blockToBuilder: (json: MitosisNode, options?: ToBuilderOptions, _internalOptions?: InternalOptions) => BuilderElement;
11
- export declare const componentToBuilder: (options?: ToBuilderOptions) => ({ component }: TranspilerArgs) => {
12
- data: {
13
- httpRequests: import("../types/json")._JSON;
14
- jsCode: string;
15
- tsCode: string;
16
- blocks: BuilderElement[];
17
- };
18
- };
11
+ export declare const componentToBuilder: (options?: ToBuilderOptions) => ({ component }: TranspilerArgs) => BuilderContent;
19
12
  export {};
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../modules/plugins';
2
+ export declare const FUNCTION_HACK_PLUGIN: Plugin;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUNCTION_HACK_PLUGIN = void 0;
4
+ var FUNCTION_HACK_PLUGIN = function () { return ({
5
+ json: {
6
+ pre: function (json) {
7
+ var _a, _b;
8
+ for (var key in json.state) {
9
+ var value = (_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.code;
10
+ var type = (_b = json.state[key]) === null || _b === void 0 ? void 0 : _b.type;
11
+ if (typeof value === 'string' && type === 'method') {
12
+ var newValue = "function ".concat(value);
13
+ json.state[key] = {
14
+ code: newValue,
15
+ type: 'method',
16
+ };
17
+ }
18
+ else if (typeof value === 'string' && type === 'function') {
19
+ json.state[key] = {
20
+ code: value,
21
+ type: 'method',
22
+ };
23
+ }
24
+ }
25
+ },
26
+ },
27
+ }); };
28
+ exports.FUNCTION_HACK_PLUGIN = FUNCTION_HACK_PLUGIN;
@@ -1,7 +1,7 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  export interface ToHtmlOptions extends BaseTranspilerOptions {
3
3
  format?: 'class' | 'script';
4
4
  prefix?: string;
5
5
  }
6
- export declare const componentToHtml: (options?: ToHtmlOptions) => Transpiler;
7
- export declare const componentToCustomElement: (options?: ToHtmlOptions) => Transpiler;
6
+ export declare const componentToHtml: TranspilerGenerator<ToHtmlOptions>;
7
+ export declare const componentToCustomElement: TranspilerGenerator<ToHtmlOptions>;
@@ -1,4 +1,4 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  export interface ToLiquidOptions extends BaseTranspilerOptions {
3
3
  reactive?: boolean;
4
4
  }
@@ -8,4 +8,4 @@ export interface ToLiquidOptions extends BaseTranspilerOptions {
8
8
  * Shopify will reject our PUT to update the template
9
9
  */
10
10
  export declare const isValidLiquidBinding: (str?: string) => boolean;
11
- export declare const componentToLiquid: (options?: ToLiquidOptions) => Transpiler;
11
+ export declare const componentToLiquid: TranspilerGenerator<ToLiquidOptions>;
@@ -1,5 +1,5 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../../types/transpiler';
2
2
  export interface ToLitOptions extends BaseTranspilerOptions {
3
3
  useShadowDom?: boolean;
4
4
  }
5
- export declare const componentToLit: (options?: ToLitOptions) => Transpiler;
5
+ export declare const componentToLit: TranspilerGenerator<ToLitOptions>;
@@ -1,7 +1,7 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../../types/transpiler';
2
2
  export interface ToMarkoOptions extends BaseTranspilerOptions {
3
3
  }
4
- export declare const componentToMarko: (userOptions?: ToMarkoOptions) => Transpiler;
4
+ export declare const componentToMarko: TranspilerGenerator<ToMarkoOptions>;
5
5
  /**
6
6
  * Convert marko expressions to valid html
7
7
  *
@@ -1,9 +1,8 @@
1
- import { Transpiler } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  import { MitosisNode } from '../types/mitosis-node';
3
- export interface ToMitosisOptions {
4
- prettier?: boolean;
3
+ export interface ToMitosisOptions extends BaseTranspilerOptions {
5
4
  format: 'react' | 'legacy';
6
5
  }
7
6
  export declare const DEFAULT_FORMAT: ToMitosisOptions['format'];
8
7
  export declare const blockToMitosis: (json: MitosisNode, toMitosisOptions?: Partial<ToMitosisOptions>) => string;
9
- export declare const componentToMitosis: (toMitosisOptions?: Partial<ToMitosisOptions>) => Transpiler;
8
+ export declare const componentToMitosis: TranspilerGenerator<Partial<ToMitosisOptions>>;
@@ -1,4 +1,4 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../../types/transpiler';
2
2
  export interface ToQwikOptions extends BaseTranspilerOptions {
3
3
  }
4
- export declare const componentToQwik: (userOptions?: ToQwikOptions) => Transpiler;
4
+ export declare const componentToQwik: TranspilerGenerator<ToQwikOptions>;
@@ -24,6 +24,7 @@ var jsx_1 = require("./jsx");
24
24
  var src_generator_1 = require("./src-generator");
25
25
  var plugins_1 = require("../../modules/plugins");
26
26
  var traverse_1 = __importDefault(require("traverse"));
27
+ var stable_serialize_1 = require("./stable-serialize");
27
28
  Error.stackTraceLimit = 9999;
28
29
  // TODO(misko): styles are not processed.
29
30
  var DEBUG = false;
@@ -78,7 +79,7 @@ var componentToQwik = function (userOptions) {
78
79
  : (0, src_generator_1.invoke)(file.import(file.qwikModule, 'component$'), [componentBody]), true, true);
79
80
  file.exportDefault(component.name);
80
81
  emitStyles(file, css_1);
81
- DEBUG && file.exportConst('COMPONENT', JSON.stringify(component, null, 2));
82
+ DEBUG && file.exportConst('COMPONENT', (0, stable_serialize_1.stableJSONserialize)(component));
82
83
  return '// GENERATED BY MITOSIS\n\n' + file.toString();
83
84
  }
84
85
  catch (e) {
@@ -161,7 +162,7 @@ function emitUseContextProvider(file, component) {
161
162
  throw new Error('Qwik: Functions are not supported in context');
162
163
  }
163
164
  else {
164
- file.src.emit(JSON.stringify(propValue));
165
+ file.src.emit((0, stable_serialize_1.stableJSONserialize)(propValue));
165
166
  }
166
167
  });
167
168
  file.src.emit('})', ');');
@@ -199,7 +200,7 @@ function emitUseStore(file, stateInit) {
199
200
  var hasState = state && Object.keys(state).length > 0;
200
201
  if (hasState) {
201
202
  file.src.emit('const state=', file.import(file.qwikModule, 'useStore').localName, '(');
202
- file.src.emit(JSON.stringify(state));
203
+ file.src.emit((0, stable_serialize_1.stableJSONserialize)(state));
203
204
  file.src.emit(');');
204
205
  }
205
206
  else {
@@ -25,6 +25,7 @@ var compile_away_builder_components_1 = require("../../plugins/compile-away-buil
25
25
  var handlers_1 = require("./handlers");
26
26
  var jsx_1 = require("./jsx");
27
27
  var src_generator_1 = require("./src-generator");
28
+ var stable_serialize_1 = require("./stable-serialize");
28
29
  var styles_1 = require("./styles");
29
30
  function createFileSet(options) {
30
31
  if (options === void 0) { options = {}; }
@@ -86,7 +87,7 @@ function addComponent(fileSet, component, opts) {
86
87
  }
87
88
  if (component.meta.cssCode) {
88
89
  var symbolName = componentName + 'UsrStyles';
89
- onRenderFile.exportConst(symbolName, JSON.stringify(component.meta.cssCode));
90
+ onRenderFile.exportConst(symbolName, (0, stable_serialize_1.stableJSONserialize)(component.meta.cssCode));
90
91
  useStyles = (function (fns) {
91
92
  return function () {
92
93
  var _this = this;
@@ -140,7 +141,7 @@ function addComponentOnMount(componentFile, onRenderEmit, componentName, compone
140
141
  if (component.inputs) {
141
142
  component.inputs.forEach(function (input) {
142
143
  input.defaultValue !== undefined &&
143
- inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=', JSON.stringify(input.defaultValue), ';');
144
+ inputInitializer.push('if(!state.hasOwnProperty("', input.name, '"))state.', input.name, '=', (0, stable_serialize_1.stableJSONserialize)(input.defaultValue), ';');
144
145
  });
145
146
  }
146
147
  componentFile.exportConst(componentName + 'OnMount', function () {
@@ -3,6 +3,7 @@ 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
5
  var builder_1 = require("../../parsers/builder");
6
+ var stable_serialize_1 = require("./stable-serialize");
6
7
  var File = /** @class */ (function () {
7
8
  function File(filename, options, qwikModule, qrlPrefix) {
8
9
  this.imports = new Imports();
@@ -477,7 +478,7 @@ function possiblyQuotePropertyName(key) {
477
478
  return /^\w[\w\d]*$/.test(key) ? key : quote(key);
478
479
  }
479
480
  function quote(text) {
480
- var string = JSON.stringify(text);
481
+ var string = (0, stable_serialize_1.stableJSONserialize)(text);
481
482
  // So \u2028 is a line separator character and prettier treats it as such
482
483
  // https://www.fileformat.info/info/unicode/char/2028/index.htm
483
484
  // That means it can't be inside of a string, so we replace it with `\\u2028`.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Same as JSON.stringify, but sorts keys ensuring that the output is stable across runs.
3
+ * @param obj
4
+ * @returns JSON serialized string
5
+ */
6
+ export declare function stableJSONserialize(obj: any): string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stableJSONserialize = void 0;
4
+ /**
5
+ * Same as JSON.stringify, but sorts keys ensuring that the output is stable across runs.
6
+ * @param obj
7
+ * @returns JSON serialized string
8
+ */
9
+ function stableJSONserialize(obj) {
10
+ var output = [];
11
+ _serialize(output, obj);
12
+ return output.join('');
13
+ }
14
+ exports.stableJSONserialize = stableJSONserialize;
15
+ function _serialize(output, obj) {
16
+ if (obj == null) {
17
+ output.push('null');
18
+ }
19
+ else if (typeof obj === 'object') {
20
+ if (Array.isArray(obj)) {
21
+ output.push('[');
22
+ var sep = '';
23
+ for (var i = 0; i < obj.length; i++) {
24
+ output.push(sep);
25
+ _serialize(output, obj[i]);
26
+ sep = ',';
27
+ }
28
+ output.push(']');
29
+ }
30
+ else {
31
+ var keys = Object.keys(obj).sort();
32
+ output.push('{');
33
+ var sep = '';
34
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
35
+ var key = keys_1[_i];
36
+ var value = obj[key];
37
+ if (value !== undefined) {
38
+ output.push(sep);
39
+ output.push(JSON.stringify(key));
40
+ output.push(':');
41
+ _serialize(output, value);
42
+ sep = ',';
43
+ }
44
+ }
45
+ output.push('}');
46
+ }
47
+ }
48
+ else {
49
+ output.push(JSON.stringify(obj));
50
+ }
51
+ }
@@ -1,6 +1,6 @@
1
- import { Transpiler } from '../../types/transpiler';
1
+ import { TranspilerGenerator } from '../../types/transpiler';
2
2
  import { MitosisNode } from '../../types/mitosis-node';
3
3
  import { ToReactOptions } from './types';
4
4
  export declare const blockToReact: (json: MitosisNode, options: ToReactOptions, parentSlots?: any[]) => string;
5
- export declare const componentToPreact: (reactOptions?: ToReactOptions) => Transpiler;
6
- export declare const componentToReact: (reactOptions?: ToReactOptions) => Transpiler;
5
+ export declare const componentToPreact: TranspilerGenerator<ToReactOptions>;
6
+ export declare const componentToReact: TranspilerGenerator<ToReactOptions>;
@@ -1,9 +1,9 @@
1
1
  import { ClassStyleMap } from '../helpers/styles/helpers';
2
2
  import { MitosisComponent } from '../types/mitosis-component';
3
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
3
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
4
4
  export interface ToReactNativeOptions extends BaseTranspilerOptions {
5
5
  stylesType?: 'emotion' | 'react-native';
6
6
  stateType?: 'useState' | 'mobx' | 'valtio' | 'solid' | 'builder';
7
7
  }
8
8
  export declare const collectReactNativeStyles: (json: MitosisComponent) => ClassStyleMap;
9
- export declare const componentToReactNative: (options?: ToReactNativeOptions) => Transpiler;
9
+ export declare const componentToReactNative: TranspilerGenerator<ToReactNativeOptions>;
@@ -1,3 +1,3 @@
1
- import { Transpiler } from '../../types/transpiler';
1
+ import { TranspilerGenerator } from '../../types/transpiler';
2
2
  import { ToSolidOptions } from './types';
3
- export declare const componentToSolid: (passedOptions?: Partial<ToSolidOptions>) => Transpiler;
3
+ export declare const componentToSolid: TranspilerGenerator<Partial<ToSolidOptions>>;
@@ -1,4 +1,4 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../../types/transpiler';
2
2
  export interface ToStencilOptions extends BaseTranspilerOptions {
3
3
  }
4
- export declare const componentToStencil: (options?: ToStencilOptions) => Transpiler;
4
+ export declare const componentToStencil: TranspilerGenerator<ToStencilOptions>;
@@ -1,6 +1,6 @@
1
1
  import { MitosisComponent } from '../types/mitosis-component';
2
2
  import { MitosisNode } from '../types/mitosis-node';
3
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
3
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
4
4
  export interface ToSvelteOptions extends BaseTranspilerOptions {
5
5
  stateType?: 'proxies' | 'variables';
6
6
  }
@@ -11,5 +11,5 @@ interface BlockToSvelteProps {
11
11
  }
12
12
  declare type BlockToSvelte = (props: BlockToSvelteProps) => string;
13
13
  export declare const blockToSvelte: BlockToSvelte;
14
- export declare const componentToSvelte: ({ plugins, ...userProvidedOptions }?: ToSvelteOptions) => Transpiler;
14
+ export declare const componentToSvelte: TranspilerGenerator<ToSvelteOptions>;
15
15
  export {};
@@ -61,9 +61,9 @@ var babel_transform_1 = require("../helpers/babel-transform");
61
61
  var function_1 = require("fp-ts/lib/function");
62
62
  var context_1 = require("./helpers/context");
63
63
  var html_tags_1 = require("../constants/html_tags");
64
- var lodash_1 = require("lodash");
65
64
  var is_upper_case_1 = require("../helpers/is-upper-case");
66
65
  var json5_1 = __importDefault(require("json5"));
66
+ var functions_1 = require("./helpers/functions");
67
67
  var mappers = {
68
68
  Fragment: function (_a) {
69
69
  var _b;
@@ -197,7 +197,13 @@ var blockToSvelte = function (_a) {
197
197
  if (key.startsWith('on')) {
198
198
  var event_1 = key.replace('on', '').toLowerCase();
199
199
  // TODO: handle quotes in event handler values
200
- str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(useValue), "}}\" ");
200
+ var valueWithoutBlock = (0, remove_surrounding_block_1.removeSurroundingBlock)(useValue);
201
+ if (valueWithoutBlock === key) {
202
+ str += " on:".concat(event_1, "={").concat(valueWithoutBlock, "} ");
203
+ }
204
+ else {
205
+ str += " on:".concat(event_1, "=\"{").concat(cusArgs.join(','), " => {").concat(valueWithoutBlock, "}}\" ");
206
+ }
201
207
  }
202
208
  else if (key === 'ref') {
203
209
  str += " bind:this={".concat(useValue, "} ");
@@ -264,31 +270,13 @@ var useBindValue = function (json, options) {
264
270
  var stripThisRefs = function (str) {
265
271
  return str.replace(/this\.([a-zA-Z_\$0-9]+)/g, '$1');
266
272
  };
267
- var FUNCTION_HACK_PLUGIN = function () { return ({
268
- json: {
269
- pre: function (json) {
270
- var _a, _b;
271
- for (var key in json.state) {
272
- var value = (_a = json.state[key]) === null || _a === void 0 ? void 0 : _a.code;
273
- var type = (_b = json.state[key]) === null || _b === void 0 ? void 0 : _b.type;
274
- if (typeof value === 'string' && type === 'method') {
275
- var newValue = "function ".concat(value);
276
- json.state[key] = {
277
- code: newValue,
278
- type: 'function',
279
- };
280
- }
281
- }
282
- },
283
- },
284
- }); };
285
273
  var componentToSvelte = function (_a) {
286
274
  if (_a === void 0) { _a = {}; }
287
275
  var _b = _a.plugins, plugins = _b === void 0 ? [] : _b, userProvidedOptions = __rest(_a, ["plugins"]);
288
276
  return function (_a) {
289
- var _b, _c, _d, _e, _f, _g, _h;
277
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
290
278
  var component = _a.component;
291
- var options = __assign({ stateType: 'variables', prettier: true, plugins: __spreadArray([FUNCTION_HACK_PLUGIN], plugins, true) }, userProvidedOptions);
279
+ var options = __assign({ stateType: 'variables', prettier: true, plugins: __spreadArray([functions_1.FUNCTION_HACK_PLUGIN], plugins, true) }, userProvidedOptions);
292
280
  // Make a copy we can safely mutate, similar to babel's toolchain
293
281
  var json = (0, fast_clone_1.fastClone)(component);
294
282
  if (options.plugins) {
@@ -325,7 +313,6 @@ var componentToSvelte = function (_a) {
325
313
  getters: false,
326
314
  functions: true,
327
315
  format: 'variables',
328
- keyPrefix: 'const ',
329
316
  valueMapper: function (code) { return (0, function_1.pipe)(stripStateAndProps(code, options), stripThisRefs); },
330
317
  }), babel_transform_1.babelTransformCode);
331
318
  var hasData = dataString.length > 4;
@@ -334,16 +321,31 @@ var componentToSvelte = function (_a) {
334
321
  return (0, function_1.pipe)(stripStateAndProps(hookCode, options), babel_transform_1.babelTransformCode);
335
322
  };
336
323
  var str = '';
337
- if ((_b = json.types) === null || _b === void 0 ? void 0 : _b.length) {
338
- str += (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script context='module' lang='ts'>\n ", "\n </script>\n \n\n \n\n "], ["\n <script context='module' lang='ts'>\n ", "\n </script>\n \\n\n \\n\n "])), json.types ? json.types.join('\n\n') + '\n' : '');
324
+ var tsLangAttribute = options.typescript ? "lang='ts'" : '';
325
+ if (options.typescript && ((_b = json.types) === null || _b === void 0 ? void 0 : _b.length)) {
326
+ str += (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n <script context='module' ", ">\n ", "\n </script>\n \n\n \n\n "], ["\n <script context='module' ", ">\n ", "\n </script>\n \\n\n \\n\n "])), tsLangAttribute, json.types ? json.types.join('\n\n') + '\n' : '');
327
+ }
328
+ // prepare svelte imports
329
+ var svelteImports = [];
330
+ if ((_d = (_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code) === null || _d === void 0 ? void 0 : _d.length) {
331
+ svelteImports.push('onMount');
332
+ }
333
+ if ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length) {
334
+ svelteImports.push('afterUpdate');
335
+ }
336
+ if ((_g = (_f = json.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code) === null || _g === void 0 ? void 0 : _g.length) {
337
+ svelteImports.push('onDestroy');
338
+ }
339
+ if ((0, context_1.hasContext)(component)) {
340
+ svelteImports.push('getContext', 'setContext');
339
341
  }
340
- str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script lang='ts'>\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script lang='ts'>\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), !((_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code) ? '' : "import { onMount } from 'svelte'", !((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length) ? '' : "import { afterUpdate } from 'svelte'", !((_e = json.hooks.onUnMount) === null || _e === void 0 ? void 0 : _e.code) ? '' : "import { onDestroy } from 'svelte'", (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), (0, context_1.hasContext)(component) ? 'import { getContext, setContext } from "svelte";' : '', !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", (0, lodash_1.uniq)(refs.map(function (ref) { return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref); }).concat(props))
342
+ str += (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "], ["\n <script ", ">\n ", "\n ", "\n\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n </script>\n\n ", "\n\n ", "\n "])), tsLangAttribute, !svelteImports.length ? '' : "import { ".concat(svelteImports.sort().join(', '), " } from 'svelte'"), (0, render_imports_1.renderPreComponent)({ component: json, target: 'svelte' }), !hasData || options.stateType === 'variables' ? '' : "import onChange from 'on-change'", props
341
343
  .map(function (name) {
342
344
  if (name === 'children') {
343
345
  return '';
344
346
  }
345
347
  var propDeclaration = "export let ".concat(name);
346
- if (json.propsTypeRef && json.propsTypeRef !== 'any') {
348
+ if (options.typescript && json.propsTypeRef && json.propsTypeRef !== 'any') {
347
349
  propDeclaration += ": ".concat(json.propsTypeRef.split(' |')[0], "['").concat(name, "']");
348
350
  }
349
351
  if (json.defaultProps && json.defaultProps.hasOwnProperty(name)) {
@@ -354,13 +356,13 @@ var componentToSvelte = function (_a) {
354
356
  })
355
357
  .join('\n'), (0, helpers_1.hasStyle)(json)
356
358
  ? "\n function mitosis_styling (node, vars) {\n Object.entries(vars).forEach(([ p, v ]) => { node.style[p] = v })\n }\n "
357
- : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, options.stateType === 'proxies'
359
+ : '', getContextCode(json), setContextCode(json), functionsString.length < 4 ? '' : functionsString, getterString.length < 4 ? '' : getterString, refs.map(function (ref) { return "let ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(ref)); }).join('\n'), options.stateType === 'proxies'
358
360
  ? dataString.length < 4
359
361
  ? ''
360
362
  : "let state = onChange(".concat(dataString, ", () => state = state)")
361
- : dataString, !((_f = json.hooks.onMount) === null || _f === void 0 ? void 0 : _f.code)
363
+ : dataString, !((_h = json.hooks.onMount) === null || _h === void 0 ? void 0 : _h.code)
362
364
  ? ''
363
- : "onMount(() => { ".concat(transformHookCode(json.hooks.onMount.code), " });"), !((_g = json.hooks.onUpdate) === null || _g === void 0 ? void 0 : _g.length)
365
+ : "onMount(() => { ".concat(transformHookCode(json.hooks.onMount.code), " });"), !((_j = json.hooks.onUpdate) === null || _j === void 0 ? void 0 : _j.length)
364
366
  ? ''
365
367
  : json.hooks.onUpdate
366
368
  .map(function (_a, index) {
@@ -374,7 +376,7 @@ var componentToSvelte = function (_a) {
374
376
  return "afterUpdate(() => { ".concat(hookCode, " })");
375
377
  }
376
378
  })
377
- .join(';'), !((_h = json.hooks.onUnMount) === null || _h === void 0 ? void 0 : _h.code)
379
+ .join(';'), !((_k = json.hooks.onUnMount) === null || _k === void 0 ? void 0 : _k.code)
378
380
  ? ''
379
381
  : "onDestroy(() => { ".concat(transformHookCode(json.hooks.onUnMount.code), " });"), json.children
380
382
  .map(function (item) {
@@ -1,5 +1,3 @@
1
- import { Transpiler } from '../types/transpiler';
2
- export declare type ToSwiftOptions = {
3
- prettier?: boolean;
4
- };
5
- export declare const componentToSwift: (options?: ToSwiftOptions) => Transpiler;
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
+ export declare type ToSwiftOptions = BaseTranspilerOptions;
3
+ export declare const componentToSwift: TranspilerGenerator<ToSwiftOptions>;
@@ -1,4 +1,4 @@
1
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
1
+ import { BaseTranspilerOptions, TranspilerGenerator } from '../types/transpiler';
2
2
  export interface ToTemplateOptions extends BaseTranspilerOptions {
3
3
  }
4
- export declare const componentToTemplate: (options?: ToTemplateOptions) => Transpiler;
4
+ export declare const componentToTemplate: TranspilerGenerator<ToTemplateOptions>;
@@ -1,7 +1,8 @@
1
1
  import { MitosisNode } from '../types/mitosis-node';
2
- import { BaseTranspilerOptions, Transpiler } from '../types/transpiler';
2
+ import { BaseTranspilerOptions } from '../types/transpiler';
3
3
  import { OmitObj } from '../helpers/typescript';
4
4
  export declare type VueVersion = 2 | 3;
5
+ export declare type Api = 'options' | 'composition';
5
6
  interface VueVersionOpt {
6
7
  vueVersion: VueVersion;
7
8
  }
@@ -9,6 +10,7 @@ export interface ToVueOptions extends BaseTranspilerOptions, VueVersionOpt {
9
10
  cssNamespace?: () => string;
10
11
  namePrefix?: (path: string) => string;
11
12
  asyncComponentImports?: boolean;
13
+ api?: Api;
12
14
  }
13
15
  declare type BlockRenderer = (json: MitosisNode, options: ToVueOptions, scope?: Scope) => string;
14
16
  interface Scope {
@@ -16,6 +18,6 @@ interface Scope {
16
18
  }
17
19
  export declare const blockToVue: BlockRenderer;
18
20
  declare type VueOptsWithoutVersion = OmitObj<ToVueOptions, VueVersionOpt>;
19
- export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
20
- export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => Transpiler;
21
+ export declare const componentToVue2: (vueOptions?: VueOptsWithoutVersion) => import("../types/transpiler").Transpiler<string>;
22
+ export declare const componentToVue3: (vueOptions?: VueOptsWithoutVersion) => import("../types/transpiler").Transpiler<string>;
21
23
  export {};