mirror of
https://github.com/morluto/rea.git
synced 2026-11-24 05:08:44 +00:00
* refactor: remove internal re-export shims and guard against new ones * fix(ci): catch namespace module re-exports
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import { tokenize } from "./source-tokens.mjs";
|
|
|
|
/** Count forwarding declarations, including named namespaces and type-only exports. */
|
|
export const moduleReExportCount = (source) => {
|
|
const { tokens } = tokenize(source);
|
|
let count = 0;
|
|
for (let at = 0; at < tokens.length; at += 1) {
|
|
if (tokens[at]?.text !== "export") continue;
|
|
let next = at + 1;
|
|
if (tokens[next]?.text === "type") next += 1;
|
|
|
|
if (tokens[next]?.text === "*") {
|
|
next += 1;
|
|
if (tokens[next]?.text === "as") {
|
|
const name = tokens[next + 1];
|
|
if (name?.kind !== "id" && name?.kind !== "string") continue;
|
|
next += 2;
|
|
}
|
|
} else if (tokens[next]?.text === "{") {
|
|
next += 1;
|
|
while (next < tokens.length && tokens[next]?.text !== "}") next += 1;
|
|
next += 1;
|
|
} else continue;
|
|
|
|
const specifier = tokens[next + 1];
|
|
if (
|
|
tokens[next]?.text === "from" &&
|
|
specifier?.kind === "string" &&
|
|
(source[specifier.start] === '"' || source[specifier.start] === "'")
|
|
)
|
|
count += 1;
|
|
}
|
|
return count;
|
|
};
|