@tailwindcss-mangle/core 2.0.5 → 2.0.6

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
@@ -7,6 +7,7 @@ const shared = require('@tailwindcss-mangle/shared');
7
7
  const babel = require('@babel/core');
8
8
  const helperPluginUtils = require('@babel/helper-plugin-utils');
9
9
  const MagicString = require('magic-string');
10
+ const escape = require('@ast-core/escape');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
13
 
@@ -340,34 +341,8 @@ createNewSortInstance({
340
341
  inPlaceSorting: true,
341
342
  });
342
343
 
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
- }
369
344
  function handleValue$1(options) {
370
- const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape = false } = options;
345
+ const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape: escape$1 = false } = options;
371
346
  let value = raw;
372
347
  const arr = sort(shared.splitCode(value)).desc((x) => x.length);
373
348
  for (const str of arr) {
@@ -380,7 +355,11 @@ function handleValue$1(options) {
380
355
  }
381
356
  }
382
357
  if (typeof node.start === "number" && typeof node.end === "number" && value) {
383
- magicString.update(node.start + offset, node.end - offset, escape ? jsStringEscape(value) : value);
358
+ const start = node.start + offset;
359
+ const end = node.end - offset;
360
+ if (start < end) {
361
+ magicString.update(start, end, escape$1 ? escape.jsStringEscape(value) : value);
362
+ }
384
363
  }
385
364
  }
386
365
  const plugin = helperPluginUtils.declare((api, options) => {
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ export { ClassGenerator } from '@tailwindcss-mangle/shared';
6
6
  import babel, { transformSync } from '@babel/core';
7
7
  import { declare } from '@babel/helper-plugin-utils';
8
8
  import MagicString from 'magic-string';
9
+ import { jsStringEscape } from '@ast-core/escape';
9
10
 
10
11
 
11
12
 
@@ -341,32 +342,6 @@ createNewSortInstance({
341
342
  inPlaceSorting: true,
342
343
  });
343
344
 
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
- }
370
345
  function handleValue$1(options) {
371
346
  const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape = false } = options;
372
347
  let value = raw;
@@ -381,7 +356,11 @@ function handleValue$1(options) {
381
356
  }
382
357
  }
383
358
  if (typeof node.start === "number" && typeof node.end === "number" && value) {
384
- magicString.update(node.start + offset, node.end - offset, escape ? jsStringEscape(value) : value);
359
+ const start = node.start + offset;
360
+ const end = node.end - offset;
361
+ if (start < end) {
362
+ magicString.update(start, end, escape ? jsStringEscape(value) : value);
363
+ }
385
364
  }
386
365
  }
387
366
  const plugin = declare((api, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailwindcss-mangle/core",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "The core of tailwindcss-mangle",
5
5
  "exports": {
6
6
  ".": {
@@ -36,14 +36,15 @@
36
36
  "registry": "https://registry.npmjs.org/"
37
37
  },
38
38
  "dependencies": {
39
+ "@ast-core/escape": "^1.0.0",
40
+ "@babel/core": "^7.22.10",
39
41
  "@babel/helper-plugin-utils": "^7.22.5",
40
42
  "@babel/preset-typescript": "^7.22.5",
41
- "@babel/core": "^7.22.10",
42
43
  "@babel/types": "^7.22.10",
44
+ "magic-string": "^0.30.2",
43
45
  "parse5": "^7.1.2",
44
46
  "postcss": "^8.4.27",
45
47
  "postcss-selector-parser": "^6.0.13",
46
- "magic-string": "^0.30.2",
47
48
  "@tailwindcss-mangle/shared": "^2.0.4"
48
49
  },
49
50
  "devDependencies": {