@tailwindcss-mangle/core 2.0.4 → 2.0.5

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.cjs CHANGED
@@ -340,8 +340,34 @@ createNewSortInstance({
340
340
  inPlaceSorting: true,
341
341
  });
342
342
 
343
+ function jsStringEscape(str) {
344
+ return ("" + str).replaceAll(/[\n\r"'\\\u2028\u2029]/g, (character) => {
345
+ switch (character) {
346
+ case '"':
347
+ case "'":
348
+ case "\\": {
349
+ return "\\" + character;
350
+ }
351
+ case "\n": {
352
+ return "\\n";
353
+ }
354
+ case "\r": {
355
+ return "\\r";
356
+ }
357
+ case "\u2028": {
358
+ return "\\u2028";
359
+ }
360
+ case "\u2029": {
361
+ return "\\u2029";
362
+ }
363
+ default: {
364
+ return character;
365
+ }
366
+ }
367
+ });
368
+ }
343
369
  function handleValue$1(options) {
344
- const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0 } = options;
370
+ const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape = false } = options;
345
371
  let value = raw;
346
372
  const arr = sort(shared.splitCode(value)).desc((x) => x.length);
347
373
  for (const str of arr) {
@@ -354,7 +380,7 @@ function handleValue$1(options) {
354
380
  }
355
381
  }
356
382
  if (typeof node.start === "number" && typeof node.end === "number" && value) {
357
- magicString.update(node.start + offset, node.end - offset, value);
383
+ magicString.update(node.start + offset, node.end - offset, escape ? jsStringEscape(value) : value);
358
384
  }
359
385
  }
360
386
  const plugin = helperPluginUtils.declare((api, options) => {
@@ -372,7 +398,8 @@ const plugin = helperPluginUtils.declare((api, options) => {
372
398
  node,
373
399
  raw: node.value,
374
400
  replaceMap,
375
- offset: 1
401
+ offset: 1,
402
+ escape: true
376
403
  });
377
404
  }
378
405
  },
@@ -386,7 +413,8 @@ const plugin = helperPluginUtils.declare((api, options) => {
386
413
  node,
387
414
  raw: node.value.raw,
388
415
  replaceMap,
389
- offset: 0
416
+ offset: 0,
417
+ escape: false
390
418
  });
391
419
  }
392
420
  }
package/dist/index.mjs CHANGED
@@ -341,8 +341,34 @@ createNewSortInstance({
341
341
  inPlaceSorting: true,
342
342
  });
343
343
 
344
+ function jsStringEscape(str) {
345
+ return ("" + str).replaceAll(/[\n\r"'\\\u2028\u2029]/g, (character) => {
346
+ switch (character) {
347
+ case '"':
348
+ case "'":
349
+ case "\\": {
350
+ return "\\" + character;
351
+ }
352
+ case "\n": {
353
+ return "\\n";
354
+ }
355
+ case "\r": {
356
+ return "\\r";
357
+ }
358
+ case "\u2028": {
359
+ return "\\u2028";
360
+ }
361
+ case "\u2029": {
362
+ return "\\u2029";
363
+ }
364
+ default: {
365
+ return character;
366
+ }
367
+ }
368
+ });
369
+ }
344
370
  function handleValue$1(options) {
345
- const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0 } = options;
371
+ const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape = false } = options;
346
372
  let value = raw;
347
373
  const arr = sort(splitCode(value)).desc((x) => x.length);
348
374
  for (const str of arr) {
@@ -355,7 +381,7 @@ function handleValue$1(options) {
355
381
  }
356
382
  }
357
383
  if (typeof node.start === "number" && typeof node.end === "number" && value) {
358
- magicString.update(node.start + offset, node.end - offset, value);
384
+ magicString.update(node.start + offset, node.end - offset, escape ? jsStringEscape(value) : value);
359
385
  }
360
386
  }
361
387
  const plugin = declare((api, options) => {
@@ -373,7 +399,8 @@ const plugin = declare((api, options) => {
373
399
  node,
374
400
  raw: node.value,
375
401
  replaceMap,
376
- offset: 1
402
+ offset: 1,
403
+ escape: true
377
404
  });
378
405
  }
379
406
  },
@@ -387,7 +414,8 @@ const plugin = declare((api, options) => {
387
414
  node,
388
415
  raw: node.value.raw,
389
416
  replaceMap,
390
- offset: 0
417
+ offset: 0,
418
+ escape: false
391
419
  });
392
420
  }
393
421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailwindcss-mangle/core",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "The core of tailwindcss-mangle",
5
5
  "exports": {
6
6
  ".": {