rollup 2.70.1 → 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 +12 -0
- package/dist/bin/rollup +2 -2
- package/dist/es/rollup.browser.js +3 -3
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/rollup.js +996 -952
- package/dist/es/shared/watch.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.d.ts +13 -17
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +996 -952
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +19 -19
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.70.
|
|
4
|
-
|
|
3
|
+
Rollup.js v2.70.2
|
|
4
|
+
Fri, 15 Apr 2022 05:14:21 GMT - commit 030c56fd6b186a0ddfd57d143ad703f34fd2c17a
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
27
27
|
return n;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version$1 = "2.70.
|
|
30
|
+
var version$1 = "2.70.2";
|
|
31
31
|
|
|
32
32
|
function ensureArray$1(items) {
|
|
33
33
|
if (Array.isArray(items)) {
|
|
@@ -608,8 +608,7 @@ const objectifyOptionWithPresets = (presets, optionName, additionalValues) => (v
|
|
|
608
608
|
return objectifyOption(value);
|
|
609
609
|
};
|
|
610
610
|
const getOptionWithPreset = (value, presets, optionName, additionalValues) => {
|
|
611
|
-
|
|
612
|
-
const presetName = (_a = value) === null || _a === void 0 ? void 0 : _a.preset;
|
|
611
|
+
const presetName = value === null || value === void 0 ? void 0 : value.preset;
|
|
613
612
|
if (presetName) {
|
|
614
613
|
const preset = presets[presetName];
|
|
615
614
|
if (preset) {
|
|
@@ -785,204 +784,208 @@ function encodeInteger(num) {
|
|
|
785
784
|
return result;
|
|
786
785
|
}
|
|
787
786
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
BitSet.prototype.add = function add (n) {
|
|
793
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
794
|
-
};
|
|
787
|
+
class BitSet {
|
|
788
|
+
constructor(arg) {
|
|
789
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
790
|
+
}
|
|
795
791
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
792
|
+
add(n) {
|
|
793
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
794
|
+
}
|
|
799
795
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
796
|
+
has(n) {
|
|
797
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
804
800
|
|
|
805
|
-
|
|
806
|
-
|
|
801
|
+
class Chunk$1 {
|
|
802
|
+
constructor(start, end, content) {
|
|
803
|
+
this.start = start;
|
|
804
|
+
this.end = end;
|
|
805
|
+
this.original = content;
|
|
807
806
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
this.edited = false;
|
|
807
|
+
this.intro = '';
|
|
808
|
+
this.outro = '';
|
|
811
809
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
next: { writable: true, value: null }
|
|
816
|
-
});
|
|
817
|
-
};
|
|
810
|
+
this.content = content;
|
|
811
|
+
this.storeName = false;
|
|
812
|
+
this.edited = false;
|
|
818
813
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
}
|
|
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
|
+
}
|
|
822
820
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
}
|
|
821
|
+
appendLeft(content) {
|
|
822
|
+
this.outro += content;
|
|
823
|
+
}
|
|
826
824
|
|
|
827
|
-
|
|
828
|
-
|
|
825
|
+
appendRight(content) {
|
|
826
|
+
this.intro = this.intro + content;
|
|
827
|
+
}
|
|
829
828
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
chunk.content = this.content;
|
|
833
|
-
chunk.storeName = this.storeName;
|
|
834
|
-
chunk.edited = this.edited;
|
|
829
|
+
clone() {
|
|
830
|
+
const chunk = new Chunk$1(this.start, this.end, this.original);
|
|
835
831
|
|
|
836
|
-
|
|
837
|
-
|
|
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;
|
|
838
837
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
};
|
|
838
|
+
return chunk;
|
|
839
|
+
}
|
|
842
840
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
while (chunk) {
|
|
846
|
-
fn(chunk);
|
|
847
|
-
chunk = chunk.next;
|
|
841
|
+
contains(index) {
|
|
842
|
+
return this.start < index && index < this.end;
|
|
848
843
|
}
|
|
849
|
-
};
|
|
850
844
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
845
|
+
eachNext(fn) {
|
|
846
|
+
let chunk = this;
|
|
847
|
+
while (chunk) {
|
|
848
|
+
fn(chunk);
|
|
849
|
+
chunk = chunk.next;
|
|
850
|
+
}
|
|
856
851
|
}
|
|
857
|
-
};
|
|
858
852
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
853
|
+
eachPrevious(fn) {
|
|
854
|
+
let chunk = this;
|
|
855
|
+
while (chunk) {
|
|
856
|
+
fn(chunk);
|
|
857
|
+
chunk = chunk.previous;
|
|
858
|
+
}
|
|
864
859
|
}
|
|
865
|
-
this.storeName = storeName;
|
|
866
860
|
|
|
867
|
-
|
|
861
|
+
edit(content, storeName, contentOnly) {
|
|
862
|
+
this.content = content;
|
|
863
|
+
if (!contentOnly) {
|
|
864
|
+
this.intro = '';
|
|
865
|
+
this.outro = '';
|
|
866
|
+
}
|
|
867
|
+
this.storeName = storeName;
|
|
868
868
|
|
|
869
|
-
|
|
870
|
-
};
|
|
869
|
+
this.edited = true;
|
|
871
870
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
};
|
|
871
|
+
return this;
|
|
872
|
+
}
|
|
875
873
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}
|
|
874
|
+
prependLeft(content) {
|
|
875
|
+
this.outro = content + this.outro;
|
|
876
|
+
}
|
|
879
877
|
|
|
880
|
-
|
|
881
|
-
|
|
878
|
+
prependRight(content) {
|
|
879
|
+
this.intro = content + this.intro;
|
|
880
|
+
}
|
|
882
881
|
|
|
883
|
-
|
|
884
|
-
|
|
882
|
+
split(index) {
|
|
883
|
+
const sliceIndex = index - this.start;
|
|
885
884
|
|
|
886
|
-
|
|
885
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
886
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
887
887
|
|
|
888
|
-
|
|
889
|
-
newChunk.outro = this.outro;
|
|
890
|
-
this.outro = '';
|
|
888
|
+
this.original = originalBefore;
|
|
891
889
|
|
|
892
|
-
|
|
890
|
+
const newChunk = new Chunk$1(index, this.end, originalAfter);
|
|
891
|
+
newChunk.outro = this.outro;
|
|
892
|
+
this.outro = '';
|
|
893
893
|
|
|
894
|
-
|
|
895
|
-
// TODO is this block necessary?...
|
|
896
|
-
newChunk.edit('', false);
|
|
897
|
-
this.content = '';
|
|
898
|
-
} else {
|
|
899
|
-
this.content = originalBefore;
|
|
900
|
-
}
|
|
894
|
+
this.end = index;
|
|
901
895
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
896
|
+
if (this.edited) {
|
|
897
|
+
// TODO is this block necessary?...
|
|
898
|
+
newChunk.edit('', false);
|
|
899
|
+
this.content = '';
|
|
900
|
+
} else {
|
|
901
|
+
this.content = originalBefore;
|
|
902
|
+
}
|
|
906
903
|
|
|
907
|
-
|
|
908
|
-
|
|
904
|
+
newChunk.next = this.next;
|
|
905
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
906
|
+
newChunk.previous = this;
|
|
907
|
+
this.next = newChunk;
|
|
909
908
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
};
|
|
909
|
+
return newChunk;
|
|
910
|
+
}
|
|
913
911
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
912
|
+
toString() {
|
|
913
|
+
return this.intro + this.content + this.outro;
|
|
914
|
+
}
|
|
917
915
|
|
|
918
|
-
|
|
916
|
+
trimEnd(rx) {
|
|
917
|
+
this.outro = this.outro.replace(rx, '');
|
|
918
|
+
if (this.outro.length) return true;
|
|
919
919
|
|
|
920
|
-
|
|
921
|
-
if (trimmed !== this.content) {
|
|
922
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
923
|
-
}
|
|
924
|
-
return true;
|
|
920
|
+
const trimmed = this.content.replace(rx, '');
|
|
925
921
|
|
|
926
|
-
|
|
927
|
-
|
|
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);
|
|
928
929
|
|
|
929
|
-
|
|
930
|
-
|
|
930
|
+
this.intro = this.intro.replace(rx, '');
|
|
931
|
+
if (this.intro.length) return true;
|
|
932
|
+
}
|
|
931
933
|
}
|
|
932
|
-
};
|
|
933
934
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
935
|
+
trimStart(rx) {
|
|
936
|
+
this.intro = this.intro.replace(rx, '');
|
|
937
|
+
if (this.intro.length) return true;
|
|
937
938
|
|
|
938
|
-
|
|
939
|
+
const trimmed = this.content.replace(rx, '');
|
|
939
940
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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 {
|
|
943
948
|
this.edit('', undefined, true);
|
|
944
|
-
}
|
|
945
|
-
return true;
|
|
946
|
-
|
|
947
|
-
} else {
|
|
948
|
-
this.edit('', undefined, true);
|
|
949
949
|
|
|
950
|
-
|
|
951
|
-
|
|
950
|
+
this.outro = this.outro.replace(rx, '');
|
|
951
|
+
if (this.outro.length) return true;
|
|
952
|
+
}
|
|
952
953
|
}
|
|
953
|
-
}
|
|
954
|
+
}
|
|
954
955
|
|
|
955
|
-
|
|
956
|
+
let btoa = () => {
|
|
956
957
|
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
957
958
|
};
|
|
958
959
|
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
959
|
-
btoa =
|
|
960
|
+
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
960
961
|
} else if (typeof Buffer === 'function') {
|
|
961
|
-
btoa =
|
|
962
|
+
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
962
963
|
}
|
|
963
964
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
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
|
+
}
|
|
972
974
|
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}
|
|
975
|
+
toString() {
|
|
976
|
+
return JSON.stringify(this);
|
|
977
|
+
}
|
|
976
978
|
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
979
|
+
toUrl() {
|
|
980
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
981
|
+
}
|
|
982
|
+
}
|
|
980
983
|
|
|
981
984
|
function guessIndent(code) {
|
|
982
|
-
|
|
985
|
+
const lines = code.split('\n');
|
|
983
986
|
|
|
984
|
-
|
|
985
|
-
|
|
987
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
988
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
986
989
|
|
|
987
990
|
if (tabbed.length === 0 && spaced.length === 0) {
|
|
988
991
|
return null;
|
|
@@ -996,8 +999,8 @@ function guessIndent(code) {
|
|
|
996
999
|
}
|
|
997
1000
|
|
|
998
1001
|
// Otherwise, we need to guess the multiple
|
|
999
|
-
|
|
1000
|
-
|
|
1002
|
+
const min = spaced.reduce((previous, current) => {
|
|
1003
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
1001
1004
|
return Math.min(numSpaces, previous);
|
|
1002
1005
|
}, Infinity);
|
|
1003
1006
|
|
|
@@ -1005,8 +1008,8 @@ function guessIndent(code) {
|
|
|
1005
1008
|
}
|
|
1006
1009
|
|
|
1007
1010
|
function getRelativePath(from, to) {
|
|
1008
|
-
|
|
1009
|
-
|
|
1011
|
+
const fromParts = from.split(/[/\\]/);
|
|
1012
|
+
const toParts = to.split(/[/\\]/);
|
|
1010
1013
|
|
|
1011
1014
|
fromParts.pop(); // get dirname
|
|
1012
1015
|
|
|
@@ -1016,1079 +1019,1120 @@ function getRelativePath(from, to) {
|
|
|
1016
1019
|
}
|
|
1017
1020
|
|
|
1018
1021
|
if (fromParts.length) {
|
|
1019
|
-
|
|
1020
|
-
while (i--)
|
|
1022
|
+
let i = fromParts.length;
|
|
1023
|
+
while (i--) fromParts[i] = '..';
|
|
1021
1024
|
}
|
|
1022
1025
|
|
|
1023
1026
|
return fromParts.concat(toParts).join('/');
|
|
1024
1027
|
}
|
|
1025
1028
|
|
|
1026
|
-
|
|
1029
|
+
const toString$1 = Object.prototype.toString;
|
|
1027
1030
|
|
|
1028
1031
|
function isObject$1(thing) {
|
|
1029
1032
|
return toString$1.call(thing) === '[object Object]';
|
|
1030
1033
|
}
|
|
1031
1034
|
|
|
1032
1035
|
function getLocator(source) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1036
|
+
const originalLines = source.split('\n');
|
|
1037
|
+
const lineOffsets = [];
|
|
1035
1038
|
|
|
1036
|
-
for (
|
|
1039
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
1037
1040
|
lineOffsets.push(pos);
|
|
1038
1041
|
pos += originalLines[i].length + 1;
|
|
1039
1042
|
}
|
|
1040
1043
|
|
|
1041
1044
|
return function locate(index) {
|
|
1042
|
-
|
|
1043
|
-
|
|
1045
|
+
let i = 0;
|
|
1046
|
+
let j = lineOffsets.length;
|
|
1044
1047
|
while (i < j) {
|
|
1045
|
-
|
|
1048
|
+
const m = (i + j) >> 1;
|
|
1046
1049
|
if (index < lineOffsets[m]) {
|
|
1047
1050
|
j = m;
|
|
1048
1051
|
} else {
|
|
1049
1052
|
i = m + 1;
|
|
1050
1053
|
}
|
|
1051
1054
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return { line
|
|
1055
|
+
const line = i - 1;
|
|
1056
|
+
const column = index - lineOffsets[line];
|
|
1057
|
+
return { line, column };
|
|
1055
1058
|
};
|
|
1056
1059
|
}
|
|
1057
1060
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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
|
+
}
|
|
1066
1070
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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);
|
|
1072
1080
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
this.
|
|
1081
|
+
|
|
1082
|
+
this.advance(content);
|
|
1083
|
+
this.pending = null;
|
|
1076
1084
|
}
|
|
1077
1085
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1086
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
1087
|
+
let originalCharIndex = chunk.start;
|
|
1088
|
+
let first = true;
|
|
1081
1089
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
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
|
+
}
|
|
1085
1094
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
+
}
|
|
1090
1107
|
|
|
1091
|
-
|
|
1092
|
-
loc.line += 1;
|
|
1093
|
-
loc.column = 0;
|
|
1094
|
-
this.generatedCodeLine += 1;
|
|
1095
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
1096
|
-
this.generatedCodeColumn = 0;
|
|
1097
|
-
first = true;
|
|
1098
|
-
} else {
|
|
1099
|
-
loc.column += 1;
|
|
1100
|
-
this.generatedCodeColumn += 1;
|
|
1101
|
-
first = false;
|
|
1108
|
+
originalCharIndex += 1;
|
|
1102
1109
|
}
|
|
1103
1110
|
|
|
1104
|
-
|
|
1111
|
+
this.pending = null;
|
|
1105
1112
|
}
|
|
1106
1113
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
Mappings.prototype.advance = function advance (str) {
|
|
1111
|
-
if (!str) { return; }
|
|
1114
|
+
advance(str) {
|
|
1115
|
+
if (!str) return;
|
|
1112
1116
|
|
|
1113
|
-
|
|
1117
|
+
const lines = str.split('\n');
|
|
1114
1118
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
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;
|
|
1119
1125
|
}
|
|
1120
|
-
this.generatedCodeColumn = 0;
|
|
1121
|
-
}
|
|
1122
1126
|
|
|
1123
|
-
|
|
1124
|
-
}
|
|
1127
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1125
1130
|
|
|
1126
|
-
|
|
1131
|
+
const n = '\n';
|
|
1127
1132
|
|
|
1128
|
-
|
|
1133
|
+
const warned = {
|
|
1129
1134
|
insertLeft: false,
|
|
1130
1135
|
insertRight: false,
|
|
1131
|
-
storeName: false
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
this.byStart[0] = chunk;
|
|
1156
|
-
this.byEnd[string.length] = chunk;
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
|
|
1160
|
-
this.sourcemapLocations.add(char);
|
|
1161
|
-
};
|
|
1162
|
-
|
|
1163
|
-
MagicString.prototype.append = function append (content) {
|
|
1164
|
-
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
1165
|
-
|
|
1166
|
-
this.outro += content;
|
|
1167
|
-
return this;
|
|
1168
|
-
};
|
|
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
|
+
});
|
|
1169
1158
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1159
|
+
this.byStart[0] = chunk;
|
|
1160
|
+
this.byEnd[string.length] = chunk;
|
|
1161
|
+
}
|
|
1172
1162
|
|
|
1173
|
-
|
|
1163
|
+
addSourcemapLocation(char) {
|
|
1164
|
+
this.sourcemapLocations.add(char);
|
|
1165
|
+
}
|
|
1174
1166
|
|
|
1175
|
-
|
|
1167
|
+
append(content) {
|
|
1168
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
1176
1169
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
} else {
|
|
1180
|
-
this.intro += content;
|
|
1170
|
+
this.outro += content;
|
|
1171
|
+
return this;
|
|
1181
1172
|
}
|
|
1182
|
-
return this;
|
|
1183
|
-
};
|
|
1184
1173
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1174
|
+
appendLeft(index, content) {
|
|
1175
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1187
1176
|
|
|
1188
|
-
|
|
1177
|
+
this._split(index);
|
|
1189
1178
|
|
|
1190
|
-
|
|
1179
|
+
const chunk = this.byEnd[index];
|
|
1191
1180
|
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1181
|
+
if (chunk) {
|
|
1182
|
+
chunk.appendLeft(content);
|
|
1183
|
+
} else {
|
|
1184
|
+
this.intro += content;
|
|
1185
|
+
}
|
|
1186
|
+
return this;
|
|
1196
1187
|
}
|
|
1197
|
-
return this;
|
|
1198
|
-
};
|
|
1199
|
-
|
|
1200
|
-
MagicString.prototype.clone = function clone () {
|
|
1201
|
-
var cloned = new MagicString(this.original, { filename: this.filename });
|
|
1202
1188
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1189
|
+
appendRight(index, content) {
|
|
1190
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1205
1191
|
|
|
1206
|
-
|
|
1207
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1208
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1192
|
+
this._split(index);
|
|
1209
1193
|
|
|
1210
|
-
|
|
1211
|
-
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1194
|
+
const chunk = this.byStart[index];
|
|
1212
1195
|
|
|
1213
|
-
if (
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
clonedChunk = nextClonedChunk;
|
|
1196
|
+
if (chunk) {
|
|
1197
|
+
chunk.appendRight(content);
|
|
1198
|
+
} else {
|
|
1199
|
+
this.outro += content;
|
|
1218
1200
|
}
|
|
1219
|
-
|
|
1220
|
-
originalChunk = nextOriginalChunk;
|
|
1201
|
+
return this;
|
|
1221
1202
|
}
|
|
1222
1203
|
|
|
1223
|
-
|
|
1204
|
+
clone() {
|
|
1205
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
1224
1206
|
|
|
1225
|
-
|
|
1226
|
-
cloned.
|
|
1227
|
-
}
|
|
1207
|
+
let originalChunk = this.firstChunk;
|
|
1208
|
+
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
1228
1209
|
|
|
1229
|
-
|
|
1210
|
+
while (originalChunk) {
|
|
1211
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1212
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1230
1213
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1214
|
+
const nextOriginalChunk = originalChunk.next;
|
|
1215
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1233
1216
|
|
|
1234
|
-
|
|
1235
|
-
|
|
1217
|
+
if (nextClonedChunk) {
|
|
1218
|
+
clonedChunk.next = nextClonedChunk;
|
|
1219
|
+
nextClonedChunk.previous = clonedChunk;
|
|
1236
1220
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1221
|
+
clonedChunk = nextClonedChunk;
|
|
1222
|
+
}
|
|
1239
1223
|
|
|
1240
|
-
|
|
1224
|
+
originalChunk = nextOriginalChunk;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
cloned.lastChunk = clonedChunk;
|
|
1228
|
+
|
|
1229
|
+
if (this.indentExclusionRanges) {
|
|
1230
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
1231
|
+
}
|
|
1241
1232
|
|
|
1242
|
-
|
|
1243
|
-
var names = Object.keys(this.storedNames);
|
|
1244
|
-
var mappings = new Mappings(options.hires);
|
|
1233
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
1245
1234
|
|
|
1246
|
-
|
|
1235
|
+
cloned.intro = this.intro;
|
|
1236
|
+
cloned.outro = this.outro;
|
|
1247
1237
|
|
|
1248
|
-
|
|
1249
|
-
mappings.advance(this.intro);
|
|
1238
|
+
return cloned;
|
|
1250
1239
|
}
|
|
1251
1240
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1241
|
+
generateDecodedMap(options) {
|
|
1242
|
+
options = options || {};
|
|
1254
1243
|
|
|
1255
|
-
|
|
1244
|
+
const sourceIndex = 0;
|
|
1245
|
+
const names = Object.keys(this.storedNames);
|
|
1246
|
+
const mappings = new Mappings(options.hires);
|
|
1256
1247
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
loc,
|
|
1262
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
1263
|
-
);
|
|
1264
|
-
} else {
|
|
1265
|
-
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);
|
|
1266
1252
|
}
|
|
1267
1253
|
|
|
1268
|
-
|
|
1269
|
-
|
|
1254
|
+
this.firstChunk.eachNext((chunk) => {
|
|
1255
|
+
const loc = locate(chunk.start);
|
|
1270
1256
|
|
|
1271
|
-
|
|
1272
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
1273
|
-
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
|
1274
|
-
sourcesContent: options.includeContent ? [this.original] : [null],
|
|
1275
|
-
names: names,
|
|
1276
|
-
mappings: mappings.raw
|
|
1277
|
-
};
|
|
1278
|
-
};
|
|
1257
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1279
1258
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
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
|
+
}
|
|
1283
1269
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
};
|
|
1270
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1271
|
+
});
|
|
1287
1272
|
|
|
1288
|
-
|
|
1289
|
-
|
|
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
|
+
}
|
|
1290
1281
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
indentStr = undefined;
|
|
1282
|
+
generateMap(options) {
|
|
1283
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
1294
1284
|
}
|
|
1295
1285
|
|
|
1296
|
-
|
|
1286
|
+
getIndentString() {
|
|
1287
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
1288
|
+
}
|
|
1297
1289
|
|
|
1298
|
-
|
|
1290
|
+
indent(indentStr, options) {
|
|
1291
|
+
const pattern = /^[^\r\n]/gm;
|
|
1299
1292
|
|
|
1300
|
-
|
|
1293
|
+
if (isObject$1(indentStr)) {
|
|
1294
|
+
options = indentStr;
|
|
1295
|
+
indentStr = undefined;
|
|
1296
|
+
}
|
|
1301
1297
|
|
|
1302
|
-
|
|
1303
|
-
var isExcluded = {};
|
|
1298
|
+
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
|
1304
1299
|
|
|
1305
|
-
|
|
1306
|
-
var exclusions =
|
|
1307
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
1308
|
-
exclusions.forEach(function (exclusion) {
|
|
1309
|
-
for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
1310
|
-
isExcluded[i] = true;
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1300
|
+
if (indentStr === '') return this; // noop
|
|
1314
1301
|
|
|
1315
|
-
|
|
1316
|
-
var replacer = function (match) {
|
|
1317
|
-
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
1318
|
-
shouldIndentNextCharacter = true;
|
|
1319
|
-
return match;
|
|
1320
|
-
};
|
|
1302
|
+
options = options || {};
|
|
1321
1303
|
|
|
1322
|
-
|
|
1304
|
+
// Process exclusion ranges
|
|
1305
|
+
const isExcluded = {};
|
|
1323
1306
|
|
|
1324
|
-
|
|
1325
|
-
|
|
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
|
+
}
|
|
1326
1316
|
|
|
1327
|
-
|
|
1328
|
-
|
|
1317
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
1318
|
+
const replacer = (match) => {
|
|
1319
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
1320
|
+
shouldIndentNextCharacter = true;
|
|
1321
|
+
return match;
|
|
1322
|
+
};
|
|
1329
1323
|
|
|
1330
|
-
|
|
1331
|
-
if (!isExcluded[charIndex]) {
|
|
1332
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
1324
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
1333
1325
|
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
charIndex = chunk.start;
|
|
1326
|
+
let charIndex = 0;
|
|
1327
|
+
let chunk = this.firstChunk;
|
|
1328
|
+
|
|
1329
|
+
while (chunk) {
|
|
1330
|
+
const end = chunk.end;
|
|
1340
1331
|
|
|
1341
|
-
|
|
1332
|
+
if (chunk.edited) {
|
|
1342
1333
|
if (!isExcluded[charIndex]) {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
if (
|
|
1346
|
-
shouldIndentNextCharacter =
|
|
1347
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
1348
|
-
shouldIndentNextCharacter = false;
|
|
1349
|
-
|
|
1350
|
-
if (charIndex === chunk.start) {
|
|
1351
|
-
chunk.prependRight(indentStr);
|
|
1352
|
-
} else {
|
|
1353
|
-
this._splitChunk(chunk, charIndex);
|
|
1354
|
-
chunk = chunk.next;
|
|
1355
|
-
chunk.prependRight(indentStr);
|
|
1356
|
-
}
|
|
1334
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
1335
|
+
|
|
1336
|
+
if (chunk.content.length) {
|
|
1337
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
1357
1338
|
}
|
|
1358
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
|
+
}
|
|
1359
1361
|
|
|
1360
|
-
|
|
1362
|
+
charIndex += 1;
|
|
1363
|
+
}
|
|
1361
1364
|
}
|
|
1365
|
+
|
|
1366
|
+
charIndex = chunk.end;
|
|
1367
|
+
chunk = chunk.next;
|
|
1362
1368
|
}
|
|
1363
1369
|
|
|
1364
|
-
|
|
1365
|
-
chunk = chunk.next;
|
|
1366
|
-
}
|
|
1370
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
1367
1371
|
|
|
1368
|
-
|
|
1372
|
+
return this;
|
|
1373
|
+
}
|
|
1369
1374
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1375
|
+
insert() {
|
|
1376
|
+
throw new Error(
|
|
1377
|
+
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1372
1380
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
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
|
+
}
|
|
1376
1388
|
|
|
1377
|
-
|
|
1378
|
-
if (!warned.insertLeft) {
|
|
1379
|
-
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
|
|
1380
|
-
warned.insertLeft = true;
|
|
1389
|
+
return this.appendLeft(index, content);
|
|
1381
1390
|
}
|
|
1382
1391
|
|
|
1383
|
-
|
|
1384
|
-
|
|
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
|
+
}
|
|
1385
1399
|
|
|
1386
|
-
|
|
1387
|
-
if (!warned.insertRight) {
|
|
1388
|
-
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
|
|
1389
|
-
warned.insertRight = true;
|
|
1400
|
+
return this.prependRight(index, content);
|
|
1390
1401
|
}
|
|
1391
1402
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1403
|
+
move(start, end, index) {
|
|
1404
|
+
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
1394
1405
|
|
|
1395
|
-
|
|
1396
|
-
|
|
1406
|
+
this._split(start);
|
|
1407
|
+
this._split(end);
|
|
1408
|
+
this._split(index);
|
|
1397
1409
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
this._split(index);
|
|
1410
|
+
const first = this.byStart[start];
|
|
1411
|
+
const last = this.byEnd[end];
|
|
1401
1412
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1413
|
+
const oldLeft = first.previous;
|
|
1414
|
+
const oldRight = last.next;
|
|
1404
1415
|
|
|
1405
|
-
|
|
1406
|
-
|
|
1416
|
+
const newRight = this.byStart[index];
|
|
1417
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
1418
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
1407
1419
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
1420
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
1421
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
1411
1422
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1423
|
+
if (newLeft) newLeft.next = first;
|
|
1424
|
+
if (newRight) newRight.previous = last;
|
|
1414
1425
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1426
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
1427
|
+
if (!last.next) {
|
|
1428
|
+
this.lastChunk = first.previous;
|
|
1429
|
+
this.lastChunk.next = null;
|
|
1430
|
+
}
|
|
1417
1431
|
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
this.lastChunk = first.previous;
|
|
1421
|
-
this.lastChunk.next = null;
|
|
1422
|
-
}
|
|
1432
|
+
first.previous = newLeft;
|
|
1433
|
+
last.next = newRight || null;
|
|
1423
1434
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1435
|
+
if (!newLeft) this.firstChunk = first;
|
|
1436
|
+
if (!newRight) this.lastChunk = last;
|
|
1437
|
+
return this;
|
|
1438
|
+
}
|
|
1426
1439
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
return this;
|
|
1430
|
-
};
|
|
1440
|
+
overwrite(start, end, content, options) {
|
|
1441
|
+
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
1431
1442
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1443
|
+
while (start < 0) start += this.original.length;
|
|
1444
|
+
while (end < 0) end += this.original.length;
|
|
1434
1445
|
|
|
1435
|
-
|
|
1436
|
-
|
|
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
|
+
);
|
|
1437
1451
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
|
|
1452
|
+
this._split(start);
|
|
1453
|
+
this._split(end);
|
|
1441
1454
|
|
|
1442
|
-
|
|
1443
|
-
|
|
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
|
+
}
|
|
1444
1462
|
|
|
1445
|
-
|
|
1446
|
-
if (!warned.storeName) {
|
|
1447
|
-
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
|
|
1448
|
-
warned.storeName = true;
|
|
1463
|
+
options = { storeName: true };
|
|
1449
1464
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
var first = this.byStart[start];
|
|
1462
|
-
var last = this.byEnd[end];
|
|
1463
|
-
|
|
1464
|
-
if (first) {
|
|
1465
|
-
if (end > first.end && first.next !== this.byStart[first.end]) {
|
|
1466
|
-
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
|
+
});
|
|
1467
1475
|
}
|
|
1468
1476
|
|
|
1469
|
-
first
|
|
1477
|
+
const first = this.byStart[start];
|
|
1478
|
+
const last = this.byEnd[end];
|
|
1470
1479
|
|
|
1471
|
-
if (first
|
|
1472
|
-
|
|
1480
|
+
if (first) {
|
|
1481
|
+
let chunk = first;
|
|
1473
1482
|
while (chunk !== last) {
|
|
1474
|
-
chunk.
|
|
1483
|
+
if (chunk.next !== this.byStart[chunk.end]) {
|
|
1484
|
+
throw new Error('Cannot overwrite across a split point');
|
|
1485
|
+
}
|
|
1475
1486
|
chunk = chunk.next;
|
|
1487
|
+
chunk.edit('', false);
|
|
1476
1488
|
}
|
|
1477
1489
|
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
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);
|
|
1483
1494
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
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;
|
|
1487
1500
|
}
|
|
1488
|
-
return this;
|
|
1489
|
-
};
|
|
1490
1501
|
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
this.intro = content + this.intro;
|
|
1495
|
-
return this;
|
|
1496
|
-
};
|
|
1502
|
+
prepend(content) {
|
|
1503
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
1497
1504
|
|
|
1498
|
-
MagicString.prototype.prependLeft = function prependLeft (index, content) {
|
|
1499
|
-
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
1500
|
-
|
|
1501
|
-
this._split(index);
|
|
1502
|
-
|
|
1503
|
-
var chunk = this.byEnd[index];
|
|
1504
|
-
|
|
1505
|
-
if (chunk) {
|
|
1506
|
-
chunk.prependLeft(content);
|
|
1507
|
-
} else {
|
|
1508
1505
|
this.intro = content + this.intro;
|
|
1506
|
+
return this;
|
|
1509
1507
|
}
|
|
1510
|
-
return this;
|
|
1511
|
-
};
|
|
1512
1508
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1509
|
+
prependLeft(index, content) {
|
|
1510
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1515
1511
|
|
|
1516
|
-
|
|
1512
|
+
this._split(index);
|
|
1517
1513
|
|
|
1518
|
-
|
|
1514
|
+
const chunk = this.byEnd[index];
|
|
1519
1515
|
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1516
|
+
if (chunk) {
|
|
1517
|
+
chunk.prependLeft(content);
|
|
1518
|
+
} else {
|
|
1519
|
+
this.intro = content + this.intro;
|
|
1520
|
+
}
|
|
1521
|
+
return this;
|
|
1524
1522
|
}
|
|
1525
|
-
return this;
|
|
1526
|
-
};
|
|
1527
|
-
|
|
1528
|
-
MagicString.prototype.remove = function remove (start, end) {
|
|
1529
|
-
while (start < 0) { start += this.original.length; }
|
|
1530
|
-
while (end < 0) { end += this.original.length; }
|
|
1531
1523
|
|
|
1532
|
-
|
|
1524
|
+
prependRight(index, content) {
|
|
1525
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1533
1526
|
|
|
1534
|
-
|
|
1535
|
-
if (start > end) { throw new Error('end must be greater than start'); }
|
|
1527
|
+
this._split(index);
|
|
1536
1528
|
|
|
1537
|
-
|
|
1538
|
-
this._split(end);
|
|
1529
|
+
const chunk = this.byStart[index];
|
|
1539
1530
|
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
chunk.outro = '';
|
|
1545
|
-
chunk.edit('');
|
|
1546
|
-
|
|
1547
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1548
|
-
}
|
|
1549
|
-
return this;
|
|
1550
|
-
};
|
|
1551
|
-
|
|
1552
|
-
MagicString.prototype.lastChar = function lastChar () {
|
|
1553
|
-
if (this.outro.length)
|
|
1554
|
-
{ return this.outro[this.outro.length - 1]; }
|
|
1555
|
-
var chunk = this.lastChunk;
|
|
1556
|
-
do {
|
|
1557
|
-
if (chunk.outro.length)
|
|
1558
|
-
{ return chunk.outro[chunk.outro.length - 1]; }
|
|
1559
|
-
if (chunk.content.length)
|
|
1560
|
-
{ return chunk.content[chunk.content.length - 1]; }
|
|
1561
|
-
if (chunk.intro.length)
|
|
1562
|
-
{ return chunk.intro[chunk.intro.length - 1]; }
|
|
1563
|
-
} while (chunk = chunk.previous);
|
|
1564
|
-
if (this.intro.length)
|
|
1565
|
-
{ return this.intro[this.intro.length - 1]; }
|
|
1566
|
-
return '';
|
|
1567
|
-
};
|
|
1568
|
-
|
|
1569
|
-
MagicString.prototype.lastLine = function lastLine () {
|
|
1570
|
-
var lineIndex = this.outro.lastIndexOf(n);
|
|
1571
|
-
if (lineIndex !== -1)
|
|
1572
|
-
{ return this.outro.substr(lineIndex + 1); }
|
|
1573
|
-
var lineStr = this.outro;
|
|
1574
|
-
var chunk = this.lastChunk;
|
|
1575
|
-
do {
|
|
1576
|
-
if (chunk.outro.length > 0) {
|
|
1577
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
1578
|
-
if (lineIndex !== -1)
|
|
1579
|
-
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
|
|
1580
|
-
lineStr = chunk.outro + lineStr;
|
|
1531
|
+
if (chunk) {
|
|
1532
|
+
chunk.prependRight(content);
|
|
1533
|
+
} else {
|
|
1534
|
+
this.outro = content + this.outro;
|
|
1581
1535
|
}
|
|
1536
|
+
return this;
|
|
1537
|
+
}
|
|
1582
1538
|
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
|
|
1587
|
-
lineStr = chunk.content + lineStr;
|
|
1588
|
-
}
|
|
1539
|
+
remove(start, end) {
|
|
1540
|
+
while (start < 0) start += this.original.length;
|
|
1541
|
+
while (end < 0) end += this.original.length;
|
|
1589
1542
|
|
|
1590
|
-
if (
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
lineStr = chunk.intro + lineStr;
|
|
1595
|
-
}
|
|
1596
|
-
} while (chunk = chunk.previous);
|
|
1597
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
1598
|
-
if (lineIndex !== -1)
|
|
1599
|
-
{ return this.intro.substr(lineIndex + 1) + lineStr; }
|
|
1600
|
-
return this.intro + lineStr;
|
|
1601
|
-
};
|
|
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');
|
|
1602
1547
|
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
if ( end === void 0 ) end = this.original.length;
|
|
1548
|
+
this._split(start);
|
|
1549
|
+
this._split(end);
|
|
1606
1550
|
|
|
1607
|
-
|
|
1608
|
-
while (end < 0) { end += this.original.length; }
|
|
1551
|
+
let chunk = this.byStart[start];
|
|
1609
1552
|
|
|
1610
|
-
|
|
1553
|
+
while (chunk) {
|
|
1554
|
+
chunk.intro = '';
|
|
1555
|
+
chunk.outro = '';
|
|
1556
|
+
chunk.edit('');
|
|
1611
1557
|
|
|
1612
|
-
|
|
1613
|
-
var chunk = this.firstChunk;
|
|
1614
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1615
|
-
// found end chunk before start
|
|
1616
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
1617
|
-
return result;
|
|
1558
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1618
1559
|
}
|
|
1560
|
+
return this;
|
|
1561
|
+
}
|
|
1619
1562
|
|
|
1620
|
-
|
|
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 '';
|
|
1621
1573
|
}
|
|
1622
1574
|
|
|
1623
|
-
|
|
1624
|
-
|
|
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
|
+
}
|
|
1625
1586
|
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
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
|
+
}
|
|
1631
1592
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
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
|
+
}
|
|
1635
1603
|
|
|
1636
|
-
|
|
1637
|
-
|
|
1604
|
+
slice(start = 0, end = this.original.length) {
|
|
1605
|
+
while (start < 0) start += this.original.length;
|
|
1606
|
+
while (end < 0) end += this.original.length;
|
|
1638
1607
|
|
|
1639
|
-
result
|
|
1608
|
+
let result = '';
|
|
1640
1609
|
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
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
|
+
}
|
|
1644
1617
|
|
|
1645
|
-
|
|
1646
|
-
break;
|
|
1618
|
+
chunk = chunk.next;
|
|
1647
1619
|
}
|
|
1648
1620
|
|
|
1649
|
-
chunk
|
|
1650
|
-
|
|
1621
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
1622
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1651
1623
|
|
|
1652
|
-
|
|
1653
|
-
|
|
1624
|
+
const startChunk = chunk;
|
|
1625
|
+
while (chunk) {
|
|
1626
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
1627
|
+
result += chunk.intro;
|
|
1628
|
+
}
|
|
1654
1629
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
clone.remove(0, start);
|
|
1659
|
-
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.`);
|
|
1660
1633
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1634
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1635
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1663
1636
|
|
|
1664
|
-
|
|
1665
|
-
if (this.byStart[index] || this.byEnd[index]) { return; }
|
|
1637
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1666
1638
|
|
|
1667
|
-
|
|
1668
|
-
|
|
1639
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
1640
|
+
result += chunk.outro;
|
|
1641
|
+
}
|
|
1669
1642
|
|
|
1670
|
-
|
|
1671
|
-
|
|
1643
|
+
if (containsEnd) {
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1672
1646
|
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
};
|
|
1647
|
+
chunk = chunk.next;
|
|
1648
|
+
}
|
|
1676
1649
|
|
|
1677
|
-
|
|
1678
|
-
if (chunk.edited && chunk.content.length) {
|
|
1679
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1680
|
-
var loc = getLocator(this.original)(index);
|
|
1681
|
-
throw new Error(
|
|
1682
|
-
("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
|
|
1683
|
-
);
|
|
1650
|
+
return result;
|
|
1684
1651
|
}
|
|
1685
1652
|
|
|
1686
|
-
|
|
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);
|
|
1687
1658
|
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1659
|
+
return clone;
|
|
1660
|
+
}
|
|
1691
1661
|
|
|
1692
|
-
|
|
1662
|
+
_split(index) {
|
|
1663
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1693
1664
|
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
};
|
|
1665
|
+
let chunk = this.lastSearchedChunk;
|
|
1666
|
+
const searchForward = index > chunk.end;
|
|
1697
1667
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1668
|
+
while (chunk) {
|
|
1669
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1700
1670
|
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
str += chunk.toString();
|
|
1704
|
-
chunk = chunk.next;
|
|
1671
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1672
|
+
}
|
|
1705
1673
|
}
|
|
1706
1674
|
|
|
1707
|
-
|
|
1708
|
-
|
|
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
|
+
}
|
|
1709
1683
|
|
|
1710
|
-
|
|
1711
|
-
var chunk = this.firstChunk;
|
|
1712
|
-
do {
|
|
1713
|
-
if (chunk.intro.length && chunk.intro.trim() ||
|
|
1714
|
-
chunk.content.length && chunk.content.trim() ||
|
|
1715
|
-
chunk.outro.length && chunk.outro.trim())
|
|
1716
|
-
{ return false; }
|
|
1717
|
-
} while (chunk = chunk.next);
|
|
1718
|
-
return true;
|
|
1719
|
-
};
|
|
1684
|
+
const newChunk = chunk.split(index);
|
|
1720
1685
|
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
do {
|
|
1725
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1726
|
-
} while (chunk = chunk.next);
|
|
1727
|
-
return length;
|
|
1728
|
-
};
|
|
1686
|
+
this.byEnd[index] = chunk;
|
|
1687
|
+
this.byStart[index] = newChunk;
|
|
1688
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
1729
1689
|
|
|
1730
|
-
|
|
1731
|
-
return this.trim('[\\r\\n]');
|
|
1732
|
-
};
|
|
1690
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1733
1691
|
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1692
|
+
this.lastSearchedChunk = chunk;
|
|
1693
|
+
return true;
|
|
1694
|
+
}
|
|
1737
1695
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1696
|
+
toString() {
|
|
1697
|
+
let str = this.intro;
|
|
1740
1698
|
|
|
1741
|
-
|
|
1742
|
-
|
|
1699
|
+
let chunk = this.firstChunk;
|
|
1700
|
+
while (chunk) {
|
|
1701
|
+
str += chunk.toString();
|
|
1702
|
+
chunk = chunk.next;
|
|
1703
|
+
}
|
|
1743
1704
|
|
|
1744
|
-
|
|
1705
|
+
return str + this.outro;
|
|
1706
|
+
}
|
|
1745
1707
|
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
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
|
+
}
|
|
1749
1720
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
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
|
+
}
|
|
1755
1729
|
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
}
|
|
1730
|
+
trimLines() {
|
|
1731
|
+
return this.trim('[\\r\\n]');
|
|
1732
|
+
}
|
|
1760
1733
|
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
}
|
|
1734
|
+
trim(charType) {
|
|
1735
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1736
|
+
}
|
|
1764
1737
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1738
|
+
trimEndAborted(charType) {
|
|
1739
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1767
1740
|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1741
|
+
this.outro = this.outro.replace(rx, '');
|
|
1742
|
+
if (this.outro.length) return true;
|
|
1743
|
+
|
|
1744
|
+
let chunk = this.lastChunk;
|
|
1745
|
+
|
|
1746
|
+
do {
|
|
1747
|
+
const end = chunk.end;
|
|
1748
|
+
const aborted = chunk.trimEnd(rx);
|
|
1774
1749
|
|
|
1775
|
-
|
|
1776
|
-
|
|
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
|
+
}
|
|
1777
1755
|
|
|
1778
|
-
|
|
1756
|
+
this.byEnd[chunk.end] = chunk;
|
|
1757
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
1758
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
1759
|
+
}
|
|
1779
1760
|
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1761
|
+
if (aborted) return true;
|
|
1762
|
+
chunk = chunk.previous;
|
|
1763
|
+
} while (chunk);
|
|
1783
1764
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1787
1767
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1768
|
+
trimEnd(charType) {
|
|
1769
|
+
this.trimEndAborted(charType);
|
|
1770
|
+
return this;
|
|
1771
|
+
}
|
|
1772
|
+
trimStartAborted(charType) {
|
|
1773
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1792
1774
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
} while (chunk);
|
|
1775
|
+
this.intro = this.intro.replace(rx, '');
|
|
1776
|
+
if (this.intro.length) return true;
|
|
1796
1777
|
|
|
1797
|
-
|
|
1798
|
-
};
|
|
1778
|
+
let chunk = this.firstChunk;
|
|
1799
1779
|
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
};
|
|
1780
|
+
do {
|
|
1781
|
+
const end = chunk.end;
|
|
1782
|
+
const aborted = chunk.trimStart(rx);
|
|
1804
1783
|
|
|
1805
|
-
|
|
1784
|
+
if (chunk.end !== end) {
|
|
1785
|
+
// special case...
|
|
1786
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1806
1787
|
|
|
1807
|
-
|
|
1808
|
-
|
|
1788
|
+
this.byEnd[chunk.end] = chunk;
|
|
1789
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
1790
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
1791
|
+
}
|
|
1809
1792
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
this.uniqueSources = [];
|
|
1814
|
-
this.uniqueSourceIndexByFilename = {};
|
|
1815
|
-
};
|
|
1793
|
+
if (aborted) return true;
|
|
1794
|
+
chunk = chunk.next;
|
|
1795
|
+
} while (chunk);
|
|
1816
1796
|
|
|
1817
|
-
|
|
1818
|
-
if (source instanceof MagicString) {
|
|
1819
|
-
return this.addSource({
|
|
1820
|
-
content: source,
|
|
1821
|
-
filename: source.filename,
|
|
1822
|
-
separator: this.separator
|
|
1823
|
-
});
|
|
1797
|
+
return false;
|
|
1824
1798
|
}
|
|
1825
1799
|
|
|
1826
|
-
|
|
1827
|
-
|
|
1800
|
+
trimStart(charType) {
|
|
1801
|
+
this.trimStartAborted(charType);
|
|
1802
|
+
return this;
|
|
1828
1803
|
}
|
|
1829
1804
|
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
});
|
|
1833
|
-
|
|
1834
|
-
if (source.separator === undefined) {
|
|
1835
|
-
// TODO there's a bunch of this sort of thing, needs cleaning up
|
|
1836
|
-
source.separator = this.separator;
|
|
1805
|
+
hasChanged() {
|
|
1806
|
+
return this.original !== this.toString();
|
|
1837
1807
|
}
|
|
1838
1808
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
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);
|
|
1847
1822
|
}
|
|
1848
1823
|
}
|
|
1824
|
+
function matchAll(re, str) {
|
|
1825
|
+
let match;
|
|
1826
|
+
const matches = [];
|
|
1827
|
+
while ((match = re.exec(str))) {
|
|
1828
|
+
matches.push(match);
|
|
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
|
+
);
|
|
1850
|
+
}
|
|
1851
|
+
return this;
|
|
1849
1852
|
}
|
|
1853
|
+
}
|
|
1850
1854
|
|
|
1851
|
-
|
|
1852
|
-
return this;
|
|
1853
|
-
};
|
|
1855
|
+
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1854
1856
|
|
|
1855
|
-
Bundle$1
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
separator
|
|
1859
|
-
|
|
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
|
+
}
|
|
1860
1865
|
|
|
1861
|
-
|
|
1862
|
-
|
|
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
|
+
}
|
|
1863
1874
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
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
|
+
}
|
|
1869
1880
|
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
filename: source.filename,
|
|
1873
|
-
content: source.content.clone(),
|
|
1874
|
-
separator: source.separator
|
|
1881
|
+
['filename', 'indentExclusionRanges', 'separator'].forEach((option) => {
|
|
1882
|
+
if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
|
|
1875
1883
|
});
|
|
1876
|
-
});
|
|
1877
1884
|
|
|
1878
|
-
|
|
1879
|
-
|
|
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
|
+
}
|
|
1880
1901
|
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1902
|
+
this.sources.push(source);
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1884
1905
|
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1906
|
+
append(str, options) {
|
|
1907
|
+
this.addSource({
|
|
1908
|
+
content: new MagicString(str),
|
|
1909
|
+
separator: (options && options.separator) || '',
|
|
1889
1910
|
});
|
|
1890
|
-
});
|
|
1891
1911
|
|
|
1892
|
-
|
|
1912
|
+
return this;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
clone() {
|
|
1916
|
+
const bundle = new Bundle$1({
|
|
1917
|
+
intro: this.intro,
|
|
1918
|
+
separator: this.separator,
|
|
1919
|
+
});
|
|
1893
1920
|
|
|
1894
|
-
|
|
1895
|
-
|
|
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;
|
|
1896
1930
|
}
|
|
1897
1931
|
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
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
|
+
});
|
|
1902
1939
|
|
|
1903
|
-
|
|
1904
|
-
var magicString = source.content;
|
|
1905
|
-
var locate = getLocator(magicString.original);
|
|
1940
|
+
const mappings = new Mappings(options.hires);
|
|
1906
1941
|
|
|
1907
|
-
if (
|
|
1908
|
-
mappings.advance(
|
|
1942
|
+
if (this.intro) {
|
|
1943
|
+
mappings.advance(this.intro);
|
|
1909
1944
|
}
|
|
1910
1945
|
|
|
1911
|
-
|
|
1912
|
-
|
|
1946
|
+
this.sources.forEach((source, i) => {
|
|
1947
|
+
if (i > 0) {
|
|
1948
|
+
mappings.advance(this.separator);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1952
|
+
const magicString = source.content;
|
|
1953
|
+
const locate = getLocator(magicString.original);
|
|
1913
1954
|
|
|
1914
|
-
if (
|
|
1955
|
+
if (magicString.intro) {
|
|
1956
|
+
mappings.advance(magicString.intro);
|
|
1957
|
+
}
|
|
1915
1958
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
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
|
+
}
|
|
1924
1981
|
} else {
|
|
1925
|
-
mappings.
|
|
1926
|
-
sourceIndex,
|
|
1927
|
-
chunk,
|
|
1928
|
-
magicString.original,
|
|
1929
|
-
loc,
|
|
1930
|
-
magicString.sourcemapLocations
|
|
1931
|
-
);
|
|
1982
|
+
mappings.advance(chunk.content);
|
|
1932
1983
|
}
|
|
1933
|
-
} else {
|
|
1934
|
-
mappings.advance(chunk.content);
|
|
1935
|
-
}
|
|
1936
1984
|
|
|
1937
|
-
|
|
1938
|
-
|
|
1985
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1986
|
+
});
|
|
1939
1987
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1988
|
+
if (magicString.outro) {
|
|
1989
|
+
mappings.advance(magicString.outro);
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1944
1992
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
}
|
|
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
|
+
}
|
|
1957
2005
|
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
}
|
|
2006
|
+
generateMap(options) {
|
|
2007
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
2008
|
+
}
|
|
1961
2009
|
|
|
1962
|
-
|
|
1963
|
-
|
|
2010
|
+
getIndentString() {
|
|
2011
|
+
const indentStringCounts = {};
|
|
1964
2012
|
|
|
1965
|
-
|
|
1966
|
-
|
|
2013
|
+
this.sources.forEach((source) => {
|
|
2014
|
+
const indentStr = source.content.indentStr;
|
|
1967
2015
|
|
|
1968
|
-
|
|
2016
|
+
if (indentStr === null) return;
|
|
1969
2017
|
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2018
|
+
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
2019
|
+
indentStringCounts[indentStr] += 1;
|
|
2020
|
+
});
|
|
1973
2021
|
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
}
|
|
2022
|
+
return (
|
|
2023
|
+
Object.keys(indentStringCounts).sort((a, b) => {
|
|
2024
|
+
return indentStringCounts[a] - indentStringCounts[b];
|
|
2025
|
+
})[0] || '\t'
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
1980
2028
|
|
|
1981
|
-
|
|
1982
|
-
|
|
2029
|
+
indent(indentStr) {
|
|
2030
|
+
if (!arguments.length) {
|
|
2031
|
+
indentStr = this.getIndentString();
|
|
2032
|
+
}
|
|
1983
2033
|
|
|
1984
|
-
|
|
1985
|
-
indentStr = this.getIndentString();
|
|
1986
|
-
}
|
|
2034
|
+
if (indentStr === '') return this; // noop
|
|
1987
2035
|
|
|
1988
|
-
|
|
2036
|
+
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1989
2037
|
|
|
1990
|
-
|
|
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));
|
|
1991
2041
|
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2042
|
+
source.content.indent(indentStr, {
|
|
2043
|
+
exclude: source.indentExclusionRanges,
|
|
2044
|
+
indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
|
2045
|
+
});
|
|
1995
2046
|
|
|
1996
|
-
|
|
1997
|
-
exclude: source.indentExclusionRanges,
|
|
1998
|
-
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
|
2047
|
+
trailingNewline = source.content.lastChar() === '\n';
|
|
1999
2048
|
});
|
|
2000
2049
|
|
|
2001
|
-
|
|
2002
|
-
|
|
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
|
+
}
|
|
2003
2057
|
|
|
2004
|
-
|
|
2005
|
-
this.intro =
|
|
2006
|
-
indentStr +
|
|
2007
|
-
this.intro.replace(/^[^\n]/gm, function (match, index) {
|
|
2008
|
-
return index > 0 ? indentStr + match : match;
|
|
2009
|
-
});
|
|
2058
|
+
return this;
|
|
2010
2059
|
}
|
|
2011
2060
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2061
|
+
prepend(str) {
|
|
2062
|
+
this.intro = str + this.intro;
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2014
2065
|
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
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();
|
|
2019
2071
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2072
|
+
return str;
|
|
2073
|
+
})
|
|
2074
|
+
.join('');
|
|
2022
2075
|
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
|
|
2026
|
-
var str = (i > 0 ? separator : '') + source.content.toString();
|
|
2076
|
+
return this.intro + body;
|
|
2077
|
+
}
|
|
2027
2078
|
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
.
|
|
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
|
+
}
|
|
2031
2084
|
|
|
2032
|
-
|
|
2033
|
-
|
|
2085
|
+
length() {
|
|
2086
|
+
return this.sources.reduce(
|
|
2087
|
+
(length, source) => length + source.content.length(),
|
|
2088
|
+
this.intro.length
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2034
2091
|
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
|
|
2039
|
-
{ return false; }
|
|
2040
|
-
return true;
|
|
2041
|
-
};
|
|
2092
|
+
trimLines() {
|
|
2093
|
+
return this.trim('[\\r\\n]');
|
|
2094
|
+
}
|
|
2042
2095
|
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
}
|
|
2096
|
+
trim(charType) {
|
|
2097
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
2098
|
+
}
|
|
2046
2099
|
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2100
|
+
trimStart(charType) {
|
|
2101
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
2102
|
+
this.intro = this.intro.replace(rx, '');
|
|
2050
2103
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
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
|
+
}
|
|
2054
2118
|
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
this.intro = this.intro.replace(rx, '');
|
|
2119
|
+
trimEnd(charType) {
|
|
2120
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
2058
2121
|
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
var i = 0;
|
|
2122
|
+
let source;
|
|
2123
|
+
let i = this.sources.length - 1;
|
|
2062
2124
|
|
|
2063
2125
|
do {
|
|
2064
|
-
source = this.sources[i
|
|
2126
|
+
source = this.sources[i--];
|
|
2065
2127
|
if (!source) {
|
|
2128
|
+
this.intro = this.intro.replace(rx, '');
|
|
2066
2129
|
break;
|
|
2067
2130
|
}
|
|
2068
|
-
} while (!source.content.
|
|
2069
|
-
}
|
|
2131
|
+
} while (!source.content.trimEndAborted(charType));
|
|
2070
2132
|
|
|
2071
|
-
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
Bundle$1.prototype.trimEnd = function trimEnd (charType) {
|
|
2075
|
-
var rx = new RegExp((charType || '\\s') + '+$');
|
|
2076
|
-
|
|
2077
|
-
var source;
|
|
2078
|
-
var i = this.sources.length - 1;
|
|
2079
|
-
|
|
2080
|
-
do {
|
|
2081
|
-
source = this.sources[i--];
|
|
2082
|
-
if (!source) {
|
|
2083
|
-
this.intro = this.intro.replace(rx, '');
|
|
2084
|
-
break;
|
|
2085
|
-
}
|
|
2086
|
-
} while (!source.content.trimEndAborted(charType));
|
|
2087
|
-
|
|
2088
|
-
return this;
|
|
2089
|
-
};
|
|
2090
|
-
|
|
2091
|
-
const MagicString$1 = MagicString;
|
|
2133
|
+
return this;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2092
2136
|
|
|
2093
2137
|
function getOrCreate(map, key, init) {
|
|
2094
2138
|
const existing = map.get(key);
|
|
@@ -4560,7 +4604,7 @@ const normalizePath = function normalizePath(filename) {
|
|
|
4560
4604
|
|
|
4561
4605
|
function getMatcherString(id, resolutionBase) {
|
|
4562
4606
|
if (resolutionBase === false || require$$0.isAbsolute(id) || id.startsWith('*')) {
|
|
4563
|
-
return id;
|
|
4607
|
+
return normalizePath(id);
|
|
4564
4608
|
}
|
|
4565
4609
|
// resolve('') is valid and will default to process.cwd()
|
|
4566
4610
|
const basePath = normalizePath(require$$0.resolve(resolutionBase || ''))
|
|
@@ -4570,7 +4614,7 @@ function getMatcherString(id, resolutionBase) {
|
|
|
4570
4614
|
// 1. the basePath has been normalized to use /
|
|
4571
4615
|
// 2. the incoming glob (id) matcher, also uses /
|
|
4572
4616
|
// otherwise Node will force backslash (\) on windows
|
|
4573
|
-
return require$$0.posix.join(basePath, id);
|
|
4617
|
+
return require$$0.posix.join(basePath, normalizePath(id));
|
|
4574
4618
|
}
|
|
4575
4619
|
const createFilter = function createFilter(include, exclude, options) {
|
|
4576
4620
|
const resolutionBase = options && options.resolve;
|
|
@@ -12760,7 +12804,7 @@ class Module {
|
|
|
12760
12804
|
// By default, `id` is the file name. Custom resolvers and loaders
|
|
12761
12805
|
// can change that, but it makes sense to use it for the source file name
|
|
12762
12806
|
const fileName = this.id;
|
|
12763
|
-
this.magicString = new MagicString
|
|
12807
|
+
this.magicString = new MagicString(code, {
|
|
12764
12808
|
filename: (this.excludeFromSourcemap ? null : fileName),
|
|
12765
12809
|
indentExclusionRanges: []
|
|
12766
12810
|
});
|
|
@@ -14796,7 +14840,7 @@ class Chunk {
|
|
|
14796
14840
|
if (namespace.renderFirst())
|
|
14797
14841
|
hoistedSource += n + rendered;
|
|
14798
14842
|
else
|
|
14799
|
-
magicString.addSource(new MagicString
|
|
14843
|
+
magicString.addSource(new MagicString(rendered));
|
|
14800
14844
|
}
|
|
14801
14845
|
}
|
|
14802
14846
|
const { renderedExports, removedExports } = module.getRenderedExports();
|
|
@@ -22026,7 +22070,7 @@ async function transform(source, module, pluginDriver, warn) {
|
|
|
22026
22070
|
getCombinedSourcemap() {
|
|
22027
22071
|
const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn);
|
|
22028
22072
|
if (!combinedMap) {
|
|
22029
|
-
const magicString = new MagicString
|
|
22073
|
+
const magicString = new MagicString(originalCode);
|
|
22030
22074
|
return magicString.generateMap({ hires: true, includeContent: true, source: id });
|
|
22031
22075
|
}
|
|
22032
22076
|
if (originalSourcemap !== combinedMap) {
|