UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

33 lines (32 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseImports = void 0; function parseImports(json, node) { var _a; const source = (_a = node.source) === null || _a === void 0 ? void 0 : _a.value; if (source === 'svelte') return; // Do not import anything from svelte // ^ Maybe this should even be stricter and only allow relative imports and alias ones // as you can't import any other svelte specific libraries either...Or can we? const importSpecifiers = Object.values(node.specifiers).map((index) => { return { [index.local.name]: index.type === 'ImportDefaultSpecifier' ? 'default' : index.local.name, }; }); const imports = {}; for (const specifier of importSpecifiers) { Object.assign(imports, specifier); } // only add imports which are actually used if (Object.keys(imports).length > 0) { json.imports = [ ...json.imports, { imports, path: source.replace('.svelte', '.lite') }, ]; // TODO: if import source already exist, combine them // e.g. import { lowercase } from 'lodash'; // e.g. import { uppercase } from 'lodash'; // should become import { lowercase, uppercase } from 'lodash'; } } exports.parseImports = parseImports;