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

Method addSource

benchmark/data-min.js:687–710  ·  view source on GitHub ↗
(t)

Source from the content-addressed store, hash-verified

685 (this.uniqueSourceIndexByFilename = {}));
686 }
687 addSource(t) {
688 if (t instanceof f)
689 return this.addSource({ content: t, filename: t.filename, separator: this.separator });
690 if (!x(t) || !t.content)
691 throw new Error(
692 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`',
693 );
694 if (
695 (['filename', 'indentExclusionRanges', 'separator'].forEach((e) => {
696 v.call(t, e) || (t[e] = t.content[e]);
697 }),
698 t.separator === void 0 && (t.separator = this.separator),
699 t.filename)
700 )
701 if (!v.call(this.uniqueSourceIndexByFilename, t.filename))
702 ((this.uniqueSourceIndexByFilename[t.filename] = this.uniqueSources.length),
703 this.uniqueSources.push({ filename: t.filename, content: t.content.original }));
704 else {
705 const e = this.uniqueSources[this.uniqueSourceIndexByFilename[t.filename]];
706 if (t.content.original !== e.content)
707 throw new Error(`Illegal source: same filename (${t.filename}), different contents`);
708 }
709 return (this.sources.push(t), this);
710 }
711 append(t, e) {
712 return (this.addSource({ content: new f(t), separator: (e && e.separator) || '' }), this);
713 }

Callers 2

appendMethod · 0.95
cloneMethod · 0.95

Calls 1

xFunction · 0.85

Tested by

no test coverage detected