rollup 2.69.2 → 2.70.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.69.2
4
- Sun, 06 Mar 2022 06:43:03 GMT - commit 68817534499a6a1392c465d7fe92a1ef6804ad45
5
-
3
+ Rollup.js v2.70.2
4
+ Fri, 15 Apr 2022 05:14:21 GMT - commit 030c56fd6b186a0ddfd57d143ad703f34fd2c17a
6
5
 
7
6
  https://github.com/rollup/rollup
8
7
 
@@ -28,7 +27,7 @@ function _interopNamespaceDefault(e) {
28
27
  return n;
29
28
  }
30
29
 
31
- var version$1 = "2.69.2";
30
+ var version$1 = "2.70.2";
32
31
 
33
32
  function ensureArray$1(items) {
34
33
  if (Array.isArray(items)) {
@@ -609,8 +608,7 @@ const objectifyOptionWithPresets = (presets, optionName, additionalValues) => (v
609
608
  return objectifyOption(value);
610
609
  };
611
610
  const getOptionWithPreset = (value, presets, optionName, additionalValues) => {
612
- var _a;
613
- const presetName = (_a = value) === null || _a === void 0 ? void 0 : _a.preset;
611
+ const presetName = value === null || value === void 0 ? void 0 : value.preset;
614
612
  if (presetName) {
615
613
  const preset = presets[presetName];
616
614
  if (preset) {
@@ -786,204 +784,208 @@ function encodeInteger(num) {
786
784
  return result;
787
785
  }
788
786
 
789
- var BitSet = function BitSet(arg) {
790
- this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
791
- };
792
-
793
- BitSet.prototype.add = function add (n) {
794
- this.bits[n >> 5] |= 1 << (n & 31);
795
- };
787
+ class BitSet {
788
+ constructor(arg) {
789
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
790
+ }
796
791
 
797
- BitSet.prototype.has = function has (n) {
798
- return !!(this.bits[n >> 5] & (1 << (n & 31)));
799
- };
792
+ add(n) {
793
+ this.bits[n >> 5] |= 1 << (n & 31);
794
+ }
800
795
 
801
- var Chunk$1 = function Chunk(start, end, content) {
802
- this.start = start;
803
- this.end = end;
804
- this.original = content;
796
+ has(n) {
797
+ return !!(this.bits[n >> 5] & (1 << (n & 31)));
798
+ }
799
+ }
805
800
 
806
- this.intro = '';
807
- this.outro = '';
801
+ class Chunk$1 {
802
+ constructor(start, end, content) {
803
+ this.start = start;
804
+ this.end = end;
805
+ this.original = content;
808
806
 
809
- this.content = content;
810
- this.storeName = false;
811
- this.edited = false;
807
+ this.intro = '';
808
+ this.outro = '';
812
809
 
813
- // we make these non-enumerable, for sanity while debugging
814
- Object.defineProperties(this, {
815
- previous: { writable: true, value: null },
816
- next: { writable: true, value: null }
817
- });
818
- };
810
+ this.content = content;
811
+ this.storeName = false;
812
+ this.edited = false;
819
813
 
820
- Chunk$1.prototype.appendLeft = function appendLeft (content) {
821
- this.outro += content;
822
- };
814
+ // we make these non-enumerable, for sanity while debugging
815
+ Object.defineProperties(this, {
816
+ previous: { writable: true, value: null },
817
+ next: { writable: true, value: null },
818
+ });
819
+ }
823
820
 
824
- Chunk$1.prototype.appendRight = function appendRight (content) {
825
- this.intro = this.intro + content;
826
- };
821
+ appendLeft(content) {
822
+ this.outro += content;
823
+ }
827
824
 
828
- Chunk$1.prototype.clone = function clone () {
829
- var chunk = new Chunk$1(this.start, this.end, this.original);
825
+ appendRight(content) {
826
+ this.intro = this.intro + content;
827
+ }
830
828
 
831
- chunk.intro = this.intro;
832
- chunk.outro = this.outro;
833
- chunk.content = this.content;
834
- chunk.storeName = this.storeName;
835
- chunk.edited = this.edited;
829
+ clone() {
830
+ const chunk = new Chunk$1(this.start, this.end, this.original);
836
831
 
837
- return chunk;
838
- };
832
+ chunk.intro = this.intro;
833
+ chunk.outro = this.outro;
834
+ chunk.content = this.content;
835
+ chunk.storeName = this.storeName;
836
+ chunk.edited = this.edited;
839
837
 
840
- Chunk$1.prototype.contains = function contains (index) {
841
- return this.start < index && index < this.end;
842
- };
838
+ return chunk;
839
+ }
843
840
 
844
- Chunk$1.prototype.eachNext = function eachNext (fn) {
845
- var chunk = this;
846
- while (chunk) {
847
- fn(chunk);
848
- chunk = chunk.next;
841
+ contains(index) {
842
+ return this.start < index && index < this.end;
849
843
  }
850
- };
851
844
 
852
- Chunk$1.prototype.eachPrevious = function eachPrevious (fn) {
853
- var chunk = this;
854
- while (chunk) {
855
- fn(chunk);
856
- chunk = chunk.previous;
845
+ eachNext(fn) {
846
+ let chunk = this;
847
+ while (chunk) {
848
+ fn(chunk);
849
+ chunk = chunk.next;
850
+ }
857
851
  }
858
- };
859
852
 
860
- Chunk$1.prototype.edit = function edit (content, storeName, contentOnly) {
861
- this.content = content;
862
- if (!contentOnly) {
863
- this.intro = '';
864
- this.outro = '';
853
+ eachPrevious(fn) {
854
+ let chunk = this;
855
+ while (chunk) {
856
+ fn(chunk);
857
+ chunk = chunk.previous;
858
+ }
865
859
  }
866
- this.storeName = storeName;
867
860
 
868
- this.edited = true;
861
+ edit(content, storeName, contentOnly) {
862
+ this.content = content;
863
+ if (!contentOnly) {
864
+ this.intro = '';
865
+ this.outro = '';
866
+ }
867
+ this.storeName = storeName;
869
868
 
870
- return this;
871
- };
869
+ this.edited = true;
872
870
 
873
- Chunk$1.prototype.prependLeft = function prependLeft (content) {
874
- this.outro = content + this.outro;
875
- };
871
+ return this;
872
+ }
876
873
 
877
- Chunk$1.prototype.prependRight = function prependRight (content) {
878
- this.intro = content + this.intro;
879
- };
874
+ prependLeft(content) {
875
+ this.outro = content + this.outro;
876
+ }
880
877
 
881
- Chunk$1.prototype.split = function split (index) {
882
- var sliceIndex = index - this.start;
878
+ prependRight(content) {
879
+ this.intro = content + this.intro;
880
+ }
883
881
 
884
- var originalBefore = this.original.slice(0, sliceIndex);
885
- var originalAfter = this.original.slice(sliceIndex);
882
+ split(index) {
883
+ const sliceIndex = index - this.start;
886
884
 
887
- this.original = originalBefore;
885
+ const originalBefore = this.original.slice(0, sliceIndex);
886
+ const originalAfter = this.original.slice(sliceIndex);
888
887
 
889
- var newChunk = new Chunk$1(index, this.end, originalAfter);
890
- newChunk.outro = this.outro;
891
- this.outro = '';
888
+ this.original = originalBefore;
892
889
 
893
- this.end = index;
890
+ const newChunk = new Chunk$1(index, this.end, originalAfter);
891
+ newChunk.outro = this.outro;
892
+ this.outro = '';
894
893
 
895
- if (this.edited) {
896
- // TODO is this block necessary?...
897
- newChunk.edit('', false);
898
- this.content = '';
899
- } else {
900
- this.content = originalBefore;
901
- }
894
+ this.end = index;
902
895
 
903
- newChunk.next = this.next;
904
- if (newChunk.next) { newChunk.next.previous = newChunk; }
905
- newChunk.previous = this;
906
- this.next = newChunk;
896
+ if (this.edited) {
897
+ // TODO is this block necessary?...
898
+ newChunk.edit('', false);
899
+ this.content = '';
900
+ } else {
901
+ this.content = originalBefore;
902
+ }
907
903
 
908
- return newChunk;
909
- };
904
+ newChunk.next = this.next;
905
+ if (newChunk.next) newChunk.next.previous = newChunk;
906
+ newChunk.previous = this;
907
+ this.next = newChunk;
910
908
 
911
- Chunk$1.prototype.toString = function toString () {
912
- return this.intro + this.content + this.outro;
913
- };
909
+ return newChunk;
910
+ }
914
911
 
915
- Chunk$1.prototype.trimEnd = function trimEnd (rx) {
916
- this.outro = this.outro.replace(rx, '');
917
- if (this.outro.length) { return true; }
912
+ toString() {
913
+ return this.intro + this.content + this.outro;
914
+ }
918
915
 
919
- var trimmed = this.content.replace(rx, '');
916
+ trimEnd(rx) {
917
+ this.outro = this.outro.replace(rx, '');
918
+ if (this.outro.length) return true;
920
919
 
921
- if (trimmed.length) {
922
- if (trimmed !== this.content) {
923
- this.split(this.start + trimmed.length).edit('', undefined, true);
924
- }
925
- return true;
920
+ const trimmed = this.content.replace(rx, '');
926
921
 
927
- } else {
928
- this.edit('', undefined, true);
922
+ if (trimmed.length) {
923
+ if (trimmed !== this.content) {
924
+ this.split(this.start + trimmed.length).edit('', undefined, true);
925
+ }
926
+ return true;
927
+ } else {
928
+ this.edit('', undefined, true);
929
929
 
930
- this.intro = this.intro.replace(rx, '');
931
- if (this.intro.length) { return true; }
930
+ this.intro = this.intro.replace(rx, '');
931
+ if (this.intro.length) return true;
932
+ }
932
933
  }
933
- };
934
934
 
935
- Chunk$1.prototype.trimStart = function trimStart (rx) {
936
- this.intro = this.intro.replace(rx, '');
937
- if (this.intro.length) { return true; }
935
+ trimStart(rx) {
936
+ this.intro = this.intro.replace(rx, '');
937
+ if (this.intro.length) return true;
938
938
 
939
- var trimmed = this.content.replace(rx, '');
939
+ const trimmed = this.content.replace(rx, '');
940
940
 
941
- if (trimmed.length) {
942
- if (trimmed !== this.content) {
943
- this.split(this.end - trimmed.length);
941
+ if (trimmed.length) {
942
+ if (trimmed !== this.content) {
943
+ this.split(this.end - trimmed.length);
944
+ this.edit('', undefined, true);
945
+ }
946
+ return true;
947
+ } else {
944
948
  this.edit('', undefined, true);
945
- }
946
- return true;
947
-
948
- } else {
949
- this.edit('', undefined, true);
950
949
 
951
- this.outro = this.outro.replace(rx, '');
952
- if (this.outro.length) { return true; }
950
+ this.outro = this.outro.replace(rx, '');
951
+ if (this.outro.length) return true;
952
+ }
953
953
  }
954
- };
954
+ }
955
955
 
956
- var btoa = function () {
956
+ let btoa = () => {
957
957
  throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
958
958
  };
959
959
  if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
960
- btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
960
+ btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
961
961
  } else if (typeof Buffer === 'function') {
962
- btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
962
+ btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
963
963
  }
964
964
 
965
- var SourceMap = function SourceMap(properties) {
966
- this.version = 3;
967
- this.file = properties.file;
968
- this.sources = properties.sources;
969
- this.sourcesContent = properties.sourcesContent;
970
- this.names = properties.names;
971
- this.mappings = encode(properties.mappings);
972
- };
965
+ class SourceMap {
966
+ constructor(properties) {
967
+ this.version = 3;
968
+ this.file = properties.file;
969
+ this.sources = properties.sources;
970
+ this.sourcesContent = properties.sourcesContent;
971
+ this.names = properties.names;
972
+ this.mappings = encode(properties.mappings);
973
+ }
973
974
 
974
- SourceMap.prototype.toString = function toString () {
975
- return JSON.stringify(this);
976
- };
975
+ toString() {
976
+ return JSON.stringify(this);
977
+ }
977
978
 
978
- SourceMap.prototype.toUrl = function toUrl () {
979
- return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
980
- };
979
+ toUrl() {
980
+ return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
981
+ }
982
+ }
981
983
 
982
984
  function guessIndent(code) {
983
- var lines = code.split('\n');
985
+ const lines = code.split('\n');
984
986
 
985
- var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
986
- var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
987
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
988
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
987
989
 
988
990
  if (tabbed.length === 0 && spaced.length === 0) {
989
991
  return null;
@@ -997,8 +999,8 @@ function guessIndent(code) {
997
999
  }
998
1000
 
999
1001
  // Otherwise, we need to guess the multiple
1000
- var min = spaced.reduce(function (previous, current) {
1001
- var numSpaces = /^ +/.exec(current)[0].length;
1002
+ const min = spaced.reduce((previous, current) => {
1003
+ const numSpaces = /^ +/.exec(current)[0].length;
1002
1004
  return Math.min(numSpaces, previous);
1003
1005
  }, Infinity);
1004
1006
 
@@ -1006,8 +1008,8 @@ function guessIndent(code) {
1006
1008
  }
1007
1009
 
1008
1010
  function getRelativePath(from, to) {
1009
- var fromParts = from.split(/[/\\]/);
1010
- var toParts = to.split(/[/\\]/);
1011
+ const fromParts = from.split(/[/\\]/);
1012
+ const toParts = to.split(/[/\\]/);
1011
1013
 
1012
1014
  fromParts.pop(); // get dirname
1013
1015
 
@@ -1017,1079 +1019,1120 @@ function getRelativePath(from, to) {
1017
1019
  }
1018
1020
 
1019
1021
  if (fromParts.length) {
1020
- var i = fromParts.length;
1021
- while (i--) { fromParts[i] = '..'; }
1022
+ let i = fromParts.length;
1023
+ while (i--) fromParts[i] = '..';
1022
1024
  }
1023
1025
 
1024
1026
  return fromParts.concat(toParts).join('/');
1025
1027
  }
1026
1028
 
1027
- var toString$1 = Object.prototype.toString;
1029
+ const toString$1 = Object.prototype.toString;
1028
1030
 
1029
1031
  function isObject$1(thing) {
1030
1032
  return toString$1.call(thing) === '[object Object]';
1031
1033
  }
1032
1034
 
1033
1035
  function getLocator(source) {
1034
- var originalLines = source.split('\n');
1035
- var lineOffsets = [];
1036
+ const originalLines = source.split('\n');
1037
+ const lineOffsets = [];
1036
1038
 
1037
- for (var i = 0, pos = 0; i < originalLines.length; i++) {
1039
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
1038
1040
  lineOffsets.push(pos);
1039
1041
  pos += originalLines[i].length + 1;
1040
1042
  }
1041
1043
 
1042
1044
  return function locate(index) {
1043
- var i = 0;
1044
- var j = lineOffsets.length;
1045
+ let i = 0;
1046
+ let j = lineOffsets.length;
1045
1047
  while (i < j) {
1046
- var m = (i + j) >> 1;
1048
+ const m = (i + j) >> 1;
1047
1049
  if (index < lineOffsets[m]) {
1048
1050
  j = m;
1049
1051
  } else {
1050
1052
  i = m + 1;
1051
1053
  }
1052
1054
  }
1053
- var line = i - 1;
1054
- var column = index - lineOffsets[line];
1055
- return { line: line, column: column };
1055
+ const line = i - 1;
1056
+ const column = index - lineOffsets[line];
1057
+ return { line, column };
1056
1058
  };
1057
1059
  }
1058
1060
 
1059
- var Mappings = function Mappings(hires) {
1060
- this.hires = hires;
1061
- this.generatedCodeLine = 0;
1062
- this.generatedCodeColumn = 0;
1063
- this.raw = [];
1064
- this.rawSegments = this.raw[this.generatedCodeLine] = [];
1065
- this.pending = null;
1066
- };
1061
+ class Mappings {
1062
+ constructor(hires) {
1063
+ this.hires = hires;
1064
+ this.generatedCodeLine = 0;
1065
+ this.generatedCodeColumn = 0;
1066
+ this.raw = [];
1067
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
1068
+ this.pending = null;
1069
+ }
1067
1070
 
1068
- Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
1069
- if (content.length) {
1070
- var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
1071
- if (nameIndex >= 0) {
1072
- segment.push(nameIndex);
1071
+ addEdit(sourceIndex, content, loc, nameIndex) {
1072
+ if (content.length) {
1073
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
1074
+ if (nameIndex >= 0) {
1075
+ segment.push(nameIndex);
1076
+ }
1077
+ this.rawSegments.push(segment);
1078
+ } else if (this.pending) {
1079
+ this.rawSegments.push(this.pending);
1073
1080
  }
1074
- this.rawSegments.push(segment);
1075
- } else if (this.pending) {
1076
- this.rawSegments.push(this.pending);
1081
+
1082
+ this.advance(content);
1083
+ this.pending = null;
1077
1084
  }
1078
1085
 
1079
- this.advance(content);
1080
- this.pending = null;
1081
- };
1086
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
1087
+ let originalCharIndex = chunk.start;
1088
+ let first = true;
1082
1089
 
1083
- Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
1084
- var originalCharIndex = chunk.start;
1085
- var first = true;
1090
+ while (originalCharIndex < chunk.end) {
1091
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
1092
+ this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
1093
+ }
1086
1094
 
1087
- while (originalCharIndex < chunk.end) {
1088
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
1089
- this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
1090
- }
1095
+ if (original[originalCharIndex] === '\n') {
1096
+ loc.line += 1;
1097
+ loc.column = 0;
1098
+ this.generatedCodeLine += 1;
1099
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
1100
+ this.generatedCodeColumn = 0;
1101
+ first = true;
1102
+ } else {
1103
+ loc.column += 1;
1104
+ this.generatedCodeColumn += 1;
1105
+ first = false;
1106
+ }
1091
1107
 
1092
- if (original[originalCharIndex] === '\n') {
1093
- loc.line += 1;
1094
- loc.column = 0;
1095
- this.generatedCodeLine += 1;
1096
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
1097
- this.generatedCodeColumn = 0;
1098
- first = true;
1099
- } else {
1100
- loc.column += 1;
1101
- this.generatedCodeColumn += 1;
1102
- first = false;
1108
+ originalCharIndex += 1;
1103
1109
  }
1104
1110
 
1105
- originalCharIndex += 1;
1111
+ this.pending = null;
1106
1112
  }
1107
1113
 
1108
- this.pending = null;
1109
- };
1110
-
1111
- Mappings.prototype.advance = function advance (str) {
1112
- if (!str) { return; }
1114
+ advance(str) {
1115
+ if (!str) return;
1113
1116
 
1114
- var lines = str.split('\n');
1117
+ const lines = str.split('\n');
1115
1118
 
1116
- if (lines.length > 1) {
1117
- for (var i = 0; i < lines.length - 1; i++) {
1118
- this.generatedCodeLine++;
1119
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
1119
+ if (lines.length > 1) {
1120
+ for (let i = 0; i < lines.length - 1; i++) {
1121
+ this.generatedCodeLine++;
1122
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
1123
+ }
1124
+ this.generatedCodeColumn = 0;
1120
1125
  }
1121
- this.generatedCodeColumn = 0;
1122
- }
1123
1126
 
1124
- this.generatedCodeColumn += lines[lines.length - 1].length;
1125
- };
1127
+ this.generatedCodeColumn += lines[lines.length - 1].length;
1128
+ }
1129
+ }
1126
1130
 
1127
- var n = '\n';
1131
+ const n = '\n';
1128
1132
 
1129
- var warned = {
1133
+ const warned = {
1130
1134
  insertLeft: false,
1131
1135
  insertRight: false,
1132
- storeName: false
1133
- };
1134
-
1135
- var MagicString = function MagicString(string, options) {
1136
- if ( options === void 0 ) options = {};
1137
-
1138
- var chunk = new Chunk$1(0, string.length, string);
1139
-
1140
- Object.defineProperties(this, {
1141
- original: { writable: true, value: string },
1142
- outro: { writable: true, value: '' },
1143
- intro: { writable: true, value: '' },
1144
- firstChunk: { writable: true, value: chunk },
1145
- lastChunk: { writable: true, value: chunk },
1146
- lastSearchedChunk: { writable: true, value: chunk },
1147
- byStart: { writable: true, value: {} },
1148
- byEnd: { writable: true, value: {} },
1149
- filename: { writable: true, value: options.filename },
1150
- indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
1151
- sourcemapLocations: { writable: true, value: new BitSet() },
1152
- storedNames: { writable: true, value: {} },
1153
- indentStr: { writable: true, value: guessIndent(string) }
1154
- });
1155
-
1156
- this.byStart[0] = chunk;
1157
- this.byEnd[string.length] = chunk;
1158
- };
1159
-
1160
- MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
1161
- this.sourcemapLocations.add(char);
1162
- };
1163
-
1164
- MagicString.prototype.append = function append (content) {
1165
- if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
1166
-
1167
- this.outro += content;
1168
- return this;
1169
- };
1136
+ storeName: false,
1137
+ };
1138
+
1139
+ class MagicString {
1140
+ constructor(string, options = {}) {
1141
+ const chunk = new Chunk$1(0, string.length, string);
1142
+
1143
+ Object.defineProperties(this, {
1144
+ original: { writable: true, value: string },
1145
+ outro: { writable: true, value: '' },
1146
+ intro: { writable: true, value: '' },
1147
+ firstChunk: { writable: true, value: chunk },
1148
+ lastChunk: { writable: true, value: chunk },
1149
+ lastSearchedChunk: { writable: true, value: chunk },
1150
+ byStart: { writable: true, value: {} },
1151
+ byEnd: { writable: true, value: {} },
1152
+ filename: { writable: true, value: options.filename },
1153
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
1154
+ sourcemapLocations: { writable: true, value: new BitSet() },
1155
+ storedNames: { writable: true, value: {} },
1156
+ indentStr: { writable: true, value: guessIndent(string) },
1157
+ });
1170
1158
 
1171
- MagicString.prototype.appendLeft = function appendLeft (index, content) {
1172
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
1159
+ this.byStart[0] = chunk;
1160
+ this.byEnd[string.length] = chunk;
1161
+ }
1173
1162
 
1174
- this._split(index);
1163
+ addSourcemapLocation(char) {
1164
+ this.sourcemapLocations.add(char);
1165
+ }
1175
1166
 
1176
- var chunk = this.byEnd[index];
1167
+ append(content) {
1168
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
1177
1169
 
1178
- if (chunk) {
1179
- chunk.appendLeft(content);
1180
- } else {
1181
- this.intro += content;
1170
+ this.outro += content;
1171
+ return this;
1182
1172
  }
1183
- return this;
1184
- };
1185
1173
 
1186
- MagicString.prototype.appendRight = function appendRight (index, content) {
1187
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
1174
+ appendLeft(index, content) {
1175
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1188
1176
 
1189
- this._split(index);
1177
+ this._split(index);
1190
1178
 
1191
- var chunk = this.byStart[index];
1179
+ const chunk = this.byEnd[index];
1192
1180
 
1193
- if (chunk) {
1194
- chunk.appendRight(content);
1195
- } else {
1196
- this.outro += content;
1181
+ if (chunk) {
1182
+ chunk.appendLeft(content);
1183
+ } else {
1184
+ this.intro += content;
1185
+ }
1186
+ return this;
1197
1187
  }
1198
- return this;
1199
- };
1200
-
1201
- MagicString.prototype.clone = function clone () {
1202
- var cloned = new MagicString(this.original, { filename: this.filename });
1203
1188
 
1204
- var originalChunk = this.firstChunk;
1205
- var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
1189
+ appendRight(index, content) {
1190
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1206
1191
 
1207
- while (originalChunk) {
1208
- cloned.byStart[clonedChunk.start] = clonedChunk;
1209
- cloned.byEnd[clonedChunk.end] = clonedChunk;
1192
+ this._split(index);
1210
1193
 
1211
- var nextOriginalChunk = originalChunk.next;
1212
- var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
1194
+ const chunk = this.byStart[index];
1213
1195
 
1214
- if (nextClonedChunk) {
1215
- clonedChunk.next = nextClonedChunk;
1216
- nextClonedChunk.previous = clonedChunk;
1217
-
1218
- clonedChunk = nextClonedChunk;
1196
+ if (chunk) {
1197
+ chunk.appendRight(content);
1198
+ } else {
1199
+ this.outro += content;
1219
1200
  }
1220
-
1221
- originalChunk = nextOriginalChunk;
1201
+ return this;
1222
1202
  }
1223
1203
 
1224
- cloned.lastChunk = clonedChunk;
1204
+ clone() {
1205
+ const cloned = new MagicString(this.original, { filename: this.filename });
1225
1206
 
1226
- if (this.indentExclusionRanges) {
1227
- cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
1228
- }
1207
+ let originalChunk = this.firstChunk;
1208
+ let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
1229
1209
 
1230
- cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
1210
+ while (originalChunk) {
1211
+ cloned.byStart[clonedChunk.start] = clonedChunk;
1212
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
1231
1213
 
1232
- cloned.intro = this.intro;
1233
- cloned.outro = this.outro;
1214
+ const nextOriginalChunk = originalChunk.next;
1215
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
1234
1216
 
1235
- return cloned;
1236
- };
1217
+ if (nextClonedChunk) {
1218
+ clonedChunk.next = nextClonedChunk;
1219
+ nextClonedChunk.previous = clonedChunk;
1220
+
1221
+ clonedChunk = nextClonedChunk;
1222
+ }
1237
1223
 
1238
- MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
1239
- var this$1$1 = this;
1224
+ originalChunk = nextOriginalChunk;
1225
+ }
1226
+
1227
+ cloned.lastChunk = clonedChunk;
1240
1228
 
1241
- options = options || {};
1229
+ if (this.indentExclusionRanges) {
1230
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
1231
+ }
1242
1232
 
1243
- var sourceIndex = 0;
1244
- var names = Object.keys(this.storedNames);
1245
- var mappings = new Mappings(options.hires);
1233
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
1246
1234
 
1247
- var locate = getLocator(this.original);
1235
+ cloned.intro = this.intro;
1236
+ cloned.outro = this.outro;
1248
1237
 
1249
- if (this.intro) {
1250
- mappings.advance(this.intro);
1238
+ return cloned;
1251
1239
  }
1252
1240
 
1253
- this.firstChunk.eachNext(function (chunk) {
1254
- var loc = locate(chunk.start);
1241
+ generateDecodedMap(options) {
1242
+ options = options || {};
1255
1243
 
1256
- if (chunk.intro.length) { mappings.advance(chunk.intro); }
1244
+ const sourceIndex = 0;
1245
+ const names = Object.keys(this.storedNames);
1246
+ const mappings = new Mappings(options.hires);
1257
1247
 
1258
- if (chunk.edited) {
1259
- mappings.addEdit(
1260
- sourceIndex,
1261
- chunk.content,
1262
- loc,
1263
- chunk.storeName ? names.indexOf(chunk.original) : -1
1264
- );
1265
- } else {
1266
- mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
1248
+ const locate = getLocator(this.original);
1249
+
1250
+ if (this.intro) {
1251
+ mappings.advance(this.intro);
1267
1252
  }
1268
1253
 
1269
- if (chunk.outro.length) { mappings.advance(chunk.outro); }
1270
- });
1254
+ this.firstChunk.eachNext((chunk) => {
1255
+ const loc = locate(chunk.start);
1271
1256
 
1272
- return {
1273
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
1274
- sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
1275
- sourcesContent: options.includeContent ? [this.original] : [null],
1276
- names: names,
1277
- mappings: mappings.raw
1278
- };
1279
- };
1257
+ if (chunk.intro.length) mappings.advance(chunk.intro);
1280
1258
 
1281
- MagicString.prototype.generateMap = function generateMap (options) {
1282
- return new SourceMap(this.generateDecodedMap(options));
1283
- };
1259
+ if (chunk.edited) {
1260
+ mappings.addEdit(
1261
+ sourceIndex,
1262
+ chunk.content,
1263
+ loc,
1264
+ chunk.storeName ? names.indexOf(chunk.original) : -1
1265
+ );
1266
+ } else {
1267
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
1268
+ }
1284
1269
 
1285
- MagicString.prototype.getIndentString = function getIndentString () {
1286
- return this.indentStr === null ? '\t' : this.indentStr;
1287
- };
1270
+ if (chunk.outro.length) mappings.advance(chunk.outro);
1271
+ });
1288
1272
 
1289
- MagicString.prototype.indent = function indent (indentStr, options) {
1290
- var pattern = /^[^\r\n]/gm;
1273
+ return {
1274
+ file: options.file ? options.file.split(/[/\\]/).pop() : null,
1275
+ sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
1276
+ sourcesContent: options.includeContent ? [this.original] : [null],
1277
+ names,
1278
+ mappings: mappings.raw,
1279
+ };
1280
+ }
1291
1281
 
1292
- if (isObject$1(indentStr)) {
1293
- options = indentStr;
1294
- indentStr = undefined;
1282
+ generateMap(options) {
1283
+ return new SourceMap(this.generateDecodedMap(options));
1295
1284
  }
1296
1285
 
1297
- indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
1286
+ getIndentString() {
1287
+ return this.indentStr === null ? '\t' : this.indentStr;
1288
+ }
1298
1289
 
1299
- if (indentStr === '') { return this; } // noop
1290
+ indent(indentStr, options) {
1291
+ const pattern = /^[^\r\n]/gm;
1300
1292
 
1301
- options = options || {};
1293
+ if (isObject$1(indentStr)) {
1294
+ options = indentStr;
1295
+ indentStr = undefined;
1296
+ }
1302
1297
 
1303
- // Process exclusion ranges
1304
- var isExcluded = {};
1298
+ indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
1305
1299
 
1306
- if (options.exclude) {
1307
- var exclusions =
1308
- typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
1309
- exclusions.forEach(function (exclusion) {
1310
- for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
1311
- isExcluded[i] = true;
1312
- }
1313
- });
1314
- }
1300
+ if (indentStr === '') return this; // noop
1315
1301
 
1316
- var shouldIndentNextCharacter = options.indentStart !== false;
1317
- var replacer = function (match) {
1318
- if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
1319
- shouldIndentNextCharacter = true;
1320
- return match;
1321
- };
1302
+ options = options || {};
1322
1303
 
1323
- this.intro = this.intro.replace(pattern, replacer);
1304
+ // Process exclusion ranges
1305
+ const isExcluded = {};
1324
1306
 
1325
- var charIndex = 0;
1326
- var chunk = this.firstChunk;
1307
+ if (options.exclude) {
1308
+ const exclusions =
1309
+ typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
1310
+ exclusions.forEach((exclusion) => {
1311
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
1312
+ isExcluded[i] = true;
1313
+ }
1314
+ });
1315
+ }
1327
1316
 
1328
- while (chunk) {
1329
- var end = chunk.end;
1317
+ let shouldIndentNextCharacter = options.indentStart !== false;
1318
+ const replacer = (match) => {
1319
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
1320
+ shouldIndentNextCharacter = true;
1321
+ return match;
1322
+ };
1330
1323
 
1331
- if (chunk.edited) {
1332
- if (!isExcluded[charIndex]) {
1333
- chunk.content = chunk.content.replace(pattern, replacer);
1324
+ this.intro = this.intro.replace(pattern, replacer);
1334
1325
 
1335
- if (chunk.content.length) {
1336
- shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
1337
- }
1338
- }
1339
- } else {
1340
- charIndex = chunk.start;
1326
+ let charIndex = 0;
1327
+ let chunk = this.firstChunk;
1328
+
1329
+ while (chunk) {
1330
+ const end = chunk.end;
1341
1331
 
1342
- while (charIndex < end) {
1332
+ if (chunk.edited) {
1343
1333
  if (!isExcluded[charIndex]) {
1344
- var char = this.original[charIndex];
1345
-
1346
- if (char === '\n') {
1347
- shouldIndentNextCharacter = true;
1348
- } else if (char !== '\r' && shouldIndentNextCharacter) {
1349
- shouldIndentNextCharacter = false;
1350
-
1351
- if (charIndex === chunk.start) {
1352
- chunk.prependRight(indentStr);
1353
- } else {
1354
- this._splitChunk(chunk, charIndex);
1355
- chunk = chunk.next;
1356
- chunk.prependRight(indentStr);
1357
- }
1334
+ chunk.content = chunk.content.replace(pattern, replacer);
1335
+
1336
+ if (chunk.content.length) {
1337
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
1358
1338
  }
1359
1339
  }
1340
+ } else {
1341
+ charIndex = chunk.start;
1342
+
1343
+ while (charIndex < end) {
1344
+ if (!isExcluded[charIndex]) {
1345
+ const char = this.original[charIndex];
1346
+
1347
+ if (char === '\n') {
1348
+ shouldIndentNextCharacter = true;
1349
+ } else if (char !== '\r' && shouldIndentNextCharacter) {
1350
+ shouldIndentNextCharacter = false;
1351
+
1352
+ if (charIndex === chunk.start) {
1353
+ chunk.prependRight(indentStr);
1354
+ } else {
1355
+ this._splitChunk(chunk, charIndex);
1356
+ chunk = chunk.next;
1357
+ chunk.prependRight(indentStr);
1358
+ }
1359
+ }
1360
+ }
1360
1361
 
1361
- charIndex += 1;
1362
+ charIndex += 1;
1363
+ }
1362
1364
  }
1365
+
1366
+ charIndex = chunk.end;
1367
+ chunk = chunk.next;
1363
1368
  }
1364
1369
 
1365
- charIndex = chunk.end;
1366
- chunk = chunk.next;
1367
- }
1370
+ this.outro = this.outro.replace(pattern, replacer);
1368
1371
 
1369
- this.outro = this.outro.replace(pattern, replacer);
1372
+ return this;
1373
+ }
1370
1374
 
1371
- return this;
1372
- };
1375
+ insert() {
1376
+ throw new Error(
1377
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
1378
+ );
1379
+ }
1373
1380
 
1374
- MagicString.prototype.insert = function insert () {
1375
- throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
1376
- };
1381
+ insertLeft(index, content) {
1382
+ if (!warned.insertLeft) {
1383
+ console.warn(
1384
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
1385
+ ); // eslint-disable-line no-console
1386
+ warned.insertLeft = true;
1387
+ }
1377
1388
 
1378
- MagicString.prototype.insertLeft = function insertLeft (index, content) {
1379
- if (!warned.insertLeft) {
1380
- console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
1381
- warned.insertLeft = true;
1389
+ return this.appendLeft(index, content);
1382
1390
  }
1383
1391
 
1384
- return this.appendLeft(index, content);
1385
- };
1392
+ insertRight(index, content) {
1393
+ if (!warned.insertRight) {
1394
+ console.warn(
1395
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
1396
+ ); // eslint-disable-line no-console
1397
+ warned.insertRight = true;
1398
+ }
1386
1399
 
1387
- MagicString.prototype.insertRight = function insertRight (index, content) {
1388
- if (!warned.insertRight) {
1389
- console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
1390
- warned.insertRight = true;
1400
+ return this.prependRight(index, content);
1391
1401
  }
1392
1402
 
1393
- return this.prependRight(index, content);
1394
- };
1403
+ move(start, end, index) {
1404
+ if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
1395
1405
 
1396
- MagicString.prototype.move = function move (start, end, index) {
1397
- if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
1406
+ this._split(start);
1407
+ this._split(end);
1408
+ this._split(index);
1398
1409
 
1399
- this._split(start);
1400
- this._split(end);
1401
- this._split(index);
1410
+ const first = this.byStart[start];
1411
+ const last = this.byEnd[end];
1402
1412
 
1403
- var first = this.byStart[start];
1404
- var last = this.byEnd[end];
1413
+ const oldLeft = first.previous;
1414
+ const oldRight = last.next;
1405
1415
 
1406
- var oldLeft = first.previous;
1407
- var oldRight = last.next;
1416
+ const newRight = this.byStart[index];
1417
+ if (!newRight && last === this.lastChunk) return this;
1418
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
1408
1419
 
1409
- var newRight = this.byStart[index];
1410
- if (!newRight && last === this.lastChunk) { return this; }
1411
- var newLeft = newRight ? newRight.previous : this.lastChunk;
1420
+ if (oldLeft) oldLeft.next = oldRight;
1421
+ if (oldRight) oldRight.previous = oldLeft;
1412
1422
 
1413
- if (oldLeft) { oldLeft.next = oldRight; }
1414
- if (oldRight) { oldRight.previous = oldLeft; }
1423
+ if (newLeft) newLeft.next = first;
1424
+ if (newRight) newRight.previous = last;
1415
1425
 
1416
- if (newLeft) { newLeft.next = first; }
1417
- if (newRight) { newRight.previous = last; }
1426
+ if (!first.previous) this.firstChunk = last.next;
1427
+ if (!last.next) {
1428
+ this.lastChunk = first.previous;
1429
+ this.lastChunk.next = null;
1430
+ }
1418
1431
 
1419
- if (!first.previous) { this.firstChunk = last.next; }
1420
- if (!last.next) {
1421
- this.lastChunk = first.previous;
1422
- this.lastChunk.next = null;
1423
- }
1432
+ first.previous = newLeft;
1433
+ last.next = newRight || null;
1424
1434
 
1425
- first.previous = newLeft;
1426
- last.next = newRight || null;
1435
+ if (!newLeft) this.firstChunk = first;
1436
+ if (!newRight) this.lastChunk = last;
1437
+ return this;
1438
+ }
1427
1439
 
1428
- if (!newLeft) { this.firstChunk = first; }
1429
- if (!newRight) { this.lastChunk = last; }
1430
- return this;
1431
- };
1440
+ overwrite(start, end, content, options) {
1441
+ if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
1432
1442
 
1433
- MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
1434
- if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
1443
+ while (start < 0) start += this.original.length;
1444
+ while (end < 0) end += this.original.length;
1435
1445
 
1436
- while (start < 0) { start += this.original.length; }
1437
- while (end < 0) { end += this.original.length; }
1446
+ if (end > this.original.length) throw new Error('end is out of bounds');
1447
+ if (start === end)
1448
+ throw new Error(
1449
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
1450
+ );
1438
1451
 
1439
- if (end > this.original.length) { throw new Error('end is out of bounds'); }
1440
- if (start === end)
1441
- { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
1452
+ this._split(start);
1453
+ this._split(end);
1442
1454
 
1443
- this._split(start);
1444
- this._split(end);
1455
+ if (options === true) {
1456
+ if (!warned.storeName) {
1457
+ console.warn(
1458
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
1459
+ ); // eslint-disable-line no-console
1460
+ warned.storeName = true;
1461
+ }
1445
1462
 
1446
- if (options === true) {
1447
- if (!warned.storeName) {
1448
- console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
1449
- warned.storeName = true;
1463
+ options = { storeName: true };
1450
1464
  }
1451
-
1452
- options = { storeName: true };
1453
- }
1454
- var storeName = options !== undefined ? options.storeName : false;
1455
- var contentOnly = options !== undefined ? options.contentOnly : false;
1456
-
1457
- if (storeName) {
1458
- var original = this.original.slice(start, end);
1459
- this.storedNames[original] = true;
1460
- }
1461
-
1462
- var first = this.byStart[start];
1463
- var last = this.byEnd[end];
1464
-
1465
- if (first) {
1466
- if (end > first.end && first.next !== this.byStart[first.end]) {
1467
- throw new Error('Cannot overwrite across a split point');
1465
+ const storeName = options !== undefined ? options.storeName : false;
1466
+ const contentOnly = options !== undefined ? options.contentOnly : false;
1467
+
1468
+ if (storeName) {
1469
+ const original = this.original.slice(start, end);
1470
+ Object.defineProperty(this.storedNames, original, {
1471
+ writable: true,
1472
+ value: true,
1473
+ enumerable: true,
1474
+ });
1468
1475
  }
1469
1476
 
1470
- first.edit(content, storeName, contentOnly);
1477
+ const first = this.byStart[start];
1478
+ const last = this.byEnd[end];
1471
1479
 
1472
- if (first !== last) {
1473
- var chunk = first.next;
1480
+ if (first) {
1481
+ let chunk = first;
1474
1482
  while (chunk !== last) {
1475
- chunk.edit('', false);
1483
+ if (chunk.next !== this.byStart[chunk.end]) {
1484
+ throw new Error('Cannot overwrite across a split point');
1485
+ }
1476
1486
  chunk = chunk.next;
1487
+ chunk.edit('', false);
1477
1488
  }
1478
1489
 
1479
- chunk.edit('', false);
1480
- }
1481
- } else {
1482
- // must be inserting at the end
1483
- var newChunk = new Chunk$1(start, end, '').edit(content, storeName);
1490
+ first.edit(content, storeName, contentOnly);
1491
+ } else {
1492
+ // must be inserting at the end
1493
+ const newChunk = new Chunk$1(start, end, '').edit(content, storeName);
1484
1494
 
1485
- // TODO last chunk in the array may not be the last chunk, if it's moved...
1486
- last.next = newChunk;
1487
- newChunk.previous = last;
1495
+ // TODO last chunk in the array may not be the last chunk, if it's moved...
1496
+ last.next = newChunk;
1497
+ newChunk.previous = last;
1498
+ }
1499
+ return this;
1488
1500
  }
1489
- return this;
1490
- };
1491
-
1492
- MagicString.prototype.prepend = function prepend (content) {
1493
- if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
1494
-
1495
- this.intro = content + this.intro;
1496
- return this;
1497
- };
1498
-
1499
- MagicString.prototype.prependLeft = function prependLeft (index, content) {
1500
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
1501
1501
 
1502
- this._split(index);
1502
+ prepend(content) {
1503
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
1503
1504
 
1504
- var chunk = this.byEnd[index];
1505
-
1506
- if (chunk) {
1507
- chunk.prependLeft(content);
1508
- } else {
1509
1505
  this.intro = content + this.intro;
1506
+ return this;
1510
1507
  }
1511
- return this;
1512
- };
1513
1508
 
1514
- MagicString.prototype.prependRight = function prependRight (index, content) {
1515
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
1509
+ prependLeft(index, content) {
1510
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1516
1511
 
1517
- this._split(index);
1512
+ this._split(index);
1518
1513
 
1519
- var chunk = this.byStart[index];
1514
+ const chunk = this.byEnd[index];
1520
1515
 
1521
- if (chunk) {
1522
- chunk.prependRight(content);
1523
- } else {
1524
- this.outro = content + this.outro;
1516
+ if (chunk) {
1517
+ chunk.prependLeft(content);
1518
+ } else {
1519
+ this.intro = content + this.intro;
1520
+ }
1521
+ return this;
1525
1522
  }
1526
- return this;
1527
- };
1528
-
1529
- MagicString.prototype.remove = function remove (start, end) {
1530
- while (start < 0) { start += this.original.length; }
1531
- while (end < 0) { end += this.original.length; }
1532
1523
 
1533
- if (start === end) { return this; }
1524
+ prependRight(index, content) {
1525
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
1534
1526
 
1535
- if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
1536
- if (start > end) { throw new Error('end must be greater than start'); }
1527
+ this._split(index);
1537
1528
 
1538
- this._split(start);
1539
- this._split(end);
1529
+ const chunk = this.byStart[index];
1540
1530
 
1541
- var chunk = this.byStart[start];
1542
-
1543
- while (chunk) {
1544
- chunk.intro = '';
1545
- chunk.outro = '';
1546
- chunk.edit('');
1547
-
1548
- chunk = end > chunk.end ? this.byStart[chunk.end] : null;
1549
- }
1550
- return this;
1551
- };
1552
-
1553
- MagicString.prototype.lastChar = function lastChar () {
1554
- if (this.outro.length)
1555
- { return this.outro[this.outro.length - 1]; }
1556
- var chunk = this.lastChunk;
1557
- do {
1558
- if (chunk.outro.length)
1559
- { return chunk.outro[chunk.outro.length - 1]; }
1560
- if (chunk.content.length)
1561
- { return chunk.content[chunk.content.length - 1]; }
1562
- if (chunk.intro.length)
1563
- { return chunk.intro[chunk.intro.length - 1]; }
1564
- } while (chunk = chunk.previous);
1565
- if (this.intro.length)
1566
- { return this.intro[this.intro.length - 1]; }
1567
- return '';
1568
- };
1569
-
1570
- MagicString.prototype.lastLine = function lastLine () {
1571
- var lineIndex = this.outro.lastIndexOf(n);
1572
- if (lineIndex !== -1)
1573
- { return this.outro.substr(lineIndex + 1); }
1574
- var lineStr = this.outro;
1575
- var chunk = this.lastChunk;
1576
- do {
1577
- if (chunk.outro.length > 0) {
1578
- lineIndex = chunk.outro.lastIndexOf(n);
1579
- if (lineIndex !== -1)
1580
- { return chunk.outro.substr(lineIndex + 1) + lineStr; }
1581
- lineStr = chunk.outro + lineStr;
1531
+ if (chunk) {
1532
+ chunk.prependRight(content);
1533
+ } else {
1534
+ this.outro = content + this.outro;
1582
1535
  }
1536
+ return this;
1537
+ }
1583
1538
 
1584
- if (chunk.content.length > 0) {
1585
- lineIndex = chunk.content.lastIndexOf(n);
1586
- if (lineIndex !== -1)
1587
- { return chunk.content.substr(lineIndex + 1) + lineStr; }
1588
- lineStr = chunk.content + lineStr;
1589
- }
1539
+ remove(start, end) {
1540
+ while (start < 0) start += this.original.length;
1541
+ while (end < 0) end += this.original.length;
1590
1542
 
1591
- if (chunk.intro.length > 0) {
1592
- lineIndex = chunk.intro.lastIndexOf(n);
1593
- if (lineIndex !== -1)
1594
- { return chunk.intro.substr(lineIndex + 1) + lineStr; }
1595
- lineStr = chunk.intro + lineStr;
1596
- }
1597
- } while (chunk = chunk.previous);
1598
- lineIndex = this.intro.lastIndexOf(n);
1599
- if (lineIndex !== -1)
1600
- { return this.intro.substr(lineIndex + 1) + lineStr; }
1601
- return this.intro + lineStr;
1602
- };
1543
+ if (start === end) return this;
1544
+
1545
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
1546
+ if (start > end) throw new Error('end must be greater than start');
1603
1547
 
1604
- MagicString.prototype.slice = function slice (start, end) {
1605
- if ( start === void 0 ) start = 0;
1606
- if ( end === void 0 ) end = this.original.length;
1548
+ this._split(start);
1549
+ this._split(end);
1607
1550
 
1608
- while (start < 0) { start += this.original.length; }
1609
- while (end < 0) { end += this.original.length; }
1551
+ let chunk = this.byStart[start];
1610
1552
 
1611
- var result = '';
1553
+ while (chunk) {
1554
+ chunk.intro = '';
1555
+ chunk.outro = '';
1556
+ chunk.edit('');
1612
1557
 
1613
- // find start chunk
1614
- var chunk = this.firstChunk;
1615
- while (chunk && (chunk.start > start || chunk.end <= start)) {
1616
- // found end chunk before start
1617
- if (chunk.start < end && chunk.end >= end) {
1618
- return result;
1558
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
1619
1559
  }
1560
+ return this;
1561
+ }
1620
1562
 
1621
- chunk = chunk.next;
1563
+ lastChar() {
1564
+ if (this.outro.length) return this.outro[this.outro.length - 1];
1565
+ let chunk = this.lastChunk;
1566
+ do {
1567
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
1568
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
1569
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
1570
+ } while ((chunk = chunk.previous));
1571
+ if (this.intro.length) return this.intro[this.intro.length - 1];
1572
+ return '';
1622
1573
  }
1623
1574
 
1624
- if (chunk && chunk.edited && chunk.start !== start)
1625
- { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
1575
+ lastLine() {
1576
+ let lineIndex = this.outro.lastIndexOf(n);
1577
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
1578
+ let lineStr = this.outro;
1579
+ let chunk = this.lastChunk;
1580
+ do {
1581
+ if (chunk.outro.length > 0) {
1582
+ lineIndex = chunk.outro.lastIndexOf(n);
1583
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
1584
+ lineStr = chunk.outro + lineStr;
1585
+ }
1626
1586
 
1627
- var startChunk = chunk;
1628
- while (chunk) {
1629
- if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
1630
- result += chunk.intro;
1631
- }
1587
+ if (chunk.content.length > 0) {
1588
+ lineIndex = chunk.content.lastIndexOf(n);
1589
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
1590
+ lineStr = chunk.content + lineStr;
1591
+ }
1632
1592
 
1633
- var containsEnd = chunk.start < end && chunk.end >= end;
1634
- if (containsEnd && chunk.edited && chunk.end !== end)
1635
- { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
1593
+ if (chunk.intro.length > 0) {
1594
+ lineIndex = chunk.intro.lastIndexOf(n);
1595
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
1596
+ lineStr = chunk.intro + lineStr;
1597
+ }
1598
+ } while ((chunk = chunk.previous));
1599
+ lineIndex = this.intro.lastIndexOf(n);
1600
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
1601
+ return this.intro + lineStr;
1602
+ }
1636
1603
 
1637
- var sliceStart = startChunk === chunk ? start - chunk.start : 0;
1638
- var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
1604
+ slice(start = 0, end = this.original.length) {
1605
+ while (start < 0) start += this.original.length;
1606
+ while (end < 0) end += this.original.length;
1639
1607
 
1640
- result += chunk.content.slice(sliceStart, sliceEnd);
1608
+ let result = '';
1641
1609
 
1642
- if (chunk.outro && (!containsEnd || chunk.end === end)) {
1643
- result += chunk.outro;
1644
- }
1610
+ // find start chunk
1611
+ let chunk = this.firstChunk;
1612
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
1613
+ // found end chunk before start
1614
+ if (chunk.start < end && chunk.end >= end) {
1615
+ return result;
1616
+ }
1645
1617
 
1646
- if (containsEnd) {
1647
- break;
1618
+ chunk = chunk.next;
1648
1619
  }
1649
1620
 
1650
- chunk = chunk.next;
1651
- }
1621
+ if (chunk && chunk.edited && chunk.start !== start)
1622
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
1652
1623
 
1653
- return result;
1654
- };
1624
+ const startChunk = chunk;
1625
+ while (chunk) {
1626
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
1627
+ result += chunk.intro;
1628
+ }
1655
1629
 
1656
- // TODO deprecate this? not really very useful
1657
- MagicString.prototype.snip = function snip (start, end) {
1658
- var clone = this.clone();
1659
- clone.remove(0, start);
1660
- clone.remove(end, clone.original.length);
1630
+ const containsEnd = chunk.start < end && chunk.end >= end;
1631
+ if (containsEnd && chunk.edited && chunk.end !== end)
1632
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
1661
1633
 
1662
- return clone;
1663
- };
1634
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
1635
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
1664
1636
 
1665
- MagicString.prototype._split = function _split (index) {
1666
- if (this.byStart[index] || this.byEnd[index]) { return; }
1637
+ result += chunk.content.slice(sliceStart, sliceEnd);
1667
1638
 
1668
- var chunk = this.lastSearchedChunk;
1669
- var searchForward = index > chunk.end;
1639
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
1640
+ result += chunk.outro;
1641
+ }
1670
1642
 
1671
- while (chunk) {
1672
- if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
1643
+ if (containsEnd) {
1644
+ break;
1645
+ }
1673
1646
 
1674
- chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
1675
- }
1676
- };
1647
+ chunk = chunk.next;
1648
+ }
1677
1649
 
1678
- MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
1679
- if (chunk.edited && chunk.content.length) {
1680
- // zero-length edited chunks are a special case (overlapping replacements)
1681
- var loc = getLocator(this.original)(index);
1682
- throw new Error(
1683
- ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
1684
- );
1650
+ return result;
1685
1651
  }
1686
1652
 
1687
- var newChunk = chunk.split(index);
1653
+ // TODO deprecate this? not really very useful
1654
+ snip(start, end) {
1655
+ const clone = this.clone();
1656
+ clone.remove(0, start);
1657
+ clone.remove(end, clone.original.length);
1688
1658
 
1689
- this.byEnd[index] = chunk;
1690
- this.byStart[index] = newChunk;
1691
- this.byEnd[newChunk.end] = newChunk;
1659
+ return clone;
1660
+ }
1692
1661
 
1693
- if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
1662
+ _split(index) {
1663
+ if (this.byStart[index] || this.byEnd[index]) return;
1694
1664
 
1695
- this.lastSearchedChunk = chunk;
1696
- return true;
1697
- };
1665
+ let chunk = this.lastSearchedChunk;
1666
+ const searchForward = index > chunk.end;
1698
1667
 
1699
- MagicString.prototype.toString = function toString () {
1700
- var str = this.intro;
1668
+ while (chunk) {
1669
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
1701
1670
 
1702
- var chunk = this.firstChunk;
1703
- while (chunk) {
1704
- str += chunk.toString();
1705
- chunk = chunk.next;
1671
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
1672
+ }
1706
1673
  }
1707
1674
 
1708
- return str + this.outro;
1709
- };
1675
+ _splitChunk(chunk, index) {
1676
+ if (chunk.edited && chunk.content.length) {
1677
+ // zero-length edited chunks are a special case (overlapping replacements)
1678
+ const loc = getLocator(this.original)(index);
1679
+ throw new Error(
1680
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
1681
+ );
1682
+ }
1710
1683
 
1711
- MagicString.prototype.isEmpty = function isEmpty () {
1712
- var chunk = this.firstChunk;
1713
- do {
1714
- if (chunk.intro.length && chunk.intro.trim() ||
1715
- chunk.content.length && chunk.content.trim() ||
1716
- chunk.outro.length && chunk.outro.trim())
1717
- { return false; }
1718
- } while (chunk = chunk.next);
1719
- return true;
1720
- };
1684
+ const newChunk = chunk.split(index);
1721
1685
 
1722
- MagicString.prototype.length = function length () {
1723
- var chunk = this.firstChunk;
1724
- var length = 0;
1725
- do {
1726
- length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1727
- } while (chunk = chunk.next);
1728
- return length;
1729
- };
1686
+ this.byEnd[index] = chunk;
1687
+ this.byStart[index] = newChunk;
1688
+ this.byEnd[newChunk.end] = newChunk;
1730
1689
 
1731
- MagicString.prototype.trimLines = function trimLines () {
1732
- return this.trim('[\\r\\n]');
1733
- };
1690
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
1734
1691
 
1735
- MagicString.prototype.trim = function trim (charType) {
1736
- return this.trimStart(charType).trimEnd(charType);
1737
- };
1692
+ this.lastSearchedChunk = chunk;
1693
+ return true;
1694
+ }
1738
1695
 
1739
- MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
1740
- var rx = new RegExp((charType || '\\s') + '+$');
1696
+ toString() {
1697
+ let str = this.intro;
1741
1698
 
1742
- this.outro = this.outro.replace(rx, '');
1743
- if (this.outro.length) { return true; }
1699
+ let chunk = this.firstChunk;
1700
+ while (chunk) {
1701
+ str += chunk.toString();
1702
+ chunk = chunk.next;
1703
+ }
1744
1704
 
1745
- var chunk = this.lastChunk;
1705
+ return str + this.outro;
1706
+ }
1746
1707
 
1747
- do {
1748
- var end = chunk.end;
1749
- var aborted = chunk.trimEnd(rx);
1708
+ isEmpty() {
1709
+ let chunk = this.firstChunk;
1710
+ do {
1711
+ if (
1712
+ (chunk.intro.length && chunk.intro.trim()) ||
1713
+ (chunk.content.length && chunk.content.trim()) ||
1714
+ (chunk.outro.length && chunk.outro.trim())
1715
+ )
1716
+ return false;
1717
+ } while ((chunk = chunk.next));
1718
+ return true;
1719
+ }
1750
1720
 
1751
- // if chunk was trimmed, we have a new lastChunk
1752
- if (chunk.end !== end) {
1753
- if (this.lastChunk === chunk) {
1754
- this.lastChunk = chunk.next;
1755
- }
1721
+ length() {
1722
+ let chunk = this.firstChunk;
1723
+ let length = 0;
1724
+ do {
1725
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1726
+ } while ((chunk = chunk.next));
1727
+ return length;
1728
+ }
1756
1729
 
1757
- this.byEnd[chunk.end] = chunk;
1758
- this.byStart[chunk.next.start] = chunk.next;
1759
- this.byEnd[chunk.next.end] = chunk.next;
1760
- }
1730
+ trimLines() {
1731
+ return this.trim('[\\r\\n]');
1732
+ }
1761
1733
 
1762
- if (aborted) { return true; }
1763
- chunk = chunk.previous;
1764
- } while (chunk);
1734
+ trim(charType) {
1735
+ return this.trimStart(charType).trimEnd(charType);
1736
+ }
1765
1737
 
1766
- return false;
1767
- };
1738
+ trimEndAborted(charType) {
1739
+ const rx = new RegExp((charType || '\\s') + '+$');
1768
1740
 
1769
- MagicString.prototype.trimEnd = function trimEnd (charType) {
1770
- this.trimEndAborted(charType);
1771
- return this;
1772
- };
1773
- MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
1774
- var rx = new RegExp('^' + (charType || '\\s') + '+');
1741
+ this.outro = this.outro.replace(rx, '');
1742
+ if (this.outro.length) return true;
1775
1743
 
1776
- this.intro = this.intro.replace(rx, '');
1777
- if (this.intro.length) { return true; }
1744
+ let chunk = this.lastChunk;
1778
1745
 
1779
- var chunk = this.firstChunk;
1746
+ do {
1747
+ const end = chunk.end;
1748
+ const aborted = chunk.trimEnd(rx);
1780
1749
 
1781
- do {
1782
- var end = chunk.end;
1783
- var aborted = chunk.trimStart(rx);
1750
+ // if chunk was trimmed, we have a new lastChunk
1751
+ if (chunk.end !== end) {
1752
+ if (this.lastChunk === chunk) {
1753
+ this.lastChunk = chunk.next;
1754
+ }
1784
1755
 
1785
- if (chunk.end !== end) {
1786
- // special case...
1787
- if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
1756
+ this.byEnd[chunk.end] = chunk;
1757
+ this.byStart[chunk.next.start] = chunk.next;
1758
+ this.byEnd[chunk.next.end] = chunk.next;
1759
+ }
1788
1760
 
1789
- this.byEnd[chunk.end] = chunk;
1790
- this.byStart[chunk.next.start] = chunk.next;
1791
- this.byEnd[chunk.next.end] = chunk.next;
1792
- }
1761
+ if (aborted) return true;
1762
+ chunk = chunk.previous;
1763
+ } while (chunk);
1793
1764
 
1794
- if (aborted) { return true; }
1795
- chunk = chunk.next;
1796
- } while (chunk);
1765
+ return false;
1766
+ }
1797
1767
 
1798
- return false;
1799
- };
1768
+ trimEnd(charType) {
1769
+ this.trimEndAborted(charType);
1770
+ return this;
1771
+ }
1772
+ trimStartAborted(charType) {
1773
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
1800
1774
 
1801
- MagicString.prototype.trimStart = function trimStart (charType) {
1802
- this.trimStartAborted(charType);
1803
- return this;
1804
- };
1775
+ this.intro = this.intro.replace(rx, '');
1776
+ if (this.intro.length) return true;
1805
1777
 
1806
- var hasOwnProp = Object.prototype.hasOwnProperty;
1778
+ let chunk = this.firstChunk;
1807
1779
 
1808
- var Bundle$1 = function Bundle(options) {
1809
- if ( options === void 0 ) options = {};
1780
+ do {
1781
+ const end = chunk.end;
1782
+ const aborted = chunk.trimStart(rx);
1810
1783
 
1811
- this.intro = options.intro || '';
1812
- this.separator = options.separator !== undefined ? options.separator : '\n';
1813
- this.sources = [];
1814
- this.uniqueSources = [];
1815
- this.uniqueSourceIndexByFilename = {};
1816
- };
1784
+ if (chunk.end !== end) {
1785
+ // special case...
1786
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
1817
1787
 
1818
- Bundle$1.prototype.addSource = function addSource (source) {
1819
- if (source instanceof MagicString) {
1820
- return this.addSource({
1821
- content: source,
1822
- filename: source.filename,
1823
- separator: this.separator
1824
- });
1825
- }
1788
+ this.byEnd[chunk.end] = chunk;
1789
+ this.byStart[chunk.next.start] = chunk.next;
1790
+ this.byEnd[chunk.next.end] = chunk.next;
1791
+ }
1792
+
1793
+ if (aborted) return true;
1794
+ chunk = chunk.next;
1795
+ } while (chunk);
1826
1796
 
1827
- if (!isObject$1(source) || !source.content) {
1828
- throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
1797
+ return false;
1829
1798
  }
1830
1799
 
1831
- ['filename', 'indentExclusionRanges', 'separator'].forEach(function (option) {
1832
- if (!hasOwnProp.call(source, option)) { source[option] = source.content[option]; }
1833
- });
1800
+ trimStart(charType) {
1801
+ this.trimStartAborted(charType);
1802
+ return this;
1803
+ }
1834
1804
 
1835
- if (source.separator === undefined) {
1836
- // TODO there's a bunch of this sort of thing, needs cleaning up
1837
- source.separator = this.separator;
1805
+ hasChanged() {
1806
+ return this.original !== this.toString();
1838
1807
  }
1839
1808
 
1840
- if (source.filename) {
1841
- if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1842
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1843
- this.uniqueSources.push({ filename: source.filename, content: source.content.original });
1844
- } else {
1845
- var uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1846
- if (source.content.original !== uniqueSource.content) {
1847
- throw new Error(("Illegal source: same filename (" + (source.filename) + "), different contents"));
1809
+ replace(searchValue, replacement) {
1810
+ function getReplacement(match, str) {
1811
+ if (typeof replacement === 'string') {
1812
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
1813
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
1814
+ if (i === '$') return '$';
1815
+ if (i === '&') return match[0];
1816
+ const num = +i;
1817
+ if (num < match.length) return match[+i];
1818
+ return `$${i}`;
1819
+ });
1820
+ } else {
1821
+ return replacement(...match, match.index, str, match.groups);
1822
+ }
1823
+ }
1824
+ function matchAll(re, str) {
1825
+ let match;
1826
+ const matches = [];
1827
+ while ((match = re.exec(str))) {
1828
+ matches.push(match);
1848
1829
  }
1830
+ return matches;
1831
+ }
1832
+ if (typeof searchValue !== 'string' && searchValue.global) {
1833
+ const matches = matchAll(searchValue, this.original);
1834
+ matches.forEach((match) => {
1835
+ if (match.index != null)
1836
+ this.overwrite(
1837
+ match.index,
1838
+ match.index + match[0].length,
1839
+ getReplacement(match, this.original)
1840
+ );
1841
+ });
1842
+ } else {
1843
+ const match = this.original.match(searchValue);
1844
+ if (match && match.index != null)
1845
+ this.overwrite(
1846
+ match.index,
1847
+ match.index + match[0].length,
1848
+ getReplacement(match, this.original)
1849
+ );
1849
1850
  }
1851
+ return this;
1850
1852
  }
1853
+ }
1851
1854
 
1852
- this.sources.push(source);
1853
- return this;
1854
- };
1855
+ const hasOwnProp = Object.prototype.hasOwnProperty;
1855
1856
 
1856
- Bundle$1.prototype.append = function append (str, options) {
1857
- this.addSource({
1858
- content: new MagicString(str),
1859
- separator: (options && options.separator) || ''
1860
- });
1857
+ class Bundle$1 {
1858
+ constructor(options = {}) {
1859
+ this.intro = options.intro || '';
1860
+ this.separator = options.separator !== undefined ? options.separator : '\n';
1861
+ this.sources = [];
1862
+ this.uniqueSources = [];
1863
+ this.uniqueSourceIndexByFilename = {};
1864
+ }
1861
1865
 
1862
- return this;
1863
- };
1866
+ addSource(source) {
1867
+ if (source instanceof MagicString) {
1868
+ return this.addSource({
1869
+ content: source,
1870
+ filename: source.filename,
1871
+ separator: this.separator,
1872
+ });
1873
+ }
1864
1874
 
1865
- Bundle$1.prototype.clone = function clone () {
1866
- var bundle = new Bundle$1({
1867
- intro: this.intro,
1868
- separator: this.separator
1869
- });
1875
+ if (!isObject$1(source) || !source.content) {
1876
+ throw new Error(
1877
+ 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
1878
+ );
1879
+ }
1870
1880
 
1871
- this.sources.forEach(function (source) {
1872
- bundle.addSource({
1873
- filename: source.filename,
1874
- content: source.content.clone(),
1875
- separator: source.separator
1881
+ ['filename', 'indentExclusionRanges', 'separator'].forEach((option) => {
1882
+ if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
1876
1883
  });
1877
- });
1878
1884
 
1879
- return bundle;
1880
- };
1885
+ if (source.separator === undefined) {
1886
+ // TODO there's a bunch of this sort of thing, needs cleaning up
1887
+ source.separator = this.separator;
1888
+ }
1889
+
1890
+ if (source.filename) {
1891
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1892
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1893
+ this.uniqueSources.push({ filename: source.filename, content: source.content.original });
1894
+ } else {
1895
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1896
+ if (source.content.original !== uniqueSource.content) {
1897
+ throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
1898
+ }
1899
+ }
1900
+ }
1881
1901
 
1882
- Bundle$1.prototype.generateDecodedMap = function generateDecodedMap (options) {
1883
- var this$1$1 = this;
1884
- if ( options === void 0 ) options = {};
1902
+ this.sources.push(source);
1903
+ return this;
1904
+ }
1885
1905
 
1886
- var names = [];
1887
- this.sources.forEach(function (source) {
1888
- Object.keys(source.content.storedNames).forEach(function (name) {
1889
- if (!~names.indexOf(name)) { names.push(name); }
1906
+ append(str, options) {
1907
+ this.addSource({
1908
+ content: new MagicString(str),
1909
+ separator: (options && options.separator) || '',
1890
1910
  });
1891
- });
1892
1911
 
1893
- var mappings = new Mappings(options.hires);
1912
+ return this;
1913
+ }
1914
+
1915
+ clone() {
1916
+ const bundle = new Bundle$1({
1917
+ intro: this.intro,
1918
+ separator: this.separator,
1919
+ });
1894
1920
 
1895
- if (this.intro) {
1896
- mappings.advance(this.intro);
1921
+ this.sources.forEach((source) => {
1922
+ bundle.addSource({
1923
+ filename: source.filename,
1924
+ content: source.content.clone(),
1925
+ separator: source.separator,
1926
+ });
1927
+ });
1928
+
1929
+ return bundle;
1897
1930
  }
1898
1931
 
1899
- this.sources.forEach(function (source, i) {
1900
- if (i > 0) {
1901
- mappings.advance(this$1$1.separator);
1902
- }
1932
+ generateDecodedMap(options = {}) {
1933
+ const names = [];
1934
+ this.sources.forEach((source) => {
1935
+ Object.keys(source.content.storedNames).forEach((name) => {
1936
+ if (!~names.indexOf(name)) names.push(name);
1937
+ });
1938
+ });
1903
1939
 
1904
- var sourceIndex = source.filename ? this$1$1.uniqueSourceIndexByFilename[source.filename] : -1;
1905
- var magicString = source.content;
1906
- var locate = getLocator(magicString.original);
1940
+ const mappings = new Mappings(options.hires);
1907
1941
 
1908
- if (magicString.intro) {
1909
- mappings.advance(magicString.intro);
1942
+ if (this.intro) {
1943
+ mappings.advance(this.intro);
1910
1944
  }
1911
1945
 
1912
- magicString.firstChunk.eachNext(function (chunk) {
1913
- var loc = locate(chunk.start);
1946
+ this.sources.forEach((source, i) => {
1947
+ if (i > 0) {
1948
+ mappings.advance(this.separator);
1949
+ }
1914
1950
 
1915
- if (chunk.intro.length) { mappings.advance(chunk.intro); }
1951
+ const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
1952
+ const magicString = source.content;
1953
+ const locate = getLocator(magicString.original);
1916
1954
 
1917
- if (source.filename) {
1918
- if (chunk.edited) {
1919
- mappings.addEdit(
1920
- sourceIndex,
1921
- chunk.content,
1922
- loc,
1923
- chunk.storeName ? names.indexOf(chunk.original) : -1
1924
- );
1955
+ if (magicString.intro) {
1956
+ mappings.advance(magicString.intro);
1957
+ }
1958
+
1959
+ magicString.firstChunk.eachNext((chunk) => {
1960
+ const loc = locate(chunk.start);
1961
+
1962
+ if (chunk.intro.length) mappings.advance(chunk.intro);
1963
+
1964
+ if (source.filename) {
1965
+ if (chunk.edited) {
1966
+ mappings.addEdit(
1967
+ sourceIndex,
1968
+ chunk.content,
1969
+ loc,
1970
+ chunk.storeName ? names.indexOf(chunk.original) : -1
1971
+ );
1972
+ } else {
1973
+ mappings.addUneditedChunk(
1974
+ sourceIndex,
1975
+ chunk,
1976
+ magicString.original,
1977
+ loc,
1978
+ magicString.sourcemapLocations
1979
+ );
1980
+ }
1925
1981
  } else {
1926
- mappings.addUneditedChunk(
1927
- sourceIndex,
1928
- chunk,
1929
- magicString.original,
1930
- loc,
1931
- magicString.sourcemapLocations
1932
- );
1982
+ mappings.advance(chunk.content);
1933
1983
  }
1934
- } else {
1935
- mappings.advance(chunk.content);
1936
- }
1937
1984
 
1938
- if (chunk.outro.length) { mappings.advance(chunk.outro); }
1939
- });
1985
+ if (chunk.outro.length) mappings.advance(chunk.outro);
1986
+ });
1940
1987
 
1941
- if (magicString.outro) {
1942
- mappings.advance(magicString.outro);
1943
- }
1944
- });
1988
+ if (magicString.outro) {
1989
+ mappings.advance(magicString.outro);
1990
+ }
1991
+ });
1945
1992
 
1946
- return {
1947
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
1948
- sources: this.uniqueSources.map(function (source) {
1949
- return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1950
- }),
1951
- sourcesContent: this.uniqueSources.map(function (source) {
1952
- return options.includeContent ? source.content : null;
1953
- }),
1954
- names: names,
1955
- mappings: mappings.raw
1956
- };
1957
- };
1993
+ return {
1994
+ file: options.file ? options.file.split(/[/\\]/).pop() : null,
1995
+ sources: this.uniqueSources.map((source) => {
1996
+ return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1997
+ }),
1998
+ sourcesContent: this.uniqueSources.map((source) => {
1999
+ return options.includeContent ? source.content : null;
2000
+ }),
2001
+ names,
2002
+ mappings: mappings.raw,
2003
+ };
2004
+ }
1958
2005
 
1959
- Bundle$1.prototype.generateMap = function generateMap (options) {
1960
- return new SourceMap(this.generateDecodedMap(options));
1961
- };
2006
+ generateMap(options) {
2007
+ return new SourceMap(this.generateDecodedMap(options));
2008
+ }
1962
2009
 
1963
- Bundle$1.prototype.getIndentString = function getIndentString () {
1964
- var indentStringCounts = {};
2010
+ getIndentString() {
2011
+ const indentStringCounts = {};
1965
2012
 
1966
- this.sources.forEach(function (source) {
1967
- var indentStr = source.content.indentStr;
2013
+ this.sources.forEach((source) => {
2014
+ const indentStr = source.content.indentStr;
1968
2015
 
1969
- if (indentStr === null) { return; }
2016
+ if (indentStr === null) return;
1970
2017
 
1971
- if (!indentStringCounts[indentStr]) { indentStringCounts[indentStr] = 0; }
1972
- indentStringCounts[indentStr] += 1;
1973
- });
2018
+ if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
2019
+ indentStringCounts[indentStr] += 1;
2020
+ });
1974
2021
 
1975
- return (
1976
- Object.keys(indentStringCounts).sort(function (a, b) {
1977
- return indentStringCounts[a] - indentStringCounts[b];
1978
- })[0] || '\t'
1979
- );
1980
- };
2022
+ return (
2023
+ Object.keys(indentStringCounts).sort((a, b) => {
2024
+ return indentStringCounts[a] - indentStringCounts[b];
2025
+ })[0] || '\t'
2026
+ );
2027
+ }
1981
2028
 
1982
- Bundle$1.prototype.indent = function indent (indentStr) {
1983
- var this$1$1 = this;
2029
+ indent(indentStr) {
2030
+ if (!arguments.length) {
2031
+ indentStr = this.getIndentString();
2032
+ }
1984
2033
 
1985
- if (!arguments.length) {
1986
- indentStr = this.getIndentString();
1987
- }
2034
+ if (indentStr === '') return this; // noop
1988
2035
 
1989
- if (indentStr === '') { return this; } // noop
2036
+ let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
1990
2037
 
1991
- var trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
2038
+ this.sources.forEach((source, i) => {
2039
+ const separator = source.separator !== undefined ? source.separator : this.separator;
2040
+ const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
1992
2041
 
1993
- this.sources.forEach(function (source, i) {
1994
- var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
1995
- var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
2042
+ source.content.indent(indentStr, {
2043
+ exclude: source.indentExclusionRanges,
2044
+ indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
2045
+ });
1996
2046
 
1997
- source.content.indent(indentStr, {
1998
- exclude: source.indentExclusionRanges,
1999
- indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
2047
+ trailingNewline = source.content.lastChar() === '\n';
2000
2048
  });
2001
2049
 
2002
- trailingNewline = source.content.lastChar() === '\n';
2003
- });
2050
+ if (this.intro) {
2051
+ this.intro =
2052
+ indentStr +
2053
+ this.intro.replace(/^[^\n]/gm, (match, index) => {
2054
+ return index > 0 ? indentStr + match : match;
2055
+ });
2056
+ }
2004
2057
 
2005
- if (this.intro) {
2006
- this.intro =
2007
- indentStr +
2008
- this.intro.replace(/^[^\n]/gm, function (match, index) {
2009
- return index > 0 ? indentStr + match : match;
2010
- });
2058
+ return this;
2011
2059
  }
2012
2060
 
2013
- return this;
2014
- };
2061
+ prepend(str) {
2062
+ this.intro = str + this.intro;
2063
+ return this;
2064
+ }
2015
2065
 
2016
- Bundle$1.prototype.prepend = function prepend (str) {
2017
- this.intro = str + this.intro;
2018
- return this;
2019
- };
2066
+ toString() {
2067
+ const body = this.sources
2068
+ .map((source, i) => {
2069
+ const separator = source.separator !== undefined ? source.separator : this.separator;
2070
+ const str = (i > 0 ? separator : '') + source.content.toString();
2020
2071
 
2021
- Bundle$1.prototype.toString = function toString () {
2022
- var this$1$1 = this;
2072
+ return str;
2073
+ })
2074
+ .join('');
2023
2075
 
2024
- var body = this.sources
2025
- .map(function (source, i) {
2026
- var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
2027
- var str = (i > 0 ? separator : '') + source.content.toString();
2076
+ return this.intro + body;
2077
+ }
2028
2078
 
2029
- return str;
2030
- })
2031
- .join('');
2079
+ isEmpty() {
2080
+ if (this.intro.length && this.intro.trim()) return false;
2081
+ if (this.sources.some((source) => !source.content.isEmpty())) return false;
2082
+ return true;
2083
+ }
2032
2084
 
2033
- return this.intro + body;
2034
- };
2085
+ length() {
2086
+ return this.sources.reduce(
2087
+ (length, source) => length + source.content.length(),
2088
+ this.intro.length
2089
+ );
2090
+ }
2035
2091
 
2036
- Bundle$1.prototype.isEmpty = function isEmpty () {
2037
- if (this.intro.length && this.intro.trim())
2038
- { return false; }
2039
- if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
2040
- { return false; }
2041
- return true;
2042
- };
2092
+ trimLines() {
2093
+ return this.trim('[\\r\\n]');
2094
+ }
2043
2095
 
2044
- Bundle$1.prototype.length = function length () {
2045
- return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
2046
- };
2096
+ trim(charType) {
2097
+ return this.trimStart(charType).trimEnd(charType);
2098
+ }
2047
2099
 
2048
- Bundle$1.prototype.trimLines = function trimLines () {
2049
- return this.trim('[\\r\\n]');
2050
- };
2100
+ trimStart(charType) {
2101
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
2102
+ this.intro = this.intro.replace(rx, '');
2051
2103
 
2052
- Bundle$1.prototype.trim = function trim (charType) {
2053
- return this.trimStart(charType).trimEnd(charType);
2054
- };
2104
+ if (!this.intro) {
2105
+ let source;
2106
+ let i = 0;
2107
+
2108
+ do {
2109
+ source = this.sources[i++];
2110
+ if (!source) {
2111
+ break;
2112
+ }
2113
+ } while (!source.content.trimStartAborted(charType));
2114
+ }
2115
+
2116
+ return this;
2117
+ }
2055
2118
 
2056
- Bundle$1.prototype.trimStart = function trimStart (charType) {
2057
- var rx = new RegExp('^' + (charType || '\\s') + '+');
2058
- this.intro = this.intro.replace(rx, '');
2119
+ trimEnd(charType) {
2120
+ const rx = new RegExp((charType || '\\s') + '+$');
2059
2121
 
2060
- if (!this.intro) {
2061
- var source;
2062
- var i = 0;
2122
+ let source;
2123
+ let i = this.sources.length - 1;
2063
2124
 
2064
2125
  do {
2065
- source = this.sources[i++];
2126
+ source = this.sources[i--];
2066
2127
  if (!source) {
2128
+ this.intro = this.intro.replace(rx, '');
2067
2129
  break;
2068
2130
  }
2069
- } while (!source.content.trimStartAborted(charType));
2070
- }
2071
-
2072
- return this;
2073
- };
2074
-
2075
- Bundle$1.prototype.trimEnd = function trimEnd (charType) {
2076
- var rx = new RegExp((charType || '\\s') + '+$');
2131
+ } while (!source.content.trimEndAborted(charType));
2077
2132
 
2078
- var source;
2079
- var i = this.sources.length - 1;
2080
-
2081
- do {
2082
- source = this.sources[i--];
2083
- if (!source) {
2084
- this.intro = this.intro.replace(rx, '');
2085
- break;
2086
- }
2087
- } while (!source.content.trimEndAborted(charType));
2088
-
2089
- return this;
2090
- };
2091
-
2092
- const MagicString$1 = MagicString;
2133
+ return this;
2134
+ }
2135
+ }
2093
2136
 
2094
2137
  function getOrCreate(map, key, init) {
2095
2138
  const existing = map.get(key);
@@ -4561,7 +4604,7 @@ const normalizePath = function normalizePath(filename) {
4561
4604
 
4562
4605
  function getMatcherString(id, resolutionBase) {
4563
4606
  if (resolutionBase === false || require$$0.isAbsolute(id) || id.startsWith('*')) {
4564
- return id;
4607
+ return normalizePath(id);
4565
4608
  }
4566
4609
  // resolve('') is valid and will default to process.cwd()
4567
4610
  const basePath = normalizePath(require$$0.resolve(resolutionBase || ''))
@@ -4571,7 +4614,7 @@ function getMatcherString(id, resolutionBase) {
4571
4614
  // 1. the basePath has been normalized to use /
4572
4615
  // 2. the incoming glob (id) matcher, also uses /
4573
4616
  // otherwise Node will force backslash (\) on windows
4574
- return require$$0.posix.join(basePath, id);
4617
+ return require$$0.posix.join(basePath, normalizePath(id));
4575
4618
  }
4576
4619
  const createFilter = function createFilter(include, exclude, options) {
4577
4620
  const resolutionBase = options && options.resolve;
@@ -12761,7 +12804,7 @@ class Module {
12761
12804
  // By default, `id` is the file name. Custom resolvers and loaders
12762
12805
  // can change that, but it makes sense to use it for the source file name
12763
12806
  const fileName = this.id;
12764
- this.magicString = new MagicString$1(code, {
12807
+ this.magicString = new MagicString(code, {
12765
12808
  filename: (this.excludeFromSourcemap ? null : fileName),
12766
12809
  indentExclusionRanges: []
12767
12810
  });
@@ -14797,7 +14840,7 @@ class Chunk {
14797
14840
  if (namespace.renderFirst())
14798
14841
  hoistedSource += n + rendered;
14799
14842
  else
14800
- magicString.addSource(new MagicString$1(rendered));
14843
+ magicString.addSource(new MagicString(rendered));
14801
14844
  }
14802
14845
  }
14803
14846
  const { renderedExports, removedExports } = module.getRenderedExports();
@@ -22027,7 +22070,7 @@ async function transform(source, module, pluginDriver, warn) {
22027
22070
  getCombinedSourcemap() {
22028
22071
  const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn);
22029
22072
  if (!combinedMap) {
22030
- const magicString = new MagicString$1(originalCode);
22073
+ const magicString = new MagicString(originalCode);
22031
22074
  return magicString.generateMap({ hires: true, includeContent: true, source: id });
22032
22075
  }
22033
22076
  if (originalSourcemap !== combinedMap) {
@@ -22617,41 +22660,6 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22617
22660
  return context;
22618
22661
  }
22619
22662
 
22620
- const unfulfilledActions = new Set();
22621
- function addUnresolvedAction(actionTuple) {
22622
- unfulfilledActions.add(actionTuple);
22623
- }
22624
- function resolveAction(actionTuple) {
22625
- unfulfilledActions.delete(actionTuple);
22626
- }
22627
- function formatAction([pluginName, hookName, args]) {
22628
- const action = `(${pluginName}) ${hookName}`;
22629
- const s = JSON.stringify;
22630
- switch (hookName) {
22631
- case 'resolveId':
22632
- return `${action} ${s(args[0])} ${s(args[1])}`;
22633
- case 'load':
22634
- return `${action} ${s(args[0])}`;
22635
- case 'transform':
22636
- return `${action} ${s(args[1])}`;
22637
- case 'shouldTransformCachedModule':
22638
- return `${action} ${s(args[0].id)}`;
22639
- case 'moduleParsed':
22640
- return `${action} ${s(args[0].id)}`;
22641
- }
22642
- return action;
22643
- }
22644
- process$1.on('exit', () => {
22645
- if (unfulfilledActions.size) {
22646
- let err = '[!] Error: unfinished hook action(s) on exit:\n';
22647
- for (const action of unfulfilledActions) {
22648
- err += formatAction(action) + '\n';
22649
- }
22650
- console.error('%s', err);
22651
- process$1.exitCode = 1;
22652
- }
22653
- });
22654
-
22655
22663
  const inputHookNames = {
22656
22664
  buildEnd: 1,
22657
22665
  buildStart: 1,
@@ -22677,6 +22685,7 @@ class PluginDriver {
22677
22685
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22678
22686
  this.graph = graph;
22679
22687
  this.options = options;
22688
+ this.unfulfilledActions = new Set();
22680
22689
  warnDeprecatedHooks(userPlugins, options);
22681
22690
  this.pluginCache = pluginCache;
22682
22691
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
@@ -22703,6 +22712,9 @@ class PluginDriver {
22703
22712
  createOutputPluginDriver(plugins) {
22704
22713
  return new PluginDriver(this.graph, this.options, plugins, this.pluginCache, this);
22705
22714
  }
22715
+ getUnfulfilledHookActions() {
22716
+ return this.unfulfilledActions;
22717
+ }
22706
22718
  // chains, first non-null result stops and returns
22707
22719
  hookFirst(hookName, args, replaceContext, skipped) {
22708
22720
  let promise = Promise.resolve(undefined);
@@ -22790,12 +22802,6 @@ class PluginDriver {
22790
22802
  }
22791
22803
  return promise;
22792
22804
  }
22793
- // chains synchronously, ignores returns
22794
- hookSeqSync(hookName, args, replaceContext) {
22795
- for (const plugin of this.plugins) {
22796
- this.runHookSync(hookName, args, plugin, replaceContext);
22797
- }
22798
- }
22799
22805
  runHook(hookName, args, plugin, permitValues, hookContext) {
22800
22806
  const hook = plugin[hookName];
22801
22807
  if (!hook)
@@ -22824,22 +22830,21 @@ class PluginDriver {
22824
22830
  // exit with a successful 0 return code but without producing any
22825
22831
  // output, errors or warnings.
22826
22832
  action = [plugin.name, hookName, args];
22827
- addUnresolvedAction(action);
22833
+ this.unfulfilledActions.add(action);
22828
22834
  // Although it would be more elegant to just return hookResult here
22829
22835
  // and put the .then() handler just above the .catch() handler below,
22830
22836
  // doing so would subtly change the defacto async event dispatch order
22831
22837
  // which at least one test and some plugins in the wild may depend on.
22832
- const promise = Promise.resolve(hookResult);
22833
- return promise.then(() => {
22838
+ return Promise.resolve(hookResult).then(result => {
22834
22839
  // action was fulfilled
22835
- resolveAction(action);
22836
- return promise;
22840
+ this.unfulfilledActions.delete(action);
22841
+ return result;
22837
22842
  });
22838
22843
  })
22839
22844
  .catch(err => {
22840
22845
  if (action !== null) {
22841
22846
  // action considered to be fulfilled since error being handled
22842
- resolveAction(action);
22847
+ this.unfulfilledActions.delete(action);
22843
22848
  }
22844
22849
  return throwPluginError(err, plugin.name, { hook: hookName });
22845
22850
  });
@@ -22928,14 +22933,10 @@ class Graph {
22928
22933
  }
22929
22934
  if (watcher) {
22930
22935
  this.watchMode = true;
22931
- const handleChange = (...args) => this.pluginDriver.hookSeqSync('watchChange', args);
22932
- const handleClose = () => this.pluginDriver.hookSeqSync('closeWatcher', []);
22933
- watcher.on('change', handleChange);
22934
- watcher.on('close', handleClose);
22935
- watcher.once('restart', () => {
22936
- watcher.removeListener('change', handleChange);
22937
- watcher.removeListener('close', handleClose);
22938
- });
22936
+ const handleChange = (...args) => this.pluginDriver.hookParallel('watchChange', args);
22937
+ const handleClose = () => this.pluginDriver.hookParallel('closeWatcher', []);
22938
+ watcher.onCurrentAwaited('change', handleChange);
22939
+ watcher.onCurrentAwaited('close', handleClose);
22939
22940
  }
22940
22941
  this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
22941
22942
  this.acornParser = Parser.extend(...options.acornInjectPlugins);
@@ -23090,6 +23091,38 @@ class Graph {
23090
23091
  }
23091
23092
  }
23092
23093
 
23094
+ function formatAction([pluginName, hookName, args]) {
23095
+ const action = `(${pluginName}) ${hookName}`;
23096
+ const s = JSON.stringify;
23097
+ switch (hookName) {
23098
+ case 'resolveId':
23099
+ return `${action} ${s(args[0])} ${s(args[1])}`;
23100
+ case 'load':
23101
+ return `${action} ${s(args[0])}`;
23102
+ case 'transform':
23103
+ return `${action} ${s(args[1])}`;
23104
+ case 'shouldTransformCachedModule':
23105
+ return `${action} ${s(args[0].id)}`;
23106
+ case 'moduleParsed':
23107
+ return `${action} ${s(args[0].id)}`;
23108
+ }
23109
+ return action;
23110
+ }
23111
+ async function catchUnfinishedHookActions(pluginDriver, callback) {
23112
+ let handleEmptyEventLoop;
23113
+ const emptyEventLoopPromise = new Promise((_, reject) => {
23114
+ handleEmptyEventLoop = () => {
23115
+ const unfulfilledActions = pluginDriver.getUnfulfilledHookActions();
23116
+ reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
23117
+ [...unfulfilledActions].map(formatAction).join('\n')));
23118
+ };
23119
+ process$1.once('beforeExit', handleEmptyEventLoop);
23120
+ });
23121
+ const result = await Promise.race([callback(), emptyEventLoopPromise]);
23122
+ process$1.off('beforeExit', handleEmptyEventLoop);
23123
+ return result;
23124
+ }
23125
+
23093
23126
  function normalizeInputOptions(config) {
23094
23127
  var _a, _b, _c;
23095
23128
  // These are options that may trigger special warnings or behaviour later
@@ -23573,20 +23606,22 @@ async function rollupInternal(rawInputOptions, watcher) {
23573
23606
  delete inputOptions.cache;
23574
23607
  delete rawInputOptions.cache;
23575
23608
  timeStart('BUILD', 1);
23576
- try {
23577
- await graph.pluginDriver.hookParallel('buildStart', [inputOptions]);
23578
- await graph.build();
23579
- }
23580
- catch (err) {
23581
- const watchFiles = Object.keys(graph.watchFiles);
23582
- if (watchFiles.length > 0) {
23583
- err.watchFiles = watchFiles;
23609
+ await catchUnfinishedHookActions(graph.pluginDriver, async () => {
23610
+ try {
23611
+ await graph.pluginDriver.hookParallel('buildStart', [inputOptions]);
23612
+ await graph.build();
23584
23613
  }
23585
- await graph.pluginDriver.hookParallel('buildEnd', [err]);
23586
- await graph.pluginDriver.hookParallel('closeBundle', []);
23587
- throw err;
23588
- }
23589
- await graph.pluginDriver.hookParallel('buildEnd', []);
23614
+ catch (err) {
23615
+ const watchFiles = Object.keys(graph.watchFiles);
23616
+ if (watchFiles.length > 0) {
23617
+ err.watchFiles = watchFiles;
23618
+ }
23619
+ await graph.pluginDriver.hookParallel('buildEnd', [err]);
23620
+ await graph.pluginDriver.hookParallel('closeBundle', []);
23621
+ throw err;
23622
+ }
23623
+ await graph.pluginDriver.hookParallel('buildEnd', []);
23624
+ });
23590
23625
  timeEnd('BUILD', 1);
23591
23626
  const result = {
23592
23627
  cache: useCache ? graph.getCache() : undefined,
@@ -23637,21 +23672,23 @@ function normalizePlugins(plugins, anonymousPrefix) {
23637
23672
  }
23638
23673
  });
23639
23674
  }
23640
- async function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
23675
+ function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
23641
23676
  const { options: outputOptions, outputPluginDriver, unsetOptions } = getOutputOptionsAndPluginDriver(rawOutputOptions, graph.pluginDriver, inputOptions, unsetInputOptions);
23642
- const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
23643
- const generated = await bundle.generate(isWrite);
23644
- if (isWrite) {
23645
- if (!outputOptions.dir && !outputOptions.file) {
23646
- return error({
23647
- code: 'MISSING_OPTION',
23648
- message: 'You must specify "output.file" or "output.dir" for the build.'
23649
- });
23677
+ return catchUnfinishedHookActions(outputPluginDriver, async () => {
23678
+ const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
23679
+ const generated = await bundle.generate(isWrite);
23680
+ if (isWrite) {
23681
+ if (!outputOptions.dir && !outputOptions.file) {
23682
+ return error({
23683
+ code: 'MISSING_OPTION',
23684
+ message: 'You must specify "output.file" or "output.dir" for the build.'
23685
+ });
23686
+ }
23687
+ await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions)));
23688
+ await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
23650
23689
  }
23651
- await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions)));
23652
- await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
23653
- }
23654
- return createOutput(generated);
23690
+ return createOutput(generated);
23691
+ });
23655
23692
  }
23656
23693
  function getOutputOptionsAndPluginDriver(rawOutputOptions, inputPluginDriver, inputOptions, unsetInputOptions) {
23657
23694
  if (!rawOutputOptions) {
@@ -23740,12 +23777,30 @@ function defineConfig(options) {
23740
23777
  class WatchEmitter extends require$$0$2.EventEmitter {
23741
23778
  constructor() {
23742
23779
  super();
23780
+ this.awaitedHandlers = Object.create(null);
23743
23781
  // Allows more than 10 bundles to be watched without
23744
23782
  // showing the `MaxListenersExceededWarning` to the user.
23745
23783
  this.setMaxListeners(Infinity);
23746
23784
  }
23747
- close() { }
23785
+ // Will be overwritten by Rollup
23786
+ async close() { }
23787
+ emitAndAwait(event, ...args) {
23788
+ this.emit(event, ...args);
23789
+ return Promise.all(this.getHandlers(event).map(handler => handler(...args)));
23790
+ }
23791
+ onCurrentAwaited(event, listener) {
23792
+ this.getHandlers(event).push(listener);
23793
+ return this;
23794
+ }
23795
+ removeAwaited() {
23796
+ this.awaitedHandlers = {};
23797
+ return this;
23798
+ }
23799
+ getHandlers(event) {
23800
+ return this.awaitedHandlers[event] || (this.awaitedHandlers[event] = []);
23801
+ }
23748
23802
  }
23803
+
23749
23804
  function watch(configs) {
23750
23805
  const emitter = new WatchEmitter();
23751
23806
  const configArray = ensureArray$1(configs);