magic-string.umd.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MagicString = factory());
  5. })(this, (function () { 'use strict';
  6. class BitSet {
  7. constructor(arg) {
  8. this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
  9. }
  10. add(n) {
  11. this.bits[n >> 5] |= 1 << (n & 31);
  12. }
  13. has(n) {
  14. return !!(this.bits[n >> 5] & (1 << (n & 31)));
  15. }
  16. }
  17. class Chunk {
  18. constructor(start, end, content) {
  19. this.start = start;
  20. this.end = end;
  21. this.original = content;
  22. this.intro = '';
  23. this.outro = '';
  24. this.content = content;
  25. this.storeName = false;
  26. this.edited = false;
  27. {
  28. this.previous = null;
  29. this.next = null;
  30. }
  31. }
  32. appendLeft(content) {
  33. this.outro += content;
  34. }
  35. appendRight(content) {
  36. this.intro = this.intro + content;
  37. }
  38. clone() {
  39. const chunk = new Chunk(this.start, this.end, this.original);
  40. chunk.intro = this.intro;
  41. chunk.outro = this.outro;
  42. chunk.content = this.content;
  43. chunk.storeName = this.storeName;
  44. chunk.edited = this.edited;
  45. return chunk;
  46. }
  47. contains(index) {
  48. return this.start < index && index < this.end;
  49. }
  50. eachNext(fn) {
  51. let chunk = this;
  52. while (chunk) {
  53. fn(chunk);
  54. chunk = chunk.next;
  55. }
  56. }
  57. eachPrevious(fn) {
  58. let chunk = this;
  59. while (chunk) {
  60. fn(chunk);
  61. chunk = chunk.previous;
  62. }
  63. }
  64. edit(content, storeName, contentOnly) {
  65. this.content = content;
  66. if (!contentOnly) {
  67. this.intro = '';
  68. this.outro = '';
  69. }
  70. this.storeName = storeName;
  71. this.edited = true;
  72. return this;
  73. }
  74. prependLeft(content) {
  75. this.outro = content + this.outro;
  76. }
  77. prependRight(content) {
  78. this.intro = content + this.intro;
  79. }
  80. split(index) {
  81. const sliceIndex = index - this.start;
  82. const originalBefore = this.original.slice(0, sliceIndex);
  83. const originalAfter = this.original.slice(sliceIndex);
  84. this.original = originalBefore;
  85. const newChunk = new Chunk(index, this.end, originalAfter);
  86. newChunk.outro = this.outro;
  87. this.outro = '';
  88. this.end = index;
  89. if (this.edited) {
  90. // TODO is this block necessary?...
  91. newChunk.edit('', false);
  92. this.content = '';
  93. } else {
  94. this.content = originalBefore;
  95. }
  96. newChunk.next = this.next;
  97. if (newChunk.next) newChunk.next.previous = newChunk;
  98. newChunk.previous = this;
  99. this.next = newChunk;
  100. return newChunk;
  101. }
  102. toString() {
  103. return this.intro + this.content + this.outro;
  104. }
  105. trimEnd(rx) {
  106. this.outro = this.outro.replace(rx, '');
  107. if (this.outro.length) return true;
  108. const trimmed = this.content.replace(rx, '');
  109. if (trimmed.length) {
  110. if (trimmed !== this.content) {
  111. this.split(this.start + trimmed.length).edit('', undefined, true);
  112. }
  113. return true;
  114. } else {
  115. this.edit('', undefined, true);
  116. this.intro = this.intro.replace(rx, '');
  117. if (this.intro.length) return true;
  118. }
  119. }
  120. trimStart(rx) {
  121. this.intro = this.intro.replace(rx, '');
  122. if (this.intro.length) return true;
  123. const trimmed = this.content.replace(rx, '');
  124. if (trimmed.length) {
  125. if (trimmed !== this.content) {
  126. this.split(this.end - trimmed.length);
  127. this.edit('', undefined, true);
  128. }
  129. return true;
  130. } else {
  131. this.edit('', undefined, true);
  132. this.outro = this.outro.replace(rx, '');
  133. if (this.outro.length) return true;
  134. }
  135. }
  136. }
  137. const comma = ','.charCodeAt(0);
  138. const semicolon = ';'.charCodeAt(0);
  139. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  140. const intToChar = new Uint8Array(64); // 64 possible chars.
  141. const charToInt = new Uint8Array(128); // z is 122 in ASCII
  142. for (let i = 0; i < chars.length; i++) {
  143. const c = chars.charCodeAt(i);
  144. intToChar[i] = c;
  145. charToInt[c] = i;
  146. }
  147. // Provide a fallback for older environments.
  148. const td = typeof TextDecoder !== 'undefined'
  149. ? /* #__PURE__ */ new TextDecoder()
  150. : typeof Buffer !== 'undefined'
  151. ? {
  152. decode(buf) {
  153. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  154. return out.toString();
  155. },
  156. }
  157. : {
  158. decode(buf) {
  159. let out = '';
  160. for (let i = 0; i < buf.length; i++) {
  161. out += String.fromCharCode(buf[i]);
  162. }
  163. return out;
  164. },
  165. };
  166. function encode(decoded) {
  167. const state = new Int32Array(5);
  168. const bufLength = 1024 * 16;
  169. const subLength = bufLength - 36;
  170. const buf = new Uint8Array(bufLength);
  171. const sub = buf.subarray(0, subLength);
  172. let pos = 0;
  173. let out = '';
  174. for (let i = 0; i < decoded.length; i++) {
  175. const line = decoded[i];
  176. if (i > 0) {
  177. if (pos === bufLength) {
  178. out += td.decode(buf);
  179. pos = 0;
  180. }
  181. buf[pos++] = semicolon;
  182. }
  183. if (line.length === 0)
  184. continue;
  185. state[0] = 0;
  186. for (let j = 0; j < line.length; j++) {
  187. const segment = line[j];
  188. // We can push up to 5 ints, each int can take at most 7 chars, and we
  189. // may push a comma.
  190. if (pos > subLength) {
  191. out += td.decode(sub);
  192. buf.copyWithin(0, subLength, pos);
  193. pos -= subLength;
  194. }
  195. if (j > 0)
  196. buf[pos++] = comma;
  197. pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
  198. if (segment.length === 1)
  199. continue;
  200. pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
  201. pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
  202. pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
  203. if (segment.length === 4)
  204. continue;
  205. pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
  206. }
  207. }
  208. return out + td.decode(buf.subarray(0, pos));
  209. }
  210. function encodeInteger(buf, pos, state, segment, j) {
  211. const next = segment[j];
  212. let num = next - state[j];
  213. state[j] = next;
  214. num = num < 0 ? (-num << 1) | 1 : num << 1;
  215. do {
  216. let clamped = num & 0b011111;
  217. num >>>= 5;
  218. if (num > 0)
  219. clamped |= 0b100000;
  220. buf[pos++] = intToChar[clamped];
  221. } while (num > 0);
  222. return pos;
  223. }
  224. function getBtoa () {
  225. if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
  226. return (str) => window.btoa(unescape(encodeURIComponent(str)));
  227. } else if (typeof Buffer === 'function') {
  228. return (str) => Buffer.from(str, 'utf-8').toString('base64');
  229. } else {
  230. return () => {
  231. throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
  232. };
  233. }
  234. }
  235. const btoa = /*#__PURE__*/ getBtoa();
  236. class SourceMap {
  237. constructor(properties) {
  238. this.version = 3;
  239. this.file = properties.file;
  240. this.sources = properties.sources;
  241. this.sourcesContent = properties.sourcesContent;
  242. this.names = properties.names;
  243. this.mappings = encode(properties.mappings);
  244. if (typeof properties.x_google_ignoreList !== 'undefined') {
  245. this.x_google_ignoreList = properties.x_google_ignoreList;
  246. }
  247. }
  248. toString() {
  249. return JSON.stringify(this);
  250. }
  251. toUrl() {
  252. return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
  253. }
  254. }
  255. function guessIndent(code) {
  256. const lines = code.split('\n');
  257. const tabbed = lines.filter((line) => /^\t+/.test(line));
  258. const spaced = lines.filter((line) => /^ {2,}/.test(line));
  259. if (tabbed.length === 0 && spaced.length === 0) {
  260. return null;
  261. }
  262. // More lines tabbed than spaced? Assume tabs, and
  263. // default to tabs in the case of a tie (or nothing
  264. // to go on)
  265. if (tabbed.length >= spaced.length) {
  266. return '\t';
  267. }
  268. // Otherwise, we need to guess the multiple
  269. const min = spaced.reduce((previous, current) => {
  270. const numSpaces = /^ +/.exec(current)[0].length;
  271. return Math.min(numSpaces, previous);
  272. }, Infinity);
  273. return new Array(min + 1).join(' ');
  274. }
  275. function getRelativePath(from, to) {
  276. const fromParts = from.split(/[/\\]/);
  277. const toParts = to.split(/[/\\]/);
  278. fromParts.pop(); // get dirname
  279. while (fromParts[0] === toParts[0]) {
  280. fromParts.shift();
  281. toParts.shift();
  282. }
  283. if (fromParts.length) {
  284. let i = fromParts.length;
  285. while (i--) fromParts[i] = '..';
  286. }
  287. return fromParts.concat(toParts).join('/');
  288. }
  289. const toString = Object.prototype.toString;
  290. function isObject(thing) {
  291. return toString.call(thing) === '[object Object]';
  292. }
  293. function getLocator(source) {
  294. const originalLines = source.split('\n');
  295. const lineOffsets = [];
  296. for (let i = 0, pos = 0; i < originalLines.length; i++) {
  297. lineOffsets.push(pos);
  298. pos += originalLines[i].length + 1;
  299. }
  300. return function locate(index) {
  301. let i = 0;
  302. let j = lineOffsets.length;
  303. while (i < j) {
  304. const m = (i + j) >> 1;
  305. if (index < lineOffsets[m]) {
  306. j = m;
  307. } else {
  308. i = m + 1;
  309. }
  310. }
  311. const line = i - 1;
  312. const column = index - lineOffsets[line];
  313. return { line, column };
  314. };
  315. }
  316. class Mappings {
  317. constructor(hires) {
  318. this.hires = hires;
  319. this.generatedCodeLine = 0;
  320. this.generatedCodeColumn = 0;
  321. this.raw = [];
  322. this.rawSegments = this.raw[this.generatedCodeLine] = [];
  323. this.pending = null;
  324. }
  325. addEdit(sourceIndex, content, loc, nameIndex) {
  326. if (content.length) {
  327. const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
  328. if (nameIndex >= 0) {
  329. segment.push(nameIndex);
  330. }
  331. this.rawSegments.push(segment);
  332. } else if (this.pending) {
  333. this.rawSegments.push(this.pending);
  334. }
  335. this.advance(content);
  336. this.pending = null;
  337. }
  338. addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
  339. let originalCharIndex = chunk.start;
  340. let first = true;
  341. while (originalCharIndex < chunk.end) {
  342. if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
  343. this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
  344. }
  345. if (original[originalCharIndex] === '\n') {
  346. loc.line += 1;
  347. loc.column = 0;
  348. this.generatedCodeLine += 1;
  349. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  350. this.generatedCodeColumn = 0;
  351. first = true;
  352. } else {
  353. loc.column += 1;
  354. this.generatedCodeColumn += 1;
  355. first = false;
  356. }
  357. originalCharIndex += 1;
  358. }
  359. this.pending = null;
  360. }
  361. advance(str) {
  362. if (!str) return;
  363. const lines = str.split('\n');
  364. if (lines.length > 1) {
  365. for (let i = 0; i < lines.length - 1; i++) {
  366. this.generatedCodeLine++;
  367. this.raw[this.generatedCodeLine] = this.rawSegments = [];
  368. }
  369. this.generatedCodeColumn = 0;
  370. }
  371. this.generatedCodeColumn += lines[lines.length - 1].length;
  372. }
  373. }
  374. const n = '\n';
  375. const warned = {
  376. insertLeft: false,
  377. insertRight: false,
  378. storeName: false,
  379. };
  380. class MagicString {
  381. constructor(string, options = {}) {
  382. const chunk = new Chunk(0, string.length, string);
  383. Object.defineProperties(this, {
  384. original: { writable: true, value: string },
  385. outro: { writable: true, value: '' },
  386. intro: { writable: true, value: '' },
  387. firstChunk: { writable: true, value: chunk },
  388. lastChunk: { writable: true, value: chunk },
  389. lastSearchedChunk: { writable: true, value: chunk },
  390. byStart: { writable: true, value: {} },
  391. byEnd: { writable: true, value: {} },
  392. filename: { writable: true, value: options.filename },
  393. indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
  394. sourcemapLocations: { writable: true, value: new BitSet() },
  395. storedNames: { writable: true, value: {} },
  396. indentStr: { writable: true, value: undefined },
  397. ignoreList: { writable: true, value: options.ignoreList },
  398. });
  399. this.byStart[0] = chunk;
  400. this.byEnd[string.length] = chunk;
  401. }
  402. addSourcemapLocation(char) {
  403. this.sourcemapLocations.add(char);
  404. }
  405. append(content) {
  406. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  407. this.outro += content;
  408. return this;
  409. }
  410. appendLeft(index, content) {
  411. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  412. this._split(index);
  413. const chunk = this.byEnd[index];
  414. if (chunk) {
  415. chunk.appendLeft(content);
  416. } else {
  417. this.intro += content;
  418. }
  419. return this;
  420. }
  421. appendRight(index, content) {
  422. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  423. this._split(index);
  424. const chunk = this.byStart[index];
  425. if (chunk) {
  426. chunk.appendRight(content);
  427. } else {
  428. this.outro += content;
  429. }
  430. return this;
  431. }
  432. clone() {
  433. const cloned = new MagicString(this.original, { filename: this.filename });
  434. let originalChunk = this.firstChunk;
  435. let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
  436. while (originalChunk) {
  437. cloned.byStart[clonedChunk.start] = clonedChunk;
  438. cloned.byEnd[clonedChunk.end] = clonedChunk;
  439. const nextOriginalChunk = originalChunk.next;
  440. const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
  441. if (nextClonedChunk) {
  442. clonedChunk.next = nextClonedChunk;
  443. nextClonedChunk.previous = clonedChunk;
  444. clonedChunk = nextClonedChunk;
  445. }
  446. originalChunk = nextOriginalChunk;
  447. }
  448. cloned.lastChunk = clonedChunk;
  449. if (this.indentExclusionRanges) {
  450. cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
  451. }
  452. cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
  453. cloned.intro = this.intro;
  454. cloned.outro = this.outro;
  455. return cloned;
  456. }
  457. generateDecodedMap(options) {
  458. options = options || {};
  459. const sourceIndex = 0;
  460. const names = Object.keys(this.storedNames);
  461. const mappings = new Mappings(options.hires);
  462. const locate = getLocator(this.original);
  463. if (this.intro) {
  464. mappings.advance(this.intro);
  465. }
  466. this.firstChunk.eachNext((chunk) => {
  467. const loc = locate(chunk.start);
  468. if (chunk.intro.length) mappings.advance(chunk.intro);
  469. if (chunk.edited) {
  470. mappings.addEdit(
  471. sourceIndex,
  472. chunk.content,
  473. loc,
  474. chunk.storeName ? names.indexOf(chunk.original) : -1
  475. );
  476. } else {
  477. mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
  478. }
  479. if (chunk.outro.length) mappings.advance(chunk.outro);
  480. });
  481. return {
  482. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  483. sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')],
  484. sourcesContent: options.includeContent ? [this.original] : undefined,
  485. names,
  486. mappings: mappings.raw,
  487. x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
  488. };
  489. }
  490. generateMap(options) {
  491. return new SourceMap(this.generateDecodedMap(options));
  492. }
  493. _ensureindentStr() {
  494. if (this.indentStr === undefined) {
  495. this.indentStr = guessIndent(this.original);
  496. }
  497. }
  498. _getRawIndentString() {
  499. this._ensureindentStr();
  500. return this.indentStr;
  501. }
  502. getIndentString() {
  503. this._ensureindentStr();
  504. return this.indentStr === null ? '\t' : this.indentStr;
  505. }
  506. indent(indentStr, options) {
  507. const pattern = /^[^\r\n]/gm;
  508. if (isObject(indentStr)) {
  509. options = indentStr;
  510. indentStr = undefined;
  511. }
  512. if (indentStr === undefined) {
  513. this._ensureindentStr();
  514. indentStr = this.indentStr || '\t';
  515. }
  516. if (indentStr === '') return this; // noop
  517. options = options || {};
  518. // Process exclusion ranges
  519. const isExcluded = {};
  520. if (options.exclude) {
  521. const exclusions =
  522. typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
  523. exclusions.forEach((exclusion) => {
  524. for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
  525. isExcluded[i] = true;
  526. }
  527. });
  528. }
  529. let shouldIndentNextCharacter = options.indentStart !== false;
  530. const replacer = (match) => {
  531. if (shouldIndentNextCharacter) return `${indentStr}${match}`;
  532. shouldIndentNextCharacter = true;
  533. return match;
  534. };
  535. this.intro = this.intro.replace(pattern, replacer);
  536. let charIndex = 0;
  537. let chunk = this.firstChunk;
  538. while (chunk) {
  539. const end = chunk.end;
  540. if (chunk.edited) {
  541. if (!isExcluded[charIndex]) {
  542. chunk.content = chunk.content.replace(pattern, replacer);
  543. if (chunk.content.length) {
  544. shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
  545. }
  546. }
  547. } else {
  548. charIndex = chunk.start;
  549. while (charIndex < end) {
  550. if (!isExcluded[charIndex]) {
  551. const char = this.original[charIndex];
  552. if (char === '\n') {
  553. shouldIndentNextCharacter = true;
  554. } else if (char !== '\r' && shouldIndentNextCharacter) {
  555. shouldIndentNextCharacter = false;
  556. if (charIndex === chunk.start) {
  557. chunk.prependRight(indentStr);
  558. } else {
  559. this._splitChunk(chunk, charIndex);
  560. chunk = chunk.next;
  561. chunk.prependRight(indentStr);
  562. }
  563. }
  564. }
  565. charIndex += 1;
  566. }
  567. }
  568. charIndex = chunk.end;
  569. chunk = chunk.next;
  570. }
  571. this.outro = this.outro.replace(pattern, replacer);
  572. return this;
  573. }
  574. insert() {
  575. throw new Error(
  576. 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
  577. );
  578. }
  579. insertLeft(index, content) {
  580. if (!warned.insertLeft) {
  581. console.warn(
  582. 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
  583. ); // eslint-disable-line no-console
  584. warned.insertLeft = true;
  585. }
  586. return this.appendLeft(index, content);
  587. }
  588. insertRight(index, content) {
  589. if (!warned.insertRight) {
  590. console.warn(
  591. 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
  592. ); // eslint-disable-line no-console
  593. warned.insertRight = true;
  594. }
  595. return this.prependRight(index, content);
  596. }
  597. move(start, end, index) {
  598. if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
  599. this._split(start);
  600. this._split(end);
  601. this._split(index);
  602. const first = this.byStart[start];
  603. const last = this.byEnd[end];
  604. const oldLeft = first.previous;
  605. const oldRight = last.next;
  606. const newRight = this.byStart[index];
  607. if (!newRight && last === this.lastChunk) return this;
  608. const newLeft = newRight ? newRight.previous : this.lastChunk;
  609. if (oldLeft) oldLeft.next = oldRight;
  610. if (oldRight) oldRight.previous = oldLeft;
  611. if (newLeft) newLeft.next = first;
  612. if (newRight) newRight.previous = last;
  613. if (!first.previous) this.firstChunk = last.next;
  614. if (!last.next) {
  615. this.lastChunk = first.previous;
  616. this.lastChunk.next = null;
  617. }
  618. first.previous = newLeft;
  619. last.next = newRight || null;
  620. if (!newLeft) this.firstChunk = first;
  621. if (!newRight) this.lastChunk = last;
  622. return this;
  623. }
  624. overwrite(start, end, content, options) {
  625. options = options || {};
  626. return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
  627. }
  628. update(start, end, content, options) {
  629. if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
  630. while (start < 0) start += this.original.length;
  631. while (end < 0) end += this.original.length;
  632. if (end > this.original.length) throw new Error('end is out of bounds');
  633. if (start === end)
  634. throw new Error(
  635. 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
  636. );
  637. this._split(start);
  638. this._split(end);
  639. if (options === true) {
  640. if (!warned.storeName) {
  641. console.warn(
  642. 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
  643. ); // eslint-disable-line no-console
  644. warned.storeName = true;
  645. }
  646. options = { storeName: true };
  647. }
  648. const storeName = options !== undefined ? options.storeName : false;
  649. const overwrite = options !== undefined ? options.overwrite : false;
  650. if (storeName) {
  651. const original = this.original.slice(start, end);
  652. Object.defineProperty(this.storedNames, original, {
  653. writable: true,
  654. value: true,
  655. enumerable: true,
  656. });
  657. }
  658. const first = this.byStart[start];
  659. const last = this.byEnd[end];
  660. if (first) {
  661. let chunk = first;
  662. while (chunk !== last) {
  663. if (chunk.next !== this.byStart[chunk.end]) {
  664. throw new Error('Cannot overwrite across a split point');
  665. }
  666. chunk = chunk.next;
  667. chunk.edit('', false);
  668. }
  669. first.edit(content, storeName, !overwrite);
  670. } else {
  671. // must be inserting at the end
  672. const newChunk = new Chunk(start, end, '').edit(content, storeName);
  673. // TODO last chunk in the array may not be the last chunk, if it's moved...
  674. last.next = newChunk;
  675. newChunk.previous = last;
  676. }
  677. return this;
  678. }
  679. prepend(content) {
  680. if (typeof content !== 'string') throw new TypeError('outro content must be a string');
  681. this.intro = content + this.intro;
  682. return this;
  683. }
  684. prependLeft(index, content) {
  685. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  686. this._split(index);
  687. const chunk = this.byEnd[index];
  688. if (chunk) {
  689. chunk.prependLeft(content);
  690. } else {
  691. this.intro = content + this.intro;
  692. }
  693. return this;
  694. }
  695. prependRight(index, content) {
  696. if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
  697. this._split(index);
  698. const chunk = this.byStart[index];
  699. if (chunk) {
  700. chunk.prependRight(content);
  701. } else {
  702. this.outro = content + this.outro;
  703. }
  704. return this;
  705. }
  706. remove(start, end) {
  707. while (start < 0) start += this.original.length;
  708. while (end < 0) end += this.original.length;
  709. if (start === end) return this;
  710. if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
  711. if (start > end) throw new Error('end must be greater than start');
  712. this._split(start);
  713. this._split(end);
  714. let chunk = this.byStart[start];
  715. while (chunk) {
  716. chunk.intro = '';
  717. chunk.outro = '';
  718. chunk.edit('');
  719. chunk = end > chunk.end ? this.byStart[chunk.end] : null;
  720. }
  721. return this;
  722. }
  723. lastChar() {
  724. if (this.outro.length) return this.outro[this.outro.length - 1];
  725. let chunk = this.lastChunk;
  726. do {
  727. if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
  728. if (chunk.content.length) return chunk.content[chunk.content.length - 1];
  729. if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
  730. } while ((chunk = chunk.previous));
  731. if (this.intro.length) return this.intro[this.intro.length - 1];
  732. return '';
  733. }
  734. lastLine() {
  735. let lineIndex = this.outro.lastIndexOf(n);
  736. if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
  737. let lineStr = this.outro;
  738. let chunk = this.lastChunk;
  739. do {
  740. if (chunk.outro.length > 0) {
  741. lineIndex = chunk.outro.lastIndexOf(n);
  742. if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
  743. lineStr = chunk.outro + lineStr;
  744. }
  745. if (chunk.content.length > 0) {
  746. lineIndex = chunk.content.lastIndexOf(n);
  747. if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
  748. lineStr = chunk.content + lineStr;
  749. }
  750. if (chunk.intro.length > 0) {
  751. lineIndex = chunk.intro.lastIndexOf(n);
  752. if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
  753. lineStr = chunk.intro + lineStr;
  754. }
  755. } while ((chunk = chunk.previous));
  756. lineIndex = this.intro.lastIndexOf(n);
  757. if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
  758. return this.intro + lineStr;
  759. }
  760. slice(start = 0, end = this.original.length) {
  761. while (start < 0) start += this.original.length;
  762. while (end < 0) end += this.original.length;
  763. let result = '';
  764. // find start chunk
  765. let chunk = this.firstChunk;
  766. while (chunk && (chunk.start > start || chunk.end <= start)) {
  767. // found end chunk before start
  768. if (chunk.start < end && chunk.end >= end) {
  769. return result;
  770. }
  771. chunk = chunk.next;
  772. }
  773. if (chunk && chunk.edited && chunk.start !== start)
  774. throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
  775. const startChunk = chunk;
  776. while (chunk) {
  777. if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
  778. result += chunk.intro;
  779. }
  780. const containsEnd = chunk.start < end && chunk.end >= end;
  781. if (containsEnd && chunk.edited && chunk.end !== end)
  782. throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
  783. const sliceStart = startChunk === chunk ? start - chunk.start : 0;
  784. const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
  785. result += chunk.content.slice(sliceStart, sliceEnd);
  786. if (chunk.outro && (!containsEnd || chunk.end === end)) {
  787. result += chunk.outro;
  788. }
  789. if (containsEnd) {
  790. break;
  791. }
  792. chunk = chunk.next;
  793. }
  794. return result;
  795. }
  796. // TODO deprecate this? not really very useful
  797. snip(start, end) {
  798. const clone = this.clone();
  799. clone.remove(0, start);
  800. clone.remove(end, clone.original.length);
  801. return clone;
  802. }
  803. _split(index) {
  804. if (this.byStart[index] || this.byEnd[index]) return;
  805. let chunk = this.lastSearchedChunk;
  806. const searchForward = index > chunk.end;
  807. while (chunk) {
  808. if (chunk.contains(index)) return this._splitChunk(chunk, index);
  809. chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
  810. }
  811. }
  812. _splitChunk(chunk, index) {
  813. if (chunk.edited && chunk.content.length) {
  814. // zero-length edited chunks are a special case (overlapping replacements)
  815. const loc = getLocator(this.original)(index);
  816. throw new Error(
  817. `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
  818. );
  819. }
  820. const newChunk = chunk.split(index);
  821. this.byEnd[index] = chunk;
  822. this.byStart[index] = newChunk;
  823. this.byEnd[newChunk.end] = newChunk;
  824. if (chunk === this.lastChunk) this.lastChunk = newChunk;
  825. this.lastSearchedChunk = chunk;
  826. return true;
  827. }
  828. toString() {
  829. let str = this.intro;
  830. let chunk = this.firstChunk;
  831. while (chunk) {
  832. str += chunk.toString();
  833. chunk = chunk.next;
  834. }
  835. return str + this.outro;
  836. }
  837. isEmpty() {
  838. let chunk = this.firstChunk;
  839. do {
  840. if (
  841. (chunk.intro.length && chunk.intro.trim()) ||
  842. (chunk.content.length && chunk.content.trim()) ||
  843. (chunk.outro.length && chunk.outro.trim())
  844. )
  845. return false;
  846. } while ((chunk = chunk.next));
  847. return true;
  848. }
  849. length() {
  850. let chunk = this.firstChunk;
  851. let length = 0;
  852. do {
  853. length += chunk.intro.length + chunk.content.length + chunk.outro.length;
  854. } while ((chunk = chunk.next));
  855. return length;
  856. }
  857. trimLines() {
  858. return this.trim('[\\r\\n]');
  859. }
  860. trim(charType) {
  861. return this.trimStart(charType).trimEnd(charType);
  862. }
  863. trimEndAborted(charType) {
  864. const rx = new RegExp((charType || '\\s') + '+$');
  865. this.outro = this.outro.replace(rx, '');
  866. if (this.outro.length) return true;
  867. let chunk = this.lastChunk;
  868. do {
  869. const end = chunk.end;
  870. const aborted = chunk.trimEnd(rx);
  871. // if chunk was trimmed, we have a new lastChunk
  872. if (chunk.end !== end) {
  873. if (this.lastChunk === chunk) {
  874. this.lastChunk = chunk.next;
  875. }
  876. this.byEnd[chunk.end] = chunk;
  877. this.byStart[chunk.next.start] = chunk.next;
  878. this.byEnd[chunk.next.end] = chunk.next;
  879. }
  880. if (aborted) return true;
  881. chunk = chunk.previous;
  882. } while (chunk);
  883. return false;
  884. }
  885. trimEnd(charType) {
  886. this.trimEndAborted(charType);
  887. return this;
  888. }
  889. trimStartAborted(charType) {
  890. const rx = new RegExp('^' + (charType || '\\s') + '+');
  891. this.intro = this.intro.replace(rx, '');
  892. if (this.intro.length) return true;
  893. let chunk = this.firstChunk;
  894. do {
  895. const end = chunk.end;
  896. const aborted = chunk.trimStart(rx);
  897. if (chunk.end !== end) {
  898. // special case...
  899. if (chunk === this.lastChunk) this.lastChunk = chunk.next;
  900. this.byEnd[chunk.end] = chunk;
  901. this.byStart[chunk.next.start] = chunk.next;
  902. this.byEnd[chunk.next.end] = chunk.next;
  903. }
  904. if (aborted) return true;
  905. chunk = chunk.next;
  906. } while (chunk);
  907. return false;
  908. }
  909. trimStart(charType) {
  910. this.trimStartAborted(charType);
  911. return this;
  912. }
  913. hasChanged() {
  914. return this.original !== this.toString();
  915. }
  916. _replaceRegexp(searchValue, replacement) {
  917. function getReplacement(match, str) {
  918. if (typeof replacement === 'string') {
  919. return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
  920. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
  921. if (i === '$') return '$';
  922. if (i === '&') return match[0];
  923. const num = +i;
  924. if (num < match.length) return match[+i];
  925. return `$${i}`;
  926. });
  927. } else {
  928. return replacement(...match, match.index, str, match.groups);
  929. }
  930. }
  931. function matchAll(re, str) {
  932. let match;
  933. const matches = [];
  934. while ((match = re.exec(str))) {
  935. matches.push(match);
  936. }
  937. return matches;
  938. }
  939. if (searchValue.global) {
  940. const matches = matchAll(searchValue, this.original);
  941. matches.forEach((match) => {
  942. if (match.index != null)
  943. this.overwrite(
  944. match.index,
  945. match.index + match[0].length,
  946. getReplacement(match, this.original)
  947. );
  948. });
  949. } else {
  950. const match = this.original.match(searchValue);
  951. if (match && match.index != null)
  952. this.overwrite(
  953. match.index,
  954. match.index + match[0].length,
  955. getReplacement(match, this.original)
  956. );
  957. }
  958. return this;
  959. }
  960. _replaceString(string, replacement) {
  961. const { original } = this;
  962. const index = original.indexOf(string);
  963. if (index !== -1) {
  964. this.overwrite(index, index + string.length, replacement);
  965. }
  966. return this;
  967. }
  968. replace(searchValue, replacement) {
  969. if (typeof searchValue === 'string') {
  970. return this._replaceString(searchValue, replacement);
  971. }
  972. return this._replaceRegexp(searchValue, replacement);
  973. }
  974. _replaceAllString(string, replacement) {
  975. const { original } = this;
  976. const stringLength = string.length;
  977. for (
  978. let index = original.indexOf(string);
  979. index !== -1;
  980. index = original.indexOf(string, index + stringLength)
  981. ) {
  982. this.overwrite(index, index + stringLength, replacement);
  983. }
  984. return this;
  985. }
  986. replaceAll(searchValue, replacement) {
  987. if (typeof searchValue === 'string') {
  988. return this._replaceAllString(searchValue, replacement);
  989. }
  990. if (!searchValue.global) {
  991. throw new TypeError(
  992. 'MagicString.prototype.replaceAll called with a non-global RegExp argument'
  993. );
  994. }
  995. return this._replaceRegexp(searchValue, replacement);
  996. }
  997. }
  998. const hasOwnProp = Object.prototype.hasOwnProperty;
  999. class Bundle {
  1000. constructor(options = {}) {
  1001. this.intro = options.intro || '';
  1002. this.separator = options.separator !== undefined ? options.separator : '\n';
  1003. this.sources = [];
  1004. this.uniqueSources = [];
  1005. this.uniqueSourceIndexByFilename = {};
  1006. }
  1007. addSource(source) {
  1008. if (source instanceof MagicString) {
  1009. return this.addSource({
  1010. content: source,
  1011. filename: source.filename,
  1012. separator: this.separator,
  1013. });
  1014. }
  1015. if (!isObject(source) || !source.content) {
  1016. throw new Error(
  1017. 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
  1018. );
  1019. }
  1020. ['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => {
  1021. if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
  1022. });
  1023. if (source.separator === undefined) {
  1024. // TODO there's a bunch of this sort of thing, needs cleaning up
  1025. source.separator = this.separator;
  1026. }
  1027. if (source.filename) {
  1028. if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
  1029. this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
  1030. this.uniqueSources.push({ filename: source.filename, content: source.content.original });
  1031. } else {
  1032. const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
  1033. if (source.content.original !== uniqueSource.content) {
  1034. throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
  1035. }
  1036. }
  1037. }
  1038. this.sources.push(source);
  1039. return this;
  1040. }
  1041. append(str, options) {
  1042. this.addSource({
  1043. content: new MagicString(str),
  1044. separator: (options && options.separator) || '',
  1045. });
  1046. return this;
  1047. }
  1048. clone() {
  1049. const bundle = new Bundle({
  1050. intro: this.intro,
  1051. separator: this.separator,
  1052. });
  1053. this.sources.forEach((source) => {
  1054. bundle.addSource({
  1055. filename: source.filename,
  1056. content: source.content.clone(),
  1057. separator: source.separator,
  1058. });
  1059. });
  1060. return bundle;
  1061. }
  1062. generateDecodedMap(options = {}) {
  1063. const names = [];
  1064. let x_google_ignoreList = undefined;
  1065. this.sources.forEach((source) => {
  1066. Object.keys(source.content.storedNames).forEach((name) => {
  1067. if (!~names.indexOf(name)) names.push(name);
  1068. });
  1069. });
  1070. const mappings = new Mappings(options.hires);
  1071. if (this.intro) {
  1072. mappings.advance(this.intro);
  1073. }
  1074. this.sources.forEach((source, i) => {
  1075. if (i > 0) {
  1076. mappings.advance(this.separator);
  1077. }
  1078. const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
  1079. const magicString = source.content;
  1080. const locate = getLocator(magicString.original);
  1081. if (magicString.intro) {
  1082. mappings.advance(magicString.intro);
  1083. }
  1084. magicString.firstChunk.eachNext((chunk) => {
  1085. const loc = locate(chunk.start);
  1086. if (chunk.intro.length) mappings.advance(chunk.intro);
  1087. if (source.filename) {
  1088. if (chunk.edited) {
  1089. mappings.addEdit(
  1090. sourceIndex,
  1091. chunk.content,
  1092. loc,
  1093. chunk.storeName ? names.indexOf(chunk.original) : -1
  1094. );
  1095. } else {
  1096. mappings.addUneditedChunk(
  1097. sourceIndex,
  1098. chunk,
  1099. magicString.original,
  1100. loc,
  1101. magicString.sourcemapLocations
  1102. );
  1103. }
  1104. } else {
  1105. mappings.advance(chunk.content);
  1106. }
  1107. if (chunk.outro.length) mappings.advance(chunk.outro);
  1108. });
  1109. if (magicString.outro) {
  1110. mappings.advance(magicString.outro);
  1111. }
  1112. if (source.ignoreList && sourceIndex !== -1) {
  1113. if (x_google_ignoreList === undefined) {
  1114. x_google_ignoreList = [];
  1115. }
  1116. x_google_ignoreList.push(sourceIndex);
  1117. }
  1118. });
  1119. return {
  1120. file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
  1121. sources: this.uniqueSources.map((source) => {
  1122. return options.file ? getRelativePath(options.file, source.filename) : source.filename;
  1123. }),
  1124. sourcesContent: this.uniqueSources.map((source) => {
  1125. return options.includeContent ? source.content : null;
  1126. }),
  1127. names,
  1128. mappings: mappings.raw,
  1129. x_google_ignoreList,
  1130. };
  1131. }
  1132. generateMap(options) {
  1133. return new SourceMap(this.generateDecodedMap(options));
  1134. }
  1135. getIndentString() {
  1136. const indentStringCounts = {};
  1137. this.sources.forEach((source) => {
  1138. const indentStr = source.content._getRawIndentString();
  1139. if (indentStr === null) return;
  1140. if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
  1141. indentStringCounts[indentStr] += 1;
  1142. });
  1143. return (
  1144. Object.keys(indentStringCounts).sort((a, b) => {
  1145. return indentStringCounts[a] - indentStringCounts[b];
  1146. })[0] || '\t'
  1147. );
  1148. }
  1149. indent(indentStr) {
  1150. if (!arguments.length) {
  1151. indentStr = this.getIndentString();
  1152. }
  1153. if (indentStr === '') return this; // noop
  1154. let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
  1155. this.sources.forEach((source, i) => {
  1156. const separator = source.separator !== undefined ? source.separator : this.separator;
  1157. const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
  1158. source.content.indent(indentStr, {
  1159. exclude: source.indentExclusionRanges,
  1160. indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
  1161. });
  1162. trailingNewline = source.content.lastChar() === '\n';
  1163. });
  1164. if (this.intro) {
  1165. this.intro =
  1166. indentStr +
  1167. this.intro.replace(/^[^\n]/gm, (match, index) => {
  1168. return index > 0 ? indentStr + match : match;
  1169. });
  1170. }
  1171. return this;
  1172. }
  1173. prepend(str) {
  1174. this.intro = str + this.intro;
  1175. return this;
  1176. }
  1177. toString() {
  1178. const body = this.sources
  1179. .map((source, i) => {
  1180. const separator = source.separator !== undefined ? source.separator : this.separator;
  1181. const str = (i > 0 ? separator : '') + source.content.toString();
  1182. return str;
  1183. })
  1184. .join('');
  1185. return this.intro + body;
  1186. }
  1187. isEmpty() {
  1188. if (this.intro.length && this.intro.trim()) return false;
  1189. if (this.sources.some((source) => !source.content.isEmpty())) return false;
  1190. return true;
  1191. }
  1192. length() {
  1193. return this.sources.reduce(
  1194. (length, source) => length + source.content.length(),
  1195. this.intro.length
  1196. );
  1197. }
  1198. trimLines() {
  1199. return this.trim('[\\r\\n]');
  1200. }
  1201. trim(charType) {
  1202. return this.trimStart(charType).trimEnd(charType);
  1203. }
  1204. trimStart(charType) {
  1205. const rx = new RegExp('^' + (charType || '\\s') + '+');
  1206. this.intro = this.intro.replace(rx, '');
  1207. if (!this.intro) {
  1208. let source;
  1209. let i = 0;
  1210. do {
  1211. source = this.sources[i++];
  1212. if (!source) {
  1213. break;
  1214. }
  1215. } while (!source.content.trimStartAborted(charType));
  1216. }
  1217. return this;
  1218. }
  1219. trimEnd(charType) {
  1220. const rx = new RegExp((charType || '\\s') + '+$');
  1221. let source;
  1222. let i = this.sources.length - 1;
  1223. do {
  1224. source = this.sources[i--];
  1225. if (!source) {
  1226. this.intro = this.intro.replace(rx, '');
  1227. break;
  1228. }
  1229. } while (!source.content.trimEndAborted(charType));
  1230. return this;
  1231. }
  1232. }
  1233. MagicString.Bundle = Bundle;
  1234. MagicString.SourceMap = SourceMap;
  1235. MagicString.default = MagicString; // work around TypeScript bug https://github.com/Rich-Harris/magic-string/pull/121
  1236. return MagicString;
  1237. }));
  1238. //# sourceMappingURL=magic-string.umd.js.map