@builder.io/mitosis 0.7.0 → 0.7.1

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.
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -19,6 +42,8 @@ const render_imports_1 = require("../../helpers/render-imports");
19
42
  const state_1 = require("../../helpers/state");
20
43
  const plugins_1 = require("../../modules/plugins");
21
44
  const mitosis_node_1 = require("../../types/mitosis-node");
45
+ const babel = __importStar(require("@babel/core"));
46
+ const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
22
47
  const json5_1 = __importDefault(require("json5"));
23
48
  const standalone_1 = require("prettier/standalone");
24
49
  const react_1 = require("../react");
@@ -87,11 +112,35 @@ const blockToMitosis = (json, toMitosisOptions = {}, component, insideJsx) => {
87
112
  </For>`;
88
113
  }
89
114
  if (json.properties._text) {
115
+ let text = json.properties._text
116
+ // Convert HTML <br> to JSX-valid <br />
117
+ .replace(/<br\s*>/g, '<br />');
118
+ let isInvalidJsx = text.includes('{') || text.includes('}');
119
+ if (text.includes('<') || text.includes('>')) {
120
+ // test if this can parse as jsx
121
+ try {
122
+ babel.parse(`let _ = <>${text}</>;`, {
123
+ plugins: [[plugin_syntax_typescript_1.default, { isTSX: true }]],
124
+ });
125
+ isInvalidJsx = false;
126
+ }
127
+ catch (e) {
128
+ isInvalidJsx = true;
129
+ }
130
+ }
131
+ if (isInvalidJsx) {
132
+ text = text
133
+ .replace(/>/g, '&gt;')
134
+ .replace(/</g, '&lt;')
135
+ .replace(/{/g, '&#123;')
136
+ .replace(/}/g, '&#125;')
137
+ .replace(/&/g, '&amp;');
138
+ }
90
139
  if (insideJsx) {
91
- return `${json.properties._text}`;
140
+ return `${text}`;
92
141
  }
93
142
  else {
94
- return `<>${json.properties._text}</>`;
143
+ return `<>${text}</>`;
95
144
  }
96
145
  }
97
146
  if ((_d = json.bindings._text) === null || _d === void 0 ? void 0 : _d.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.7.0",
25
+ "version": "0.7.1",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {