| 838 | this.uniqueSourceIndexByFilename = {}; |
| 839 | } |
| 840 | addSource(source) { |
| 841 | if (source instanceof MagicString) { |
| 842 | return this.addSource({ |
| 843 | content: source, |
| 844 | filename: source.filename, |
| 845 | separator: this.separator, |
| 846 | }); |
| 847 | } |
| 848 | if (!isObject(source) || !source.content) { |
| 849 | throw new Error( |
| 850 | 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`', |
| 851 | ); |
| 852 | } |
| 853 | ['filename', 'indentExclusionRanges', 'separator'].forEach((option) => { |
| 854 | if (!hasOwnProp.call(source, option)) source[option] = source.content[option]; |
| 855 | }); |
| 856 | if (source.separator === void 0) { |
| 857 | source.separator = this.separator; |
| 858 | } |
| 859 | if (source.filename) { |
| 860 | if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) { |
| 861 | this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length; |
| 862 | this.uniqueSources.push({ filename: source.filename, content: source.content.original }); |
| 863 | } else { |
| 864 | const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]]; |
| 865 | if (source.content.original !== uniqueSource.content) { |
| 866 | throw new Error(`Illegal source: same filename (${source.filename}), different contents`); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | this.sources.push(source); |
| 871 | return this; |
| 872 | } |
| 873 | append(str, options) { |
| 874 | this.addSource({ |
| 875 | content: new MagicString(str), |