MCPcopy Create free account
hub / github.com/cure53/DOMPurify / rewriteInlineTypeExports

Function rewriteInlineTypeExports

scripts/fix-types.js:29–46  ·  view source on GitHub ↗

* Rewrites bundled export statements that use inline `type` modifiers into a * plain value export plus a type-only export: * * export { type Config, ... }; * -> export type { Config, ... }; * * The inline form requires TypeScript 4.5, so emitting it narrows the range of * TypeScript ve

(types)

Source from the content-addressed store, hash-verified

27 * @returns {string}
28 */
29function rewriteInlineTypeExports(types) {
30 return types.replace(/^export \{([^}]*)\};$/gm, (statement, specifiers) => {
31 const parts = specifiers.split(',').map((s) => s.trim());
32 const values = parts.filter((s) => s && !s.startsWith('type '));
33 const names = parts
34 .filter((s) => s.startsWith('type '))
35 .map((s) => s.slice(5));
36
37 if (names.length === 0) return statement;
38
39 return [
40 values.length > 0 && `export { ${values.join(', ')} };`,
41 `export type { ${names.join(', ')} };`,
42 ]
43 .filter(Boolean)
44 .join('\n');
45 });
46}
47
48/**
49 * Fixes the ES module type declarations file.

Callers 2

fixEsmTypesFunction · 0.85
fixCjsTypesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected