@builder.io/mitosis 0.0.56-84 → 0.0.56-85
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.
- package/dist/src/__tests__/angular.test.d.ts +1 -0
- package/dist/src/__tests__/angular.test.js +10 -0
- package/dist/src/__tests__/builder.test.d.ts +1 -0
- package/dist/src/__tests__/builder.test.js +235 -0
- package/dist/src/__tests__/context.test.d.ts +1 -0
- package/dist/src/__tests__/context.test.js +35 -0
- package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +3 -0
- package/dist/src/__tests__/data/context/component-with-context.lite.jsx +21 -0
- package/dist/src/__tests__/data/context/simple.context.lite.d.ts +9 -0
- package/dist/src/__tests__/data/context/simple.context.lite.js +15 -0
- package/dist/src/__tests__/data/nested-styles.lite.d.ts +1 -0
- package/dist/src/__tests__/data/nested-styles.lite.jsx +20 -0
- package/dist/src/__tests__/data/types/foo-type.d.ts +1 -0
- package/dist/src/__tests__/data/types/foo-type.js +2 -0
- package/dist/src/__tests__/data/types/type-export.lite.d.ts +3 -0
- package/dist/src/__tests__/data/types/type-export.lite.jsx +6 -0
- package/dist/src/__tests__/hash-code.test.d.ts +1 -0
- package/dist/src/__tests__/hash-code.test.js +11 -0
- package/dist/src/__tests__/html.test.d.ts +1 -0
- package/dist/src/__tests__/html.test.js +7 -0
- package/dist/src/__tests__/liquid.test.d.ts +1 -0
- package/dist/src/__tests__/liquid.test.js +7 -0
- package/dist/src/__tests__/lit.test.d.ts +1 -0
- package/dist/src/__tests__/lit.test.js +7 -0
- package/dist/src/__tests__/marko.test.d.ts +1 -0
- package/dist/src/__tests__/marko.test.js +14 -0
- package/dist/src/__tests__/parse-jsx.test.d.ts +1 -0
- package/dist/src/__tests__/parse-jsx.test.js +37 -0
- package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +1 -0
- package/dist/src/__tests__/qwik/convert-method-to-function.test.js +37 -0
- package/dist/src/__tests__/qwik/src-generator.test.d.ts +1 -0
- package/dist/src/__tests__/qwik/src-generator.test.js +65 -0
- package/dist/src/__tests__/qwik.directive.test.d.ts +1 -0
- package/dist/src/__tests__/qwik.directive.test.js +108 -0
- package/dist/src/__tests__/qwik.test.d.ts +1 -0
- package/dist/src/__tests__/qwik.test.js +465 -0
- package/dist/src/__tests__/react-native.test.d.ts +1 -0
- package/dist/src/__tests__/react-native.test.js +7 -0
- package/dist/src/__tests__/react.test.d.ts +1 -0
- package/dist/src/__tests__/react.test.js +20 -0
- package/dist/src/__tests__/shared.d.ts +3 -0
- package/dist/src/__tests__/shared.js +305 -0
- package/dist/src/__tests__/solid.test.d.ts +1 -0
- package/dist/src/__tests__/solid.test.js +10 -0
- package/dist/src/__tests__/stencil.test.d.ts +1 -0
- package/dist/src/__tests__/stencil.test.js +7 -0
- package/dist/src/__tests__/styles.test.d.ts +1 -0
- package/dist/src/__tests__/styles.test.js +23 -0
- package/dist/src/__tests__/svelte.test.d.ts +1 -0
- package/dist/src/__tests__/svelte.test.js +7 -0
- package/dist/src/__tests__/vue.test.d.ts +1 -0
- package/dist/src/__tests__/vue.test.js +7 -0
- package/dist/src/__tests__/webcomponent.test.d.ts +1 -0
- package/dist/src/__tests__/webcomponent.test.js +15 -0
- package/dist/src/constants/html_tags.d.ts +1 -0
- package/dist/src/constants/html_tags.js +119 -0
- package/dist/src/generators/context/qwik.d.ts +8 -0
- package/dist/src/generators/context/qwik.js +27 -0
- package/dist/src/generators/context/react.d.ts +8 -0
- package/dist/src/generators/context/react.js +28 -0
- package/dist/src/generators/context/solid.d.ts +8 -0
- package/dist/src/generators/context/solid.js +28 -0
- package/dist/src/generators/context/svelte.d.ts +8 -0
- package/dist/src/generators/context/svelte.js +28 -0
- package/dist/src/generators/context/vue.d.ts +6 -0
- package/dist/src/generators/context/vue.js +9 -0
- package/dist/src/generators/helpers/context.d.ts +2 -0
- package/dist/src/generators/helpers/context.js +7 -0
- package/dist/src/generators/html.d.ts +7 -0
- package/dist/src/generators/lit/collect-class-string.d.ts +2 -0
- package/dist/src/generators/lit/collect-class-string.js +43 -0
- package/dist/src/generators/lit/generate.d.ts +4 -0
- package/dist/src/generators/lit/generate.js +203 -0
- package/dist/src/generators/lit/index.d.ts +1 -0
- package/dist/src/generators/lit/index.js +17 -0
- package/dist/src/generators/marko/generate.d.ts +21 -0
- package/dist/src/generators/marko/generate.js +301 -0
- package/dist/src/generators/marko/index.d.ts +1 -0
- package/dist/src/generators/marko/index.js +17 -0
- package/dist/src/generators/mitosis.d.ts +9 -0
- package/dist/src/generators/mitosis.js +183 -0
- package/dist/src/generators/qwik/add-prevent-default.d.ts +7 -0
- package/dist/src/generators/qwik/add-prevent-default.js +32 -0
- package/dist/src/generators/qwik/component-generator.d.ts +4 -0
- package/dist/src/generators/qwik/component-generator.js +304 -0
- package/dist/src/generators/qwik/component.d.ts +22 -0
- package/dist/src/generators/qwik/component.js +180 -0
- package/dist/src/generators/qwik/convert-method-to-function.d.ts +1 -0
- package/dist/src/generators/qwik/convert-method-to-function.js +162 -0
- package/dist/src/generators/qwik/directives.d.ts +31 -0
- package/dist/src/generators/qwik/directives.js +138 -0
- package/dist/src/generators/qwik/handlers.d.ts +4 -0
- package/dist/src/generators/qwik/handlers.js +69 -0
- package/dist/src/generators/qwik/index.d.ts +4 -0
- package/dist/src/generators/qwik/index.js +11 -0
- package/dist/src/generators/qwik/jsx.d.ts +16 -0
- package/dist/src/generators/qwik/jsx.js +218 -0
- package/dist/src/generators/qwik/src-generator.d.ts +86 -0
- package/dist/src/generators/qwik/src-generator.js +579 -0
- package/dist/src/generators/qwik/styles.d.ts +7 -0
- package/dist/src/generators/qwik/styles.js +91 -0
- package/dist/src/generators/react-native.d.ts +9 -0
- package/dist/src/generators/react-native.js +110 -0
- package/dist/src/generators/react.d.ts +14 -0
- package/dist/src/generators/react.js +542 -0
- package/dist/src/generators/solid.d.ts +5 -0
- package/dist/src/generators/solid.js +306 -0
- package/dist/src/generators/stencil/collect-class-string.d.ts +2 -0
- package/dist/src/generators/stencil/collect-class-string.js +43 -0
- package/dist/src/generators/stencil/generate.d.ts +4 -0
- package/dist/src/generators/stencil/generate.js +182 -0
- package/dist/src/generators/stencil/index.d.ts +1 -0
- package/dist/src/generators/stencil/index.js +17 -0
- package/dist/src/generators/swift-ui.d.ts +5 -0
- package/dist/src/generators/swift-ui.js +271 -0
- package/dist/src/generators/template.d.ts +4 -0
- package/dist/src/generators/template.js +135 -0
- package/dist/src/generators/vue.d.ts +21 -0
- package/dist/src/generators/vue.js +548 -0
- package/dist/src/helpers/babel-transform.test.d.ts +1 -0
- package/dist/src/helpers/babel-transform.test.js +7 -0
- package/dist/src/helpers/camel-case.d.ts +8 -0
- package/dist/src/helpers/camel-case.js +18 -0
- package/dist/src/helpers/generic-format.d.ts +6 -0
- package/dist/src/helpers/generic-format.js +36 -0
- package/dist/src/helpers/generic-format.test.d.ts +1 -0
- package/dist/src/helpers/generic-format.test.js +8 -0
- package/dist/src/helpers/get-components.d.ts +2 -0
- package/dist/src/helpers/get-components.js +21 -0
- package/dist/src/helpers/get-state-used.d.ts +5 -0
- package/dist/src/helpers/get-state-used.js +29 -0
- package/dist/src/helpers/get-styles.d.ts +4 -0
- package/dist/src/helpers/get-styles.js +33 -0
- package/dist/src/helpers/getters-to-functions.d.ts +5 -0
- package/dist/src/helpers/getters-to-functions.js +50 -0
- package/dist/src/helpers/handle-missing-state.d.ts +2 -0
- package/dist/src/helpers/handle-missing-state.js +13 -0
- package/dist/src/helpers/has.d.ts +9 -0
- package/dist/src/helpers/has.js +27 -0
- package/dist/src/helpers/html-escape.d.ts +1 -0
- package/dist/src/helpers/html-escape.js +7 -0
- package/dist/src/helpers/is-valid-attribute-name.d.ts +1 -0
- package/dist/src/helpers/is-valid-attribute-name.js +7 -0
- package/dist/src/helpers/parse-node.d.ts +2 -0
- package/dist/src/helpers/parse-node.js +12 -0
- package/dist/src/helpers/parse-reactive-script.d.ts +7 -0
- package/dist/src/helpers/parse-reactive-script.js +87 -0
- package/dist/src/helpers/process-http-requests.d.ts +2 -0
- package/dist/src/helpers/process-http-requests.js +21 -0
- package/dist/src/helpers/process-tag-references.d.ts +2 -0
- package/dist/src/helpers/process-tag-references.js +31 -0
- package/dist/src/helpers/remove-surrounding-block.test.d.ts +1 -0
- package/dist/src/helpers/remove-surrounding-block.test.js +9 -0
- package/dist/src/helpers/render-imports.d.ts +20 -0
- package/dist/src/helpers/render-imports.js +156 -0
- package/dist/src/helpers/render-imports.test.d.ts +1 -0
- package/dist/src/helpers/render-imports.test.js +33 -0
- package/dist/src/helpers/styles/collect-css.test.d.ts +1 -0
- package/dist/src/helpers/styles/collect-css.test.js +18 -0
- package/dist/src/helpers/styles/collect-styled-components.d.ts +2 -0
- package/dist/src/helpers/styles/collect-styled-components.js +61 -0
- package/dist/src/helpers/traverse-nodes.d.ts +4 -0
- package/dist/src/helpers/traverse-nodes.js +16 -0
- package/dist/src/helpers/try-prettier-format.d.ts +1 -0
- package/dist/src/helpers/try-prettier-format.js +24 -0
- package/dist/src/index.d.ts +59 -0
- package/dist/src/index.js +98 -0
- package/dist/src/parsers/html.d.ts +0 -0
- package/dist/src/parsers/html.js +2 -0
- package/dist/src/plugins/compile-away-builder-components.d.ts +18 -0
- package/dist/src/plugins/compile-away-builder-components.js +562 -0
- package/dist/src/plugins/compile-away-components.d.ts +33 -0
- package/dist/src/plugins/compile-away-components.js +58 -0
- package/dist/src/plugins/map-styles.d.ts +12 -0
- package/dist/src/plugins/map-styles.js +16 -0
- package/dist/src/targets.d.ts +30 -0
- package/dist/src/targets.js +43 -0
- package/dist/src/types/config.d.ts +54 -0
- package/dist/src/types/config.js +2 -0
- package/dist/src/types/mitosis-styles.d.ts +1 -0
- package/dist/src/types/mitosis-styles.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var angular_1 = require("../generators/angular");
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
describe('Angular', function () {
|
|
6
|
+
(0, shared_1.runTestsForTarget)('angular', (0, angular_1.componentToAngular)());
|
|
7
|
+
(0, shared_1.runTestsForTarget)('angular', (0, angular_1.componentToAngular)({
|
|
8
|
+
standalone: true,
|
|
9
|
+
}));
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
39
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
40
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
41
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
42
|
+
function step(op) {
|
|
43
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
44
|
+
while (_) try {
|
|
45
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
46
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
47
|
+
switch (op[0]) {
|
|
48
|
+
case 0: case 1: t = op; break;
|
|
49
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
50
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
51
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
52
|
+
default:
|
|
53
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
54
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
55
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
56
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
57
|
+
if (t[2]) _.ops.pop();
|
|
58
|
+
_.trys.pop(); continue;
|
|
59
|
+
}
|
|
60
|
+
op = body.call(thisArg, _);
|
|
61
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
62
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
66
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
|
+
};
|
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
var dedent_1 = __importDefault(require("dedent"));
|
|
70
|
+
var fs = __importStar(require("fs"));
|
|
71
|
+
var builder_1 = require("../generators/builder");
|
|
72
|
+
var mitosis_1 = require("../generators/mitosis");
|
|
73
|
+
var html_1 = require("../generators/html");
|
|
74
|
+
var builder_2 = require("../parsers/builder");
|
|
75
|
+
var jsx_1 = require("../parsers/jsx");
|
|
76
|
+
var compile_away_builder_components_1 = require("../plugins/compile-away-builder-components");
|
|
77
|
+
var __1 = require("..");
|
|
78
|
+
/**
|
|
79
|
+
* Load a file using nodejs resolution as a string.
|
|
80
|
+
*/
|
|
81
|
+
function fixture(path) {
|
|
82
|
+
var localpath = require.resolve(path);
|
|
83
|
+
return fs.readFileSync(localpath, { encoding: 'utf-8' });
|
|
84
|
+
}
|
|
85
|
+
var stamped = fixture('./data/blocks/stamped-io.raw');
|
|
86
|
+
var customCode = fixture('./data/blocks/custom-code.raw');
|
|
87
|
+
var embed = fixture('./data/blocks/embed.raw');
|
|
88
|
+
var image = fixture('./data/blocks/image.raw');
|
|
89
|
+
var columns = fixture('./data/blocks/columns.raw');
|
|
90
|
+
var lazyLoadSection = JSON.parse(fixture('./data/builder/lazy-load-section.json'));
|
|
91
|
+
var mitosisOptions = {
|
|
92
|
+
format: 'legacy',
|
|
93
|
+
};
|
|
94
|
+
describe('Builder', function () {
|
|
95
|
+
test('extractStateHook', function () {
|
|
96
|
+
var code = "useState({ foo: 'bar' }); alert('hi');";
|
|
97
|
+
expect((0, builder_2.extractStateHook)(code)).toEqual({
|
|
98
|
+
code: "alert('hi');",
|
|
99
|
+
state: { foo: 'bar' },
|
|
100
|
+
});
|
|
101
|
+
expect((0, builder_2.extractStateHook)(code)).toEqual({
|
|
102
|
+
code: "alert('hi');",
|
|
103
|
+
state: { foo: 'bar' },
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
test('Stamped', function () {
|
|
107
|
+
var component = (0, jsx_1.parseJsx)(stamped);
|
|
108
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
109
|
+
expect(builderJson).toMatchSnapshot();
|
|
110
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
111
|
+
var mitosis = (0, mitosis_1.componentToMitosis)()({ component: backToMitosis });
|
|
112
|
+
expect(mitosis).toMatchSnapshot();
|
|
113
|
+
});
|
|
114
|
+
test('CustomCode', function () {
|
|
115
|
+
var component = (0, jsx_1.parseJsx)(customCode);
|
|
116
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
117
|
+
expect(builderJson).toMatchSnapshot();
|
|
118
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
119
|
+
var mitosis = (0, mitosis_1.componentToMitosis)()({ component: backToMitosis });
|
|
120
|
+
expect(mitosis).toMatchSnapshot();
|
|
121
|
+
});
|
|
122
|
+
test('Embed', function () {
|
|
123
|
+
var component = (0, jsx_1.parseJsx)(embed);
|
|
124
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
125
|
+
expect(builderJson).toMatchSnapshot();
|
|
126
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
127
|
+
var mitosis = (0, mitosis_1.componentToMitosis)()({ component: backToMitosis });
|
|
128
|
+
expect(mitosis).toMatchSnapshot();
|
|
129
|
+
});
|
|
130
|
+
test('Image', function () {
|
|
131
|
+
var component = (0, jsx_1.parseJsx)(image);
|
|
132
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
133
|
+
expect(builderJson).toMatchSnapshot();
|
|
134
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
135
|
+
var mitosis = (0, mitosis_1.componentToMitosis)()({ component: backToMitosis });
|
|
136
|
+
expect(mitosis).toMatchSnapshot();
|
|
137
|
+
});
|
|
138
|
+
test('Columns', function () {
|
|
139
|
+
var component = (0, jsx_1.parseJsx)(columns);
|
|
140
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
141
|
+
expect(builderJson).toMatchSnapshot();
|
|
142
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
143
|
+
var mitosis = (0, mitosis_1.componentToMitosis)()({ component: backToMitosis });
|
|
144
|
+
expect(mitosis).toMatchSnapshot();
|
|
145
|
+
});
|
|
146
|
+
test('Section', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
147
|
+
var component, html;
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0:
|
|
151
|
+
component = (0, builder_2.builderContentToMitosisComponent)(lazyLoadSection);
|
|
152
|
+
return [4 /*yield*/, (0, html_1.componentToHtml)({
|
|
153
|
+
plugins: [(0, compile_away_builder_components_1.compileAwayBuilderComponents)()],
|
|
154
|
+
})({ component: component })];
|
|
155
|
+
case 1:
|
|
156
|
+
html = _a.sent();
|
|
157
|
+
expect(html).toMatchSnapshot();
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}); });
|
|
162
|
+
test('Regenerate Image', function () {
|
|
163
|
+
var code = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { useStore } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"https://cdn.builder.io/api/v1/image/foobar\"\n sizes=\"100vw\"\n backgroundSize=\"contain\"\n css={{\n marignTop: \"50px\",\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "], ["\n import { useStore } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"https://cdn.builder.io/api/v1/image/foobar\"\n sizes=\"100vw\"\n backgroundSize=\"contain\"\n css={{\n marignTop: \"50px\",\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "])));
|
|
164
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
165
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
166
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
167
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
168
|
+
component: backToMitosis,
|
|
169
|
+
});
|
|
170
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
171
|
+
var react = (0, __1.componentToReact)({
|
|
172
|
+
plugins: [(0, compile_away_builder_components_1.compileAwayBuilderComponents)()],
|
|
173
|
+
})({ component: component });
|
|
174
|
+
expect(react).toMatchSnapshot();
|
|
175
|
+
});
|
|
176
|
+
test('Regenerate Text', function () {
|
|
177
|
+
var code = (0, dedent_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <h2\n css={{\n marginBottom: \"20px\",\n }}\n >\n Hello!\n </h2>\n </div>\n );\n }\n "], ["\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <h2\n css={{\n marginBottom: \"20px\",\n }}\n >\n Hello!\n </h2>\n </div>\n );\n }\n "])));
|
|
178
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
179
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
180
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
181
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
182
|
+
component: backToMitosis,
|
|
183
|
+
});
|
|
184
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
185
|
+
});
|
|
186
|
+
test('Regenerate loop', function () {
|
|
187
|
+
var code = (0, dedent_1.default)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n import { useStore, For } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <For each={state.people}>\n {(person, index) => (\n <div\n key={person}\n css={{\n padding: \"10px 0\",\n }}\n >\n <span>{person}</span>\n <span>{index}</span>\n </div>\n )}\n </For>\n );\n }\n "], ["\n import { useStore, For } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <For each={state.people}>\n {(person, index) => (\n <div\n key={person}\n css={{\n padding: \"10px 0\",\n }}\n >\n <span>{person}</span>\n <span>{index}</span>\n </div>\n )}\n </For>\n );\n }\n "])));
|
|
188
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
189
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
190
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
191
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
192
|
+
component: backToMitosis,
|
|
193
|
+
});
|
|
194
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
195
|
+
});
|
|
196
|
+
test('Regenerate custom Hero', function () {
|
|
197
|
+
var code = (0, dedent_1.default)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n import { Hero } from \"@components\";\n\n export default function MyComponent(props) {\n return (\n <Hero\n title=\"Your Title Here\"\n image=\"https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F52dcecf48f9c48cc8ddd8f81fec63236\"\n buttonLink=\"https://example.com\"\n buttonText=\"Click\"\n height={400}\n css={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"stretch\",\n position: \"relative\",\n flexShrink: \"0\",\n boxSizing: \"border-box\",\n marginTop: \"200px\",\n }}\n />\n );\n }\n "], ["\n import { Hero } from \"@components\";\n\n export default function MyComponent(props) {\n return (\n <Hero\n title=\"Your Title Here\"\n image=\"https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F52dcecf48f9c48cc8ddd8f81fec63236\"\n buttonLink=\"https://example.com\"\n buttonText=\"Click\"\n height={400}\n css={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"stretch\",\n position: \"relative\",\n flexShrink: \"0\",\n boxSizing: \"border-box\",\n marginTop: \"200px\",\n }}\n />\n );\n }\n "])));
|
|
198
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
199
|
+
expect(component).toMatchSnapshot();
|
|
200
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
201
|
+
expect(builderJson).toMatchSnapshot();
|
|
202
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
203
|
+
expect(backToMitosis).toMatchSnapshot();
|
|
204
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
205
|
+
component: backToMitosis,
|
|
206
|
+
});
|
|
207
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
208
|
+
});
|
|
209
|
+
// TODO: fix divs and CoreFragment - need to find way to reproduce
|
|
210
|
+
test.skip('Regenerate fragments', function () {
|
|
211
|
+
var code = (0, dedent_1.default)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n export default function MyComponent(props) {\n return (\n <>\n Hello world\n\n <>\n <Fragment>Hi</Fragment>\n </>\n </>\n );\n }\n "], ["\n export default function MyComponent(props) {\n return (\n <>\n Hello world\n\n <>\n <Fragment>Hi</Fragment>\n </>\n </>\n );\n }\n "])));
|
|
212
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
213
|
+
expect(component).toMatchSnapshot();
|
|
214
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
215
|
+
expect(builderJson).toMatchSnapshot();
|
|
216
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
217
|
+
expect(backToMitosis).toMatchSnapshot();
|
|
218
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
219
|
+
component: backToMitosis,
|
|
220
|
+
});
|
|
221
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
222
|
+
});
|
|
223
|
+
// TODO: get passing, don't add extra divs. or at least use spans instead so don't break layout
|
|
224
|
+
test.skip('Regenerate span text', function () {
|
|
225
|
+
var code = (0, dedent_1.default)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n export default function MyComponent(props) {\n return (\n <div\n css={{\n display: \"block\",\n }}\n >\n Hi there\n <span\n css={{\n color: \"red\",\n }}\n >\n Hello world\n </span>\n </div>\n );\n }\n "], ["\n export default function MyComponent(props) {\n return (\n <div\n css={{\n display: \"block\",\n }}\n >\n Hi there\n <span\n css={{\n color: \"red\",\n }}\n >\n Hello world\n </span>\n </div>\n );\n }\n "])));
|
|
226
|
+
var component = (0, jsx_1.parseJsx)(code);
|
|
227
|
+
var builderJson = (0, builder_1.componentToBuilder)()({ component: component });
|
|
228
|
+
var backToMitosis = (0, builder_2.builderContentToMitosisComponent)(builderJson);
|
|
229
|
+
var mitosis = (0, mitosis_1.componentToMitosis)(mitosisOptions)({
|
|
230
|
+
component: backToMitosis,
|
|
231
|
+
});
|
|
232
|
+
expect(mitosis.trim()).toEqual(code.trim());
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var jsx_1 = require("../parsers/jsx");
|
|
4
|
+
var react_1 = require("../generators/context/react");
|
|
5
|
+
var context_1 = require("../parsers/context");
|
|
6
|
+
var react_2 = require("../generators/react");
|
|
7
|
+
var react_native_1 = require("../generators/react-native");
|
|
8
|
+
var simpleExample = require('./data/context/simple.context.lite');
|
|
9
|
+
var componentWithContext = require('./data/context/component-with-context.lite');
|
|
10
|
+
var renderBlock = require('./data/blocks/builder-render-block.raw');
|
|
11
|
+
describe('Context', function () {
|
|
12
|
+
test('Parse context', function () {
|
|
13
|
+
var component = (0, context_1.parseContext)(simpleExample, { name: 'SimpleExample' });
|
|
14
|
+
if (!component) {
|
|
15
|
+
throw new Error('No parseable context found for simple.context.lite.ts');
|
|
16
|
+
}
|
|
17
|
+
expect(component).toMatchSnapshot();
|
|
18
|
+
var reactContext = (0, react_1.contextToReact)()({ context: component });
|
|
19
|
+
expect(reactContext).toMatchSnapshot();
|
|
20
|
+
});
|
|
21
|
+
test('Use and set context in components', function () {
|
|
22
|
+
var component = (0, jsx_1.parseJsx)(componentWithContext);
|
|
23
|
+
expect(component).toMatchSnapshot();
|
|
24
|
+
var reactComponent = (0, react_2.componentToReact)()({ component: component });
|
|
25
|
+
expect(reactComponent).toMatchSnapshot();
|
|
26
|
+
var reactNativeComponent = (0, react_native_1.componentToReactNative)()({ component: component });
|
|
27
|
+
expect(reactNativeComponent).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
test('Use and set context in complex components', function () {
|
|
30
|
+
var component = (0, jsx_1.parseJsx)(renderBlock);
|
|
31
|
+
expect(component).toMatchSnapshot();
|
|
32
|
+
var reactComponent = (0, react_2.componentToReact)()({ component: component });
|
|
33
|
+
expect(reactComponent).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var _1_1 = __importDefault(require("@dummy/1"));
|
|
7
|
+
var _2_1 = __importDefault(require("@dummy/2"));
|
|
8
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
9
|
+
function ComponentWithContext(props) {
|
|
10
|
+
var foo = (0, mitosis_1.useContext)(_1_1.default);
|
|
11
|
+
(0, mitosis_1.setContext)(_1_1.default, {
|
|
12
|
+
foo: 'bar',
|
|
13
|
+
content: function () {
|
|
14
|
+
return props.content;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return (<_2_1.default.Provider value={{ bar: 'baz' }}>
|
|
18
|
+
<>{foo.value}</>
|
|
19
|
+
</_2_1.default.Provider>);
|
|
20
|
+
}
|
|
21
|
+
exports.default = ComponentWithContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
exports.default = (0, mitosis_1.createContext)({
|
|
5
|
+
foo: 'bar',
|
|
6
|
+
get fooUpperCase() {
|
|
7
|
+
return this.foo.toUpperCase();
|
|
8
|
+
},
|
|
9
|
+
someMethod: function () {
|
|
10
|
+
return this.fooUpperCase.toLowercase();
|
|
11
|
+
},
|
|
12
|
+
content: null,
|
|
13
|
+
context: {},
|
|
14
|
+
state: {},
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function NestedStyles(): import("@builder.io/mitosis/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function NestedStyles() {
|
|
4
|
+
return (<div css={{
|
|
5
|
+
display: 'flex',
|
|
6
|
+
foo: 'var(--bar)',
|
|
7
|
+
'@media (max-width: env(--mobile))': {
|
|
8
|
+
display: 'block',
|
|
9
|
+
},
|
|
10
|
+
'&:hover': {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
},
|
|
13
|
+
'.nested-selector': {
|
|
14
|
+
display: 'grid',
|
|
15
|
+
},
|
|
16
|
+
}}>
|
|
17
|
+
Hello world
|
|
18
|
+
</div>);
|
|
19
|
+
}
|
|
20
|
+
exports.default = NestedStyles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type Foo = null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var __1 = require("..");
|
|
4
|
+
describe('hashCode', function () {
|
|
5
|
+
test('should compute object', function () {
|
|
6
|
+
expect((0, __1.hashCodeAsString)({ foo: 'bar' })).toEqual('1jo4fm');
|
|
7
|
+
});
|
|
8
|
+
test('order of properties should not matter', function () {
|
|
9
|
+
expect((0, __1.hashCodeAsString)({ a: 'first', b: 'second' })).toEqual((0, __1.hashCodeAsString)({ b: 'second', a: 'first' }));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var html_1 = require("../generators/html");
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
describe('Html', function () {
|
|
6
|
+
(0, shared_1.runTestsForTarget)('html', (0, html_1.componentToHtml)());
|
|
7
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var liquid_1 = require("../generators/liquid");
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
describe('Liquid', function () {
|
|
6
|
+
(0, shared_1.runTestsForTarget)('liquid', (0, liquid_1.componentToLiquid)());
|
|
7
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var lit_1 = require("../generators/lit");
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
describe('Lit', function () {
|
|
6
|
+
(0, shared_1.runTestsForTarget)('lit', (0, lit_1.componentToLit)());
|
|
7
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var marko_1 = require("../generators/marko");
|
|
4
|
+
var shared_1 = require("./shared");
|
|
5
|
+
describe('Marko format', function () {
|
|
6
|
+
var exampleCode = "\n <div>\n <if(input.foo === 'bar')>\n Hello\n </if>\n <for|items| of=(some.long ? expression : yo)>\n World\n </for>\n <input \n placeholder=\"Hello world...\"\n value=(this.state.name) \n on-click=(event => {\n console.log('hello', \"world\")\n })\n on-input=(event => this.state.name = event.target.value) /> \n \n Hello! I can run in React, Vue, Solid, or Liquid!\n </div>";
|
|
7
|
+
var preprocessed = (0, marko_1.preprocessHtml)(exampleCode);
|
|
8
|
+
expect(preprocessed).toMatchSnapshot();
|
|
9
|
+
expect((0, marko_1.postprocessHtml)(preprocessed)).toMatchSnapshot();
|
|
10
|
+
expect((0, marko_1.markoFormatHtml)(exampleCode)).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
describe('Marko', function () {
|
|
13
|
+
(0, shared_1.runTestsForTarget)('marko', (0, marko_1.componentToMarko)());
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var jsx_1 = require("../parsers/jsx");
|
|
4
|
+
var buttonWithMetadata = require('./data/blocks/button-with-metadata.raw');
|
|
5
|
+
var image = require('./data/blocks/image.raw');
|
|
6
|
+
var basicOnUpdateReturn = require('./data/basic-onUpdate-return.raw');
|
|
7
|
+
var basicMitosis = require('./data/basic-custom-mitosis-package.raw');
|
|
8
|
+
var basicRef = require('./data/basic-ref.raw');
|
|
9
|
+
var basicPropsRaw = require('./data/basic-props.raw');
|
|
10
|
+
var basicPropsDestructureRaw = require('./data/basic-props-destructure.raw');
|
|
11
|
+
describe('Parse JSX', function () {
|
|
12
|
+
test('metadata', function () {
|
|
13
|
+
var json = (0, jsx_1.parseJsx)(buttonWithMetadata);
|
|
14
|
+
expect(json).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
test('Image', function () {
|
|
17
|
+
var json = (0, jsx_1.parseJsx)(image);
|
|
18
|
+
expect(json).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
test('onUpdate return', function () {
|
|
21
|
+
var json = (0, jsx_1.parseJsx)(basicOnUpdateReturn);
|
|
22
|
+
expect(json).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
test('useRef', function () {
|
|
25
|
+
var json = (0, jsx_1.parseJsx)(basicRef);
|
|
26
|
+
expect(json).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
test('custom mitosis package', function () {
|
|
29
|
+
var json = (0, jsx_1.parseJsx)(basicMitosis, {
|
|
30
|
+
compileAwayPackages: ['@dummy/custom-mitosis'],
|
|
31
|
+
});
|
|
32
|
+
expect(json).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
test('custom mitosis package', function () {
|
|
35
|
+
expect((0, jsx_1.parseJsx)(basicPropsRaw)).toEqual((0, jsx_1.parseJsx)(basicPropsDestructureRaw));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var convert_method_to_function_1 = require("../../generators/qwik/convert-method-to-function");
|
|
4
|
+
describe('convertMethodToFunction', function () {
|
|
5
|
+
var methodMap = {
|
|
6
|
+
methodA: 'method',
|
|
7
|
+
getterB: 'getter',
|
|
8
|
+
getCssFromFont: 'method',
|
|
9
|
+
};
|
|
10
|
+
var lexicalArgs = ['props', 'state'];
|
|
11
|
+
describe('rewrite', function () {
|
|
12
|
+
test('method', function () {
|
|
13
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('this.methodA(123)', methodMap, lexicalArgs)).toEqual('methodA(props,state,123)');
|
|
14
|
+
});
|
|
15
|
+
test('getter', function () {
|
|
16
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('this.getterB', methodMap, lexicalArgs)).toEqual('getterB(props,state)');
|
|
17
|
+
});
|
|
18
|
+
test('method binding', function () {
|
|
19
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('this.methodA', methodMap, lexicalArgs)).toEqual('methodA.bind(null,props,state)');
|
|
20
|
+
});
|
|
21
|
+
test('handle comments', function () {
|
|
22
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('//\nreturn this.getterB;', methodMap, lexicalArgs)).toEqual('//\nreturn getterB(props,state);');
|
|
23
|
+
});
|
|
24
|
+
test('braces', function () {
|
|
25
|
+
var code = 'getFontCss({}: {}) { this.getCssFromFont(font) }';
|
|
26
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)(code, methodMap, lexicalArgs)).toEqual('getFontCss({}: {}) { getCssFromFont(props,state,font) }');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('string', function () {
|
|
30
|
+
test('should not rewrite string', function () {
|
|
31
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('"this.getterB"', methodMap, lexicalArgs)).toEqual('"this.getterB"');
|
|
32
|
+
});
|
|
33
|
+
test('should rewrite template string', function () {
|
|
34
|
+
expect((0, convert_method_to_function_1.convertMethodToFunction)('`${this.getterB}this.getterB`', methodMap, lexicalArgs)).toEqual('`${getterB(props,state)}this.getterB`');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var src_generator_1 = require("../../generators/qwik/src-generator");
|
|
4
|
+
describe('src-generator', function () {
|
|
5
|
+
describe('isStatement', function () {
|
|
6
|
+
test('is an expression', function () {
|
|
7
|
+
expect((0, src_generator_1.isStatement)('a.b')).toBe(false);
|
|
8
|
+
expect((0, src_generator_1.isStatement)('1?2:"bar"')).toBe(false);
|
|
9
|
+
expect((0, src_generator_1.isStatement)('"var x; return foo + \'\\"\';"')).toBe(false);
|
|
10
|
+
expect((0, src_generator_1.isStatement)('"foo" + `bar\nbaz`')).toBe(false);
|
|
11
|
+
expect((0, src_generator_1.isStatement)('(...)()')).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
test('regression', function () {
|
|
14
|
+
expect((0, src_generator_1.isStatement)('props.attributes?.class || props.attributes?.className')).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
test('is a statement', function () {
|
|
17
|
+
expect((0, src_generator_1.isStatement)('var x; return x;')).toBe(true);
|
|
18
|
+
expect((0, src_generator_1.isStatement)('var x')).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('import', function () {
|
|
22
|
+
var options;
|
|
23
|
+
var src;
|
|
24
|
+
describe('module', function () {
|
|
25
|
+
beforeEach(function () {
|
|
26
|
+
options = {
|
|
27
|
+
isJSX: true,
|
|
28
|
+
isPretty: false,
|
|
29
|
+
isTypeScript: false,
|
|
30
|
+
isModule: true,
|
|
31
|
+
isBuilder: false,
|
|
32
|
+
};
|
|
33
|
+
src = new src_generator_1.SrcBuilder(new src_generator_1.File('test', options, '', ''), options);
|
|
34
|
+
});
|
|
35
|
+
test('import to string', function () {
|
|
36
|
+
src.import('module', [new src_generator_1.Symbol('importName', 'asLocalName')]);
|
|
37
|
+
expect(src.toString()).toEqual('import{importName as asLocalName}from"module";');
|
|
38
|
+
});
|
|
39
|
+
test('import from default', function () {
|
|
40
|
+
src.import('module', [new src_generator_1.Symbol('default', 'asLocalName')]);
|
|
41
|
+
expect(src.toString()).toEqual('import asLocalName from"module";');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('require', function () {
|
|
45
|
+
beforeEach(function () {
|
|
46
|
+
options = {
|
|
47
|
+
isJSX: true,
|
|
48
|
+
isPretty: false,
|
|
49
|
+
isTypeScript: false,
|
|
50
|
+
isModule: false,
|
|
51
|
+
isBuilder: false,
|
|
52
|
+
};
|
|
53
|
+
src = new src_generator_1.SrcBuilder(new src_generator_1.File('test', options, '', ''), options);
|
|
54
|
+
});
|
|
55
|
+
test('import to string', function () {
|
|
56
|
+
src.import('module', [new src_generator_1.Symbol('importName', 'asLocalName')]);
|
|
57
|
+
expect(src.toString()).toEqual('const asLocalName=require("module").importName;');
|
|
58
|
+
});
|
|
59
|
+
test('import from default', function () {
|
|
60
|
+
src.import('module', [new src_generator_1.Symbol('default', 'asLocalName')]);
|
|
61
|
+
expect(src.toString()).toEqual('const asLocalName=require("module");');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|