UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

94 lines (89 loc) 3.09 kB
'use strict'; var chunkQH6JOSVV_cjs = require('./chunk-QH6JOSVV.cjs'); var chunk3ONWID2V_cjs = require('./chunk-3ONWID2V.cjs'); var t = require('@babel/types'); var isString = require('@stryke/type-checks/is-string'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var t__namespace = /*#__PURE__*/_interopNamespace(t); function findExport(ast, key) { const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration"; for (const node of ast.program.body) { if (node.type === type) { if (key === "default") { return node.declaration; } if (node.declaration && "declarations" in node.declaration) { const declaration = node.declaration.declarations[0]; if (declaration && "name" in declaration.id && declaration.id.name === key) { return declaration.init; } } } } } chunk3ONWID2V_cjs.__name(findExport, "findExport"); function listExports(codeOrAst) { const ast = isString.isString(codeOrAst) ? chunkQH6JOSVV_cjs.parseAst(codeOrAst) : codeOrAst; return ast.program.body.flatMap((i) => { if (i.type === "ExportDefaultDeclaration") { return [ "default" ]; } if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) { return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : ""); } return []; }).filter(Boolean); } chunk3ONWID2V_cjs.__name(listExports, "listExports"); function listImports(ast) { return ast.program.body.flatMap((i) => { if (i.type === "ImportDeclaration") { return i.specifiers.map((s) => { if (s.type === "ImportDefaultSpecifier") { return "default"; } if (s.type === "ImportSpecifier" && "imported" in s) { return s.imported.type === "Identifier" ? s.imported.name : s.imported.value; } return ""; }); } return []; }).filter(Boolean); } chunk3ONWID2V_cjs.__name(listImports, "listImports"); function isImportCall(calleePath) { return t__namespace.isImport(calleePath.node.callee); } chunk3ONWID2V_cjs.__name(isImportCall, "isImportCall"); function getImport(specifier, name, named) { return t__namespace.importDeclaration([ t__namespace.importSpecifier(t__namespace.identifier(name), t__namespace.stringLiteral(named || name)) ], t__namespace.stringLiteral(specifier)); } chunk3ONWID2V_cjs.__name(getImport, "getImport"); exports.findExport = findExport; exports.getImport = getImport; exports.isImportCall = isImportCall; exports.listExports = listExports; exports.listImports = listImports; //# sourceMappingURL=chunk-SQHGN4CZ.cjs.map //# sourceMappingURL=chunk-SQHGN4CZ.cjs.map