* Adds the specified source to the bundle, which can either be a `MagicString` object directly, * or an options object that holds a magic string `content` property and optionally provides * a `filename` for the source within the bundle, as well as an optional `ignoreList` hint * (which defa
(source: MagicString | BundleSourceDescription)
| 64 | * (depending on user preferences). |
| 65 | */ |
| 66 | addSource(source: MagicString | BundleSourceDescription): this { |
| 67 | if (source instanceof MagicString) { |
| 68 | return this.addSource({ |
| 69 | content: source, |
| 70 | filename: source.filename, |
| 71 | separator: this.separator, |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | if (!isObject(source) || !source.content) { |
| 76 | throw new MagicStringError('addSource() requires a `content` property that is a MagicString') |
| 77 | } |
| 78 | |
| 79 | ['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => { |
| 80 | if (!hasOwnProp.call(source, option)) |
| 81 | source[option] = source.content[option] |
| 82 | }) |
| 83 | |
| 84 | if (source.separator === undefined) { |
| 85 | // TODO there's a bunch of this sort of thing, needs cleaning up |
| 86 | source.separator = this.separator |
| 87 | } |
| 88 | |
| 89 | if (source.filename) { |
| 90 | if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) { |
| 91 | this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length |
| 92 | this.uniqueSources.push({ filename: source.filename, content: source.content.original }) |
| 93 | } |
| 94 | else { |
| 95 | const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]] |
| 96 | if (source.content.original !== uniqueSource.content) { |
| 97 | throw new MagicStringError( |
| 98 | `duplicate filename "${source.filename}" with different content, use unique filenames`, |
| 99 | ) |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | this.sources.push(source) |
| 105 | return this |
| 106 | } |
| 107 | |
| 108 | append(str: string, options?: BundleOptions): this { |
| 109 | this.addSource({ |
no test coverage detected