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.
- package/CHANGELOG.md +42 -0
- package/dist/bin/rollup +2 -3
- package/dist/es/rollup.browser.js +3 -4
- package/dist/es/rollup.js +2 -3
- package/dist/es/shared/rollup.js +1098 -1043
- package/dist/es/shared/watch.js +22 -11
- package/dist/loadConfigFile.js +2 -3
- package/dist/rollup.browser.js +3 -4
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.d.ts +46 -33
- package/dist/rollup.js +2 -3
- package/dist/shared/index.js +2 -3
- package/dist/shared/loadConfigFile.js +2 -3
- package/dist/shared/mergeOptions.js +2 -3
- package/dist/shared/rollup.js +1090 -1035
- package/dist/shared/watch-cli.js +5 -6
- package/dist/shared/watch.js +22 -11
- package/package.json +23 -25
package/dist/shared/rollup.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.
|
|
4
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
790
|
-
|
|
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
|
-
|
|
798
|
-
|
|
799
|
-
}
|
|
792
|
+
add(n) {
|
|
793
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
794
|
+
}
|
|
800
795
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
796
|
+
has(n) {
|
|
797
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
805
800
|
|
|
806
|
-
|
|
807
|
-
|
|
801
|
+
class Chunk$1 {
|
|
802
|
+
constructor(start, end, content) {
|
|
803
|
+
this.start = start;
|
|
804
|
+
this.end = end;
|
|
805
|
+
this.original = content;
|
|
808
806
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
this.edited = false;
|
|
807
|
+
this.intro = '';
|
|
808
|
+
this.outro = '';
|
|
812
809
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
next: { writable: true, value: null }
|
|
817
|
-
});
|
|
818
|
-
};
|
|
810
|
+
this.content = content;
|
|
811
|
+
this.storeName = false;
|
|
812
|
+
this.edited = false;
|
|
819
813
|
|
|
820
|
-
|
|
821
|
-
|
|
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
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
821
|
+
appendLeft(content) {
|
|
822
|
+
this.outro += content;
|
|
823
|
+
}
|
|
827
824
|
|
|
828
|
-
|
|
829
|
-
|
|
825
|
+
appendRight(content) {
|
|
826
|
+
this.intro = this.intro + content;
|
|
827
|
+
}
|
|
830
828
|
|
|
831
|
-
|
|
832
|
-
|
|
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
|
-
|
|
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
|
-
|
|
841
|
-
|
|
842
|
-
};
|
|
838
|
+
return chunk;
|
|
839
|
+
}
|
|
843
840
|
|
|
844
|
-
|
|
845
|
-
|
|
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
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
845
|
+
eachNext(fn) {
|
|
846
|
+
let chunk = this;
|
|
847
|
+
while (chunk) {
|
|
848
|
+
fn(chunk);
|
|
849
|
+
chunk = chunk.next;
|
|
850
|
+
}
|
|
857
851
|
}
|
|
858
|
-
};
|
|
859
852
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
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
|
-
|
|
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
|
-
|
|
871
|
-
};
|
|
869
|
+
this.edited = true;
|
|
872
870
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
};
|
|
871
|
+
return this;
|
|
872
|
+
}
|
|
876
873
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
}
|
|
874
|
+
prependLeft(content) {
|
|
875
|
+
this.outro = content + this.outro;
|
|
876
|
+
}
|
|
880
877
|
|
|
881
|
-
|
|
882
|
-
|
|
878
|
+
prependRight(content) {
|
|
879
|
+
this.intro = content + this.intro;
|
|
880
|
+
}
|
|
883
881
|
|
|
884
|
-
|
|
885
|
-
|
|
882
|
+
split(index) {
|
|
883
|
+
const sliceIndex = index - this.start;
|
|
886
884
|
|
|
887
|
-
|
|
885
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
886
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
888
887
|
|
|
889
|
-
|
|
890
|
-
newChunk.outro = this.outro;
|
|
891
|
-
this.outro = '';
|
|
888
|
+
this.original = originalBefore;
|
|
892
889
|
|
|
893
|
-
|
|
890
|
+
const newChunk = new Chunk$1(index, this.end, originalAfter);
|
|
891
|
+
newChunk.outro = this.outro;
|
|
892
|
+
this.outro = '';
|
|
894
893
|
|
|
895
|
-
|
|
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
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
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
|
-
|
|
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
|
-
|
|
912
|
-
|
|
913
|
-
};
|
|
909
|
+
return newChunk;
|
|
910
|
+
}
|
|
914
911
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
912
|
+
toString() {
|
|
913
|
+
return this.intro + this.content + this.outro;
|
|
914
|
+
}
|
|
918
915
|
|
|
919
|
-
|
|
916
|
+
trimEnd(rx) {
|
|
917
|
+
this.outro = this.outro.replace(rx, '');
|
|
918
|
+
if (this.outro.length) return true;
|
|
920
919
|
|
|
921
|
-
|
|
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
|
-
|
|
928
|
-
|
|
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
|
-
|
|
931
|
-
|
|
930
|
+
this.intro = this.intro.replace(rx, '');
|
|
931
|
+
if (this.intro.length) return true;
|
|
932
|
+
}
|
|
932
933
|
}
|
|
933
|
-
};
|
|
934
934
|
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
935
|
+
trimStart(rx) {
|
|
936
|
+
this.intro = this.intro.replace(rx, '');
|
|
937
|
+
if (this.intro.length) return true;
|
|
938
938
|
|
|
939
|
-
|
|
939
|
+
const trimmed = this.content.replace(rx, '');
|
|
940
940
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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
|
-
|
|
952
|
-
|
|
950
|
+
this.outro = this.outro.replace(rx, '');
|
|
951
|
+
if (this.outro.length) return true;
|
|
952
|
+
}
|
|
953
953
|
}
|
|
954
|
-
}
|
|
954
|
+
}
|
|
955
955
|
|
|
956
|
-
|
|
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 =
|
|
960
|
+
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
961
961
|
} else if (typeof Buffer === 'function') {
|
|
962
|
-
btoa =
|
|
962
|
+
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
963
963
|
}
|
|
964
964
|
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
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
|
-
|
|
975
|
-
|
|
976
|
-
}
|
|
975
|
+
toString() {
|
|
976
|
+
return JSON.stringify(this);
|
|
977
|
+
}
|
|
977
978
|
|
|
978
|
-
|
|
979
|
-
|
|
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
|
-
|
|
985
|
+
const lines = code.split('\n');
|
|
984
986
|
|
|
985
|
-
|
|
986
|
-
|
|
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
|
-
|
|
1001
|
-
|
|
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
|
-
|
|
1010
|
-
|
|
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
|
-
|
|
1021
|
-
while (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
|
-
|
|
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
|
-
|
|
1035
|
-
|
|
1036
|
+
const originalLines = source.split('\n');
|
|
1037
|
+
const lineOffsets = [];
|
|
1036
1038
|
|
|
1037
|
-
for (
|
|
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
|
-
|
|
1044
|
-
|
|
1045
|
+
let i = 0;
|
|
1046
|
+
let j = lineOffsets.length;
|
|
1045
1047
|
while (i < j) {
|
|
1046
|
-
|
|
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
|
-
|
|
1054
|
-
|
|
1055
|
-
return { line
|
|
1055
|
+
const line = i - 1;
|
|
1056
|
+
const column = index - lineOffsets[line];
|
|
1057
|
+
return { line, column };
|
|
1056
1058
|
};
|
|
1057
1059
|
}
|
|
1058
1060
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
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
|
-
|
|
1075
|
-
|
|
1076
|
-
this.
|
|
1081
|
+
|
|
1082
|
+
this.advance(content);
|
|
1083
|
+
this.pending = null;
|
|
1077
1084
|
}
|
|
1078
1085
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1086
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
1087
|
+
let originalCharIndex = chunk.start;
|
|
1088
|
+
let first = true;
|
|
1082
1089
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1111
|
+
this.pending = null;
|
|
1106
1112
|
}
|
|
1107
1113
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
Mappings.prototype.advance = function advance (str) {
|
|
1112
|
-
if (!str) { return; }
|
|
1114
|
+
advance(str) {
|
|
1115
|
+
if (!str) return;
|
|
1113
1116
|
|
|
1114
|
-
|
|
1117
|
+
const lines = str.split('\n');
|
|
1115
1118
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
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
|
-
|
|
1125
|
-
}
|
|
1127
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1126
1130
|
|
|
1127
|
-
|
|
1131
|
+
const n = '\n';
|
|
1128
1132
|
|
|
1129
|
-
|
|
1133
|
+
const warned = {
|
|
1130
1134
|
insertLeft: false,
|
|
1131
1135
|
insertRight: false,
|
|
1132
|
-
storeName: false
|
|
1133
|
-
};
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
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
|
-
|
|
1172
|
-
|
|
1159
|
+
this.byStart[0] = chunk;
|
|
1160
|
+
this.byEnd[string.length] = chunk;
|
|
1161
|
+
}
|
|
1173
1162
|
|
|
1174
|
-
|
|
1163
|
+
addSourcemapLocation(char) {
|
|
1164
|
+
this.sourcemapLocations.add(char);
|
|
1165
|
+
}
|
|
1175
1166
|
|
|
1176
|
-
|
|
1167
|
+
append(content) {
|
|
1168
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
1177
1169
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
} else {
|
|
1181
|
-
this.intro += content;
|
|
1170
|
+
this.outro += content;
|
|
1171
|
+
return this;
|
|
1182
1172
|
}
|
|
1183
|
-
return this;
|
|
1184
|
-
};
|
|
1185
1173
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1174
|
+
appendLeft(index, content) {
|
|
1175
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1188
1176
|
|
|
1189
|
-
|
|
1177
|
+
this._split(index);
|
|
1190
1178
|
|
|
1191
|
-
|
|
1179
|
+
const chunk = this.byEnd[index];
|
|
1192
1180
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
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
|
-
|
|
1205
|
-
|
|
1189
|
+
appendRight(index, content) {
|
|
1190
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1206
1191
|
|
|
1207
|
-
|
|
1208
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1209
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1192
|
+
this._split(index);
|
|
1210
1193
|
|
|
1211
|
-
|
|
1212
|
-
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1194
|
+
const chunk = this.byStart[index];
|
|
1213
1195
|
|
|
1214
|
-
if (
|
|
1215
|
-
|
|
1216
|
-
|
|
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
|
-
|
|
1204
|
+
clone() {
|
|
1205
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
1225
1206
|
|
|
1226
|
-
|
|
1227
|
-
cloned.
|
|
1228
|
-
}
|
|
1207
|
+
let originalChunk = this.firstChunk;
|
|
1208
|
+
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
1229
1209
|
|
|
1230
|
-
|
|
1210
|
+
while (originalChunk) {
|
|
1211
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1212
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1231
1213
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1214
|
+
const nextOriginalChunk = originalChunk.next;
|
|
1215
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1234
1216
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1217
|
+
if (nextClonedChunk) {
|
|
1218
|
+
clonedChunk.next = nextClonedChunk;
|
|
1219
|
+
nextClonedChunk.previous = clonedChunk;
|
|
1220
|
+
|
|
1221
|
+
clonedChunk = nextClonedChunk;
|
|
1222
|
+
}
|
|
1237
1223
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1224
|
+
originalChunk = nextOriginalChunk;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
cloned.lastChunk = clonedChunk;
|
|
1240
1228
|
|
|
1241
|
-
|
|
1229
|
+
if (this.indentExclusionRanges) {
|
|
1230
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
1231
|
+
}
|
|
1242
1232
|
|
|
1243
|
-
|
|
1244
|
-
var names = Object.keys(this.storedNames);
|
|
1245
|
-
var mappings = new Mappings(options.hires);
|
|
1233
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
1246
1234
|
|
|
1247
|
-
|
|
1235
|
+
cloned.intro = this.intro;
|
|
1236
|
+
cloned.outro = this.outro;
|
|
1248
1237
|
|
|
1249
|
-
|
|
1250
|
-
mappings.advance(this.intro);
|
|
1238
|
+
return cloned;
|
|
1251
1239
|
}
|
|
1252
1240
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1241
|
+
generateDecodedMap(options) {
|
|
1242
|
+
options = options || {};
|
|
1255
1243
|
|
|
1256
|
-
|
|
1244
|
+
const sourceIndex = 0;
|
|
1245
|
+
const names = Object.keys(this.storedNames);
|
|
1246
|
+
const mappings = new Mappings(options.hires);
|
|
1257
1247
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
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
|
-
|
|
1270
|
-
|
|
1254
|
+
this.firstChunk.eachNext((chunk) => {
|
|
1255
|
+
const loc = locate(chunk.start);
|
|
1271
1256
|
|
|
1272
|
-
|
|
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
|
-
|
|
1282
|
-
|
|
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
|
-
|
|
1286
|
-
|
|
1287
|
-
};
|
|
1270
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1271
|
+
});
|
|
1288
1272
|
|
|
1289
|
-
|
|
1290
|
-
|
|
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
|
-
|
|
1293
|
-
|
|
1294
|
-
indentStr = undefined;
|
|
1282
|
+
generateMap(options) {
|
|
1283
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
1295
1284
|
}
|
|
1296
1285
|
|
|
1297
|
-
|
|
1286
|
+
getIndentString() {
|
|
1287
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
1288
|
+
}
|
|
1298
1289
|
|
|
1299
|
-
|
|
1290
|
+
indent(indentStr, options) {
|
|
1291
|
+
const pattern = /^[^\r\n]/gm;
|
|
1300
1292
|
|
|
1301
|
-
|
|
1293
|
+
if (isObject$1(indentStr)) {
|
|
1294
|
+
options = indentStr;
|
|
1295
|
+
indentStr = undefined;
|
|
1296
|
+
}
|
|
1302
1297
|
|
|
1303
|
-
|
|
1304
|
-
var isExcluded = {};
|
|
1298
|
+
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
|
1305
1299
|
|
|
1306
|
-
|
|
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
|
-
|
|
1317
|
-
var replacer = function (match) {
|
|
1318
|
-
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
1319
|
-
shouldIndentNextCharacter = true;
|
|
1320
|
-
return match;
|
|
1321
|
-
};
|
|
1302
|
+
options = options || {};
|
|
1322
1303
|
|
|
1323
|
-
|
|
1304
|
+
// Process exclusion ranges
|
|
1305
|
+
const isExcluded = {};
|
|
1324
1306
|
|
|
1325
|
-
|
|
1326
|
-
|
|
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
|
-
|
|
1329
|
-
|
|
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
|
-
|
|
1332
|
-
if (!isExcluded[charIndex]) {
|
|
1333
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
1324
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
1334
1325
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
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
|
-
|
|
1332
|
+
if (chunk.edited) {
|
|
1343
1333
|
if (!isExcluded[charIndex]) {
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
if (
|
|
1347
|
-
shouldIndentNextCharacter =
|
|
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
|
-
|
|
1362
|
+
charIndex += 1;
|
|
1363
|
+
}
|
|
1362
1364
|
}
|
|
1365
|
+
|
|
1366
|
+
charIndex = chunk.end;
|
|
1367
|
+
chunk = chunk.next;
|
|
1363
1368
|
}
|
|
1364
1369
|
|
|
1365
|
-
|
|
1366
|
-
chunk = chunk.next;
|
|
1367
|
-
}
|
|
1370
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
1368
1371
|
|
|
1369
|
-
|
|
1372
|
+
return this;
|
|
1373
|
+
}
|
|
1370
1374
|
|
|
1371
|
-
|
|
1372
|
-
|
|
1375
|
+
insert() {
|
|
1376
|
+
throw new Error(
|
|
1377
|
+
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1373
1380
|
|
|
1374
|
-
|
|
1375
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1394
|
-
|
|
1403
|
+
move(start, end, index) {
|
|
1404
|
+
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
1395
1405
|
|
|
1396
|
-
|
|
1397
|
-
|
|
1406
|
+
this._split(start);
|
|
1407
|
+
this._split(end);
|
|
1408
|
+
this._split(index);
|
|
1398
1409
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
this._split(index);
|
|
1410
|
+
const first = this.byStart[start];
|
|
1411
|
+
const last = this.byEnd[end];
|
|
1402
1412
|
|
|
1403
|
-
|
|
1404
|
-
|
|
1413
|
+
const oldLeft = first.previous;
|
|
1414
|
+
const oldRight = last.next;
|
|
1405
1415
|
|
|
1406
|
-
|
|
1407
|
-
|
|
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
|
-
|
|
1410
|
-
|
|
1411
|
-
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
1420
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
1421
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
1412
1422
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1423
|
+
if (newLeft) newLeft.next = first;
|
|
1424
|
+
if (newRight) newRight.previous = last;
|
|
1415
1425
|
|
|
1416
|
-
|
|
1417
|
-
|
|
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
|
-
|
|
1420
|
-
|
|
1421
|
-
this.lastChunk = first.previous;
|
|
1422
|
-
this.lastChunk.next = null;
|
|
1423
|
-
}
|
|
1432
|
+
first.previous = newLeft;
|
|
1433
|
+
last.next = newRight || null;
|
|
1424
1434
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1435
|
+
if (!newLeft) this.firstChunk = first;
|
|
1436
|
+
if (!newRight) this.lastChunk = last;
|
|
1437
|
+
return this;
|
|
1438
|
+
}
|
|
1427
1439
|
|
|
1428
|
-
|
|
1429
|
-
|
|
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
|
-
|
|
1434
|
-
|
|
1443
|
+
while (start < 0) start += this.original.length;
|
|
1444
|
+
while (end < 0) end += this.original.length;
|
|
1435
1445
|
|
|
1436
|
-
|
|
1437
|
-
|
|
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
|
-
|
|
1440
|
-
|
|
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
|
-
|
|
1444
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
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
|
|
1477
|
+
const first = this.byStart[start];
|
|
1478
|
+
const last = this.byEnd[end];
|
|
1471
1479
|
|
|
1472
|
-
if (first
|
|
1473
|
-
|
|
1480
|
+
if (first) {
|
|
1481
|
+
let chunk = first;
|
|
1474
1482
|
while (chunk !== last) {
|
|
1475
|
-
chunk.
|
|
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
|
-
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
|
|
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
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1515
|
-
|
|
1509
|
+
prependLeft(index, content) {
|
|
1510
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1516
1511
|
|
|
1517
|
-
|
|
1512
|
+
this._split(index);
|
|
1518
1513
|
|
|
1519
|
-
|
|
1514
|
+
const chunk = this.byEnd[index];
|
|
1520
1515
|
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
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
|
-
|
|
1524
|
+
prependRight(index, content) {
|
|
1525
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1534
1526
|
|
|
1535
|
-
|
|
1536
|
-
if (start > end) { throw new Error('end must be greater than start'); }
|
|
1527
|
+
this._split(index);
|
|
1537
1528
|
|
|
1538
|
-
|
|
1539
|
-
this._split(end);
|
|
1529
|
+
const chunk = this.byStart[index];
|
|
1540
1530
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
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 (
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
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
|
-
|
|
1605
|
-
|
|
1606
|
-
if ( end === void 0 ) end = this.original.length;
|
|
1548
|
+
this._split(start);
|
|
1549
|
+
this._split(end);
|
|
1607
1550
|
|
|
1608
|
-
|
|
1609
|
-
while (end < 0) { end += this.original.length; }
|
|
1551
|
+
let chunk = this.byStart[start];
|
|
1610
1552
|
|
|
1611
|
-
|
|
1553
|
+
while (chunk) {
|
|
1554
|
+
chunk.intro = '';
|
|
1555
|
+
chunk.outro = '';
|
|
1556
|
+
chunk.edit('');
|
|
1612
1557
|
|
|
1613
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1625
|
-
|
|
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
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
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
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
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
|
-
|
|
1638
|
-
|
|
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
|
|
1608
|
+
let result = '';
|
|
1641
1609
|
|
|
1642
|
-
|
|
1643
|
-
|
|
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
|
-
|
|
1647
|
-
break;
|
|
1618
|
+
chunk = chunk.next;
|
|
1648
1619
|
}
|
|
1649
1620
|
|
|
1650
|
-
chunk
|
|
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
|
-
|
|
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
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1666
|
-
if (this.byStart[index] || this.byEnd[index]) { return; }
|
|
1637
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1667
1638
|
|
|
1668
|
-
|
|
1669
|
-
|
|
1639
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
1640
|
+
result += chunk.outro;
|
|
1641
|
+
}
|
|
1670
1642
|
|
|
1671
|
-
|
|
1672
|
-
|
|
1643
|
+
if (containsEnd) {
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1673
1646
|
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
};
|
|
1647
|
+
chunk = chunk.next;
|
|
1648
|
+
}
|
|
1677
1649
|
|
|
1678
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1690
|
-
|
|
1691
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1659
|
+
return clone;
|
|
1660
|
+
}
|
|
1692
1661
|
|
|
1693
|
-
|
|
1662
|
+
_split(index) {
|
|
1663
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1694
1664
|
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
};
|
|
1665
|
+
let chunk = this.lastSearchedChunk;
|
|
1666
|
+
const searchForward = index > chunk.end;
|
|
1698
1667
|
|
|
1699
|
-
|
|
1700
|
-
|
|
1668
|
+
while (chunk) {
|
|
1669
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1701
1670
|
|
|
1702
|
-
|
|
1703
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
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
|
-
|
|
1732
|
-
return this.trim('[\\r\\n]');
|
|
1733
|
-
};
|
|
1690
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1734
1691
|
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
}
|
|
1692
|
+
this.lastSearchedChunk = chunk;
|
|
1693
|
+
return true;
|
|
1694
|
+
}
|
|
1738
1695
|
|
|
1739
|
-
|
|
1740
|
-
|
|
1696
|
+
toString() {
|
|
1697
|
+
let str = this.intro;
|
|
1741
1698
|
|
|
1742
|
-
|
|
1743
|
-
|
|
1699
|
+
let chunk = this.firstChunk;
|
|
1700
|
+
while (chunk) {
|
|
1701
|
+
str += chunk.toString();
|
|
1702
|
+
chunk = chunk.next;
|
|
1703
|
+
}
|
|
1744
1704
|
|
|
1745
|
-
|
|
1705
|
+
return str + this.outro;
|
|
1706
|
+
}
|
|
1746
1707
|
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
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
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
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
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
}
|
|
1730
|
+
trimLines() {
|
|
1731
|
+
return this.trim('[\\r\\n]');
|
|
1732
|
+
}
|
|
1761
1733
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
}
|
|
1734
|
+
trim(charType) {
|
|
1735
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1736
|
+
}
|
|
1765
1737
|
|
|
1766
|
-
|
|
1767
|
-
|
|
1738
|
+
trimEndAborted(charType) {
|
|
1739
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1768
1740
|
|
|
1769
|
-
|
|
1770
|
-
|
|
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
|
-
|
|
1777
|
-
if (this.intro.length) { return true; }
|
|
1744
|
+
let chunk = this.lastChunk;
|
|
1778
1745
|
|
|
1779
|
-
|
|
1746
|
+
do {
|
|
1747
|
+
const end = chunk.end;
|
|
1748
|
+
const aborted = chunk.trimEnd(rx);
|
|
1780
1749
|
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
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
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
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
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
}
|
|
1761
|
+
if (aborted) return true;
|
|
1762
|
+
chunk = chunk.previous;
|
|
1763
|
+
} while (chunk);
|
|
1793
1764
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
} while (chunk);
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1797
1767
|
|
|
1798
|
-
|
|
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
|
-
|
|
1802
|
-
|
|
1803
|
-
return this;
|
|
1804
|
-
};
|
|
1775
|
+
this.intro = this.intro.replace(rx, '');
|
|
1776
|
+
if (this.intro.length) return true;
|
|
1805
1777
|
|
|
1806
|
-
|
|
1778
|
+
let chunk = this.firstChunk;
|
|
1807
1779
|
|
|
1808
|
-
|
|
1809
|
-
|
|
1780
|
+
do {
|
|
1781
|
+
const end = chunk.end;
|
|
1782
|
+
const aborted = chunk.trimStart(rx);
|
|
1810
1783
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
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
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1800
|
+
trimStart(charType) {
|
|
1801
|
+
this.trimStartAborted(charType);
|
|
1802
|
+
return this;
|
|
1803
|
+
}
|
|
1834
1804
|
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
source.separator = this.separator;
|
|
1805
|
+
hasChanged() {
|
|
1806
|
+
return this.original !== this.toString();
|
|
1838
1807
|
}
|
|
1839
1808
|
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
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
|
-
|
|
1853
|
-
return this;
|
|
1854
|
-
};
|
|
1855
|
+
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1855
1856
|
|
|
1856
|
-
Bundle$1
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
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
|
-
|
|
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
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
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
|
-
|
|
1872
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1902
|
+
this.sources.push(source);
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1885
1905
|
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1906
|
+
append(str, options) {
|
|
1907
|
+
this.addSource({
|
|
1908
|
+
content: new MagicString(str),
|
|
1909
|
+
separator: (options && options.separator) || '',
|
|
1890
1910
|
});
|
|
1891
|
-
});
|
|
1892
1911
|
|
|
1893
|
-
|
|
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
|
-
|
|
1896
|
-
|
|
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
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
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
|
-
|
|
1905
|
-
var magicString = source.content;
|
|
1906
|
-
var locate = getLocator(magicString.original);
|
|
1940
|
+
const mappings = new Mappings(options.hires);
|
|
1907
1941
|
|
|
1908
|
-
if (
|
|
1909
|
-
mappings.advance(
|
|
1942
|
+
if (this.intro) {
|
|
1943
|
+
mappings.advance(this.intro);
|
|
1910
1944
|
}
|
|
1911
1945
|
|
|
1912
|
-
|
|
1913
|
-
|
|
1946
|
+
this.sources.forEach((source, i) => {
|
|
1947
|
+
if (i > 0) {
|
|
1948
|
+
mappings.advance(this.separator);
|
|
1949
|
+
}
|
|
1914
1950
|
|
|
1915
|
-
|
|
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 (
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
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.
|
|
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
|
-
|
|
1939
|
-
|
|
1985
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1986
|
+
});
|
|
1940
1987
|
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1988
|
+
if (magicString.outro) {
|
|
1989
|
+
mappings.advance(magicString.outro);
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1945
1992
|
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
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
|
-
|
|
1960
|
-
|
|
1961
|
-
}
|
|
2006
|
+
generateMap(options) {
|
|
2007
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
2008
|
+
}
|
|
1962
2009
|
|
|
1963
|
-
|
|
1964
|
-
|
|
2010
|
+
getIndentString() {
|
|
2011
|
+
const indentStringCounts = {};
|
|
1965
2012
|
|
|
1966
|
-
|
|
1967
|
-
|
|
2013
|
+
this.sources.forEach((source) => {
|
|
2014
|
+
const indentStr = source.content.indentStr;
|
|
1968
2015
|
|
|
1969
|
-
|
|
2016
|
+
if (indentStr === null) return;
|
|
1970
2017
|
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
2018
|
+
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
2019
|
+
indentStringCounts[indentStr] += 1;
|
|
2020
|
+
});
|
|
1974
2021
|
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
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
|
-
|
|
1983
|
-
|
|
2029
|
+
indent(indentStr) {
|
|
2030
|
+
if (!arguments.length) {
|
|
2031
|
+
indentStr = this.getIndentString();
|
|
2032
|
+
}
|
|
1984
2033
|
|
|
1985
|
-
|
|
1986
|
-
indentStr = this.getIndentString();
|
|
1987
|
-
}
|
|
2034
|
+
if (indentStr === '') return this; // noop
|
|
1988
2035
|
|
|
1989
|
-
|
|
2036
|
+
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1990
2037
|
|
|
1991
|
-
|
|
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
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2014
|
-
|
|
2061
|
+
prepend(str) {
|
|
2062
|
+
this.intro = str + this.intro;
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2015
2065
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
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
|
-
|
|
2022
|
-
|
|
2072
|
+
return str;
|
|
2073
|
+
})
|
|
2074
|
+
.join('');
|
|
2023
2075
|
|
|
2024
|
-
|
|
2025
|
-
|
|
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
|
-
|
|
2030
|
-
|
|
2031
|
-
.
|
|
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
|
-
|
|
2034
|
-
|
|
2085
|
+
length() {
|
|
2086
|
+
return this.sources.reduce(
|
|
2087
|
+
(length, source) => length + source.content.length(),
|
|
2088
|
+
this.intro.length
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2035
2091
|
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
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
|
-
|
|
2045
|
-
|
|
2046
|
-
}
|
|
2096
|
+
trim(charType) {
|
|
2097
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
2098
|
+
}
|
|
2047
2099
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2100
|
+
trimStart(charType) {
|
|
2101
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
2102
|
+
this.intro = this.intro.replace(rx, '');
|
|
2051
2103
|
|
|
2052
|
-
|
|
2053
|
-
|
|
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
|
-
|
|
2057
|
-
|
|
2058
|
-
this.intro = this.intro.replace(rx, '');
|
|
2119
|
+
trimEnd(charType) {
|
|
2120
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
2059
2121
|
|
|
2060
|
-
|
|
2061
|
-
|
|
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.
|
|
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
|
-
|
|
2079
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
22833
|
-
return promise.then(() => {
|
|
22838
|
+
return Promise.resolve(hookResult).then(result => {
|
|
22834
22839
|
// action was fulfilled
|
|
22835
|
-
|
|
22836
|
-
return
|
|
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
|
-
|
|
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.
|
|
22932
|
-
const handleClose = () => this.pluginDriver.
|
|
22933
|
-
watcher.
|
|
22934
|
-
watcher.
|
|
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
|
-
|
|
23577
|
-
|
|
23578
|
-
|
|
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
|
-
|
|
23586
|
-
|
|
23587
|
-
|
|
23588
|
-
|
|
23589
|
-
|
|
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
|
-
|
|
23675
|
+
function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
|
|
23641
23676
|
const { options: outputOptions, outputPluginDriver, unsetOptions } = getOutputOptionsAndPluginDriver(rawOutputOptions, graph.pluginDriver, inputOptions, unsetInputOptions);
|
|
23642
|
-
|
|
23643
|
-
|
|
23644
|
-
|
|
23645
|
-
if (
|
|
23646
|
-
|
|
23647
|
-
|
|
23648
|
-
|
|
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
|
-
|
|
23652
|
-
|
|
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
|
-
|
|
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);
|