@mbler/mcx-core 0.0.2-alpha.r5 → 0.0.2-beta.r1

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/dist/index.js CHANGED
@@ -1468,7 +1468,7 @@ async function transform(compileData, cache, id, context) {
1468
1468
  for (const imp of compileData.JSIR.BuildCache.import || []) {
1469
1469
  if (path.parse(imp.source).dir == "")
1470
1470
  continue;
1471
- const source = path.join(id, imp.source);
1471
+ const source = path.join(path.dirname(id), imp.source);
1472
1472
  if (!source.endsWith(".mcx"))
1473
1473
  continue;
1474
1474
  let moduleData;
@@ -1522,11 +1522,1389 @@ async function transform(compileData, cache, id, context) {
1522
1522
  return generator__namespace.generate(t__namespace.program(statement)).code;
1523
1523
  }
1524
1524
 
1525
+ // src/vlq.ts
1526
+ var comma = ",".charCodeAt(0);
1527
+ var semicolon = ";".charCodeAt(0);
1528
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1529
+ var intToChar = new Uint8Array(64);
1530
+ var charToInt = new Uint8Array(128);
1531
+ for (let i = 0; i < chars.length; i++) {
1532
+ const c = chars.charCodeAt(i);
1533
+ intToChar[i] = c;
1534
+ charToInt[c] = i;
1535
+ }
1536
+ function encodeInteger(builder, num, relative) {
1537
+ let delta = num - relative;
1538
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
1539
+ do {
1540
+ let clamped = delta & 31;
1541
+ delta >>>= 5;
1542
+ if (delta > 0) clamped |= 32;
1543
+ builder.write(intToChar[clamped]);
1544
+ } while (delta > 0);
1545
+ return num;
1546
+ }
1547
+
1548
+ // src/strings.ts
1549
+ var bufLength = 1024 * 16;
1550
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
1551
+ decode(buf) {
1552
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
1553
+ return out.toString();
1554
+ }
1555
+ } : {
1556
+ decode(buf) {
1557
+ let out = "";
1558
+ for (let i = 0; i < buf.length; i++) {
1559
+ out += String.fromCharCode(buf[i]);
1560
+ }
1561
+ return out;
1562
+ }
1563
+ };
1564
+ var StringWriter = class {
1565
+ constructor() {
1566
+ this.pos = 0;
1567
+ this.out = "";
1568
+ this.buffer = new Uint8Array(bufLength);
1569
+ }
1570
+ write(v) {
1571
+ const { buffer } = this;
1572
+ buffer[this.pos++] = v;
1573
+ if (this.pos === bufLength) {
1574
+ this.out += td.decode(buffer);
1575
+ this.pos = 0;
1576
+ }
1577
+ }
1578
+ flush() {
1579
+ const { buffer, out, pos } = this;
1580
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
1581
+ }
1582
+ };
1583
+ function encode(decoded) {
1584
+ const writer = new StringWriter();
1585
+ let sourcesIndex = 0;
1586
+ let sourceLine = 0;
1587
+ let sourceColumn = 0;
1588
+ let namesIndex = 0;
1589
+ for (let i = 0; i < decoded.length; i++) {
1590
+ const line = decoded[i];
1591
+ if (i > 0) writer.write(semicolon);
1592
+ if (line.length === 0) continue;
1593
+ let genColumn = 0;
1594
+ for (let j = 0; j < line.length; j++) {
1595
+ const segment = line[j];
1596
+ if (j > 0) writer.write(comma);
1597
+ genColumn = encodeInteger(writer, segment[0], genColumn);
1598
+ if (segment.length === 1) continue;
1599
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
1600
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
1601
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
1602
+ if (segment.length === 4) continue;
1603
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
1604
+ }
1605
+ }
1606
+ return writer.flush();
1607
+ }
1608
+
1609
+ class BitSet {
1610
+ constructor(arg) {
1611
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
1612
+ }
1613
+
1614
+ add(n) {
1615
+ this.bits[n >> 5] |= 1 << (n & 31);
1616
+ }
1617
+
1618
+ has(n) {
1619
+ return !!(this.bits[n >> 5] & (1 << (n & 31)));
1620
+ }
1621
+ }
1622
+
1623
+ class Chunk {
1624
+ constructor(start, end, content) {
1625
+ this.start = start;
1626
+ this.end = end;
1627
+ this.original = content;
1628
+
1629
+ this.intro = '';
1630
+ this.outro = '';
1631
+
1632
+ this.content = content;
1633
+ this.storeName = false;
1634
+ this.edited = false;
1635
+
1636
+ {
1637
+ this.previous = null;
1638
+ this.next = null;
1639
+ }
1640
+ }
1641
+
1642
+ appendLeft(content) {
1643
+ this.outro += content;
1644
+ }
1645
+
1646
+ appendRight(content) {
1647
+ this.intro = this.intro + content;
1648
+ }
1649
+
1650
+ clone() {
1651
+ const chunk = new Chunk(this.start, this.end, this.original);
1652
+
1653
+ chunk.intro = this.intro;
1654
+ chunk.outro = this.outro;
1655
+ chunk.content = this.content;
1656
+ chunk.storeName = this.storeName;
1657
+ chunk.edited = this.edited;
1658
+
1659
+ return chunk;
1660
+ }
1661
+
1662
+ contains(index) {
1663
+ return this.start < index && index < this.end;
1664
+ }
1665
+
1666
+ eachNext(fn) {
1667
+ let chunk = this;
1668
+ while (chunk) {
1669
+ fn(chunk);
1670
+ chunk = chunk.next;
1671
+ }
1672
+ }
1673
+
1674
+ eachPrevious(fn) {
1675
+ let chunk = this;
1676
+ while (chunk) {
1677
+ fn(chunk);
1678
+ chunk = chunk.previous;
1679
+ }
1680
+ }
1681
+
1682
+ edit(content, storeName, contentOnly) {
1683
+ this.content = content;
1684
+ if (!contentOnly) {
1685
+ this.intro = '';
1686
+ this.outro = '';
1687
+ }
1688
+ this.storeName = storeName;
1689
+
1690
+ this.edited = true;
1691
+
1692
+ return this;
1693
+ }
1694
+
1695
+ prependLeft(content) {
1696
+ this.outro = content + this.outro;
1697
+ }
1698
+
1699
+ prependRight(content) {
1700
+ this.intro = content + this.intro;
1701
+ }
1702
+
1703
+ reset() {
1704
+ this.intro = '';
1705
+ this.outro = '';
1706
+ if (this.edited) {
1707
+ this.content = this.original;
1708
+ this.storeName = false;
1709
+ this.edited = false;
1710
+ }
1711
+ }
1712
+
1713
+ split(index) {
1714
+ const sliceIndex = index - this.start;
1715
+
1716
+ const originalBefore = this.original.slice(0, sliceIndex);
1717
+ const originalAfter = this.original.slice(sliceIndex);
1718
+
1719
+ this.original = originalBefore;
1720
+
1721
+ const newChunk = new Chunk(index, this.end, originalAfter);
1722
+ newChunk.outro = this.outro;
1723
+ this.outro = '';
1724
+
1725
+ this.end = index;
1726
+
1727
+ if (this.edited) {
1728
+ // after split we should save the edit content record into the correct chunk
1729
+ // to make sure sourcemap correct
1730
+ // For example:
1731
+ // ' test'.trim()
1732
+ // split -> ' ' + 'test'
1733
+ // ✔️ edit -> '' + 'test'
1734
+ // ✖️ edit -> 'test' + ''
1735
+ // TODO is this block necessary?...
1736
+ newChunk.edit('', false);
1737
+ this.content = '';
1738
+ } else {
1739
+ this.content = originalBefore;
1740
+ }
1741
+
1742
+ newChunk.next = this.next;
1743
+ if (newChunk.next) newChunk.next.previous = newChunk;
1744
+ newChunk.previous = this;
1745
+ this.next = newChunk;
1746
+
1747
+ return newChunk;
1748
+ }
1749
+
1750
+ toString() {
1751
+ return this.intro + this.content + this.outro;
1752
+ }
1753
+
1754
+ trimEnd(rx) {
1755
+ this.outro = this.outro.replace(rx, '');
1756
+ if (this.outro.length) return true;
1757
+
1758
+ const trimmed = this.content.replace(rx, '');
1759
+
1760
+ if (trimmed.length) {
1761
+ if (trimmed !== this.content) {
1762
+ this.split(this.start + trimmed.length).edit('', undefined, true);
1763
+ if (this.edited) {
1764
+ // save the change, if it has been edited
1765
+ this.edit(trimmed, this.storeName, true);
1766
+ }
1767
+ }
1768
+ return true;
1769
+ } else {
1770
+ this.edit('', undefined, true);
1771
+
1772
+ this.intro = this.intro.replace(rx, '');
1773
+ if (this.intro.length) return true;
1774
+ }
1775
+ }
1776
+
1777
+ trimStart(rx) {
1778
+ this.intro = this.intro.replace(rx, '');
1779
+ if (this.intro.length) return true;
1780
+
1781
+ const trimmed = this.content.replace(rx, '');
1782
+
1783
+ if (trimmed.length) {
1784
+ if (trimmed !== this.content) {
1785
+ const newChunk = this.split(this.end - trimmed.length);
1786
+ if (this.edited) {
1787
+ // save the change, if it has been edited
1788
+ newChunk.edit(trimmed, this.storeName, true);
1789
+ }
1790
+ this.edit('', undefined, true);
1791
+ }
1792
+ return true;
1793
+ } else {
1794
+ this.edit('', undefined, true);
1795
+
1796
+ this.outro = this.outro.replace(rx, '');
1797
+ if (this.outro.length) return true;
1798
+ }
1799
+ }
1800
+ }
1801
+
1802
+ function getBtoa() {
1803
+ if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
1804
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
1805
+ } else if (typeof Buffer === 'function') {
1806
+ return (str) => Buffer.from(str, 'utf-8').toString('base64');
1807
+ } else {
1808
+ return () => {
1809
+ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
1810
+ };
1811
+ }
1812
+ }
1813
+
1814
+ const btoa = /*#__PURE__*/ getBtoa();
1815
+
1816
+ class SourceMap {
1817
+ constructor(properties) {
1818
+ this.version = 3;
1819
+ this.file = properties.file;
1820
+ this.sources = properties.sources;
1821
+ this.sourcesContent = properties.sourcesContent;
1822
+ this.names = properties.names;
1823
+ this.mappings = encode(properties.mappings);
1824
+ if (typeof properties.x_google_ignoreList !== 'undefined') {
1825
+ this.x_google_ignoreList = properties.x_google_ignoreList;
1826
+ }
1827
+ if (typeof properties.debugId !== 'undefined') {
1828
+ this.debugId = properties.debugId;
1829
+ }
1830
+ }
1831
+
1832
+ toString() {
1833
+ return JSON.stringify(this);
1834
+ }
1835
+
1836
+ toUrl() {
1837
+ return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
1838
+ }
1839
+ }
1840
+
1841
+ function guessIndent(code) {
1842
+ const lines = code.split('\n');
1843
+
1844
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
1845
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
1846
+
1847
+ if (tabbed.length === 0 && spaced.length === 0) {
1848
+ return null;
1849
+ }
1850
+
1851
+ // More lines tabbed than spaced? Assume tabs, and
1852
+ // default to tabs in the case of a tie (or nothing
1853
+ // to go on)
1854
+ if (tabbed.length >= spaced.length) {
1855
+ return '\t';
1856
+ }
1857
+
1858
+ // Otherwise, we need to guess the multiple
1859
+ const min = spaced.reduce((previous, current) => {
1860
+ const numSpaces = /^ +/.exec(current)[0].length;
1861
+ return Math.min(numSpaces, previous);
1862
+ }, Infinity);
1863
+
1864
+ return new Array(min + 1).join(' ');
1865
+ }
1866
+
1867
+ function getRelativePath(from, to) {
1868
+ const fromParts = from.split(/[/\\]/);
1869
+ const toParts = to.split(/[/\\]/);
1870
+
1871
+ fromParts.pop(); // get dirname
1872
+
1873
+ while (fromParts[0] === toParts[0]) {
1874
+ fromParts.shift();
1875
+ toParts.shift();
1876
+ }
1877
+
1878
+ if (fromParts.length) {
1879
+ let i = fromParts.length;
1880
+ while (i--) fromParts[i] = '..';
1881
+ }
1882
+
1883
+ return fromParts.concat(toParts).join('/');
1884
+ }
1885
+
1886
+ const toString = Object.prototype.toString;
1887
+
1888
+ function isObject(thing) {
1889
+ return toString.call(thing) === '[object Object]';
1890
+ }
1891
+
1892
+ function getLocator(source) {
1893
+ const originalLines = source.split('\n');
1894
+ const lineOffsets = [];
1895
+
1896
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
1897
+ lineOffsets.push(pos);
1898
+ pos += originalLines[i].length + 1;
1899
+ }
1900
+
1901
+ return function locate(index) {
1902
+ let i = 0;
1903
+ let j = lineOffsets.length;
1904
+ while (i < j) {
1905
+ const m = (i + j) >> 1;
1906
+ if (index < lineOffsets[m]) {
1907
+ j = m;
1908
+ } else {
1909
+ i = m + 1;
1910
+ }
1911
+ }
1912
+ const line = i - 1;
1913
+ const column = index - lineOffsets[line];
1914
+ return { line, column };
1915
+ };
1916
+ }
1917
+
1918
+ const wordRegex = /\w/;
1919
+
1920
+ class Mappings {
1921
+ constructor(hires) {
1922
+ this.hires = hires;
1923
+ this.generatedCodeLine = 0;
1924
+ this.generatedCodeColumn = 0;
1925
+ this.raw = [];
1926
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
1927
+ this.pending = null;
1928
+ }
1929
+
1930
+ addEdit(sourceIndex, content, loc, nameIndex) {
1931
+ if (content.length) {
1932
+ const contentLengthMinusOne = content.length - 1;
1933
+ let contentLineEnd = content.indexOf('\n', 0);
1934
+ let previousContentLineEnd = -1;
1935
+ // Loop through each line in the content and add a segment, but stop if the last line is empty,
1936
+ // else code afterwards would fill one line too many
1937
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
1938
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
1939
+ if (nameIndex >= 0) {
1940
+ segment.push(nameIndex);
1941
+ }
1942
+ this.rawSegments.push(segment);
1943
+
1944
+ this.generatedCodeLine += 1;
1945
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
1946
+ this.generatedCodeColumn = 0;
1947
+
1948
+ previousContentLineEnd = contentLineEnd;
1949
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
1950
+ }
1951
+
1952
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
1953
+ if (nameIndex >= 0) {
1954
+ segment.push(nameIndex);
1955
+ }
1956
+ this.rawSegments.push(segment);
1957
+
1958
+ this.advance(content.slice(previousContentLineEnd + 1));
1959
+ } else if (this.pending) {
1960
+ this.rawSegments.push(this.pending);
1961
+ this.advance(content);
1962
+ }
1963
+
1964
+ this.pending = null;
1965
+ }
1966
+
1967
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
1968
+ let originalCharIndex = chunk.start;
1969
+ let first = true;
1970
+ // when iterating each char, check if it's in a word boundary
1971
+ let charInHiresBoundary = false;
1972
+
1973
+ while (originalCharIndex < chunk.end) {
1974
+ if (original[originalCharIndex] === '\n') {
1975
+ loc.line += 1;
1976
+ loc.column = 0;
1977
+ this.generatedCodeLine += 1;
1978
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
1979
+ this.generatedCodeColumn = 0;
1980
+ first = true;
1981
+ charInHiresBoundary = false;
1982
+ } else {
1983
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
1984
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
1985
+
1986
+ if (this.hires === 'boundary') {
1987
+ // in hires "boundary", group segments per word boundary than per char
1988
+ if (wordRegex.test(original[originalCharIndex])) {
1989
+ // for first char in the boundary found, start the boundary by pushing a segment
1990
+ if (!charInHiresBoundary) {
1991
+ this.rawSegments.push(segment);
1992
+ charInHiresBoundary = true;
1993
+ }
1994
+ } else {
1995
+ // for non-word char, end the boundary by pushing a segment
1996
+ this.rawSegments.push(segment);
1997
+ charInHiresBoundary = false;
1998
+ }
1999
+ } else {
2000
+ this.rawSegments.push(segment);
2001
+ }
2002
+ }
2003
+
2004
+ loc.column += 1;
2005
+ this.generatedCodeColumn += 1;
2006
+ first = false;
2007
+ }
2008
+
2009
+ originalCharIndex += 1;
2010
+ }
2011
+
2012
+ this.pending = null;
2013
+ }
2014
+
2015
+ advance(str) {
2016
+ if (!str) return;
2017
+
2018
+ const lines = str.split('\n');
2019
+
2020
+ if (lines.length > 1) {
2021
+ for (let i = 0; i < lines.length - 1; i++) {
2022
+ this.generatedCodeLine++;
2023
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
2024
+ }
2025
+ this.generatedCodeColumn = 0;
2026
+ }
2027
+
2028
+ this.generatedCodeColumn += lines[lines.length - 1].length;
2029
+ }
2030
+ }
2031
+
2032
+ const n = '\n';
2033
+
2034
+ const warned = {
2035
+ insertLeft: false,
2036
+ insertRight: false,
2037
+ storeName: false,
2038
+ };
2039
+
2040
+ class MagicString {
2041
+ constructor(string, options = {}) {
2042
+ const chunk = new Chunk(0, string.length, string);
2043
+
2044
+ Object.defineProperties(this, {
2045
+ original: { writable: true, value: string },
2046
+ outro: { writable: true, value: '' },
2047
+ intro: { writable: true, value: '' },
2048
+ firstChunk: { writable: true, value: chunk },
2049
+ lastChunk: { writable: true, value: chunk },
2050
+ lastSearchedChunk: { writable: true, value: chunk },
2051
+ byStart: { writable: true, value: {} },
2052
+ byEnd: { writable: true, value: {} },
2053
+ filename: { writable: true, value: options.filename },
2054
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
2055
+ sourcemapLocations: { writable: true, value: new BitSet() },
2056
+ storedNames: { writable: true, value: {} },
2057
+ indentStr: { writable: true, value: undefined },
2058
+ ignoreList: { writable: true, value: options.ignoreList },
2059
+ offset: { writable: true, value: options.offset || 0 },
2060
+ });
2061
+
2062
+ this.byStart[0] = chunk;
2063
+ this.byEnd[string.length] = chunk;
2064
+ }
2065
+
2066
+ addSourcemapLocation(char) {
2067
+ this.sourcemapLocations.add(char);
2068
+ }
2069
+
2070
+ append(content) {
2071
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
2072
+
2073
+ this.outro += content;
2074
+ return this;
2075
+ }
2076
+
2077
+ appendLeft(index, content) {
2078
+ index = index + this.offset;
2079
+
2080
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2081
+
2082
+ this._split(index);
2083
+
2084
+ const chunk = this.byEnd[index];
2085
+
2086
+ if (chunk) {
2087
+ chunk.appendLeft(content);
2088
+ } else {
2089
+ this.intro += content;
2090
+ }
2091
+ return this;
2092
+ }
2093
+
2094
+ appendRight(index, content) {
2095
+ index = index + this.offset;
2096
+
2097
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2098
+
2099
+ this._split(index);
2100
+
2101
+ const chunk = this.byStart[index];
2102
+
2103
+ if (chunk) {
2104
+ chunk.appendRight(content);
2105
+ } else {
2106
+ this.outro += content;
2107
+ }
2108
+ return this;
2109
+ }
2110
+
2111
+ clone() {
2112
+ const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
2113
+
2114
+ let originalChunk = this.firstChunk;
2115
+ let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
2116
+
2117
+ while (originalChunk) {
2118
+ cloned.byStart[clonedChunk.start] = clonedChunk;
2119
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
2120
+
2121
+ const nextOriginalChunk = originalChunk.next;
2122
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
2123
+
2124
+ if (nextClonedChunk) {
2125
+ clonedChunk.next = nextClonedChunk;
2126
+ nextClonedChunk.previous = clonedChunk;
2127
+
2128
+ clonedChunk = nextClonedChunk;
2129
+ }
2130
+
2131
+ originalChunk = nextOriginalChunk;
2132
+ }
2133
+
2134
+ cloned.lastChunk = clonedChunk;
2135
+
2136
+ if (this.indentExclusionRanges) {
2137
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
2138
+ }
2139
+
2140
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
2141
+
2142
+ cloned.intro = this.intro;
2143
+ cloned.outro = this.outro;
2144
+
2145
+ return cloned;
2146
+ }
2147
+
2148
+ generateDecodedMap(options) {
2149
+ options = options || {};
2150
+
2151
+ const sourceIndex = 0;
2152
+ const names = Object.keys(this.storedNames);
2153
+ const mappings = new Mappings(options.hires);
2154
+
2155
+ const locate = getLocator(this.original);
2156
+
2157
+ if (this.intro) {
2158
+ mappings.advance(this.intro);
2159
+ }
2160
+
2161
+ this.firstChunk.eachNext((chunk) => {
2162
+ const loc = locate(chunk.start);
2163
+
2164
+ if (chunk.intro.length) mappings.advance(chunk.intro);
2165
+
2166
+ if (chunk.edited) {
2167
+ mappings.addEdit(
2168
+ sourceIndex,
2169
+ chunk.content,
2170
+ loc,
2171
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
2172
+ );
2173
+ } else {
2174
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
2175
+ }
2176
+
2177
+ if (chunk.outro.length) mappings.advance(chunk.outro);
2178
+ });
2179
+
2180
+ if (this.outro) {
2181
+ mappings.advance(this.outro);
2182
+ }
2183
+
2184
+ return {
2185
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
2186
+ sources: [
2187
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
2188
+ ],
2189
+ sourcesContent: options.includeContent ? [this.original] : undefined,
2190
+ names,
2191
+ mappings: mappings.raw,
2192
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
2193
+ };
2194
+ }
2195
+
2196
+ generateMap(options) {
2197
+ return new SourceMap(this.generateDecodedMap(options));
2198
+ }
2199
+
2200
+ _ensureindentStr() {
2201
+ if (this.indentStr === undefined) {
2202
+ this.indentStr = guessIndent(this.original);
2203
+ }
2204
+ }
2205
+
2206
+ _getRawIndentString() {
2207
+ this._ensureindentStr();
2208
+ return this.indentStr;
2209
+ }
2210
+
2211
+ getIndentString() {
2212
+ this._ensureindentStr();
2213
+ return this.indentStr === null ? '\t' : this.indentStr;
2214
+ }
2215
+
2216
+ indent(indentStr, options) {
2217
+ const pattern = /^[^\r\n]/gm;
2218
+
2219
+ if (isObject(indentStr)) {
2220
+ options = indentStr;
2221
+ indentStr = undefined;
2222
+ }
2223
+
2224
+ if (indentStr === undefined) {
2225
+ this._ensureindentStr();
2226
+ indentStr = this.indentStr || '\t';
2227
+ }
2228
+
2229
+ if (indentStr === '') return this; // noop
2230
+
2231
+ options = options || {};
2232
+
2233
+ // Process exclusion ranges
2234
+ const isExcluded = {};
2235
+
2236
+ if (options.exclude) {
2237
+ const exclusions =
2238
+ typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
2239
+ exclusions.forEach((exclusion) => {
2240
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
2241
+ isExcluded[i] = true;
2242
+ }
2243
+ });
2244
+ }
2245
+
2246
+ let shouldIndentNextCharacter = options.indentStart !== false;
2247
+ const replacer = (match) => {
2248
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
2249
+ shouldIndentNextCharacter = true;
2250
+ return match;
2251
+ };
2252
+
2253
+ this.intro = this.intro.replace(pattern, replacer);
2254
+
2255
+ let charIndex = 0;
2256
+ let chunk = this.firstChunk;
2257
+
2258
+ while (chunk) {
2259
+ const end = chunk.end;
2260
+
2261
+ if (chunk.edited) {
2262
+ if (!isExcluded[charIndex]) {
2263
+ chunk.content = chunk.content.replace(pattern, replacer);
2264
+
2265
+ if (chunk.content.length) {
2266
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
2267
+ }
2268
+ }
2269
+ } else {
2270
+ charIndex = chunk.start;
2271
+
2272
+ while (charIndex < end) {
2273
+ if (!isExcluded[charIndex]) {
2274
+ const char = this.original[charIndex];
2275
+
2276
+ if (char === '\n') {
2277
+ shouldIndentNextCharacter = true;
2278
+ } else if (char !== '\r' && shouldIndentNextCharacter) {
2279
+ shouldIndentNextCharacter = false;
2280
+
2281
+ if (charIndex === chunk.start) {
2282
+ chunk.prependRight(indentStr);
2283
+ } else {
2284
+ this._splitChunk(chunk, charIndex);
2285
+ chunk = chunk.next;
2286
+ chunk.prependRight(indentStr);
2287
+ }
2288
+ }
2289
+ }
2290
+
2291
+ charIndex += 1;
2292
+ }
2293
+ }
2294
+
2295
+ charIndex = chunk.end;
2296
+ chunk = chunk.next;
2297
+ }
2298
+
2299
+ this.outro = this.outro.replace(pattern, replacer);
2300
+
2301
+ return this;
2302
+ }
2303
+
2304
+ insert() {
2305
+ throw new Error(
2306
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
2307
+ );
2308
+ }
2309
+
2310
+ insertLeft(index, content) {
2311
+ if (!warned.insertLeft) {
2312
+ console.warn(
2313
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
2314
+ );
2315
+ warned.insertLeft = true;
2316
+ }
2317
+
2318
+ return this.appendLeft(index, content);
2319
+ }
2320
+
2321
+ insertRight(index, content) {
2322
+ if (!warned.insertRight) {
2323
+ console.warn(
2324
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
2325
+ );
2326
+ warned.insertRight = true;
2327
+ }
2328
+
2329
+ return this.prependRight(index, content);
2330
+ }
2331
+
2332
+ move(start, end, index) {
2333
+ start = start + this.offset;
2334
+ end = end + this.offset;
2335
+ index = index + this.offset;
2336
+
2337
+ if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
2338
+
2339
+ this._split(start);
2340
+ this._split(end);
2341
+ this._split(index);
2342
+
2343
+ const first = this.byStart[start];
2344
+ const last = this.byEnd[end];
2345
+
2346
+ const oldLeft = first.previous;
2347
+ const oldRight = last.next;
2348
+
2349
+ const newRight = this.byStart[index];
2350
+ if (!newRight && last === this.lastChunk) return this;
2351
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
2352
+
2353
+ if (oldLeft) oldLeft.next = oldRight;
2354
+ if (oldRight) oldRight.previous = oldLeft;
2355
+
2356
+ if (newLeft) newLeft.next = first;
2357
+ if (newRight) newRight.previous = last;
2358
+
2359
+ if (!first.previous) this.firstChunk = last.next;
2360
+ if (!last.next) {
2361
+ this.lastChunk = first.previous;
2362
+ this.lastChunk.next = null;
2363
+ }
2364
+
2365
+ first.previous = newLeft;
2366
+ last.next = newRight || null;
2367
+
2368
+ if (!newLeft) this.firstChunk = first;
2369
+ if (!newRight) this.lastChunk = last;
2370
+ return this;
2371
+ }
2372
+
2373
+ overwrite(start, end, content, options) {
2374
+ options = options || {};
2375
+ return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
2376
+ }
2377
+
2378
+ update(start, end, content, options) {
2379
+ start = start + this.offset;
2380
+ end = end + this.offset;
2381
+
2382
+ if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
2383
+
2384
+ if (this.original.length !== 0) {
2385
+ while (start < 0) start += this.original.length;
2386
+ while (end < 0) end += this.original.length;
2387
+ }
2388
+
2389
+ if (end > this.original.length) throw new Error('end is out of bounds');
2390
+ if (start === end)
2391
+ throw new Error(
2392
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
2393
+ );
2394
+
2395
+ this._split(start);
2396
+ this._split(end);
2397
+
2398
+ if (options === true) {
2399
+ if (!warned.storeName) {
2400
+ console.warn(
2401
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
2402
+ );
2403
+ warned.storeName = true;
2404
+ }
2405
+
2406
+ options = { storeName: true };
2407
+ }
2408
+ const storeName = options !== undefined ? options.storeName : false;
2409
+ const overwrite = options !== undefined ? options.overwrite : false;
2410
+
2411
+ if (storeName) {
2412
+ const original = this.original.slice(start, end);
2413
+ Object.defineProperty(this.storedNames, original, {
2414
+ writable: true,
2415
+ value: true,
2416
+ enumerable: true,
2417
+ });
2418
+ }
2419
+
2420
+ const first = this.byStart[start];
2421
+ const last = this.byEnd[end];
2422
+
2423
+ if (first) {
2424
+ let chunk = first;
2425
+ while (chunk !== last) {
2426
+ if (chunk.next !== this.byStart[chunk.end]) {
2427
+ throw new Error('Cannot overwrite across a split point');
2428
+ }
2429
+ chunk = chunk.next;
2430
+ chunk.edit('', false);
2431
+ }
2432
+
2433
+ first.edit(content, storeName, !overwrite);
2434
+ } else {
2435
+ // must be inserting at the end
2436
+ const newChunk = new Chunk(start, end, '').edit(content, storeName);
2437
+
2438
+ // TODO last chunk in the array may not be the last chunk, if it's moved...
2439
+ last.next = newChunk;
2440
+ newChunk.previous = last;
2441
+ }
2442
+ return this;
2443
+ }
2444
+
2445
+ prepend(content) {
2446
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
2447
+
2448
+ this.intro = content + this.intro;
2449
+ return this;
2450
+ }
2451
+
2452
+ prependLeft(index, content) {
2453
+ index = index + this.offset;
2454
+
2455
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2456
+
2457
+ this._split(index);
2458
+
2459
+ const chunk = this.byEnd[index];
2460
+
2461
+ if (chunk) {
2462
+ chunk.prependLeft(content);
2463
+ } else {
2464
+ this.intro = content + this.intro;
2465
+ }
2466
+ return this;
2467
+ }
2468
+
2469
+ prependRight(index, content) {
2470
+ index = index + this.offset;
2471
+
2472
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
2473
+
2474
+ this._split(index);
2475
+
2476
+ const chunk = this.byStart[index];
2477
+
2478
+ if (chunk) {
2479
+ chunk.prependRight(content);
2480
+ } else {
2481
+ this.outro = content + this.outro;
2482
+ }
2483
+ return this;
2484
+ }
2485
+
2486
+ remove(start, end) {
2487
+ start = start + this.offset;
2488
+ end = end + this.offset;
2489
+
2490
+ if (this.original.length !== 0) {
2491
+ while (start < 0) start += this.original.length;
2492
+ while (end < 0) end += this.original.length;
2493
+ }
2494
+
2495
+ if (start === end) return this;
2496
+
2497
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
2498
+ if (start > end) throw new Error('end must be greater than start');
2499
+
2500
+ this._split(start);
2501
+ this._split(end);
2502
+
2503
+ let chunk = this.byStart[start];
2504
+
2505
+ while (chunk) {
2506
+ chunk.intro = '';
2507
+ chunk.outro = '';
2508
+ chunk.edit('');
2509
+
2510
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
2511
+ }
2512
+ return this;
2513
+ }
2514
+
2515
+ reset(start, end) {
2516
+ start = start + this.offset;
2517
+ end = end + this.offset;
2518
+
2519
+ if (this.original.length !== 0) {
2520
+ while (start < 0) start += this.original.length;
2521
+ while (end < 0) end += this.original.length;
2522
+ }
2523
+
2524
+ if (start === end) return this;
2525
+
2526
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
2527
+ if (start > end) throw new Error('end must be greater than start');
2528
+
2529
+ this._split(start);
2530
+ this._split(end);
2531
+
2532
+ let chunk = this.byStart[start];
2533
+
2534
+ while (chunk) {
2535
+ chunk.reset();
2536
+
2537
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
2538
+ }
2539
+ return this;
2540
+ }
2541
+
2542
+ lastChar() {
2543
+ if (this.outro.length) return this.outro[this.outro.length - 1];
2544
+ let chunk = this.lastChunk;
2545
+ do {
2546
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
2547
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
2548
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
2549
+ } while ((chunk = chunk.previous));
2550
+ if (this.intro.length) return this.intro[this.intro.length - 1];
2551
+ return '';
2552
+ }
2553
+
2554
+ lastLine() {
2555
+ let lineIndex = this.outro.lastIndexOf(n);
2556
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
2557
+ let lineStr = this.outro;
2558
+ let chunk = this.lastChunk;
2559
+ do {
2560
+ if (chunk.outro.length > 0) {
2561
+ lineIndex = chunk.outro.lastIndexOf(n);
2562
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
2563
+ lineStr = chunk.outro + lineStr;
2564
+ }
2565
+
2566
+ if (chunk.content.length > 0) {
2567
+ lineIndex = chunk.content.lastIndexOf(n);
2568
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
2569
+ lineStr = chunk.content + lineStr;
2570
+ }
2571
+
2572
+ if (chunk.intro.length > 0) {
2573
+ lineIndex = chunk.intro.lastIndexOf(n);
2574
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
2575
+ lineStr = chunk.intro + lineStr;
2576
+ }
2577
+ } while ((chunk = chunk.previous));
2578
+ lineIndex = this.intro.lastIndexOf(n);
2579
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
2580
+ return this.intro + lineStr;
2581
+ }
2582
+
2583
+ slice(start = 0, end = this.original.length - this.offset) {
2584
+ start = start + this.offset;
2585
+ end = end + this.offset;
2586
+
2587
+ if (this.original.length !== 0) {
2588
+ while (start < 0) start += this.original.length;
2589
+ while (end < 0) end += this.original.length;
2590
+ }
2591
+
2592
+ let result = '';
2593
+
2594
+ // find start chunk
2595
+ let chunk = this.firstChunk;
2596
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
2597
+ // found end chunk before start
2598
+ if (chunk.start < end && chunk.end >= end) {
2599
+ return result;
2600
+ }
2601
+
2602
+ chunk = chunk.next;
2603
+ }
2604
+
2605
+ if (chunk && chunk.edited && chunk.start !== start)
2606
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
2607
+
2608
+ const startChunk = chunk;
2609
+ while (chunk) {
2610
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
2611
+ result += chunk.intro;
2612
+ }
2613
+
2614
+ const containsEnd = chunk.start < end && chunk.end >= end;
2615
+ if (containsEnd && chunk.edited && chunk.end !== end)
2616
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
2617
+
2618
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
2619
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
2620
+
2621
+ result += chunk.content.slice(sliceStart, sliceEnd);
2622
+
2623
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
2624
+ result += chunk.outro;
2625
+ }
2626
+
2627
+ if (containsEnd) {
2628
+ break;
2629
+ }
2630
+
2631
+ chunk = chunk.next;
2632
+ }
2633
+
2634
+ return result;
2635
+ }
2636
+
2637
+ // TODO deprecate this? not really very useful
2638
+ snip(start, end) {
2639
+ const clone = this.clone();
2640
+ clone.remove(0, start);
2641
+ clone.remove(end, clone.original.length);
2642
+
2643
+ return clone;
2644
+ }
2645
+
2646
+ _split(index) {
2647
+ if (this.byStart[index] || this.byEnd[index]) return;
2648
+
2649
+ let chunk = this.lastSearchedChunk;
2650
+ let previousChunk = chunk;
2651
+ const searchForward = index > chunk.end;
2652
+
2653
+ while (chunk) {
2654
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
2655
+
2656
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
2657
+
2658
+ // Prevent infinite loop (e.g. via empty chunks, where start === end)
2659
+ if (chunk === previousChunk) return;
2660
+
2661
+ previousChunk = chunk;
2662
+ }
2663
+ }
2664
+
2665
+ _splitChunk(chunk, index) {
2666
+ if (chunk.edited && chunk.content.length) {
2667
+ // zero-length edited chunks are a special case (overlapping replacements)
2668
+ const loc = getLocator(this.original)(index);
2669
+ throw new Error(
2670
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
2671
+ );
2672
+ }
2673
+
2674
+ const newChunk = chunk.split(index);
2675
+
2676
+ this.byEnd[index] = chunk;
2677
+ this.byStart[index] = newChunk;
2678
+ this.byEnd[newChunk.end] = newChunk;
2679
+
2680
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
2681
+
2682
+ this.lastSearchedChunk = chunk;
2683
+ return true;
2684
+ }
2685
+
2686
+ toString() {
2687
+ let str = this.intro;
2688
+
2689
+ let chunk = this.firstChunk;
2690
+ while (chunk) {
2691
+ str += chunk.toString();
2692
+ chunk = chunk.next;
2693
+ }
2694
+
2695
+ return str + this.outro;
2696
+ }
2697
+
2698
+ isEmpty() {
2699
+ let chunk = this.firstChunk;
2700
+ do {
2701
+ if (
2702
+ (chunk.intro.length && chunk.intro.trim()) ||
2703
+ (chunk.content.length && chunk.content.trim()) ||
2704
+ (chunk.outro.length && chunk.outro.trim())
2705
+ )
2706
+ return false;
2707
+ } while ((chunk = chunk.next));
2708
+ return true;
2709
+ }
2710
+
2711
+ length() {
2712
+ let chunk = this.firstChunk;
2713
+ let length = 0;
2714
+ do {
2715
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
2716
+ } while ((chunk = chunk.next));
2717
+ return length;
2718
+ }
2719
+
2720
+ trimLines() {
2721
+ return this.trim('[\\r\\n]');
2722
+ }
2723
+
2724
+ trim(charType) {
2725
+ return this.trimStart(charType).trimEnd(charType);
2726
+ }
2727
+
2728
+ trimEndAborted(charType) {
2729
+ const rx = new RegExp((charType || '\\s') + '+$');
2730
+
2731
+ this.outro = this.outro.replace(rx, '');
2732
+ if (this.outro.length) return true;
2733
+
2734
+ let chunk = this.lastChunk;
2735
+
2736
+ do {
2737
+ const end = chunk.end;
2738
+ const aborted = chunk.trimEnd(rx);
2739
+
2740
+ // if chunk was trimmed, we have a new lastChunk
2741
+ if (chunk.end !== end) {
2742
+ if (this.lastChunk === chunk) {
2743
+ this.lastChunk = chunk.next;
2744
+ }
2745
+
2746
+ this.byEnd[chunk.end] = chunk;
2747
+ this.byStart[chunk.next.start] = chunk.next;
2748
+ this.byEnd[chunk.next.end] = chunk.next;
2749
+ }
2750
+
2751
+ if (aborted) return true;
2752
+ chunk = chunk.previous;
2753
+ } while (chunk);
2754
+
2755
+ return false;
2756
+ }
2757
+
2758
+ trimEnd(charType) {
2759
+ this.trimEndAborted(charType);
2760
+ return this;
2761
+ }
2762
+ trimStartAborted(charType) {
2763
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
2764
+
2765
+ this.intro = this.intro.replace(rx, '');
2766
+ if (this.intro.length) return true;
2767
+
2768
+ let chunk = this.firstChunk;
2769
+
2770
+ do {
2771
+ const end = chunk.end;
2772
+ const aborted = chunk.trimStart(rx);
2773
+
2774
+ if (chunk.end !== end) {
2775
+ // special case...
2776
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
2777
+
2778
+ this.byEnd[chunk.end] = chunk;
2779
+ this.byStart[chunk.next.start] = chunk.next;
2780
+ this.byEnd[chunk.next.end] = chunk.next;
2781
+ }
2782
+
2783
+ if (aborted) return true;
2784
+ chunk = chunk.next;
2785
+ } while (chunk);
2786
+
2787
+ return false;
2788
+ }
2789
+
2790
+ trimStart(charType) {
2791
+ this.trimStartAborted(charType);
2792
+ return this;
2793
+ }
2794
+
2795
+ hasChanged() {
2796
+ return this.original !== this.toString();
2797
+ }
2798
+
2799
+ _replaceRegexp(searchValue, replacement) {
2800
+ function getReplacement(match, str) {
2801
+ if (typeof replacement === 'string') {
2802
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
2803
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
2804
+ if (i === '$') return '$';
2805
+ if (i === '&') return match[0];
2806
+ const num = +i;
2807
+ if (num < match.length) return match[+i];
2808
+ return `$${i}`;
2809
+ });
2810
+ } else {
2811
+ return replacement(...match, match.index, str, match.groups);
2812
+ }
2813
+ }
2814
+ function matchAll(re, str) {
2815
+ let match;
2816
+ const matches = [];
2817
+ while ((match = re.exec(str))) {
2818
+ matches.push(match);
2819
+ }
2820
+ return matches;
2821
+ }
2822
+ if (searchValue.global) {
2823
+ const matches = matchAll(searchValue, this.original);
2824
+ matches.forEach((match) => {
2825
+ if (match.index != null) {
2826
+ const replacement = getReplacement(match, this.original);
2827
+ if (replacement !== match[0]) {
2828
+ this.overwrite(match.index, match.index + match[0].length, replacement);
2829
+ }
2830
+ }
2831
+ });
2832
+ } else {
2833
+ const match = this.original.match(searchValue);
2834
+ if (match && match.index != null) {
2835
+ const replacement = getReplacement(match, this.original);
2836
+ if (replacement !== match[0]) {
2837
+ this.overwrite(match.index, match.index + match[0].length, replacement);
2838
+ }
2839
+ }
2840
+ }
2841
+ return this;
2842
+ }
2843
+
2844
+ _replaceString(string, replacement) {
2845
+ const { original } = this;
2846
+ const index = original.indexOf(string);
2847
+
2848
+ if (index !== -1) {
2849
+ if (typeof replacement === 'function') {
2850
+ replacement = replacement(string, index, original);
2851
+ }
2852
+ if (string !== replacement) {
2853
+ this.overwrite(index, index + string.length, replacement);
2854
+ }
2855
+ }
2856
+
2857
+ return this;
2858
+ }
2859
+
2860
+ replace(searchValue, replacement) {
2861
+ if (typeof searchValue === 'string') {
2862
+ return this._replaceString(searchValue, replacement);
2863
+ }
2864
+
2865
+ return this._replaceRegexp(searchValue, replacement);
2866
+ }
2867
+
2868
+ _replaceAllString(string, replacement) {
2869
+ const { original } = this;
2870
+ const stringLength = string.length;
2871
+ for (
2872
+ let index = original.indexOf(string);
2873
+ index !== -1;
2874
+ index = original.indexOf(string, index + stringLength)
2875
+ ) {
2876
+ const previous = original.slice(index, index + stringLength);
2877
+ let _replacement = replacement;
2878
+ if (typeof replacement === 'function') {
2879
+ _replacement = replacement(previous, index, original);
2880
+ }
2881
+ if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
2882
+ }
2883
+
2884
+ return this;
2885
+ }
2886
+
2887
+ replaceAll(searchValue, replacement) {
2888
+ if (typeof searchValue === 'string') {
2889
+ return this._replaceAllString(searchValue, replacement);
2890
+ }
2891
+
2892
+ if (!searchValue.global) {
2893
+ throw new TypeError(
2894
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
2895
+ );
2896
+ }
2897
+
2898
+ return this._replaceRegexp(searchValue, replacement);
2899
+ }
2900
+ }
2901
+
1525
2902
  const cache = new Map();
1526
2903
  function mcxPlugn() {
1527
2904
  return {
1528
2905
  name: "mbler-mcx-core",
1529
2906
  async transform(code, id, options) {
2907
+ const magic = new MagicString(code);
1530
2908
  const ext = path.extname(id).slice(1);
1531
2909
  if (ext == "mcx") {
1532
2910
  let compileData;
@@ -1547,7 +2925,8 @@ function mcxPlugn() {
1547
2925
  }
1548
2926
  compileData.setFilePath(id);
1549
2927
  return {
1550
- code: await transform(compileData, cache, id, this)
2928
+ code: await transform(compileData, cache, id, this),
2929
+ map: magic.generateMap({ hires: true, source: id })
1551
2930
  };
1552
2931
  }
1553
2932
  return null;