@jsenv/core 30.3.1 → 30.3.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,12 +1,11 @@
1
- /* eslint-disable no-void */
2
1
  export default function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
3
2
  var desc = {};
4
3
  Object.keys(descriptor).forEach(function (key) {
5
4
  desc[key] = descriptor[key];
6
5
  });
7
- desc.enumerable = Boolean(desc.enumerable);
8
- desc.configurable = Boolean(desc.configurable);
9
- if ("value" in desc || desc.initializer) {
6
+ desc.enumerable = !!desc.enumerable;
7
+ desc.configurable = !!desc.configurable;
8
+ if ('value' in desc || desc.initializer) {
10
9
  desc.writable = true;
11
10
  }
12
11
  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * NOTE: This is an old version of the helper, used for 2021-12 decorators.
5
- * Updates should be done in applyDecs2203.js.
5
+ * Updates should be done in applyDecs2203R.js.
6
6
  */
7
7
 
8
8
  /**
@@ -0,0 +1,494 @@
1
+ /* @minVersion 7.19.0 */
2
+
3
+ /**
4
+ * NOTE: This is an old version of the helper, used for 2022-03 decorators.
5
+ * Updates should be done in applyDecs2203R.js.
6
+ */
7
+
8
+ /**
9
+ Enums are used in this file, but not assigned to vars to avoid non-hoistable values
10
+
11
+ CONSTRUCTOR = 0;
12
+ PUBLIC = 1;
13
+ PRIVATE = 2;
14
+
15
+ FIELD = 0;
16
+ ACCESSOR = 1;
17
+ METHOD = 2;
18
+ GETTER = 3;
19
+ SETTER = 4;
20
+
21
+ STATIC = 5;
22
+
23
+ CLASS = 10; // only used in assertValidReturnValue
24
+ */
25
+ function applyDecs2203Factory() {
26
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
27
+ return function addInitializer(initializer) {
28
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
29
+ assertCallable(initializer, "An initializer");
30
+ initializers.push(initializer);
31
+ };
32
+ }
33
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value) {
34
+ var kindStr;
35
+ switch (kind) {
36
+ case 1 /* ACCESSOR */:
37
+ kindStr = "accessor";
38
+ break;
39
+ case 2 /* METHOD */:
40
+ kindStr = "method";
41
+ break;
42
+ case 3 /* GETTER */:
43
+ kindStr = "getter";
44
+ break;
45
+ case 4 /* SETTER */:
46
+ kindStr = "setter";
47
+ break;
48
+ default:
49
+ kindStr = "field";
50
+ }
51
+ var ctx = {
52
+ kind: kindStr,
53
+ name: isPrivate ? "#" + name : name,
54
+ static: isStatic,
55
+ private: isPrivate
56
+ };
57
+ var decoratorFinishedRef = {
58
+ v: false
59
+ };
60
+ if (kind !== 0 /* FIELD */) {
61
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
62
+ }
63
+ var get, set;
64
+ if (kind === 0 /* FIELD */) {
65
+ if (isPrivate) {
66
+ get = desc.get;
67
+ set = desc.set;
68
+ } else {
69
+ get = function () {
70
+ return this[name];
71
+ };
72
+ set = function (v) {
73
+ this[name] = v;
74
+ };
75
+ }
76
+ } else if (kind === 2 /* METHOD */) {
77
+ get = function () {
78
+ return desc.value;
79
+ };
80
+ } else {
81
+ // replace with values that will go through the final getter and setter
82
+ if (kind === 1 /* ACCESSOR */ || kind === 3 /* GETTER */) {
83
+ get = function () {
84
+ return desc.get.call(this);
85
+ };
86
+ }
87
+ if (kind === 1 /* ACCESSOR */ || kind === 4 /* SETTER */) {
88
+ set = function (v) {
89
+ desc.set.call(this, v);
90
+ };
91
+ }
92
+ }
93
+ ctx.access = get && set ? {
94
+ get: get,
95
+ set: set
96
+ } : get ? {
97
+ get: get
98
+ } : {
99
+ set: set
100
+ };
101
+ try {
102
+ return dec(value, ctx);
103
+ } finally {
104
+ decoratorFinishedRef.v = true;
105
+ }
106
+ }
107
+ function assertNotFinished(decoratorFinishedRef, fnName) {
108
+ if (decoratorFinishedRef.v) {
109
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
110
+ }
111
+ }
112
+ function assertCallable(fn, hint) {
113
+ if (typeof fn !== "function") {
114
+ throw new TypeError(hint + " must be a function");
115
+ }
116
+ }
117
+ function assertValidReturnValue(kind, value) {
118
+ var type = typeof value;
119
+ if (kind === 1 /* ACCESSOR */) {
120
+ if (type !== "object" || value === null) {
121
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
122
+ }
123
+ if (value.get !== undefined) {
124
+ assertCallable(value.get, "accessor.get");
125
+ }
126
+ if (value.set !== undefined) {
127
+ assertCallable(value.set, "accessor.set");
128
+ }
129
+ if (value.init !== undefined) {
130
+ assertCallable(value.init, "accessor.init");
131
+ }
132
+ } else if (type !== "function") {
133
+ var hint;
134
+ if (kind === 0 /* FIELD */) {
135
+ hint = "field";
136
+ } else if (kind === 10 /* CLASS */) {
137
+ hint = "class";
138
+ } else {
139
+ hint = "method";
140
+ }
141
+ throw new TypeError(hint + " decorators must return a function or void 0");
142
+ }
143
+ }
144
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers) {
145
+ var decs = decInfo[0];
146
+ var desc, init, value;
147
+ if (isPrivate) {
148
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
149
+ desc = {
150
+ get: decInfo[3],
151
+ set: decInfo[4]
152
+ };
153
+ } else if (kind === 3 /* GETTER */) {
154
+ desc = {
155
+ get: decInfo[3]
156
+ };
157
+ } else if (kind === 4 /* SETTER */) {
158
+ desc = {
159
+ set: decInfo[3]
160
+ };
161
+ } else {
162
+ desc = {
163
+ value: decInfo[3]
164
+ };
165
+ }
166
+ } else if (kind !== 0 /* FIELD */) {
167
+ desc = Object.getOwnPropertyDescriptor(base, name);
168
+ }
169
+ if (kind === 1 /* ACCESSOR */) {
170
+ value = {
171
+ get: desc.get,
172
+ set: desc.set
173
+ };
174
+ } else if (kind === 2 /* METHOD */) {
175
+ value = desc.value;
176
+ } else if (kind === 3 /* GETTER */) {
177
+ value = desc.get;
178
+ } else if (kind === 4 /* SETTER */) {
179
+ value = desc.set;
180
+ }
181
+ var newValue, get, set;
182
+ if (typeof decs === "function") {
183
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, value);
184
+ if (newValue !== void 0) {
185
+ assertValidReturnValue(kind, newValue);
186
+ if (kind === 0 /* FIELD */) {
187
+ init = newValue;
188
+ } else if (kind === 1 /* ACCESSOR */) {
189
+ init = newValue.init;
190
+ get = newValue.get || value.get;
191
+ set = newValue.set || value.set;
192
+ value = {
193
+ get: get,
194
+ set: set
195
+ };
196
+ } else {
197
+ value = newValue;
198
+ }
199
+ }
200
+ } else {
201
+ for (var i = decs.length - 1; i >= 0; i--) {
202
+ var dec = decs[i];
203
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value);
204
+ if (newValue !== void 0) {
205
+ assertValidReturnValue(kind, newValue);
206
+ var newInit;
207
+ if (kind === 0 /* FIELD */) {
208
+ newInit = newValue;
209
+ } else if (kind === 1 /* ACCESSOR */) {
210
+ newInit = newValue.init;
211
+ get = newValue.get || value.get;
212
+ set = newValue.set || value.set;
213
+ value = {
214
+ get: get,
215
+ set: set
216
+ };
217
+ } else {
218
+ value = newValue;
219
+ }
220
+ if (newInit !== void 0) {
221
+ if (init === void 0) {
222
+ init = newInit;
223
+ } else if (typeof init === "function") {
224
+ init = [init, newInit];
225
+ } else {
226
+ init.push(newInit);
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
233
+ if (init === void 0) {
234
+ // If the initializer was void 0, sub in a dummy initializer
235
+ init = function (instance, init) {
236
+ return init;
237
+ };
238
+ } else if (typeof init !== "function") {
239
+ var ownInitializers = init;
240
+ init = function (instance, init) {
241
+ var value = init;
242
+ for (var i = 0; i < ownInitializers.length; i++) {
243
+ value = ownInitializers[i].call(instance, value);
244
+ }
245
+ return value;
246
+ };
247
+ } else {
248
+ var originalInitializer = init;
249
+ init = function (instance, init) {
250
+ return originalInitializer.call(instance, init);
251
+ };
252
+ }
253
+ ret.push(init);
254
+ }
255
+ if (kind !== 0 /* FIELD */) {
256
+ if (kind === 1 /* ACCESSOR */) {
257
+ desc.get = value.get;
258
+ desc.set = value.set;
259
+ } else if (kind === 2 /* METHOD */) {
260
+ desc.value = value;
261
+ } else if (kind === 3 /* GETTER */) {
262
+ desc.get = value;
263
+ } else if (kind === 4 /* SETTER */) {
264
+ desc.set = value;
265
+ }
266
+ if (isPrivate) {
267
+ if (kind === 1 /* ACCESSOR */) {
268
+ ret.push(function (instance, args) {
269
+ return value.get.call(instance, args);
270
+ });
271
+ ret.push(function (instance, args) {
272
+ return value.set.call(instance, args);
273
+ });
274
+ } else if (kind === 2 /* METHOD */) {
275
+ ret.push(value);
276
+ } else {
277
+ ret.push(function (instance, args) {
278
+ return value.call(instance, args);
279
+ });
280
+ }
281
+ } else {
282
+ Object.defineProperty(base, name, desc);
283
+ }
284
+ }
285
+ }
286
+ function applyMemberDecs(ret, Class, decInfos) {
287
+ var protoInitializers;
288
+ var staticInitializers;
289
+ var existingProtoNonFields = new Map();
290
+ var existingStaticNonFields = new Map();
291
+ for (var i = 0; i < decInfos.length; i++) {
292
+ var decInfo = decInfos[i];
293
+
294
+ // skip computed property names
295
+ if (!Array.isArray(decInfo)) continue;
296
+ var kind = decInfo[1];
297
+ var name = decInfo[2];
298
+ var isPrivate = decInfo.length > 3;
299
+ var isStatic = kind >= 5; /* STATIC */
300
+ var base;
301
+ var initializers;
302
+ if (isStatic) {
303
+ base = Class;
304
+ kind = kind - 5 /* STATIC */;
305
+ // initialize staticInitializers when we see a non-field static member
306
+ if (kind !== 0 /* FIELD */) {
307
+ staticInitializers = staticInitializers || [];
308
+ initializers = staticInitializers;
309
+ }
310
+ } else {
311
+ base = Class.prototype;
312
+ // initialize protoInitializers when we see a non-field member
313
+ if (kind !== 0 /* FIELD */) {
314
+ protoInitializers = protoInitializers || [];
315
+ initializers = protoInitializers;
316
+ }
317
+ }
318
+ if (kind !== 0 /* FIELD */ && !isPrivate) {
319
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
320
+ var existingKind = existingNonFields.get(name) || 0;
321
+ if (existingKind === true || existingKind === 3 /* GETTER */ && kind !== 4 /* SETTER */ || existingKind === 4 /* SETTER */ && kind !== 3 /* GETTER */) {
322
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
323
+ } else if (!existingKind && kind > 2 /* METHOD */) {
324
+ existingNonFields.set(name, kind);
325
+ } else {
326
+ existingNonFields.set(name, true);
327
+ }
328
+ }
329
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);
330
+ }
331
+ pushInitializers(ret, protoInitializers);
332
+ pushInitializers(ret, staticInitializers);
333
+ }
334
+ function pushInitializers(ret, initializers) {
335
+ if (initializers) {
336
+ ret.push(function (instance) {
337
+ for (var i = 0; i < initializers.length; i++) {
338
+ initializers[i].call(instance);
339
+ }
340
+ return instance;
341
+ });
342
+ }
343
+ }
344
+ function applyClassDecs(ret, targetClass, classDecs) {
345
+ if (classDecs.length > 0) {
346
+ var initializers = [];
347
+ var newClass = targetClass;
348
+ var name = targetClass.name;
349
+ for (var i = classDecs.length - 1; i >= 0; i--) {
350
+ var decoratorFinishedRef = {
351
+ v: false
352
+ };
353
+ try {
354
+ var nextNewClass = classDecs[i](newClass, {
355
+ kind: "class",
356
+ name: name,
357
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)
358
+ });
359
+ } finally {
360
+ decoratorFinishedRef.v = true;
361
+ }
362
+ if (nextNewClass !== undefined) {
363
+ assertValidReturnValue(10 /* CLASS */, nextNewClass);
364
+ newClass = nextNewClass;
365
+ }
366
+ }
367
+ ret.push(newClass, function () {
368
+ for (var i = 0; i < initializers.length; i++) {
369
+ initializers[i].call(newClass);
370
+ }
371
+ });
372
+ }
373
+ }
374
+
375
+ /**
376
+ Basic usage:
377
+ applyDecs(
378
+ Class,
379
+ [
380
+ // member decorators
381
+ [
382
+ dec, // dec or array of decs
383
+ 0, // kind of value being decorated
384
+ 'prop', // name of public prop on class containing the value being decorated,
385
+ '#p', // the name of the private property (if is private, void 0 otherwise),
386
+ ]
387
+ ],
388
+ [
389
+ // class decorators
390
+ dec1, dec2
391
+ ]
392
+ )
393
+ ```
394
+ Fully transpiled example:
395
+ ```js
396
+ @dec
397
+ class Class {
398
+ @dec
399
+ a = 123;
400
+ @dec
401
+ #a = 123;
402
+ @dec
403
+ @dec2
404
+ accessor b = 123;
405
+ @dec
406
+ accessor #b = 123;
407
+ @dec
408
+ c() { console.log('c'); }
409
+ @dec
410
+ #c() { console.log('privC'); }
411
+ @dec
412
+ get d() { console.log('d'); }
413
+ @dec
414
+ get #d() { console.log('privD'); }
415
+ @dec
416
+ set e(v) { console.log('e'); }
417
+ @dec
418
+ set #e(v) { console.log('privE'); }
419
+ }
420
+
421
+ // becomes
422
+ let initializeInstance;
423
+ let initializeClass;
424
+ let initA;
425
+ let initPrivA;
426
+ let initB;
427
+ let initPrivB, getPrivB, setPrivB;
428
+ let privC;
429
+ let privD;
430
+ let privE;
431
+ let Class;
432
+ class _Class {
433
+ static {
434
+ let ret = applyDecs(
435
+ this,
436
+ [
437
+ [dec, 0, 'a'],
438
+ [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
439
+ [[dec, dec2], 1, 'b'],
440
+ [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
441
+ [dec, 2, 'c'],
442
+ [dec, 2, 'c', () => console.log('privC')],
443
+ [dec, 3, 'd'],
444
+ [dec, 3, 'd', () => console.log('privD')],
445
+ [dec, 4, 'e'],
446
+ [dec, 4, 'e', () => console.log('privE')],
447
+ ],
448
+ [
449
+ dec
450
+ ]
451
+ )
452
+ initA = ret[0];
453
+ initPrivA = ret[1];
454
+ initB = ret[2];
455
+ initPrivB = ret[3];
456
+ getPrivB = ret[4];
457
+ setPrivB = ret[5];
458
+ privC = ret[6];
459
+ privD = ret[7];
460
+ privE = ret[8];
461
+ initializeInstance = ret[9];
462
+ Class = ret[10]
463
+ initializeClass = ret[11];
464
+ }
465
+ a = (initializeInstance(this), initA(this, 123));
466
+ #a = initPrivA(this, 123);
467
+ #bData = initB(this, 123);
468
+ get b() { return this.#bData }
469
+ set b(v) { this.#bData = v }
470
+ #privBData = initPrivB(this, 123);
471
+ get #b() { return getPrivB(this); }
472
+ set #b(v) { setPrivB(this, v); }
473
+ c() { console.log('c'); }
474
+ #c(...args) { return privC(this, ...args) }
475
+ get d() { console.log('d'); }
476
+ get #d() { return privD(this); }
477
+ set e(v) { console.log('e'); }
478
+ set #e(v) { privE(this, v); }
479
+ }
480
+ initializeClass(Class);
481
+ */
482
+
483
+ return function applyDecs2203Impl(targetClass, memberDecs, classDecs) {
484
+ var ret = [];
485
+ applyMemberDecs(ret, targetClass, memberDecs);
486
+ applyClassDecs(ret, targetClass, classDecs);
487
+ return ret;
488
+ };
489
+ }
490
+ var applyDecs2203Impl;
491
+ export default function applyDecs2203(targetClass, memberDecs, classDecs) {
492
+ applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory();
493
+ return applyDecs2203Impl(targetClass, memberDecs, classDecs);
494
+ }
@@ -1,4 +1,4 @@
1
- /* @minVersion 7.19.0 */
1
+ /* @minVersion 7.20.0 */
2
2
 
