esupgrade 2025.3.0 → 2025.3.1

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,221 +1,379 @@
1
1
  import { describe, test } from "node:test"
2
- import assert from "node:assert"
2
+ import assert from "node:assert/strict"
3
3
  import { transform } from "../src/index.js"
4
4
 
5
5
  describe("newly-available", () => {
6
6
  describe("Promise.try", () => {
7
- test("Promise.try transformation - newly-available", () => {
8
- const input = `const p = new Promise((resolve) => resolve(getData()));`
9
-
10
- const result = transform(input, "newly-available")
11
-
12
- assert.strictEqual(result.modified, true)
13
- assert.match(result.code, /Promise\.try/)
7
+ test("transforms resolve call with argument", () => {
8
+ assert(
9
+ transform(
10
+ `const p = new Promise((resolve) => resolve(getData()));`,
11
+ "newly-available",
12
+ ).modified,
13
+ "transform Promise constructor to Promise.try",
14
+ )
15
+ assert.match(
16
+ transform(
17
+ `const p = new Promise((resolve) => resolve(getData()));`,
18
+ "newly-available",
19
+ ).code,
20
+ /Promise\.try/,
21
+ )
14
22
  })
15
23
 
16
- test("Promise.try not in widely-available", () => {
17
- const input = `const p = new Promise((resolve) => resolve(getData()));`
18
-
19
- const result = transform(input, "widely-available")
20
-
21
- // Should not transform Promise with widely-available baseline
22
- assert.doesNotMatch(result.code, /Promise\.try/)
24
+ test("not available in widely-available baseline", () => {
25
+ assert.doesNotMatch(
26
+ transform(
27
+ `const p = new Promise((resolve) => resolve(getData()));`,
28
+ "widely-available",
29
+ ).code,
30
+ /Promise\.try/,
31
+ "do not transform with widely-available baseline",
32
+ )
23
33
  })
24
34
 
25
- test("Promise.try with function passed to resolve", () => {
26
- const input = `const p = new Promise((resolve) => setTimeout(resolve));`
27
-
28
- const result = transform(input, "newly-available")
29
-
30
- assert.strictEqual(result.modified, true)
31
- // Should transform to Promise.try(setTimeout) not Promise.try(() => setTimeout(resolve))
32
- assert.match(result.code, /Promise\.try\(setTimeout\)/)
33
- assert.doesNotMatch(result.code, /resolve/)
35
+ test("transforms function passed to resolve", () => {
36
+ assert(
37
+ transform(
38
+ `const p = new Promise((resolve) => setTimeout(resolve));`,
39
+ "newly-available",
40
+ ).modified,
41
+ )
42
+ assert.match(
43
+ transform(
44
+ `const p = new Promise((resolve) => setTimeout(resolve));`,
45
+ "newly-available",
46
+ ).code,
47
+ /Promise\.try\(setTimeout\)/,
48
+ "transform to Promise.try(setTimeout) not Promise.try(() => setTimeout(resolve))",
49
+ )
50
+ assert.doesNotMatch(
51
+ transform(
52
+ `const p = new Promise((resolve) => setTimeout(resolve));`,
53
+ "newly-available",
54
+ ).code,
55
+ /resolve/,
56
+ )
34
57
  })
35
58
 
36
- test("Promise.try should not transform when awaited", () => {
37
- const input = `async function foo() {
59
+ test("skip when awaited", () => {
60
+ assert(
61
+ !transform(
62
+ `async function foo() {
38
63
  await new Promise((resolve) => setTimeout(resolve, 1000));
39
- }`
40
-
41
- const result = transform(input, "newly-available")
42
-
43
- // Should NOT transform awaited Promises
44
- assert.strictEqual(result.modified, false)
45
- assert.match(result.code, /await new Promise/)
46
- assert.doesNotMatch(result.code, /Promise\.try/)
64
+ }`,
65
+ "newly-available",
66
+ ).modified,
67
+ "do not transform awaited Promises",
68
+ )
69
+ assert.match(
70
+ transform(
71
+ `async function foo() {
72
+ await new Promise((resolve) => setTimeout(resolve, 1000));
73
+ }`,
74
+ "newly-available",
75
+ ).code,
76
+ /await new Promise/,
77
+ )
78
+ assert.doesNotMatch(
79
+ transform(
80
+ `async function foo() {
81
+ await new Promise((resolve) => setTimeout(resolve, 1000));
82
+ }`,
83
+ "newly-available",
84
+ ).code,
85
+ /Promise\.try/,
86
+ )
47
87
  })
48
88
 
49
- test("Promise.try should not transform non-Promise constructors", () => {
50
- const input = `const p = new MyPromise((resolve) => resolve(getData()));`
51
-
52
- const result = transform(input, "newly-available")
53
-
54
- assert.strictEqual(result.modified, false)
55
- assert.match(result.code, /new MyPromise/)
89
+ test("skip non-Promise constructors", () => {
90
+ assert(
91
+ !transform(
92
+ `const p = new MyPromise((resolve) => resolve(getData()));`,
93
+ "newly-available",
94
+ ).modified,
95
+ )
96
+ assert.match(
97
+ transform(
98
+ `const p = new MyPromise((resolve) => resolve(getData()));`,
99
+ "newly-available",
100
+ ).code,
101
+ /new MyPromise/,
102
+ )
56
103
  })
57
104
 
58
- test("Promise.try should not transform with 0 arguments", () => {
59
- const input = `const p = new Promise();`
60
-
61
- const result = transform(input, "newly-available")
62
-
63
- assert.strictEqual(result.modified, false)
64
- assert.match(result.code, /new Promise\(\)/)
105
+ test("skip with 0 arguments", () => {
106
+ assert(!transform(`const p = new Promise();`, "newly-available").modified)
107
+ assert.match(
108
+ transform(`const p = new Promise();`, "newly-available").code,
109
+ /new Promise\(\)/,
110
+ )
65
111
  })
66
112
 
67
- test("Promise.try should not transform with multiple arguments", () => {
68
- const input = `const p = new Promise((resolve) => resolve(1), extraArg);`
69
-
70
- const result = transform(input, "newly-available")
71
-
72
- assert.strictEqual(result.modified, false)
73
- assert.match(result.code, /new Promise/)
113
+ test("skip with multiple arguments", () => {
114
+ assert(
115
+ !transform(
116
+ `const p = new Promise((resolve) => resolve(1), extraArg);`,
117
+ "newly-available",
118
+ ).modified,
119
+ )
120
+ assert.match(
121
+ transform(
122
+ `const p = new Promise((resolve) => resolve(1), extraArg);`,
123
+ "newly-available",
124
+ ).code,
125
+ /new Promise/,
126
+ )
74
127
  })
75
128
 
76
- test("Promise.try should not transform with non-function argument", () => {
77
- const input = `const p = new Promise(executor);`
78
-
79
- const result = transform(input, "newly-available")
80
-
81
- assert.strictEqual(result.modified, false)
82
- assert.match(result.code, /new Promise\(executor\)/)
129
+ test("skip with non-function argument", () => {
130
+ assert(!transform(`const p = new Promise(executor);`, "newly-available").modified)
131
+ assert.match(
132
+ transform(`const p = new Promise(executor);`, "newly-available").code,
133
+ /new Promise\(executor\)/,
134
+ )
83
135
  })
84
136
 
85
- test("Promise.try should not transform with 0 params", () => {
86
- const input = `const p = new Promise(() => console.log('test'));`
87
-
88
- const result = transform(input, "newly-available")
89
-
90
- assert.strictEqual(result.modified, false)
91
- assert.match(result.code, /new Promise/)
137
+ test("skip with 0 params", () => {
138
+ assert(
139
+ !transform(
140
+ `const p = new Promise(() => console.log('test'));`,
141
+ "newly-available",
142
+ ).modified,
143
+ )
144
+ assert.match(
145
+ transform(
146
+ `const p = new Promise(() => console.log('test'));`,
147
+ "newly-available",
148
+ ).code,
149
+ /new Promise/,
150
+ )
92
151
  })
93
152
 
94
- test("Promise.try should not transform with more than 2 params", () => {
95
- const input = `const p = new Promise((resolve, reject, extra) => resolve(1));`
96
-
97
- const result = transform(input, "newly-available")
98
-
99
- assert.strictEqual(result.modified, false)
100
- assert.match(result.code, /new Promise/)
153
+ test("skip with more than 2 params", () => {
154
+ assert(
155
+ !transform(
156
+ `const p = new Promise((resolve, reject, extra) => resolve(1));`,
157
+ "newly-available",
158
+ ).modified,
159
+ )
160
+ assert.match(
161
+ transform(
162
+ `const p = new Promise((resolve, reject, extra) => resolve(1));`,
163
+ "newly-available",
164
+ ).code,
165
+ /new Promise/,
166
+ )
101
167
  })
102
168
 
103
- test("Promise.try with block statement and resolve call", () => {
104
- const input = `const p = new Promise((resolve) => { resolve(getData()); });`
105
-
106
- const result = transform(input, "newly-available")
107
-
108
- assert.strictEqual(result.modified, true)
109
- assert.match(result.code, /Promise\.try/)
169
+ test("transforms block statement with resolve call", () => {
170
+ assert(
171
+ transform(
172
+ `const p = new Promise((resolve) => { resolve(getData()); });`,
173
+ "newly-available",
174
+ ).modified,
175
+ )
176
+ assert.match(
177
+ transform(
178
+ `const p = new Promise((resolve) => { resolve(getData()); });`,
179
+ "newly-available",
180
+ ).code,
181
+ /Promise\.try/,
182
+ )
110
183
  })
111
184
 
112
- test("Promise.try with arrow function expression body as function call", () => {
113
- const input = `const p = new Promise((resolve) => computeValue());`
114
-
115
- const result = transform(input, "newly-available")
116
-
117
- // This should not transform because computeValue() is not calling resolve
118
- assert.strictEqual(result.modified, false)
119
- assert.match(result.code, /new Promise/)
185
+ test("skip with arrow function expression body as function call", () => {
186
+ assert(
187
+ !transform(
188
+ `const p = new Promise((resolve) => computeValue());`,
189
+ "newly-available",
190
+ ).modified,
191
+ "do not transform because computeValue() is not calling resolve",
192
+ )
193
+ assert.match(
194
+ transform(
195
+ `const p = new Promise((resolve) => computeValue());`,
196
+ "newly-available",
197
+ ).code,
198
+ /new Promise/,
199
+ )
120
200
  })
121
201
 
122
- test("Promise.try with arrow function returning a value directly", () => {
123
- const input = `const p = new Promise((resolve) => someFunction(arg1, arg2));`
124
-
125
- const result = transform(input, "newly-available")
126
-
127
- // This should not transform - function call that doesn't involve resolve
128
- assert.strictEqual(result.modified, false)
129
- assert.match(result.code, /new Promise/)
202
+ test("skip with arrow function returning a value directly", () => {
203
+ assert(
204
+ !transform(
205
+ `const p = new Promise((resolve) => someFunction(arg1, arg2));`,
206
+ "newly-available",
207
+ ).modified,
208
+ "do not transform function call that doesn't involve resolve",
209
+ )
210
+ assert.match(
211
+ transform(
212
+ `const p = new Promise((resolve) => someFunction(arg1, arg2));`,
213
+ "newly-available",
214
+ ).code,
215
+ /new Promise/,
216
+ )
130
217
  })
131
218
 
132
- test("Promise.try should not transform non-call expression body", () => {
133
- const input = `const p = new Promise((resolve) => someValue);`
134
-
135
- const result = transform(input, "newly-available")
136
-
137
- assert.strictEqual(result.modified, false)
138
- assert.match(result.code, /new Promise/)
219
+ test("skip with non-call expression body", () => {
220
+ assert(
221
+ !transform(`const p = new Promise((resolve) => someValue);`, "newly-available")
222
+ .modified,
223
+ )
224
+ assert.match(
225
+ transform(`const p = new Promise((resolve) => someValue);`, "newly-available")
226
+ .code,
227
+ /new Promise/,
228
+ )
139
229
  })
140
230
 
141
- test("Promise.try should not transform call with wrong number of arguments to resolve", () => {
142
- const input = `const p = new Promise((resolve) => func(resolve, extra));`
143
-
144
- const result = transform(input, "newly-available")
145
-
146
- assert.strictEqual(result.modified, false)
147
- assert.match(result.code, /new Promise/)
231
+ test("skip with wrong number of arguments to resolve", () => {
232
+ assert(
233
+ !transform(
234
+ `const p = new Promise((resolve) => func(resolve, extra));`,
235
+ "newly-available",
236
+ ).modified,
237
+ )
238
+ assert.match(
239
+ transform(
240
+ `const p = new Promise((resolve) => func(resolve, extra));`,
241
+ "newly-available",
242
+ ).code,
243
+ /new Promise/,
244
+ )
148
245
  })
149
246
 
150
- test("Promise.try should not transform call with non-identifier resolve", () => {
151
- const input = `const p = new Promise((resolve) => func(123));`
152
-
153
- const result = transform(input, "newly-available")
154
-
155
- assert.strictEqual(result.modified, false)
156
- assert.match(result.code, /new Promise/)
247
+ test("skip with non-identifier resolve", () => {
248
+ assert(
249
+ !transform(`const p = new Promise((resolve) => func(123));`, "newly-available")
250
+ .modified,
251
+ )
252
+ assert.match(
253
+ transform(`const p = new Promise((resolve) => func(123));`, "newly-available")
254
+ .code,
255
+ /new Promise/,
256
+ )
157
257
  })
158
258
 
159
- test("Promise.try should not transform resolve call with 0 arguments", () => {
160
- const input = `const p = new Promise((resolve) => resolve());`
161
-
162
- const result = transform(input, "newly-available")
163
-
164
- assert.strictEqual(result.modified, false)
165
- assert.match(result.code, /new Promise/)
259
+ test("skip with resolve call with 0 arguments", () => {
260
+ assert(
261
+ !transform(`const p = new Promise((resolve) => resolve());`, "newly-available")
262
+ .modified,
263
+ )
264
+ assert.match(
265
+ transform(`const p = new Promise((resolve) => resolve());`, "newly-available")
266
+ .code,
267
+ /new Promise/,
268
+ )
166
269
  })
167
270
 
168
- test("Promise.try should not transform block with multiple statements", () => {
169
- const input = `const p = new Promise((resolve) => {
271
+ test("skip with block with multiple statements", () => {
272
+ assert(
273
+ !transform(
274
+ `const p = new Promise((resolve) => {
170
275
  const data = getData();
171
276
  resolve(data);
172
- });`
173
-
174
- const result = transform(input, "newly-available")
175
-
176
- assert.strictEqual(result.modified, false)
177
- assert.match(result.code, /new Promise/)
277
+ });`,
278
+ "newly-available",
279
+ ).modified,
280
+ )
281
+ assert.match(
282
+ transform(
283
+ `const p = new Promise((resolve) => {
284
+ const data = getData();
285
+ resolve(data);
286
+ });`,
287
+ "newly-available",
288
+ ).code,
289
+ /new Promise/,
290
+ )
178
291
  })
179
292
 
180
- test("Promise.try should not transform block with non-expression statement", () => {
181
- const input = `const p = new Promise((resolve) => {
293
+ test("skip with block with non-expression statement", () => {
294
+ assert(
295
+ !transform(
296
+ `const p = new Promise((resolve) => {
182
297
  if (true) resolve(1);
183
- });`
184
-
185
- const result = transform(input, "newly-available")
186
-
187
- assert.strictEqual(result.modified, false)
188
- assert.match(result.code, /new Promise/)
298
+ });`,
299
+ "newly-available",
300
+ ).modified,
301
+ )
302
+ assert.match(
303
+ transform(
304
+ `const p = new Promise((resolve) => {
305
+ if (true) resolve(1);
306
+ });`,
307
+ "newly-available",
308
+ ).code,
309
+ /new Promise/,
310
+ )
189
311
  })
190
312
 
191
- test("Promise.try with function expression", () => {
192
- const input = `const p = new Promise(function(resolve) { resolve(getData()); });`
193
-
194
- const result = transform(input, "newly-available")
195
-
196
- assert.strictEqual(result.modified, true)
197
- assert.match(result.code, /Promise\.try/)
313
+ test("transforms function expression", () => {
314
+ assert(
315
+ transform(
316
+ `const p = new Promise(function(resolve) { resolve(getData()); });`,
317
+ "newly-available",
318
+ ).modified,
319
+ )
320
+ assert.match(
321
+ transform(
322
+ `const p = new Promise(function(resolve) { resolve(getData()); });`,
323
+ "newly-available",
324
+ ).code,
325
+ /Promise\.try/,
326
+ )
198
327
  })
199
328
 
200
- test("Promise.try with both resolve and reject params", () => {
201
- const input = `const p = new Promise((resolve, reject) => resolve(getData()));`
202
-
203
- const result = transform(input, "newly-available")
204
-
205
- assert.strictEqual(result.modified, true)
206
- assert.match(result.code, /Promise\.try/)
329
+ test("transforms with both resolve and reject params", () => {
330
+ assert(
331
+ transform(
332
+ `const p = new Promise((resolve, reject) => resolve(getData()));`,
333
+ "newly-available",
334
+ ).modified,
335
+ )
336
+ assert.match(
337
+ transform(
338
+ `const p = new Promise((resolve, reject) => resolve(getData()));`,
339
+ "newly-available",
340
+ ).code,
341
+ /Promise\.try/,
342
+ )
207
343
  })
208
344
 
209
- test("Promise.try tracks line numbers correctly", () => {
210
- const input = `// Line 1
211
- const p = new Promise((resolve) => resolve(getData()));`
212
-
213
- const result = transform(input, "newly-available")
214
-
215
- assert.strictEqual(result.modified, true)
216
- assert.strictEqual(result.changes.length, 1)
217
- assert.strictEqual(result.changes[0].type, "promiseTry")
218
- assert.strictEqual(result.changes[0].line, 2)
345
+ test("tracks line numbers correctly", () => {
346
+ assert(
347
+ transform(
348
+ `// Line 1
349
+ const p = new Promise((resolve) => resolve(getData()));`,
350
+ "newly-available",
351
+ ).modified,
352
+ )
353
+ assert.equal(
354
+ transform(
355
+ `// Line 1
356
+ const p = new Promise((resolve) => resolve(getData()));`,
357
+ "newly-available",
358
+ ).changes.length,
359
+ 1,
360
+ )
361
+ assert.equal(
362
+ transform(
363
+ `// Line 1
364
+ const p = new Promise((resolve) => resolve(getData()));`,
365
+ "newly-available",
366
+ ).changes[0].type,
367
+ "promiseTry",
368
+ )
369
+ assert.equal(
370
+ transform(
371
+ `// Line 1
372
+ const p = new Promise((resolve) => resolve(getData()));`,
373
+ "newly-available",
374
+ ).changes[0].line,
375
+ 2,
376
+ )
219
377
  })
220
378
  })
221
379
  })