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

Class S

benchmark/data-min.js:675–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673}
674const v = Object.prototype.hasOwnProperty;
675class S {
676 constructor(t = {}) {
677 ((this.intro = t.intro || ''),
678 (this.separator =
679 t.separator !== void 0
680 ? t.separator
681 : `
682`),
683 (this.sources = []),
684 (this.uniqueSources = []),
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 }
714 clone() {
715 const t = new S({ intro: this.intro, separator: this.separator });
716 return (
717 this.sources.forEach((e) => {
718 t.addSource({ filename: e.filename, content: e.content.clone(), separator: e.separator });
719 }),
720 t
721 );
722 }
723 generateDecodedMap(t = {}) {
724 const e = [];
725 this.sources.forEach((i) => {
726 Object.keys(i.content.storedNames).forEach((r) => {
727 ~e.indexOf(r) || e.push(r);
728 });
729 });
730 const n = new y(t.hires);
731 return (
732 this.intro && n.advance(this.intro),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected