poe-code 4.0.57 → 4.0.59

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.
Files changed (51) hide show
  1. package/dist/cli/program.js +2 -1
  2. package/dist/cli/program.js.map +1 -1
  3. package/dist/index.js +1755 -2241
  4. package/dist/index.js.map +4 -4
  5. package/dist/metafile.json +1 -1
  6. package/package.json +1 -1
  7. package/packages/safejs/dist/graph-depth.js +4 -0
  8. package/packages/safejs/dist/interp/arguments.d.ts +10 -0
  9. package/packages/safejs/dist/interp/arguments.js +44 -0
  10. package/packages/safejs/dist/interp/async.js +3 -1
  11. package/packages/safejs/dist/interp/values.d.ts +1 -1
  12. package/packages/safejs/dist/interp/values.js +27 -2
  13. package/packages/safejs/dist/lint/index.js +0 -4
  14. package/packages/safejs/dist/lint/rules/AS-async-not-needed.d.ts +1 -1
  15. package/packages/safejs/dist/lint/rules/AS-async-not-needed.js +15 -3
  16. package/packages/safejs/dist/lint/rules/AS-await-non-promise.js +10 -0
  17. package/packages/safejs/dist/lint/rules/AS-destructure-null-default.js +9 -0
  18. package/packages/safejs/dist/lint/rules/AS-export-import-meta.js +17 -0
  19. package/packages/safejs/dist/lint/rules/AS-floating-promise.js +23 -2
  20. package/packages/safejs/dist/lint/rules/AS-frontmatter-field-unused.js +9 -0
  21. package/packages/safejs/dist/lint/rules/AS-jsdoc-type.js +10 -0
  22. package/packages/safejs/dist/lint/rules/AS-large-literal.js +9 -0
  23. package/packages/safejs/dist/lint/rules/AS-missing-async.d.ts +1 -1
  24. package/packages/safejs/dist/lint/rules/AS-missing-async.js +9 -1
  25. package/packages/safejs/dist/lint/rules/AS-mutating-frozen.js +9 -0
  26. package/packages/safejs/dist/lint/rules/AS-needless-template.js +9 -0
  27. package/packages/safejs/dist/lint/rules/AS-shadow-global.js +12 -0
  28. package/packages/safejs/dist/lint/rules/AS-unbounded-loop.js +9 -0
  29. package/packages/safejs/dist/lint/rules/AS-unreachable.js +9 -1
  30. package/packages/safejs/dist/lint/rules/AS-unused-import.js +22 -0
  31. package/packages/safejs/dist/lint/rules/AS001.js +0 -6
  32. package/packages/safejs/dist/lint/rules/AS003.js +22 -0
  33. package/packages/safejs/dist/lint/rules/AS006-007.js +19 -0
  34. package/packages/safejs/dist/lint/rules/AS008.js +9 -0
  35. package/packages/safejs/dist/lint/rules/AS009.js +9 -0
  36. package/packages/safejs/dist/lint/rules/AS010.js +9 -0
  37. package/packages/safejs/dist/lint/rules/AS011.js +9 -0
  38. package/packages/safejs/dist/lint/rules/AS015.js +9 -0
  39. package/packages/safejs/dist/parse/parser.d.ts +1 -0
  40. package/packages/safejs/dist/parse/parser.js +4 -7
  41. package/packages/safejs/dist/snapshot/arguments.d.ts +17 -0
  42. package/packages/safejs/dist/snapshot/arguments.js +34 -0
  43. package/packages/safejs/dist/snapshot/dump-format.js +15 -3
  44. package/packages/safejs/dist/snapshot/restore.js +27 -1
  45. package/packages/safejs/dist/snapshot/serialize.d.ts +2 -1
  46. package/packages/safejs/dist/snapshot/serialize.js +20 -10
  47. package/packages/safejs/dist/snapshot/validation.js +50 -1
  48. package/packages/safejs/dist/lint/rules/AS002.d.ts +0 -13
  49. package/packages/safejs/dist/lint/rules/AS002.js +0 -525
  50. package/packages/safejs/dist/lint/rules/AS012.d.ts +0 -13
  51. package/packages/safejs/dist/lint/rules/AS012.js +0 -384
@@ -1,384 +0,0 @@
1
- import { parseModule } from "../../parse/parser.js";
2
- const SORT_MESSAGE = "Array#sort only supports comparators that are arrows returning a number.";
3
- const NUMBER_RETURNING_BINARY_OPERATORS = new Set([
4
- "%",
5
- "*",
6
- "**",
7
- "-",
8
- "/",
9
- "<<",
10
- ">>",
11
- ">>>",
12
- "&",
13
- "^",
14
- "|"
15
- ]);
16
- export function AS012(source, options = {}) {
17
- return new AS012Scanner(options.filename ?? "<input>").scan(source);
18
- }
19
- class AS012Scanner {
20
- filename;
21
- diagnostics = [];
22
- constructor(filename) {
23
- this.filename = filename;
24
- }
25
- scan(source) {
26
- this.visitModule(parseModule(source, this.filename));
27
- return this.diagnostics;
28
- }
29
- visitModule(node) {
30
- for (const statement of node.body) {
31
- this.visitStatement(statement);
32
- }
33
- }
34
- visitStatement(node) {
35
- switch (node.type) {
36
- case "BlockStatement":
37
- for (const statement of node.body) {
38
- this.visitStatement(statement);
39
- }
40
- return;
41
- case "ExpressionStatement":
42
- this.visitExpression(node.expression);
43
- return;
44
- case "IfStatement":
45
- this.visitIfStatement(node);
46
- return;
47
- case "ForStatement":
48
- this.visitForStatement(node);
49
- return;
50
- case "ForInStatement":
51
- case "ForOfStatement":
52
- this.visitForOfStatement(node);
53
- return;
54
- case "WhileStatement":
55
- case "DoWhileStatement":
56
- this.visitWhileStatement(node);
57
- return;
58
- case "TryStatement":
59
- this.visitTryStatement(node);
60
- return;
61
- case "VariableDeclaration":
62
- this.visitVariableDeclaration(node);
63
- return;
64
- case "ReturnStatement":
65
- this.visitReturnStatement(node);
66
- return;
67
- case "ThrowStatement":
68
- this.visitThrowStatement(node);
69
- return;
70
- case "ExportNamedDeclaration":
71
- this.visitVariableDeclaration(node.declaration);
72
- return;
73
- case "ExportDefaultDeclaration":
74
- this.visitExpression(node.declaration);
75
- return;
76
- case "ImportDeclaration":
77
- case "BreakStatement":
78
- case "ContinueStatement":
79
- return;
80
- }
81
- }
82
- visitIfStatement(node) {
83
- this.visitExpression(node.test);
84
- this.visitStatement(node.consequent);
85
- if (node.alternate !== undefined) {
86
- this.visitStatement(node.alternate);
87
- }
88
- }
89
- visitForStatement(node) {
90
- if (node.init !== undefined) {
91
- if (node.init.type === "VariableDeclaration") {
92
- this.visitVariableDeclaration(node.init);
93
- }
94
- else {
95
- this.visitExpression(node.init);
96
- }
97
- }
98
- if (node.test !== undefined) {
99
- this.visitExpression(node.test);
100
- }
101
- if (node.update !== undefined) {
102
- this.visitExpression(node.update);
103
- }
104
- this.visitStatement(node.body);
105
- }
106
- visitForOfStatement(node) {
107
- if (node.left.type === "VariableDeclaration") {
108
- this.visitVariableDeclaration(node.left);
109
- }
110
- else {
111
- this.visitPattern(node.left);
112
- }
113
- this.visitExpression(node.right);
114
- this.visitStatement(node.body);
115
- }
116
- visitWhileStatement(node) {
117
- this.visitExpression(node.test);
118
- this.visitStatement(node.body);
119
- }
120
- visitTryStatement(node) {
121
- this.visitStatement(node.block);
122
- if (node.handler !== undefined) {
123
- this.visitCatchClause(node.handler);
124
- }
125
- if (node.finalizer !== undefined) {
126
- this.visitStatement(node.finalizer);
127
- }
128
- }
129
- visitCatchClause(node) {
130
- if (node.param !== undefined) {
131
- this.visitPattern(node.param);
132
- }
133
- this.visitStatement(node.body);
134
- }
135
- visitVariableDeclaration(node) {
136
- for (const declarator of node.declarations) {
137
- this.visitVariableDeclarator(declarator);
138
- }
139
- }
140
- visitVariableDeclarator(node) {
141
- this.visitPattern(node.id);
142
- if (node.init !== undefined) {
143
- this.visitExpression(node.init);
144
- }
145
- }
146
- visitReturnStatement(node) {
147
- if (node.argument !== undefined) {
148
- this.visitExpression(node.argument);
149
- }
150
- }
151
- visitThrowStatement(node) {
152
- this.visitExpression(node.argument);
153
- }
154
- visitExpression(node) {
155
- switch (node.type) {
156
- case "ArrowFunctionExpression":
157
- this.visitArrowFunction(node);
158
- return;
159
- case "AwaitExpression":
160
- this.visitExpression(node.argument);
161
- return;
162
- case "ArrayExpression":
163
- this.visitArrayExpression(node);
164
- return;
165
- case "ObjectExpression":
166
- this.visitObjectExpression(node);
167
- return;
168
- case "UnaryExpression":
169
- this.visitUnaryExpression(node);
170
- return;
171
- case "BinaryExpression":
172
- case "LogicalExpression":
173
- this.visitBinaryLikeExpression(node);
174
- return;
175
- case "ConditionalExpression":
176
- this.visitConditionalExpression(node);
177
- return;
178
- case "MemberExpression":
179
- this.visitMemberExpression(node);
180
- return;
181
- case "AssignmentExpression":
182
- this.visitAssignmentExpression(node);
183
- return;
184
- case "CallExpression":
185
- this.visitCallExpression(node);
186
- return;
187
- case "TemplateLiteral":
188
- this.visitTemplateLiteral(node);
189
- return;
190
- case "Identifier":
191
- case "BooleanLiteral":
192
- case "NullLiteral":
193
- case "NumericLiteral":
194
- case "RegexLiteral":
195
- case "StringLiteral":
196
- case "UndefinedLiteral":
197
- return;
198
- }
199
- }
200
- visitArrowFunction(node) {
201
- for (const parameter of node.params) {
202
- this.visitPattern(parameter);
203
- }
204
- if (node.body.type === "BlockStatement") {
205
- for (const statement of node.body.body) {
206
- this.visitStatement(statement);
207
- }
208
- return;
209
- }
210
- this.visitExpression(node.body);
211
- }
212
- visitArrayExpression(node) {
213
- for (const element of node.elements) {
214
- if (element.type === "SpreadElement") {
215
- this.visitExpression(element.argument);
216
- continue;
217
- }
218
- this.visitExpression(element);
219
- }
220
- }
221
- visitObjectExpression(node) {
222
- for (const property of node.properties) {
223
- if (property.type === "SpreadElement") {
224
- this.visitExpression(property.argument);
225
- continue;
226
- }
227
- this.visitProperty(property);
228
- }
229
- }
230
- visitProperty(node) {
231
- if (node.computed) {
232
- this.visitExpression(node.key);
233
- }
234
- this.visitExpression(node.value);
235
- }
236
- visitUnaryExpression(node) {
237
- this.visitExpression(node.argument);
238
- }
239
- visitBinaryLikeExpression(node) {
240
- this.visitExpression(node.left);
241
- this.visitExpression(node.right);
242
- }
243
- visitConditionalExpression(node) {
244
- this.visitExpression(node.test);
245
- this.visitExpression(node.consequent);
246
- this.visitExpression(node.alternate);
247
- }
248
- visitMemberExpression(node) {
249
- this.visitExpression(node.object);
250
- if (node.computed) {
251
- this.visitExpression(node.property);
252
- }
253
- }
254
- visitAssignmentExpression(node) {
255
- this.visitPattern(node.left);
256
- this.visitExpression(node.right);
257
- }
258
- visitCallExpression(node) {
259
- this.visitExpression(node.callee);
260
- this.reportUnsupportedMethodArgs(node);
261
- for (const argument of node.arguments) {
262
- this.visitCallArgument(argument);
263
- }
264
- }
265
- visitCallArgument(node) {
266
- if (node.type === "SpreadElement") {
267
- this.visitExpression(node.argument);
268
- return;
269
- }
270
- this.visitExpression(node);
271
- }
272
- visitTemplateLiteral(node) {
273
- for (const expression of node.expressions) {
274
- this.visitExpression(expression);
275
- }
276
- }
277
- visitPattern(node) {
278
- switch (node.type) {
279
- case "Identifier":
280
- case "MetaProperty":
281
- return;
282
- case "MemberExpression":
283
- this.visitMemberExpression(node);
284
- return;
285
- case "ArrayPattern":
286
- for (const element of node.elements) {
287
- if (element === null) {
288
- continue;
289
- }
290
- this.visitPattern(element);
291
- }
292
- return;
293
- case "ObjectPattern":
294
- for (const property of node.properties) {
295
- if (property.type === "RestElement") {
296
- this.visitPattern(property);
297
- continue;
298
- }
299
- if (property.computed) {
300
- this.visitExpression(property.key);
301
- }
302
- this.visitPattern(property.value);
303
- }
304
- return;
305
- case "AssignmentPattern":
306
- this.visitPattern(node.left);
307
- this.visitExpression(node.right);
308
- return;
309
- case "RestElement":
310
- this.visitPattern(node.argument);
311
- return;
312
- }
313
- }
314
- reportUnsupportedMethodArgs(node) {
315
- const methodName = getMemberPropertyName(node.callee);
316
- if (methodName === undefined) {
317
- return;
318
- }
319
- if (methodName !== "sort") {
320
- return;
321
- }
322
- const comparator = node.arguments[0];
323
- if (comparator === undefined || comparator.type === "SpreadElement") {
324
- return;
325
- }
326
- if (!isSupportedSortComparator(comparator)) {
327
- this.report(comparator.span, SORT_MESSAGE);
328
- }
329
- }
330
- report(span, message) {
331
- this.diagnostics.push({
332
- code: "AS012",
333
- severity: "error",
334
- message,
335
- filename: this.filename,
336
- line: span.start.line,
337
- column: span.start.column,
338
- span
339
- });
340
- }
341
- }
342
- function getMemberPropertyName(node) {
343
- if (node.type !== "MemberExpression") {
344
- return undefined;
345
- }
346
- if (!node.computed && node.property.type === "Identifier") {
347
- return node.property.name;
348
- }
349
- if (node.computed && node.property.type === "StringLiteral") {
350
- return node.property.value;
351
- }
352
- return undefined;
353
- }
354
- function isSupportedSortComparator(node) {
355
- return node.type === "ArrowFunctionExpression" && !node.async && isNumberReturningArrow(node);
356
- }
357
- function isNumberReturningArrow(node) {
358
- if (node.body.type === "BlockStatement") {
359
- return false;
360
- }
361
- return isClearlyNumberExpression(node.body);
362
- }
363
- function isClearlyNumberExpression(node) {
364
- switch (node.type) {
365
- case "NumericLiteral":
366
- return true;
367
- case "RegexLiteral":
368
- return false;
369
- case "UnaryExpression":
370
- return ((node.operator === "+" || node.operator === "-" || node.operator === "~") &&
371
- isClearlyNumberExpression(node.argument));
372
- case "BinaryExpression":
373
- return NUMBER_RETURNING_BINARY_OPERATORS.has(node.operator);
374
- case "ConditionalExpression":
375
- return (isClearlyNumberExpression(node.consequent) && isClearlyNumberExpression(node.alternate));
376
- case "CallExpression":
377
- return isLocaleCompareCall(node);
378
- default:
379
- return false;
380
- }
381
- }
382
- function isLocaleCompareCall(node) {
383
- return getMemberPropertyName(node.callee) === "localeCompare";
384
- }