UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

33 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NoExportNamedDeclarationWithSourceError = void 0; const errors_1 = require("../../errors"); const helpers_1 = require("../../../utils/ast/helpers"); class NoExportNamedDeclarationWithSourceError extends errors_1.RuleError { explain() { return 'exports of the form `export { a } from "./file.js";` are not allowed.'; } elaborate() { const [imports, exps] = this.node.specifiers.reduce(([ins, outs], spec) => [ [...ins, spec.local.name], [...outs, (0, helpers_1.speciferToString)(spec)] ], [[], []]); const importStr = `import { ${imports.join(', ')} } from "${this.node.source.value}";`; const exportStr = `export { ${exps.join(', ')} };`; return `Import what you are trying to export, then export it again, like this:\n${importStr}\n${exportStr}`; } } exports.NoExportNamedDeclarationWithSourceError = NoExportNamedDeclarationWithSourceError; const noExportNamedDeclarationWithSource = { name: 'no-export-named-declaration-with-source', checkers: { ExportNamedDeclaration(node) { if (node.source !== null) { return [new NoExportNamedDeclarationWithSourceError(node)]; } return []; } } }; exports.default = noExportNamedDeclarationWithSource; //# sourceMappingURL=noExportNamedDeclarationWithSource.js.map