| 830 | } |
| 831 | const hasOwnProp = Object.prototype.hasOwnProperty; |
| 832 | class Bundle { |
| 833 | constructor(options = {}) { |
| 834 | this.intro = options.intro || ''; |
| 835 | this.separator = options.separator !== void 0 ? options.separator : '\n'; |
| 836 | this.sources = []; |
| 837 | this.uniqueSources = []; |
| 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), |
| 876 | separator: (options && options.separator) || '', |
| 877 | }); |
| 878 | return this; |
| 879 | } |
| 880 | clone() { |
| 881 | const bundle = new Bundle({ |
| 882 | intro: this.intro, |
| 883 | separator: this.separator, |
| 884 | }); |
| 885 | this.sources.forEach((source) => { |
| 886 | bundle.addSource({ |
| 887 | filename: source.filename, |
| 888 | content: source.content.clone(), |
| 889 | separator: source.separator, |
nothing calls this directly
no outgoing calls
no test coverage detected