INNER CODE UNIT · JavaScript
mapComment
postalsys/postal-mime · scripts/build.js:106
mapComment === -1 ? source + shim : source.slice(0, mapComment) + shim + source.slice(mapComment);
fs.writeFileSync(file, patched);
}
}
// The entry point is declared in ES module form, `export default class` with named
// exports beside it. Read from a CommonJS project, TypeScript takes that as
// `exports.default`, so `import PostalMime = require('postal-mime')` types the class as
// the module object and `new PostalMime()` does not compile even though it runs, and a
// project with verbatimModuleSyntax has no typed import form at all. This declaration
// transformer turns it into the shape `require()` returns: the class merged with a
// namespace that carries the named exports and the types, exported with `export =`.
// A hand-written declaration would have to repeat the class signature, so it is
// generated from the same source instead.
//
// Type-only imports stay, since the class signature refers to them. Value exports become
// `typeof import()` members and type re-exports become `import()` type aliases, so that
// the namespace members can not shadow what they alias. The class keeps its source