3
3
  /**
4
4
  Enums are used in this file, but not assigned to vars to avoid non-hoistable values
@@ -278,7 +278,8 @@ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, ini
278
278
  }
279
279
  }
280
280
  }
281
- function applyMemberDecs(ret, Class, decInfos) {
281
+ function applyMemberDecs(Class, decInfos) {
282
+ var ret = [];
282
283
  var protoInitializers;
283
284
  var staticInitializers;
284
285
  var existingProtoNonFields = new Map();
@@ -325,6 +326,7 @@ function applyMemberDecs(ret, Class, decInfos) {
325
326
  }
326
327
  pushInitializers(ret, protoInitializers);
327
328
  pushInitializers(ret, staticInitializers);
329
+ return ret;
328
330
  }
329
331
  function pushInitializers(ret, initializers) {
330
332
  if (initializers) {
@@ -336,7 +338,7 @@ function pushInitializers(ret, initializers) {
336
338
  });
337
339
  }
338
340
  }
339
- function applyClassDecs(ret, targetClass, classDecs) {
341
+ function applyClassDecs(targetClass, classDecs) {
340
342
  if (classDecs.length > 0) {
341
343
  var initializers = [];
342
344
  var newClass = targetClass;
@@ -359,12 +361,14 @@ function applyClassDecs(ret, targetClass, classDecs) {
359
361
  newClass = nextNewClass;
360
362
  }
361
363
  }
362
- ret.push(newClass, function () {
364
+ return [newClass, function () {
363
365
  for (var i = 0; i < initializers.length; i++) {
364
366
  initializers[i].call(newClass);
365
367
  }
366
- });
368
+ }];
367
369
  }
370
+ // The transformer will not emit assignment when there are no class decorators,
371
+ // so we don't have to return an empty array here.
368
372
  }
369
373
 
370
374
  /**
@@ -512,9 +516,12 @@ function applyClassDecs(ret, targetClass, classDecs) {
512
516
 
513
517
  initializeClass(Class);
514
518
  */
515
- export default function applyDecs2203(targetClass, memberDecs, classDecs) {
516
- var ret = [];
517
- applyMemberDecs(ret, targetClass, memberDecs);
518
- applyClassDecs(ret, targetClass, classDecs);
519
- return ret;
519
+ export default function applyDecs2203R(targetClass, memberDecs, classDecs) {
520
+ return {
521
+ e: applyMemberDecs(targetClass, memberDecs),
522
+ // Lazily apply class decorations so that member init locals can be properly bound.
523
+ get c() {
524
+ return applyClassDecs(targetClass, classDecs);
525
+ }
526
+ };
520
527
  }
package/dist/main.js CHANGED
@@ -16,14 +16,14 @@ import { Readable, Stream, Writable } from "node:stream";
16
16
  import { Http2ServerResponse } from "node:http2";
17
17
  import { lookup } from "node:dns";
18
18
  import { SOURCEMAP, generateSourcemapFileUrl, composeTwoSourcemaps, generateSourcemapDataUrl, createMagicSource, getOriginalPosition } from "@jsenv/sourcemap";
19
- import { parseHtmlString, stringifyHtmlAst, getHtmlNodeAttribute, visitHtmlNodes, analyzeScriptNode, setHtmlNodeAttributes, parseSrcSet, getHtmlNodePosition, getHtmlNodeAttributePosition, applyPostCss, postCssPluginUrlVisitor, parseJsUrls, getHtmlNodeText, setHtmlNodeText, applyBabelPlugins, injectScriptNodeAsEarlyAsPossible, createHtmlNode, findHtmlNode, removeHtmlNode, removeHtmlNodeText, injectJsImport, analyzeLinkNode, injectHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
19
+ import { parseHtmlString, stringifyHtmlAst, getHtmlNodeAttribute, visitHtmlNodes, analyzeScriptNode, setHtmlNodeAttributes, parseSrcSet, getHtmlNodePosition, getHtmlNodeAttributePosition, parseCssUrls, parseJsUrls, getHtmlNodeText, setHtmlNodeText, applyBabelPlugins, injectScriptNodeAsEarlyAsPossible, createHtmlNode, findHtmlNode, removeHtmlNode, removeHtmlNodeText, injectJsImport, analyzeLinkNode, injectHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
20
20
  import { createRequire } from "node:module";
21
21
  import babelParser from "@babel/parser";
22
22
  import { bundleJsModules } from "@jsenv/plugin-bundling";
23
23
  import v8, { takeCoverage } from "node:v8";
24
24
  import wrapAnsi from "wrap-ansi";
25
25
  import stripAnsi from "strip-ansi";
26
- import cuid from "cuid";
26
+ import { createId } from "@paralleldrive/cuid2";
27
27
  import { runInNewContext } from "node:vm";
28
28
  import { fork } from "node:child_process";
29
29
 
@@ -9668,21 +9668,22 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
9668
9668
  url,
9669
9669
  htmlAst
9670
9670
  });
9671
- const actions = [];
9672
9671
  const mutations = [];
9673
- mentions.forEach(({
9674
- type,
9675
- subtype,
9676
- expectedType,
9677
- line,
9678
- column,
9679
- originalLine,
9680
- originalColumn,
9681
- node,
9682
- attributeName,
9683
- debug,
9684
- specifier
9685
- }) => {
9672
+ const actions = [];
9673
+ for (const mention of mentions) {
9674
+ const {
9675
+ type,
9676
+ subtype,
9677
+ expectedType,
9678
+ line,
9679
+ column,
9680
+ originalLine,
9681
+ originalColumn,
9682
+ node,
9683
+ attributeName,
9684
+ debug,
9685
+ specifier
9686
+ } = mention;
9686
9687
  const {
9687
9688
  crossorigin,
9688
9689
  integrity
@@ -9704,13 +9705,13 @@ const parseAndTransformHtmlUrls = async (urlInfo, context) => {
9704
9705
  });
9705
9706
  actions.push(async () => {
9706
9707
  await context.referenceUtils.readGeneratedSpecifier(reference);
9707
- });
9708
- mutations.push(() => {
9709
- setHtmlNodeAttributes(node, {
9710
- [attributeName]: reference.generatedSpecifier
9708
+ mutations.push(() => {
9709
+ setHtmlNodeAttributes(node, {
9710
+ [attributeName]: reference.generatedSpecifier
9711
+ });
9711
9712
  });
9712
9713
  });
9713
- });
9714
+ }
9714
9715
  if (actions.length > 0) {
9715
9716
  await Promise.all(actions.map(action => action()));
9716
9717
  }
@@ -9958,40 +9959,33 @@ const decideLinkExpectedType = (linkMention, mentions) => {
9958
9959
  * https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
9959
9960
  */
9960
9961
  const parseAndTransformCssUrls = async (urlInfo, context) => {
9962
+ const cssUrls = await parseCssUrls({
9963
+ css: urlInfo.content,
9964
+ url: urlInfo.originalUrl
9965
+ });
9961
9966
  const actions = [];
9962
9967
  const magicSource = createMagicSource(urlInfo.content);
9963
- await applyPostCss({
9964
- sourcemaps: false,
9965
- plugins: [postCssPluginUrlVisitor({
9966
- urlVisitor: ({
9967
- type,
9968
- specifier,
9969
- specifierStart,
9970
- specifierEnd,
9971
- specifierLine,
9972
- specifierColumn
9973
- }) => {
9974
- const [reference] = context.referenceUtils.found({
9975
- type: `css_${type}`,
9976
- specifier,
9977
- specifierStart,
9978
- specifierEnd,
9979
- specifierLine,
9980
- specifierColumn
9981
- });
9982
- actions.push(async () => {
9983
- magicSource.replace({
9984
- start: specifierStart,
9985
- end: specifierEnd,
9986
- replacement: await context.referenceUtils.readGeneratedSpecifier(reference)
9987
- });
9988
- });
9989
- }
9990
- })],
9991
- url: urlInfo.originalUrl,
9992
- content: urlInfo.content
9993
- });
9994
- await Promise.all(actions.map(action => action()));
9968
+ for (const cssUrl of cssUrls) {
9969
+ const [reference] = context.referenceUtils.found({
9970
+ type: cssUrl.type,
9971
+ specifier: cssUrl.specifier,
9972
+ specifierStart: cssUrl.start,
9973
+ specifierEnd: cssUrl.end,
9974
+ specifierLine: cssUrl.line,
9975
+ specifierColumn: cssUrl.column
9976
+ });
9977
+ actions.push(async () => {
9978
+ const replacement = await context.referenceUtils.readGeneratedSpecifier(reference);
9979
+ magicSource.replace({
9980
+ start: cssUrl.start,
9981
+ end: cssUrl.end,
9982
+ replacement
9983
+ });
9984
+ });
9985
+ }
9986
+ if (actions.length > 0) {
9987
+ await Promise.all(actions.map(action => action()));
9988
+ }
9995
9989
  return magicSource.toContentAndSourcemap();
9996
9990
  };
9997
9991
 
@@ -10004,7 +9998,7 @@ const parseAndTransformJsUrls = async (urlInfo, context) => {
10004
9998
  });
10005
9999
  const actions = [];
10006
10000
  const magicSource = createMagicSource(urlInfo.content);
10007
- jsMentions.forEach(jsMention => {
10001
+ for (const jsMention of jsMentions) {
10008
10002
  if (jsMention.subtype === "import_static" || jsMention.subtype === "import_dynamic") {
10009
10003
  urlInfo.data.usesImport = true;
10010
10004
  }
@@ -10015,10 +10009,10 @@ const parseAndTransformJsUrls = async (urlInfo, context) => {
10015
10009
  expectedType: jsMention.expectedType,
10016
10010
  expectedSubtype: jsMention.expectedSubtype || urlInfo.subtype,
10017
10011
  specifier: jsMention.specifier,
10018
- specifierStart: jsMention.specifierStart,
10019
- specifierEnd: jsMention.specifierEnd,
10020
- specifierLine: jsMention.specifierLine,
10021
- specifierColumn: jsMention.specifierColumn,
10012
+ specifierStart: jsMention.start,
10013
+ specifierEnd: jsMention.end,
10014
+ specifierLine: jsMention.line,
10015
+ specifierColumn: jsMention.column,
10022
10016
  data: jsMention.data,
10023
10017
  baseUrl: {
10024
10018
  "StringLiteral": jsMention.baseUrl,
@@ -10035,16 +10029,18 @@ const parseAndTransformJsUrls = async (urlInfo, context) => {
10035
10029
  actions.push(async () => {
10036
10030
  const replacement = await context.referenceUtils.readGeneratedSpecifier(reference);
10037
10031
  magicSource.replace({
10038
- start: jsMention.specifierStart,
10039
- end: jsMention.specifierEnd,
10032
+ start: jsMention.start,
10033
+ end: jsMention.end,
10040
10034
  replacement
10041
10035
  });
10042
10036
  if (reference.mutation) {
10043
10037
  reference.mutation(magicSource);
10044
10038
  }
10045
10039
  });
10046
- });
10047
- await Promise.all(actions.map(action => action()));
10040
+ }
10041
+ if (actions.length > 0) {
10042
+ await Promise.all(actions.map(action => action()));
10043
+ }
10048
10044
  const {
10049
10045
  content,
10050
10046
  sourcemap
@@ -21735,6 +21731,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21735
21731
  const getBuildRelativeUrl = url => {
21736
21732
  const urlObject = new URL(url);
21737
21733
  urlObject.searchParams.delete("as_js_classic");
21734
+ urlObject.searchParams.delete("as_css_module");
21735
+ urlObject.searchParams.delete("as_json_module");
21736
+ urlObject.searchParams.delete("as_text_module");
21738
21737
  url = urlObject.href;
21739
21738
  const buildRelativeUrl = urlToRelativeUrl(url, buildDirectoryUrl);
21740
21739
  return buildRelativeUrl;
@@ -23385,7 +23384,7 @@ const run = async ({
23385
23384
  // and they can be read later at "coverageFileUrl"
23386
23385
  let coverageFileUrl;
23387
23386
  if (coverageEnabled) {
23388
- coverageFileUrl = new URL(`./${runtime.name}/${cuid()}.json`, coverageTempDirectoryUrl).href;
23387
+ coverageFileUrl = new URL(`./${runtime.name}/${createId()}.json`, coverageTempDirectoryUrl).href;
23389
23388
  await ensureParentDirectories(coverageFileUrl);
23390
23389
  if (coverageEnabled) {
23391
23390
  result.coverageFileUrl = coverageFileUrl;
@@ -25014,7 +25013,7 @@ const registerEvent = ({
25014
25013
 
25015
25014
  const chromium = createRuntimeFromPlaywright({
25016
25015
  browserName: "chromium",
25017
- browserVersion: "109.0.5414.46",
25016
+ browserVersion: "110.0.5481.38",
25018
25017
  // to update, check https://github.com/microsoft/playwright/releases
25019
25018
  coveragePlaywrightAPIAvailable: true
25020
25019
  });
@@ -25022,7 +25021,7 @@ const chromiumIsolatedTab = chromium.isolatedTab;
25022
25021
 
25023
25022
  const firefox = createRuntimeFromPlaywright({
25024
25023
  browserName: "firefox",
25025
- browserVersion: "107.0" // to update, check https://github.com/microsoft/playwright/releases
25024
+ browserVersion: "108.0.2" // to update, check https://github.com/microsoft/playwright/releases
25026
25025
  });
25027
25026
 
25028
25027
  const firefoxIsolatedTab = firefox.isolatedTab;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "30.3.1",
3
+ "version": "30.3.3",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -67,7 +67,7 @@
67
67
  "@c88/v8-coverage": "0.1.1",
68
68
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
69
69
  "@jsenv/abort": "4.2.4",
70
- "@jsenv/ast": "2.0.1",
70
+ "@jsenv/ast": "3.0.0",
71
71
  "@jsenv/babel-plugins": "1.1.2",
72
72
  "@jsenv/plugin-bundling": "1.1.1",
73
73
  "@jsenv/filesystem": "4.1.9",
@@ -81,8 +81,8 @@
81
81
  "@jsenv/url-meta": "7.0.2",
82
82
  "@jsenv/urls": "1.2.8",
83
83
  "@jsenv/utils": "2.0.1",
84
+ "@paralleldrive/cuid2": "2.0.1",
84
85
  "construct-style-sheets-polyfill": "3.1.0",
85
- "cuid": "2.1.8",
86
86
  "istanbul-lib-coverage": "3.2.0",
87
87
  "istanbul-lib-instrument": "5.2.1",
88
88
  "istanbul-lib-report": "3.0.0",
@@ -93,25 +93,25 @@
93
93
  "string-width": "5.1.2",
94
94
  "strip-ansi": "7.0.1",
95
95
  "v8-to-istanbul": "9.0.1",
96
- "wrap-ansi": "8.0.1"
96
+ "wrap-ansi": "8.1.0"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@babel/eslint-parser": "7.19.1",
100
100
  "@babel/plugin-syntax-import-assertions": "7.20.0",
101
101
  "@jsenv/assert": "./packages/assert/",
102
102
  "@jsenv/eslint-config": "./packages/eslint-config/",
103
- "@jsenv/file-size-impact": "13.0.2",
104
- "@jsenv/https-local": "3.0.5",
103
+ "@jsenv/file-size-impact": "14.0.0",
104
+ "@jsenv/https-local": "3.0.6",
105
105
  "@jsenv/package-workspace": "0.5.1",
106
106
  "@jsenv/plugin-minification": "./packages/jsenv-plugin-minification/",
107
107
  "@jsenv/plugin-globals": "./packages/jsenv-plugin-globals/",
108
108
  "@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
109
109
  "@jsenv/performance-impact": "4.1.0",
110
- "eslint": "8.31.0",
110
+ "eslint": "8.32.0",
111
111
  "eslint-plugin-html": "7.1.0",
112
- "eslint-plugin-import": "2.26.0",
113
- "eslint-plugin-react": "7.31.11",
114
- "playwright": "1.29.2",
115
- "prettier": "2.8.2"
112
+ "eslint-plugin-import": "2.27.5",
113
+ "eslint-plugin-react": "7.32.1",
114
+ "playwright": "1.30.0",
115
+ "prettier": "2.8.3"
116
116
  }
117
117
  }
@@ -1539,6 +1539,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1539
1539
  const getBuildRelativeUrl = (url) => {
1540
1540
  const urlObject = new URL(url)
1541
1541
  urlObject.searchParams.delete("as_js_classic")
1542
+ urlObject.searchParams.delete("as_css_module")
1543
+ urlObject.searchParams.delete("as_json_module")
1544
+ urlObject.searchParams.delete("as_text_module")
1542
1545
  url = urlObject.href
1543
1546
  const buildRelativeUrl = urlToRelativeUrl(url, buildDirectoryUrl)
1544
1547
  return buildRelativeUrl
@@ -1,4 +1,4 @@
1
- import cuid from "cuid"
1
+ import { createId } from "@paralleldrive/cuid2"
2
2
  import { Abort, raceCallbacks } from "@jsenv/abort"
3
3
  import { ensureParentDirectories } from "@jsenv/filesystem"
4
4
 
@@ -62,7 +62,7 @@ export const run = async ({
62
62
  let coverageFileUrl
63
63
  if (coverageEnabled) {
64
64
  coverageFileUrl = new URL(
65
- `./${runtime.name}/${cuid()}.json`,
65
+ `./${runtime.name}/${createId()}.json`,
66
66
  coverageTempDirectoryUrl,
67
67
  ).href
68
68
  await ensureParentDirectories(coverageFileUrl)
@@ -2,7 +2,7 @@ import { createRuntimeFromPlaywright } from "./from_playwright.js"
2
2
 
3
3
  export const chromium = createRuntimeFromPlaywright({
4
4
  browserName: "chromium",
5
- browserVersion: "109.0.5414.46", // to update, check https://github.com/microsoft/playwright/releases
5
+ browserVersion: "110.0.5481.38", // to update, check https://github.com/microsoft/playwright/releases
6
6
  coveragePlaywrightAPIAvailable: true,
7
7
  })
8
8
  export const chromiumIsolatedTab = chromium.isolatedTab
@@ -2,6 +2,6 @@ import { createRuntimeFromPlaywright } from "./from_playwright.js"
2
2
 
3
3
  export const firefox = createRuntimeFromPlaywright({
4
4
  browserName: "firefox",
5
- browserVersion: "107.0", // to update, check https://github.com/microsoft/playwright/releases
5
+ browserVersion: "108.0.2", // to update, check https://github.com/microsoft/playwright/releases
6
6
  })
7
7
  export const firefoxIsolatedTab = firefox.isolatedTab
@@ -2,47 +2,38 @@
2
2
  * https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
3
3
  */
4
4
 
5
+ import { parseCssUrls } from "@jsenv/ast"
5
6
  import { createMagicSource } from "@jsenv/sourcemap"
6
- import { applyPostCss, postCssPluginUrlVisitor } from "@jsenv/ast"
7
7
 
8
8
  export const parseAndTransformCssUrls = async (urlInfo, context) => {
9
- const actions = []
10
- const magicSource = createMagicSource(urlInfo.content)
11
- await applyPostCss({
12
- sourcemaps: false,
13
- plugins: [
14
- postCssPluginUrlVisitor({
15
- urlVisitor: ({
16
- type,
17
- specifier,
18
- specifierStart,
19
- specifierEnd,
20
- specifierLine,
21
- specifierColumn,
22
- }) => {
23
- const [reference] = context.referenceUtils.found({
24
- type: `css_${type}`,
25
- specifier,
26
- specifierStart,
27
- specifierEnd,
28
- specifierLine,
29
- specifierColumn,
30
- })
31
- actions.push(async () => {
32
- magicSource.replace({
33
- start: specifierStart,
34
- end: specifierEnd,
35
- replacement: await context.referenceUtils.readGeneratedSpecifier(
36
- reference,
37
- ),
38
- })
39
- })
40
- },
41
- }),
42
- ],
9
+ const cssUrls = await parseCssUrls({
10
+ css: urlInfo.content,
43
11
  url: urlInfo.originalUrl,
44
- content: urlInfo.content,
45
12
  })
46
- await Promise.all(actions.map((action) => action()))
13
+ const actions = []
14
+ const magicSource = createMagicSource(urlInfo.content)
15
+ for (const cssUrl of cssUrls) {
16
+ const [reference] = context.referenceUtils.found({
17
+ type: cssUrl.type,
18
+ specifier: cssUrl.specifier,
19
+ specifierStart: cssUrl.start,
20
+ specifierEnd: cssUrl.end,
21
+ specifierLine: cssUrl.line,
22
+ specifierColumn: cssUrl.column,
23
+ })
24
+ actions.push(async () => {
25
+ const replacement = await context.referenceUtils.readGeneratedSpecifier(
26
+ reference,
27
+ )
28
+ magicSource.replace({
29
+ start: cssUrl.start,
30
+ end: cssUrl.end,
31
+ replacement,
32
+ })
33
+ })
34
+ }
35
+ if (actions.length > 0) {
36
+ await Promise.all(actions.map((action) => action()))
37
+ }
47
38
  return magicSource.toContentAndSourcemap()
48
39
  }
@@ -20,10 +20,10 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
20
20
  url,
21
21
  htmlAst,
22
22
  })
23
- const actions = []
24
23
  const mutations = []
25
- mentions.forEach(
26
- ({
24
+ const actions = []
25
+ for (const mention of mentions) {
26
+ const {
27
27
  type,
28
28
  subtype,
29
29
  expectedType,
@@ -35,39 +35,38 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
35
35
  attributeName,
36
36
  debug,
37
37
  specifier,
38
- }) => {
39
- const { crossorigin, integrity } = readFetchMetas(node)
40
- const isResourceHint = [
41
- "preconnect",
42
- "dns-prefetch",
43
- "prefetch",
44
- "preload",
45
- "modulepreload",
46
- ].includes(subtype)
47
- const [reference] = context.referenceUtils.found({
48
- type,
49
- subtype,
50
- expectedType,
51
- originalLine,
52
- originalColumn,
53
- specifier,
54
- specifierLine: line,
55
- specifierColumn: column,
56
- isResourceHint,
57
- crossorigin,
58
- integrity,
59
- debug,
60
- })
61
- actions.push(async () => {
62
- await context.referenceUtils.readGeneratedSpecifier(reference)
63
- })
38
+ } = mention
39
+ const { crossorigin, integrity } = readFetchMetas(node)
40
+ const isResourceHint = [
41
+ "preconnect",
42
+ "dns-prefetch",
43
+ "prefetch",
44
+ "preload",
45
+ "modulepreload",
46
+ ].includes(subtype)
47
+ const [reference] = context.referenceUtils.found({
48
+ type,
49
+ subtype,
50
+ expectedType,
51
+ originalLine,
52
+ originalColumn,
53
+ specifier,
54
+ specifierLine: line,
55
+ specifierColumn: column,
56
+ isResourceHint,
57
+ crossorigin,
58
+ integrity,
59
+ debug,
60
+ })
61
+ actions.push(async () => {
62
+ await context.referenceUtils.readGeneratedSpecifier(reference)
64
63
  mutations.push(() => {
65
64
  setHtmlNodeAttributes(node, {
66
65
  [attributeName]: reference.generatedSpecifier,
67
66
  })
68
67
  })
69
- },
70
- )
68
+ })
69
+ }
71
70
  if (actions.length > 0) {
72
71
  await Promise.all(actions.map((action) => action()))
73
72
  }
@@ -12,7 +12,7 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
12
12
  })
13
13
  const actions = []
14
14
  const magicSource = createMagicSource(urlInfo.content)
15
- jsMentions.forEach((jsMention) => {
15
+ for (const jsMention of jsMentions) {
16
16
  if (
17
17
  jsMention.subtype === "import_static" ||
18
18
  jsMention.subtype === "import_dynamic"
@@ -26,10 +26,10 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
26
26
  expectedType: jsMention.expectedType,
27
27
  expectedSubtype: jsMention.expectedSubtype || urlInfo.subtype,
28
28
  specifier: jsMention.specifier,
29
- specifierStart: jsMention.specifierStart,
30
- specifierEnd: jsMention.specifierEnd,
31
- specifierLine: jsMention.specifierLine,
32
- specifierColumn: jsMention.specifierColumn,
29
+ specifierStart: jsMention.start,
30
+ specifierEnd: jsMention.end,
31
+ specifierLine: jsMention.line,
32
+ specifierColumn: jsMention.column,
33
33
  data: jsMention.data,
34
34
  baseUrl: {
35
35
  "StringLiteral": jsMention.baseUrl,
@@ -48,16 +48,18 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
48
48
  reference,
49
49
  )
50
50
  magicSource.replace({
51
- start: jsMention.specifierStart,
52
- end: jsMention.specifierEnd,
51
+ start: jsMention.start,
52
+ end: jsMention.end,
53
53
  replacement,
54
54
  })
55
55
  if (reference.mutation) {
56
56
  reference.mutation(magicSource)
57
57
  }
58
58
  })
59
- })
60
- await Promise.all(actions.map((action) => action()))
59
+ }
60
+ if (actions.length > 0) {
61
+ await Promise.all(actions.map((action) => action()))
62
+ }
61
63
  const { content, sourcemap } = magicSource.toContentAndSourcemap()
62
64
  return { content, sourcemap }
63
65
  }