uglify-js-minify-css-allfiles 2.8.0 → 2.8.2

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/module.js CHANGED
@@ -98,7 +98,6 @@ async function processPattern(pattern, content, fileExt, filePath, logger, hashM
98
98
  }
99
99
  }
100
100
 
101
- await Promise.all(promises.filter((p) => p instanceof Promise));
102
101
  }
103
102
 
104
103
  return { content: newContent, modified };
@@ -252,7 +251,7 @@ async function processFile(filePath, logger, options) {
252
251
 
253
252
  if (options.useJsMap) {
254
253
  const fileName = path.basename(filePath);
255
- const mapFilePath = filePath.replace('.js', '.js.map');
254
+ const mapFilePath = filePath.replace(/\.js$/, '.js.map');
256
255
 
257
256
  await writeFile(filePath, result.code + `\n//# sourceMappingURL=${fileName}.map`, logger);
258
257
  await writeFile(mapFilePath, result.map, logger);
@@ -269,7 +268,7 @@ async function processFile(filePath, logger, options) {
269
268
 
270
269
  if (options.useCssMap && output.sourceMap) {
271
270
  const fileName = path.basename(filePath);
272
- const mapFilePath = filePath.replace('.css', '.css.map');
271
+ const mapFilePath = filePath.replace(/\.css$/, '.css.map');
273
272
 
274
273
  // Add source map reference to the CSS file
275
274
  const sourceMapComment = `\n/*# sourceMappingURL=${fileName}.map */`;
@@ -2,7 +2,8 @@
2
2
  * Babel plugin to transform Element.append() calls to be compatible with older browsers.
3
3
  * This plugin converts:
4
4
  * - element.append("text") to element.appendChild(document.createTextNode("text"))
5
- * - element.append(node) to element.appendChild(node)
5
+ * - element.append(3) to element.appendChild(document.createTextNode(3))
6
+ * - element.append(node) to element.appendChild(node instanceof Node ? node : document.createTextNode(String(node)))
6
7
  * - element.append(node1, "text", node2) to a sequence of appendChild calls
7
8
  *
8
9
  * @param {Object} param0 - Babel plugin parameters
@@ -10,6 +11,34 @@
10
11
  * @returns {Object} Babel plugin object
11
12
  */
12
13
  export default function ({ types: t }) {
14
+ function createTextNodeExpression(arg) {
15
+ return t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]);
16
+ }
17
+
18
+ function isLiteral(node) {
19
+ return (
20
+ t.isStringLiteral(node) ||
21
+ t.isNumericLiteral(node) ||
22
+ t.isBooleanLiteral(node) ||
23
+ t.isNullLiteral(node) ||
24
+ t.isTemplateLiteral(node)
25
+ );
26
+ }
27
+
28
+ function toAppendChildArg(arg) {
29
+ // Known primitives: always wrap with createTextNode
30
+ if (isLiteral(arg)) {
31
+ return createTextNodeExpression(arg);
32
+ }
33
+ // Unknown values (variables, expressions): runtime check
34
+ // If it's a Node, use directly; otherwise wrap with createTextNode
35
+ return t.conditionalExpression(
36
+ t.binaryExpression('instanceof', t.cloneNode(arg), t.identifier('Node')),
37
+ t.cloneNode(arg),
38
+ createTextNodeExpression(t.cloneNode(arg)),
39
+ );
40
+ }
41
+
13
42
  return {
14
43
  name: 'append-polyfill-transform',
15
44
  visitor: {
@@ -28,39 +57,22 @@ export default function ({ types: t }) {
28
57
 
29
58
  // Handle single argument case
30
59
  if (args.length === 1) {
31
- const arg = args[0];
32
-
33
- // String literal case: element.append("text")
34
- if (t.isStringLiteral(arg)) {
35
- path.replaceWith(
36
- t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
37
- t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]),
38
- ]),
39
- );
40
- } else {
41
- // Node case: element.append(node)
42
- callee.get('property').replaceWith(t.identifier('appendChild'));
43
- }
60
+ path.replaceWith(
61
+ t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
62
+ toAppendChildArg(args[0]),
63
+ ]),
64
+ );
44
65
  return;
45
66
  }
46
67
 
47
68
  // Handle multiple arguments: element.append(node1, "text", node2)
48
- const statements = args.map((arg) => {
49
- // String literal case
50
- if (t.isStringLiteral(arg)) {
51
- return t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
52
- t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]),
53
- ]);
54
- } else {
55
- // Node case
56
- return t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [arg]);
57
- }
58
- });
69
+ const statements = args.map((arg) =>
70
+ t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
71
+ toAppendChildArg(arg),
72
+ ]),
73
+ );
59
74
 
60
- if (statements.length > 0) {
61
- // Combine multiple statements into a sequence expression
62
- path.replaceWith(t.sequenceExpression(statements));
63
- }
75
+ path.replaceWith(t.sequenceExpression(statements));
64
76
  },
65
77
  },
66
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uglify-js-minify-css-allfiles",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "you will be able to minify all files as same file names which is js or css",
5
5
  "main": "minify.js",
6
6
  "type": "module",