MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / addSource

Method addSource

benchmark/data.js:840–872  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

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),

Callers 2

appendMethod · 0.95
cloneMethod · 0.95

Calls 1

isObjectFunction · 0.70

Tested by

no test coverage detected