| 50 | } |
| 51 | |
| 52 | export class Bundle { |
| 53 | /** @internal */ |
| 54 | declare intro: string |
| 55 | /** @internal */ |
| 56 | declare separator: string |
| 57 | /** @internal */ |
| 58 | declare sources: BundleSourceDescription[] |
| 59 | /** @internal */ |
| 60 | declare uniqueSources: UniqueSource[] |
| 61 | /** @internal */ |
| 62 | declare uniqueSourceIndexByFilename: Record<string, number> |
| 63 | declare indentExclusionRanges: ExclusionRange | ExclusionRange[] | undefined |
| 64 | |
| 65 | constructor(options: BundleOptions = {}) { |
| 66 | this.intro = options.intro || '' |
| 67 | this.separator = options.separator !== undefined ? options.separator : '\n' |
| 68 | this.sources = [] |
| 69 | this.uniqueSources = [] |
| 70 | this.uniqueSourceIndexByFilename = {} |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Adds the specified source to the bundle, which can either be a `MagicString` object directly, |
| 75 | * or an options object that holds a magic string `content` property and optionally provides |
| 76 | * a `filename` for the source within the bundle, as well as an optional `ignoreList` hint |
| 77 | * (which defaults to `false`). The `filename` is used when constructing the source map for the |
| 78 | * bundle, to identify this `source` in the source map's `sources` field. The `ignoreList` hint |
| 79 | * is used to populate the `x_google_ignoreList` extension field in the source map, which is a |
| 80 | * mechanism for tools to signal to debuggers that certain sources should be ignored by default |
| 81 | * (depending on user preferences). |
| 82 | */ |
| 83 | addSource(source: MagicString | BundleSourceDescription): this { |
| 84 | if (source instanceof MagicString) { |
| 85 | return this.addSource({ |
| 86 | content: source, |
| 87 | filename: source.filename, |
| 88 | separator: this.separator, |
| 89 | }) |
| 90 | } |
| 91 | |
| 92 | if (!isObject(source) || !source.content) { |
| 93 | throw new MagicStringError('addSource() requires a `content` property that is a MagicString') |
| 94 | } |
| 95 | |
| 96 | ['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => { |
| 97 | if (!hasOwnProp.call(source, option)) |
| 98 | source[option] = source.content[option] |
| 99 | }) |
| 100 | |
| 101 | if (source.separator === undefined) { |
| 102 | // TODO there's a bunch of this sort of thing, needs cleaning up |
| 103 | source.separator = this.separator |
| 104 | } |
| 105 | |
| 106 | if (source.filename) { |
| 107 | if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) { |
| 108 | this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length |
| 109 | this.uniqueSources.push({ filename: source.filename, content: source.content.original }) |
nothing calls this directly
no outgoing calls
no test coverage detected