uglify-js-minify-css-allfiles 2.8.1 → 2.8.3

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.
@@ -1,8 +1,11 @@
1
1
  /**
2
- * Babel plugin to transform Element.append() calls to be compatible with older browsers.
2
+ * Babel plugin to transform native DOM Element.append() calls to be compatible with older browsers.
3
+ * Skips jQuery/library .append() calls (e.g., $(...).append(), jQuery(...).append()).
4
+ *
3
5
  * This plugin converts:
4
6
  * - element.append("text") to element.appendChild(document.createTextNode("text"))
5
- * - element.append(node) to element.appendChild(node)
7
+ * - element.append(3) to element.appendChild(document.createTextNode(3))
8
+ * - element.append(node) to element.appendChild(node instanceof Node ? node : document.createTextNode(String(node)))
6
9
  * - element.append(node1, "text", node2) to a sequence of appendChild calls
7
10
  *
8
11
  * @param {Object} param0 - Babel plugin parameters
@@ -10,6 +13,63 @@
10
13
  * @returns {Object} Babel plugin object
11
14
  */
12
15
  export default function ({ types: t }) {
16
+ function createTextNodeExpression(arg) {
17
+ return t.callExpression(t.memberExpression(t.identifier('document'), t.identifier('createTextNode')), [arg]);
18
+ }
19
+
20
+ function isLiteral(node) {
21
+ return (
22
+ t.isStringLiteral(node) ||
23
+ t.isNumericLiteral(node) ||
24
+ t.isBooleanLiteral(node) ||
25
+ t.isNullLiteral(node) ||
26
+ t.isTemplateLiteral(node)
27
+ );
28
+ }
29
+
30
+ function toAppendChildArg(arg) {
31
+ // Known primitives: always wrap with createTextNode
32
+ if (isLiteral(arg)) {
33
+ return createTextNodeExpression(arg);
34
+ }
35
+ // Unknown values (variables, expressions): runtime check
36
+ // If it's a Node, use directly; otherwise wrap with createTextNode
37
+ return t.conditionalExpression(
38
+ t.binaryExpression('instanceof', t.cloneNode(arg), t.identifier('Node')),
39
+ t.cloneNode(arg),
40
+ createTextNodeExpression(t.cloneNode(arg)),
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Checks if the object of a .append() call is a jQuery/library wrapper.
46
+ * Skips patterns like: $(...).append(), jQuery(...).append(), $el.append(),
47
+ * $(...).find(...).append() (chained jQuery calls)
48
+ */
49
+ function isJQueryCall(objectPath) {
50
+ const node = objectPath.node;
51
+
52
+ // $(...).append() or jQuery(...).append()
53
+ if (t.isCallExpression(node)) {
54
+ const callee = node.callee;
55
+ // $() or jQuery()
56
+ if (t.isIdentifier(callee, { name: '$' }) || t.isIdentifier(callee, { name: 'jQuery' })) {
57
+ return true;
58
+ }
59
+ // $(...).find(...).append() — chained jQuery method calls
60
+ if (t.isMemberExpression(callee) && t.isCallExpression(callee.object)) {
61
+ return isJQueryCall(objectPath.get('callee').get('object'));
62
+ }
63
+ }
64
+
65
+ // $el.append() — variables starting with $
66
+ if (t.isIdentifier(node) && node.name.startsWith('$')) {
67
+ return true;
68
+ }
69
+
70
+ return false;
71
+ }
72
+
13
73
  return {
14
74
  name: 'append-polyfill-transform',
15
75
  visitor: {
@@ -20,6 +80,9 @@ export default function ({ types: t }) {
20
80
  if (!callee.isMemberExpression()) return;
21
81
  if (!callee.get('property').isIdentifier({ name: 'append' })) return;
22
82
 
83
+ // Skip jQuery .append() calls
84
+ if (isJQueryCall(callee.get('object'))) return;
85
+
23
86
  const args = path.node.arguments;
24
87
  const objectNode = callee.get('object').node;
25
88
 
@@ -28,39 +91,22 @@ export default function ({ types: t }) {
28
91
 
29
92
  // Handle single argument case
30
93
  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
- }
94
+ path.replaceWith(
95
+ t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
96
+ toAppendChildArg(args[0]),
97
+ ]),
98
+ );
44
99
  return;
45
100
  }
46
101
 
47
102
  // 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
- });
103
+ const statements = args.map((arg) =>
104
+ t.callExpression(t.memberExpression(t.cloneNode(objectNode), t.identifier('appendChild')), [
105
+ toAppendChildArg(arg),
106
+ ]),
107
+ );
59
108
 
60
- if (statements.length > 0) {
61
- // Combine multiple statements into a sequence expression
62
- path.replaceWith(t.sequenceExpression(statements));
63
- }
109
+ path.replaceWith(t.sequenceExpression(statements));
64
110
  },
65
111
  },
66
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uglify-js-minify-css-allfiles",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
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",