@tailwindcss-mangle/core 5.1.1 → 5.1.2-alpha.0

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
@@ -323,7 +323,8 @@ var Context = class {
323
323
  import_fs_extra.default.writeFileSync(outputFile, JSON.stringify(arr, null, 2));
324
324
  }
325
325
  } catch (error) {
326
- console.error(`[tailwindcss-mangle]: ${error}`);
326
+ import_node_process.default.stderr.write(`[tailwindcss-mangle]: ${String(error)}
327
+ `);
327
328
  }
328
329
  }
329
330
  };
@@ -501,24 +502,6 @@ function jsHandler(rawSource, options) {
501
502
  // src/svelte/index.ts
502
503
  var import_magic_string3 = __toESM(require("magic-string"), 1);
503
504
  var import_compiler = require("svelte/compiler");
504
- async function svelteHandler(rawSource, options) {
505
- const { ctx, id } = options;
506
- const ms = new import_magic_string3.default(rawSource);
507
- try {
508
- const ast = (0, import_compiler.parse)(rawSource, {
509
- filename: id || "unknown.svelte"
510
- });
511
- await processSvelteAst(ast, ms, ctx, id);
512
- return {
513
- code: ms.toString(),
514
- get map() {
515
- return ms.generateMap();
516
- }
517
- };
518
- } catch (error) {
519
- return jsHandler(rawSource, options);
520
- }
521
- }
522
505
  async function processSvelteAst(ast, ms, ctx, id) {
523
506
  const { replaceMap, classGenerator } = ctx;
524
507
  const stylePromises = [];
@@ -592,41 +575,33 @@ async function processSvelteAst(ast, ms, ctx, id) {
592
575
  await walk(ast);
593
576
  await Promise.all(stylePromises);
594
577
  }
595
-
596
- // src/vue/index.ts
597
- var import_compiler_sfc = require("@vue/compiler-sfc");
598
- var import_magic_string4 = __toESM(require("magic-string"), 1);
599
- async function vueHandler(rawSource, options) {
578
+ async function svelteHandler(rawSource, options) {
600
579
  const { ctx, id } = options;
601
- const ms = new import_magic_string4.default(rawSource);
580
+ const ms = new import_magic_string3.default(rawSource);
602
581
  try {
603
- const { descriptor } = (0, import_compiler_sfc.parse)(rawSource, {
604
- filename: id || "unknown.vue"
582
+ const ast = (0, import_compiler.parse)(rawSource, {
583
+ filename: id || "unknown.svelte"
605
584
  });
606
- if (descriptor.template) {
607
- await processTemplate(descriptor.template, ms, ctx, id);
608
- }
609
- if (descriptor.script || descriptor.scriptSetup) {
610
- await processScript(descriptor, ms, ctx, id);
611
- }
612
- if (descriptor.styles && descriptor.styles.length > 0) {
613
- await processStyles(descriptor.styles, ms, ctx, id);
614
- }
585
+ await processSvelteAst(ast, ms, ctx, id);
615
586
  return {
616
587
  code: ms.toString(),
617
588
  get map() {
618
589
  return ms.generateMap();
619
590
  }
620
591
  };
621
- } catch (error) {
592
+ } catch {
622
593
  return jsHandler(rawSource, options);
623
594
  }
624
595
  }
596
+
597
+ // src/vue/index.ts
598
+ var import_compiler_sfc = require("@vue/compiler-sfc");
599
+ var import_magic_string4 = __toESM(require("magic-string"), 1);
625
600
  async function processTemplate(template, ms, ctx, id) {
626
601
  const { replaceMap, classGenerator } = ctx;
627
602
  if (!template.ast) {
628
603
  try {
629
- const compiled = (0, import_compiler_sfc.compileTemplate)({
604
+ (0, import_compiler_sfc.compileTemplate)({
630
605
  source: template.content,
631
606
  filename: id || "unknown.vue",
632
607
  id: `${id || "unknown"}?template`
@@ -636,12 +611,11 @@ async function processTemplate(template, ms, ctx, id) {
636
611
  }
637
612
  }
638
613
  const classAttrRegex = /\sclass\s*=\s*["']([^"']+)["']/g;
639
- let match;
640
614
  const templateStart = template.loc.start.offset;
641
615
  const templateEnd = template.loc.end.offset;
642
616
  const templateContent = ms.original.slice(templateStart, templateEnd);
643
617
  const replacements = [];
644
- while ((match = classAttrRegex.exec(templateContent)) !== null) {
618
+ for (const match of templateContent.matchAll(classAttrRegex)) {
645
619
  const fullMatch = match[0];
646
620
  const classValue = match[1];
647
621
  if (classValue === void 0) {
@@ -710,6 +684,32 @@ async function processStyles(styles, ms, ctx, id) {
710
684
  }
711
685
  }
712
686
  }
687
+ async function vueHandler(rawSource, options) {
688
+ const { ctx, id } = options;
689
+ const ms = new import_magic_string4.default(rawSource);
690
+ try {
691
+ const { descriptor } = (0, import_compiler_sfc.parse)(rawSource, {
692
+ filename: id || "unknown.vue"
693
+ });
694
+ if (descriptor.template) {
695
+ await processTemplate(descriptor.template, ms, ctx, id);
696
+ }
697
+ if (descriptor.script || descriptor.scriptSetup) {
698
+ await processScript(descriptor, ms, ctx, id);
699
+ }
700
+ if (descriptor.styles && descriptor.styles.length > 0) {
701
+ await processStyles(descriptor.styles, ms, ctx, id);
702
+ }
703
+ return {
704
+ code: ms.toString(),
705
+ get map() {
706
+ return ms.generateMap();
707
+ }
708
+ };
709
+ } catch {
710
+ return jsHandler(rawSource, options);
711
+ }
712
+ }
713
713
  // Annotate the CommonJS export names for ESM import in node:
714
714
  0 && (module.exports = {
715
715
  ClassGenerator,
package/dist/index.js CHANGED
@@ -294,7 +294,8 @@ var Context = class {
294
294
  fs.writeFileSync(outputFile, JSON.stringify(arr, null, 2));
295
295
  }
296
296
  } catch (error) {
297
- console.error(`[tailwindcss-mangle]: ${error}`);
297
+ process.stderr.write(`[tailwindcss-mangle]: ${String(error)}
298
+ `);
298
299
  }
299
300
  }
300
301
  };
@@ -472,24 +473,6 @@ function jsHandler(rawSource, options) {
472
473
  // src/svelte/index.ts
473
474
  import MagicString3 from "magic-string";
474
475
  import { parse as parse2 } from "svelte/compiler";
475
- async function svelteHandler(rawSource, options) {
476
- const { ctx, id } = options;
477
- const ms = new MagicString3(rawSource);
478
- try {
479
- const ast = parse2(rawSource, {
480
- filename: id || "unknown.svelte"
481
- });
482
- await processSvelteAst(ast, ms, ctx, id);
483
- return {
484
- code: ms.toString(),
485
- get map() {
486
- return ms.generateMap();
487
- }
488
- };
489
- } catch (error) {
490
- return jsHandler(rawSource, options);
491
- }
492
- }
493
476
  async function processSvelteAst(ast, ms, ctx, id) {
494
477
  const { replaceMap, classGenerator } = ctx;
495
478
  const stylePromises = [];
@@ -563,41 +546,33 @@ async function processSvelteAst(ast, ms, ctx, id) {
563
546
  await walk(ast);
564
547
  await Promise.all(stylePromises);
565
548
  }
566
-
567
- // src/vue/index.ts
568
- import { compileTemplate, parse as parse3 } from "@vue/compiler-sfc";
569
- import MagicString4 from "magic-string";
570
- async function vueHandler(rawSource, options) {
549
+ async function svelteHandler(rawSource, options) {
571
550
  const { ctx, id } = options;
572
- const ms = new MagicString4(rawSource);
551
+ const ms = new MagicString3(rawSource);
573
552
  try {
574
- const { descriptor } = parse3(rawSource, {
575
- filename: id || "unknown.vue"
553
+ const ast = parse2(rawSource, {
554
+ filename: id || "unknown.svelte"
576
555
  });
577
- if (descriptor.template) {
578
- await processTemplate(descriptor.template, ms, ctx, id);
579
- }
580
- if (descriptor.script || descriptor.scriptSetup) {
581
- await processScript(descriptor, ms, ctx, id);
582
- }
583
- if (descriptor.styles && descriptor.styles.length > 0) {
584
- await processStyles(descriptor.styles, ms, ctx, id);
585
- }
556
+ await processSvelteAst(ast, ms, ctx, id);
586
557
  return {
587
558
  code: ms.toString(),
588
559
  get map() {
589
560
  return ms.generateMap();
590
561
  }
591
562
  };
592
- } catch (error) {
563
+ } catch {
593
564
  return jsHandler(rawSource, options);
594
565
  }
595
566
  }
567
+
568
+ // src/vue/index.ts
569
+ import { compileTemplate, parse as parse3 } from "@vue/compiler-sfc";
570
+ import MagicString4 from "magic-string";
596
571
  async function processTemplate(template, ms, ctx, id) {
597
572
  const { replaceMap, classGenerator } = ctx;
598
573
  if (!template.ast) {
599
574
  try {
600
- const compiled = compileTemplate({
575
+ compileTemplate({
601
576
  source: template.content,
602
577
  filename: id || "unknown.vue",
603
578
  id: `${id || "unknown"}?template`
@@ -607,12 +582,11 @@ async function processTemplate(template, ms, ctx, id) {
607
582
  }
608
583
  }
609
584
  const classAttrRegex = /\sclass\s*=\s*["']([^"']+)["']/g;
610
- let match;
611
585
  const templateStart = template.loc.start.offset;
612
586
  const templateEnd = template.loc.end.offset;
613
587
  const templateContent = ms.original.slice(templateStart, templateEnd);
614
588
  const replacements = [];
615
- while ((match = classAttrRegex.exec(templateContent)) !== null) {
589
+ for (const match of templateContent.matchAll(classAttrRegex)) {
616
590
  const fullMatch = match[0];
617
591
  const classValue = match[1];
618
592
  if (classValue === void 0) {
@@ -681,6 +655,32 @@ async function processStyles(styles, ms, ctx, id) {
681
655
  }
682
656
  }
683
657
  }
658
+ async function vueHandler(rawSource, options) {
659
+ const { ctx, id } = options;
660
+ const ms = new MagicString4(rawSource);
661
+ try {
662
+ const { descriptor } = parse3(rawSource, {
663
+ filename: id || "unknown.vue"
664
+ });
665
+ if (descriptor.template) {
666
+ await processTemplate(descriptor.template, ms, ctx, id);
667
+ }
668
+ if (descriptor.script || descriptor.scriptSetup) {
669
+ await processScript(descriptor, ms, ctx, id);
670
+ }
671
+ if (descriptor.styles && descriptor.styles.length > 0) {
672
+ await processStyles(descriptor.styles, ms, ctx, id);
673
+ }
674
+ return {
675
+ code: ms.toString(),
676
+ get map() {
677
+ return ms.generateMap();
678
+ }
679
+ };
680
+ } catch {
681
+ return jsHandler(rawSource, options);
682
+ }
683
+ }
684
684
  var export_ClassGenerator = shared_exports.ClassGenerator;
685
685
  export {
686
686
  export_ClassGenerator as ClassGenerator,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tailwindcss-mangle/core",
3
3
  "type": "module",
4
- "version": "5.1.1",
4
+ "version": "5.1.2-alpha.0",
5
5
  "description": "The core of tailwindcss-mangle",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -50,18 +50,18 @@
50
50
  "@babel/parser": "^7.29.0",
51
51
  "@babel/traverse": "^7.29.0",
52
52
  "@babel/types": "^7.29.0",
53
- "@vue/compiler-sfc": "^3.5.28",
53
+ "@vue/compiler-sfc": "^3.5.30",
54
54
  "fast-sort": "^3.4.1",
55
- "fs-extra": "^11.3.3",
55
+ "fs-extra": "^11.3.4",
56
56
  "htmlparser2": "10.1.0",
57
57
  "magic-string": "^0.30.21",
58
58
  "parse5": "^8.0.0",
59
59
  "pathe": "^2.0.3",
60
- "postcss": "^8.5.6",
60
+ "postcss": "^8.5.8",
61
61
  "postcss-selector-parser": "^7.1.1",
62
- "svelte": "^5.53.3",
63
- "@tailwindcss-mangle/config": "^6.1.2",
64
- "@tailwindcss-mangle/shared": "^4.1.2"
62
+ "svelte": "^5.53.11",
63
+ "@tailwindcss-mangle/config": "^6.1.4-alpha.0",
64
+ "@tailwindcss-mangle/shared": "^4.1.3"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/parse5": "^7.0.0"