@builder.io/mitosis 0.5.24 → 0.5.26
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/generators/alpine/generate.js +4 -3
- package/dist/src/generators/angular/index.js +35 -25
- package/dist/src/generators/angular/types.d.ts +12 -0
- package/dist/src/generators/helpers/rsc.js +2 -1
- package/dist/src/generators/html/generator.js +8 -7
- package/dist/src/generators/liquid/generator.js +2 -1
- package/dist/src/generators/lit/generate.js +2 -1
- package/dist/src/generators/marko/generate.js +2 -1
- package/dist/src/generators/mitosis/generator.js +6 -5
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +3 -2
- package/dist/src/generators/qwik/helpers/handlers.js +2 -1
- package/dist/src/generators/qwik/src-generator.js +2 -1
- package/dist/src/generators/react/blocks.js +2 -1
- package/dist/src/generators/solid/blocks.js +2 -1
- package/dist/src/generators/stencil/helpers/index.js +2 -1
- package/dist/src/generators/svelte/blocks.js +3 -2
- package/dist/src/generators/swift/generator.js +2 -1
- package/dist/src/generators/template/generator.js +2 -1
- package/dist/src/generators/vue/blocks.js +3 -2
- package/dist/src/helpers/event-handlers.d.ts +2 -1
- package/dist/src/helpers/event-handlers.js +110 -3
- package/dist/src/parsers/jsx/helpers.d.ts +6 -0
- package/dist/src/parsers/jsx/helpers.js +28 -4
- package/dist/src/parsers/jsx/hooks/index.d.ts +4 -3
- package/dist/src/parsers/jsx/hooks/index.js +37 -26
- package/dist/src/parsers/jsx/hooks/use-metadata.d.ts +9 -0
- package/dist/src/parsers/jsx/hooks/use-metadata.js +184 -0
- package/dist/src/parsers/jsx/imports.d.ts +0 -2
- package/dist/src/parsers/jsx/imports.js +8 -26
- package/dist/src/parsers/jsx/jsx.js +87 -106
- package/dist/src/parsers/jsx/types.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1,5 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
exports.
|
|
3
|
+
exports.checkIsBindingNativeEvent = exports.checkIsEvent = void 0;
|
|
4
|
+
const checkIsEvent = (code) => code.startsWith('on');
|
|
5
|
+
exports.checkIsEvent = checkIsEvent;
|
|
6
|
+
const nativeEvents = [
|
|
7
|
+
'abort',
|
|
8
|
+
'animationcancel',
|
|
9
|
+
'animationend',
|
|
10
|
+
'animationiteration',
|
|
11
|
+
'animationstart',
|
|
12
|
+
'auxclick',
|
|
13
|
+
'beforeinput',
|
|
14
|
+
'beforetoggle',
|
|
15
|
+
'blur',
|
|
16
|
+
'cancel',
|
|
17
|
+
'canplay',
|
|
18
|
+
'canplaythrough',
|
|
19
|
+
'change',
|
|
20
|
+
'click',
|
|
21
|
+
'close',
|
|
22
|
+
'compositionend',
|
|
23
|
+
'compositionstart',
|
|
24
|
+
'compositionupdate',
|
|
25
|
+
'contextlost',
|
|
26
|
+
'contextmenu',
|
|
27
|
+
'contextrestored',
|
|
28
|
+
'copy',
|
|
29
|
+
'cuechange',
|
|
30
|
+
'cut',
|
|
31
|
+
'dblclick',
|
|
32
|
+
'drag',
|
|
33
|
+
'dragend',
|
|
34
|
+
'dragenter',
|
|
35
|
+
'dragleave',
|
|
36
|
+
'dragover',
|
|
37
|
+
'dragstart',
|
|
38
|
+
'drop',
|
|
39
|
+
'durationchange',
|
|
40
|
+
'emptied',
|
|
41
|
+
'ended',
|
|
42
|
+
'error',
|
|
43
|
+
'focus',
|
|
44
|
+
'focusin',
|
|
45
|
+
'focusout',
|
|
46
|
+
'formdata',
|
|
47
|
+
'gotpointercapture',
|
|
48
|
+
'input',
|
|
49
|
+
'invalid',
|
|
50
|
+
'keydown',
|
|
51
|
+
'keypress',
|
|
52
|
+
'keyup',
|
|
53
|
+
'load',
|
|
54
|
+
'loadeddata',
|
|
55
|
+
'loadedmetadata',
|
|
56
|
+
'loadstart',
|
|
57
|
+
'lostpointercapture',
|
|
58
|
+
'mousedown',
|
|
59
|
+
'mouseenter',
|
|
60
|
+
'mouseleave',
|
|
61
|
+
'mousemove',
|
|
62
|
+
'mouseout',
|
|
63
|
+
'mouseover',
|
|
64
|
+
'mouseup',
|
|
65
|
+
'paste',
|
|
66
|
+
'pause',
|
|
67
|
+
'play',
|
|
68
|
+
'playing',
|
|
69
|
+
'pointercancel',
|
|
70
|
+
'pointerdown',
|
|
71
|
+
'pointerenter',
|
|
72
|
+
'pointerleave',
|
|
73
|
+
'pointermove',
|
|
74
|
+
'pointerout',
|
|
75
|
+
'pointerover',
|
|
76
|
+
'pointerup',
|
|
77
|
+
'progress',
|
|
78
|
+
'ratechange',
|
|
79
|
+
'reset',
|
|
80
|
+
'resize',
|
|
81
|
+
'scroll',
|
|
82
|
+
'scrollend',
|
|
83
|
+
'securitypolicyviolation',
|
|
84
|
+
'seeked',
|
|
85
|
+
'seeking',
|
|
86
|
+
'select',
|
|
87
|
+
'selectionchange',
|
|
88
|
+
'selectstart',
|
|
89
|
+
'slotchange',
|
|
90
|
+
'stalled',
|
|
91
|
+
'submit',
|
|
92
|
+
'suspend',
|
|
93
|
+
'timeupdate',
|
|
94
|
+
'toggle',
|
|
95
|
+
'touchcancel',
|
|
96
|
+
'touchend',
|
|
97
|
+
'touchmove',
|
|
98
|
+
'touchstart',
|
|
99
|
+
'transitioncancel',
|
|
100
|
+
'transitionend',
|
|
101
|
+
'transitionrun',
|
|
102
|
+
'transitionstart',
|
|
103
|
+
'volumechange',
|
|
104
|
+
'waiting',
|
|
105
|
+
'webkitanimationend',
|
|
106
|
+
'webkitanimationiteration',
|
|
107
|
+
'webkitanimationstart',
|
|
108
|
+
'webkittransitionend',
|
|
109
|
+
'wheel',
|
|
110
|
+
];
|
|
111
|
+
const checkIsBindingNativeEvent = (code) => !!nativeEvents.find((nativeEvent) => nativeEvent === code.toLowerCase());
|
|
112
|
+
exports.checkIsBindingNativeEvent = checkIsBindingNativeEvent;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { Context } from '../../parsers/jsx/types';
|
|
1
2
|
import * as babel from '@babel/core';
|
|
3
|
+
import { BabelFileResult } from '@babel/core';
|
|
4
|
+
import { Visitor } from '@babel/traverse';
|
|
2
5
|
declare const types: typeof babel.types;
|
|
3
6
|
export declare const uncapitalize: (str: string) => string;
|
|
4
7
|
export declare const parseCode: (node: babel.types.Node) => string;
|
|
@@ -8,4 +11,7 @@ export declare const HTML_ATTR_FROM_JSX: {
|
|
|
8
11
|
htmlFor: string;
|
|
9
12
|
};
|
|
10
13
|
export declare const transformAttributeName: (name: string) => string;
|
|
14
|
+
export declare const babelStripTypes: (code: string, typescript?: boolean) => string;
|
|
15
|
+
export declare const babelDefaultTransform: (code: string, visitor: Visitor<Context>) => BabelFileResult | null;
|
|
16
|
+
export declare const isTypescriptFile: (fileName: string) => boolean;
|
|
11
17
|
export {};
|
|
@@ -26,11 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.transformAttributeName = exports.HTML_ATTR_FROM_JSX = exports.isImportOrDefaultExport = exports.parseCodeJson = exports.parseCode = exports.uncapitalize = void 0;
|
|
30
|
-
const babel = __importStar(require("@babel/core"));
|
|
31
|
-
const generator_1 = __importDefault(require("@babel/generator"));
|
|
29
|
+
exports.isTypescriptFile = exports.babelDefaultTransform = exports.babelStripTypes = exports.transformAttributeName = exports.HTML_ATTR_FROM_JSX = exports.isImportOrDefaultExport = exports.parseCodeJson = exports.parseCode = exports.uncapitalize = void 0;
|
|
32
30
|
const json_1 = require("../../helpers/json");
|
|
33
31
|
const typescript_1 = require("../../helpers/typescript");
|
|
32
|
+
const babel = __importStar(require("@babel/core"));
|
|
33
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
34
|
+
const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
35
|
+
const preset_typescript_1 = __importDefault(require("@babel/preset-typescript"));
|
|
36
|
+
const typescriptBabelPreset = [preset_typescript_1.default, { isTSX: true, allExtensions: true }];
|
|
34
37
|
const { types } = babel;
|
|
35
38
|
const uncapitalize = (str) => {
|
|
36
39
|
if (!str) {
|
|
@@ -40,7 +43,8 @@ const uncapitalize = (str) => {
|
|
|
40
43
|
};
|
|
41
44
|
exports.uncapitalize = uncapitalize;
|
|
42
45
|
const parseCode = (node) => {
|
|
43
|
-
|
|
46
|
+
const generatorResult = (0, generator_1.default)(node);
|
|
47
|
+
return generatorResult.code;
|
|
44
48
|
};
|
|
45
49
|
exports.parseCode = parseCode;
|
|
46
50
|
const parseCodeJson = (node) => {
|
|
@@ -59,3 +63,23 @@ const transformAttributeName = (name) => {
|
|
|
59
63
|
return name;
|
|
60
64
|
};
|
|
61
65
|
exports.transformAttributeName = transformAttributeName;
|
|
66
|
+
const babelStripTypes = (code, typescript) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return typescript
|
|
69
|
+
? (_a = babel.transform(code, {
|
|
70
|
+
configFile: false,
|
|
71
|
+
babelrc: false,
|
|
72
|
+
presets: [typescriptBabelPreset],
|
|
73
|
+
})) === null || _a === void 0 ? void 0 : _a.code
|
|
74
|
+
: code;
|
|
75
|
+
};
|
|
76
|
+
exports.babelStripTypes = babelStripTypes;
|
|
77
|
+
const babelDefaultTransform = (code, visitor) => babel.transform(code, {
|
|
78
|
+
configFile: false,
|
|
79
|
+
babelrc: false,
|
|
80
|
+
comments: false,
|
|
81
|
+
plugins: [[plugin_syntax_typescript_1.default, { isTSX: true }], () => ({ visitor })],
|
|
82
|
+
});
|
|
83
|
+
exports.babelDefaultTransform = babelDefaultTransform;
|
|
84
|
+
const isTypescriptFile = (fileName) => fileName.endsWith('.ts') || fileName.endsWith('.tsx');
|
|
85
|
+
exports.isTypescriptFile = isTypescriptFile;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import * as babel from '@babel/core';
|
|
2
1
|
import { MitosisComponent } from '../../../types/mitosis-component';
|
|
3
|
-
import
|
|
2
|
+
import * as babel from '@babel/core';
|
|
3
|
+
import { NodePath } from '@babel/core';
|
|
4
|
+
import { Context, ParseMitosisOptions } from '../types';
|
|
4
5
|
declare const types: typeof babel.types;
|
|
5
6
|
export declare function parseDefaultPropsHook(component: MitosisComponent, expression: babel.types.CallExpression): void;
|
|
6
7
|
export declare function generateUseStyleCode(expression: babel.types.CallExpression): string;
|
|
@@ -11,5 +12,5 @@ export declare function generateUseStyleCode(expression: babel.types.CallExpress
|
|
|
11
12
|
* This function collects metadata and removes the statement from
|
|
12
13
|
* the returned nodes array
|
|
13
14
|
*/
|
|
14
|
-
export declare const collectModuleScopeHooks: (
|
|
15
|
+
export declare const collectModuleScopeHooks: (context: Context, options: ParseMitosisOptions) => (path: NodePath<babel.types.Program>) => babel.types.Statement[];
|
|
15
16
|
export {};
|
|
@@ -27,9 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.collectModuleScopeHooks = exports.generateUseStyleCode = exports.parseDefaultPropsHook = void 0;
|
|
30
|
+
const hooks_1 = require("../../../constants/hooks");
|
|
31
|
+
const use_metadata_1 = require("../../../parsers/jsx/hooks/use-metadata");
|
|
30
32
|
const babel = __importStar(require("@babel/core"));
|
|
31
33
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
32
|
-
const hooks_1 = require("../../../constants/hooks");
|
|
33
34
|
const helpers_1 = require("../helpers");
|
|
34
35
|
const state_1 = require("../state");
|
|
35
36
|
const helpers_2 = require("./helpers");
|
|
@@ -52,34 +53,44 @@ exports.generateUseStyleCode = generateUseStyleCode;
|
|
|
52
53
|
* This function collects metadata and removes the statement from
|
|
53
54
|
* the returned nodes array
|
|
54
55
|
*/
|
|
55
|
-
const collectModuleScopeHooks = (
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
const collectModuleScopeHooks = (context, options) => (path) => {
|
|
57
|
+
const programNodes = path.node.body;
|
|
58
|
+
return programNodes.filter((node) => {
|
|
59
|
+
const hook = (0, helpers_2.getHook)(node);
|
|
60
|
+
if (!hook) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (types.isIdentifier(hook.callee)) {
|
|
64
|
+
const metadataHooks = new Set((options.jsonHookNames || []).concat(hooks_1.HOOKS.METADATA));
|
|
65
|
+
const name = hook.callee.name;
|
|
66
|
+
if (metadataHooks.has(name)) {
|
|
67
|
+
const metaDataObjectNode = hook.arguments[0];
|
|
68
|
+
let json;
|
|
69
|
+
try {
|
|
70
|
+
json = options.filePath
|
|
71
|
+
? (0, use_metadata_1.resolveMetadata)({ context, node: metaDataObjectNode, nodePath: path, options })
|
|
72
|
+
: (0, helpers_1.parseCodeJson)(metaDataObjectNode);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// Meta data isn't simple json convert it to ast
|
|
76
|
+
console.error(`Error parsing metadata hook ${name}`);
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
79
|
+
context.builder.component.meta[name] = {
|
|
80
|
+
...(context.builder.component.meta[name] || {}),
|
|
81
|
+
...json,
|
|
67
82
|
};
|
|
68
83
|
return false;
|
|
69
84
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
else if (name === hooks_1.HOOKS.STYLE) {
|
|
86
|
+
context.builder.component.style = generateUseStyleCode(hook);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
else if (name === hooks_1.HOOKS.DEFAULT_PROPS) {
|
|
90
|
+
parseDefaultPropsHook(context.builder.component, hook);
|
|
73
91
|
}
|
|
74
92
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
else if (hook.callee.name === hooks_1.HOOKS.DEFAULT_PROPS) {
|
|
80
|
-
parseDefaultPropsHook(component, hook);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
});
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
85
96
|
exports.collectModuleScopeHooks = collectModuleScopeHooks;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, ParseMitosisOptions } from '../../../parsers/jsx/types';
|
|
2
|
+
import * as babel from '@babel/core';
|
|
3
|
+
import { NodePath } from '@babel/core';
|
|
4
|
+
export declare const resolveMetadata: ({ context, node, nodePath, options, }: {
|
|
5
|
+
context: Context;
|
|
6
|
+
node: babel.types.Node;
|
|
7
|
+
nodePath: NodePath<babel.types.Program>;
|
|
8
|
+
options: ParseMitosisOptions;
|
|
9
|
+
}) => Record<string, any>;
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.resolveMetadata = void 0;
|
|
27
|
+
const mitosis_imports_1 = require("../../../helpers/mitosis-imports");
|
|
28
|
+
const helpers_1 = require("../../../parsers/jsx/helpers");
|
|
29
|
+
const babel = __importStar(require("@babel/core"));
|
|
30
|
+
const fs_extra_promise_1 = require("fs-extra-promise");
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const getCodeFromImport = (importObject, currentFile) => {
|
|
33
|
+
if (currentFile) {
|
|
34
|
+
// resolve path of import
|
|
35
|
+
const originFile = path.basename(currentFile);
|
|
36
|
+
const typescript = (0, helpers_1.isTypescriptFile)(originFile);
|
|
37
|
+
const importFile = (0, helpers_1.isTypescriptFile)(importObject.path) || importObject.path.endsWith('.js')
|
|
38
|
+
? importObject.path
|
|
39
|
+
: `${importObject.path}.${typescript ? 'ts' : 'js'}`;
|
|
40
|
+
const importFilePath = path.resolve(path.dirname(currentFile), importFile);
|
|
41
|
+
if ((0, fs_extra_promise_1.existsSync)(importFilePath)) {
|
|
42
|
+
return { code: (0, fs_extra_promise_1.readFileSync)(importFilePath).toString(), typescript, importFilePath };
|
|
43
|
+
}
|
|
44
|
+
return { typescript };
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
|
+
};
|
|
48
|
+
const fillDeclarations = ({ declaration, valueToResolve, currentFilePath, nodePath, }) => {
|
|
49
|
+
let result = {};
|
|
50
|
+
for (const variable of declaration.declarations) {
|
|
51
|
+
if (babel.types.isIdentifier(variable.id)) {
|
|
52
|
+
if (variable.id.name === valueToResolve && variable.init) {
|
|
53
|
+
const filled = resolveObjectsRecursive({
|
|
54
|
+
node: variable.init,
|
|
55
|
+
nodePath,
|
|
56
|
+
currentFilePath,
|
|
57
|
+
});
|
|
58
|
+
result = {
|
|
59
|
+
...result,
|
|
60
|
+
...filled,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
const resolve = ({ nodePath, currentFilePath, valueToResolve, resolvedImports, }) => {
|
|
68
|
+
let result = {};
|
|
69
|
+
const programNodes = nodePath.node.body;
|
|
70
|
+
for (const statement of programNodes) {
|
|
71
|
+
if (babel.types.isImportDeclaration(statement)) {
|
|
72
|
+
const importObject = (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(statement);
|
|
73
|
+
if (Object.keys(importObject.imports).includes(valueToResolve)) {
|
|
74
|
+
if (resolvedImports) {
|
|
75
|
+
// We add this statement, to remove it from imports of generated file
|
|
76
|
+
resolvedImports.push({ path: importObject.path, value: valueToResolve });
|
|
77
|
+
}
|
|
78
|
+
// In this case the variable was imported
|
|
79
|
+
const { code, typescript, importFilePath } = getCodeFromImport(importObject, currentFilePath);
|
|
80
|
+
if (code) {
|
|
81
|
+
const jsxToUse = (0, helpers_1.babelStripTypes)(code, typescript);
|
|
82
|
+
(0, helpers_1.babelDefaultTransform)(jsxToUse, {
|
|
83
|
+
Program(path) {
|
|
84
|
+
const statements = path.node.body;
|
|
85
|
+
for (const pStatement of statements) {
|
|
86
|
+
if (babel.types.isExportNamedDeclaration(pStatement)) {
|
|
87
|
+
const declaration = pStatement.declaration;
|
|
88
|
+
if (babel.types.isVariableDeclaration(declaration)) {
|
|
89
|
+
const filledDeclaration = fillDeclarations({
|
|
90
|
+
declaration,
|
|
91
|
+
valueToResolve,
|
|
92
|
+
currentFilePath: importFilePath,
|
|
93
|
+
nodePath: path,
|
|
94
|
+
});
|
|
95
|
+
result = {
|
|
96
|
+
...result,
|
|
97
|
+
...filledDeclaration,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (babel.types.isVariableDeclaration(statement)) {
|
|
108
|
+
// In this case the variable is inside the same file
|
|
109
|
+
const filledDeclaration = fillDeclarations({
|
|
110
|
+
declaration: statement,
|
|
111
|
+
valueToResolve,
|
|
112
|
+
currentFilePath,
|
|
113
|
+
nodePath,
|
|
114
|
+
});
|
|
115
|
+
result = {
|
|
116
|
+
...result,
|
|
117
|
+
...filledDeclaration,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
const resolveObjectsRecursive = ({ node, nodePath, currentFilePath, resolvedImports, }) => {
|
|
124
|
+
let result = {};
|
|
125
|
+
if (babel.types.isObjectExpression(node)) {
|
|
126
|
+
for (const prop of node.properties) {
|
|
127
|
+
if (babel.types.isObjectProperty(prop)) {
|
|
128
|
+
if (babel.types.isIdentifier(prop.key)) {
|
|
129
|
+
const objectKey = prop.key.name;
|
|
130
|
+
if (babel.types.isIdentifier(prop.value)) {
|
|
131
|
+
const valueToResolve = prop.value.name;
|
|
132
|
+
// In this case we have some variable defined in the same or another file
|
|
133
|
+
const resolved = resolve({
|
|
134
|
+
nodePath,
|
|
135
|
+
currentFilePath,
|
|
136
|
+
valueToResolve,
|
|
137
|
+
resolvedImports,
|
|
138
|
+
});
|
|
139
|
+
result = {
|
|
140
|
+
...result,
|
|
141
|
+
[objectKey]: { ...resolved },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// In this case we have a primitive value
|
|
146
|
+
const json = (0, helpers_1.parseCodeJson)(prop.value);
|
|
147
|
+
result = {
|
|
148
|
+
...result,
|
|
149
|
+
[objectKey]: json,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (babel.types.isSpreadElement(prop)) {
|
|
155
|
+
if (babel.types.isIdentifier(prop.argument)) {
|
|
156
|
+
const valueToResolve = prop.argument.name;
|
|
157
|
+
result = {
|
|
158
|
+
...result,
|
|
159
|
+
...resolve({ nodePath, currentFilePath, valueToResolve }),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// In this case we have a primitive value
|
|
165
|
+
result = {
|
|
166
|
+
...result,
|
|
167
|
+
...(0, helpers_1.parseCodeJson)(prop),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
};
|
|
174
|
+
const resolveMetadata = ({ context, node, nodePath, options, }) => {
|
|
175
|
+
if (context.cwd && (options === null || options === void 0 ? void 0 : options.filePath)) {
|
|
176
|
+
const resolvedImports = [];
|
|
177
|
+
const currentFilePath = `${context.cwd}/${options.filePath}`;
|
|
178
|
+
const metadata = resolveObjectsRecursive({ node, nodePath, currentFilePath, resolvedImports });
|
|
179
|
+
context.builder.resolvedImports = resolvedImports;
|
|
180
|
+
return metadata;
|
|
181
|
+
}
|
|
182
|
+
return {};
|
|
183
|
+
};
|
|
184
|
+
exports.resolveMetadata = resolveMetadata;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
2
|
import { Context, ParseMitosisOptions } from './types';
|
|
3
|
-
declare const types: typeof babel.types;
|
|
4
3
|
export declare const handleImportDeclaration: ({ options, path, context, }: {
|
|
5
4
|
options: Partial<ParseMitosisOptions>;
|
|
6
5
|
path: babel.NodePath<babel.types.ImportDeclaration>;
|
|
7
6
|
context: Context;
|
|
8
7
|
}) => void;
|
|
9
|
-
export {};
|
|
@@ -1,33 +1,9 @@
|
|
|
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
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.handleImportDeclaration = void 0;
|
|
27
|
-
const babel = __importStar(require("@babel/core"));
|
|
28
4
|
const mitosis_imports_1 = require("../../helpers/mitosis-imports");
|
|
29
|
-
const { types } = babel;
|
|
30
5
|
const handleImportDeclaration = ({ options, path, context, }) => {
|
|
6
|
+
var _a;
|
|
31
7
|
// @builder.io/mitosis or React imports compile away
|
|
32
8
|
const customPackages = (options === null || options === void 0 ? void 0 : options.compileAwayPackages) || [];
|
|
33
9
|
if (['react', '@builder.io/mitosis', '@emotion/react', ...customPackages].includes(path.node.source.value)) {
|
|
@@ -35,7 +11,13 @@ const handleImportDeclaration = ({ options, path, context, }) => {
|
|
|
35
11
|
return;
|
|
36
12
|
}
|
|
37
13
|
const importObject = (0, mitosis_imports_1.mapImportDeclarationToMitosisImport)(path.node);
|
|
38
|
-
context.builder.
|
|
14
|
+
const resolvedImport = (_a = context.builder.resolvedImports) === null || _a === void 0 ? void 0 : _a.find((rImport) => rImport.path === importObject.path);
|
|
15
|
+
if (resolvedImport) {
|
|
16
|
+
delete importObject.imports[resolvedImport.value];
|
|
17
|
+
}
|
|
18
|
+
if (Object.keys(importObject.imports).length > 0) {
|
|
19
|
+
context.builder.component.imports.push(importObject);
|
|
20
|
+
}
|
|
39
21
|
path.remove();
|
|
40
22
|
};
|
|
41
23
|
exports.handleImportDeclaration = handleImportDeclaration;
|