es-check 9.6.1 → 9.6.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.
@@ -27,6 +27,7 @@ const ES12_FEATURES = {
27
27
  example: "Promise.any(promises)",
28
28
  astInfo: {
29
29
  nodeType: "CallExpression",
30
+ object: "Promise",
30
31
  property: "any",
31
32
  },
32
33
  },
@@ -48,6 +48,7 @@ const ES13_FEATURES = {
48
48
  property: "at",
49
49
  excludeCallerTypes: ["ObjectExpression"],
50
50
  requireNumericArg: true,
51
+ requireArrayLikeCall: true,
51
52
  },
52
53
  },
53
54
  ObjectHasOwn: {
@@ -43,6 +43,7 @@ const ES16_FEATURES = {
43
43
  astInfo: {
44
44
  nodeType: "CallExpression",
45
45
  property: "union",
46
+ requireSetLikeCall: true,
46
47
  },
47
48
  },
48
49
  SetIntersection: {
@@ -51,6 +52,7 @@ const ES16_FEATURES = {
51
52
  astInfo: {
52
53
  nodeType: "CallExpression",
53
54
  property: "intersection",
55
+ requireSetLikeCall: true,
54
56
  },
55
57
  },
56
58
  SetDifference: {
@@ -59,6 +61,7 @@ const ES16_FEATURES = {
59
61
  astInfo: {
60
62
  nodeType: "CallExpression",
61
63
  property: "difference",
64
+ requireSetLikeCall: true,
62
65
  },
63
66
  },
64
67
  SetSymmetricDifference: {
@@ -67,6 +70,7 @@ const ES16_FEATURES = {
67
70
  astInfo: {
68
71
  nodeType: "CallExpression",
69
72
  property: "symmetricDifference",
73
+ requireSetLikeCall: true,
70
74
  },
71
75
  },
72
76
  SetIsSubsetOf: {
@@ -75,6 +79,7 @@ const ES16_FEATURES = {
75
79
  astInfo: {
76
80
  nodeType: "CallExpression",
77
81
  property: "isSubsetOf",
82
+ requireSetLikeCall: true,
78
83
  },
79
84
  },
80
85
  SetIsSupersetOf: {
@@ -83,6 +88,7 @@ const ES16_FEATURES = {
83
88
  astInfo: {
84
89
  nodeType: "CallExpression",
85
90
  property: "isSupersetOf",
91
+ requireSetLikeCall: true,
86
92
  },
87
93
  },
88
94
  SetIsDisjointFrom: {
@@ -91,6 +97,7 @@ const ES16_FEATURES = {
91
97
  astInfo: {
92
98
  nodeType: "CallExpression",
93
99
  property: "isDisjointFrom",
100
+ requireSetLikeCall: true,
94
101
  },
95
102
  },
96
103
  Float16Array: {
@@ -32,6 +32,177 @@ function hasNumericArgument(node) {
32
32
  return isNumericLiteral || isNegativeNumeric;
33
33
  }
34
34
 
35
+ const ARRAY_LIKE_NAMES = new Set([
36
+ "arr",
37
+ "array",
38
+ "list",
39
+ "items",
40
+ "values",
41
+ "arguments",
42
+ ]);
43
+
44
+ const ARRAY_CONSTRUCTOR_FUNCTIONS = new Set([
45
+ "Array",
46
+ "from",
47
+ "of",
48
+ "slice",
49
+ "filter",
50
+ "map",
51
+ "concat",
52
+ ]);
53
+
54
+ const ARRAY_METHODS = new Set([
55
+ "slice",
56
+ "filter",
57
+ "map",
58
+ "concat",
59
+ "from",
60
+ "of",
61
+ ]);
62
+
63
+ const COMMON_NON_ARRAY_NAMES = new Set([
64
+ "obj",
65
+ "object",
66
+ "foo",
67
+ "bar",
68
+ "baz",
69
+ "data",
70
+ "config",
71
+ "options",
72
+ "params",
73
+ "props",
74
+ "state",
75
+ "item",
76
+ "element",
77
+ "node",
78
+ "target",
79
+ "source",
80
+ "result",
81
+ "response",
82
+ "request",
83
+ "payload",
84
+ "model",
85
+ "view",
86
+ "controller",
87
+ "service",
88
+ "utils",
89
+ "helpers",
90
+ "custom",
91
+ ]);
92
+ function isArrayExpression(calleeObject) {
93
+ return calleeObject.type === "ArrayExpression";
94
+ }
95
+
96
+ function isArrayLikeIdentifier(calleeObject) {
97
+ const isIdentifier = calleeObject.type === "Identifier";
98
+ if (!isIdentifier) return false;
99
+
100
+ const objectName = calleeObject.name.toLowerCase();
101
+
102
+ const isCommonNonArrayName = COMMON_NON_ARRAY_NAMES.has(objectName);
103
+ if (isCommonNonArrayName) return false;
104
+
105
+ return ARRAY_LIKE_NAMES.has(objectName);
106
+ }
107
+
108
+ function isArrayConstructorCall(calleeObject) {
109
+ const isCallExpression = calleeObject.type === "CallExpression";
110
+ if (!isCallExpression) return false;
111
+
112
+ const innerCallee = calleeObject.callee;
113
+ const isIdentifierCallee = innerCallee?.type === "Identifier";
114
+ const isMemberExpressionCallee = innerCallee?.type === "MemberExpression";
115
+
116
+ if (isIdentifierCallee) {
117
+ const functionName = innerCallee.name;
118
+ return ARRAY_CONSTRUCTOR_FUNCTIONS.has(functionName);
119
+ }
120
+
121
+ if (isMemberExpressionCallee) {
122
+ const innerProperty = innerCallee.property;
123
+ const hasPropertyName = innerProperty?.name;
124
+ const isArrayMethod =
125
+ hasPropertyName && ARRAY_METHODS.has(innerProperty.name);
126
+ return isArrayMethod;
127
+ }
128
+
129
+ return false;
130
+ }
131
+
132
+ function isArrayLikeCall(node) {
133
+ const callee = node.callee;
134
+ const calleeObject = callee?.object;
135
+ const hasCalleeObject = calleeObject != null;
136
+
137
+ if (!hasCalleeObject) return false;
138
+
139
+ const isArrayExpr = isArrayExpression(calleeObject);
140
+ const isArrayIdent = isArrayLikeIdentifier(calleeObject);
141
+ const isArrayConstr = isArrayConstructorCall(calleeObject);
142
+ const isArray = isArrayExpr || isArrayIdent || isArrayConstr;
143
+
144
+ return isArray;
145
+ }
146
+
147
+ // ── Set-like call detection (mirrors Array-like approach) ──
148
+
149
+ const SET_LIKE_NAMES = new Set(["set", "sets", "seta", "setb", "set1", "set2"]);
150
+
151
+ /**
152
+ * Words that start/end with "set" but are not Set instances.
153
+ * Used as a blocklist when the broader startsWith/endsWith heuristic is active.
154
+ */
155
+ const COMMON_NON_SET_NAMES = new Set([
156
+ "settings",
157
+ "setup",
158
+ "setter",
159
+ "setstate",
160
+ "setvalue",
161
+ "setdata",
162
+ "setitem",
163
+ "setinterval",
164
+ "settimeout",
165
+ "offset",
166
+ "dataset",
167
+ "reset",
168
+ "asset",
169
+ "charset",
170
+ "onset",
171
+ "subset",
172
+ "mindset",
173
+ "closet",
174
+ "baseset",
175
+ ]);
176
+
177
+ function isSetConstructorCall(calleeObject) {
178
+ // new Set() or new Set([...])
179
+ if (
180
+ calleeObject.type === "NewExpression" &&
181
+ calleeObject.callee?.name === "Set"
182
+ ) {
183
+ return true;
184
+ }
185
+ return false;
186
+ }
187
+
188
+ function isSetLikeIdentifier(calleeObject) {
189
+ if (calleeObject.type !== "Identifier") return false;
190
+ const name = calleeObject.name.toLowerCase();
191
+ if (COMMON_NON_SET_NAMES.has(name)) return false;
192
+ return (
193
+ SET_LIKE_NAMES.has(name) || name.startsWith("set") || name.endsWith("set")
194
+ );
195
+ }
196
+
197
+ function isSetLikeCall(node) {
198
+ const calleeObject = node.callee?.object;
199
+ if (!calleeObject) return false;
200
+
201
+ return (
202
+ isSetConstructorCall(calleeObject) || isSetLikeIdentifier(calleeObject)
203
+ );
204
+ }
205
+
35
206
  function checkMap(node, astInfo) {
36
207
  const callee = node.callee;
37
208
  const calleeObject = callee?.object;
@@ -82,6 +253,12 @@ function checkMap(node, astInfo) {
82
253
  const hasNumericArgMismatch =
83
254
  astInfo.requireNumericArg && !hasNumericArgument(node);
84
255
 
256
+ const hasArrayLikeCallMismatch =
257
+ astInfo.requireArrayLikeCall && !isArrayLikeCall(node);
258
+
259
+ const hasSetLikeCallMismatch =
260
+ astInfo.requireSetLikeCall && !isSetLikeCall(node);
261
+
85
262
  const hasMismatch =
86
263
  hasKindMismatch ||
87
264
  hasOperatorMismatch ||
@@ -93,7 +270,9 @@ function checkMap(node, astInfo) {
93
270
  hasObjectAndPropertyMismatch ||
94
271
  hasOptionsCauseMismatch ||
95
272
  hasExcludedCallerType ||
96
- hasNumericArgMismatch;
273
+ hasNumericArgMismatch ||
274
+ hasArrayLikeCallMismatch ||
275
+ hasSetLikeCallMismatch;
97
276
 
98
277
  if (hasMismatch) return false;
99
278
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-check",
3
- "version": "9.6.1",
3
+ "version": "9.6.3",
4
4
  "description": "Checks the ECMAScript version of .js glob against a specified version of ECMAScript with a shell command",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",