@jsenv/plugin-transpilation 1.0.0 → 1.1.0

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 (21) hide show
  1. package/package.json +26 -26
  2. package/src/as_js_module/jsenv_plugin_as_js_module.js +4 -1
  3. package/src/babel/babel_helper_directory/README.md +1 -1
  4. package/src/babel/babel_helper_directory/babel_helpers/applyDecs2301/applyDecs2301.js +547 -528
  5. package/src/babel/babel_helper_directory/babel_helpers/applyDecs2305/applyDecs2305.js +681 -0
  6. package/src/babel/jsenv_plugin_babel.js +89 -17
  7. package/src/babel/new_stylesheet/babel_plugin_new_stylesheet_injector.js +11 -135
  8. package/src/babel/new_stylesheet/constructable_stylesheet_usage.js +114 -0
  9. package/src/babel/new_stylesheet/new_stylesheet_client_file_url.js +4 -0
  10. package/src/babel/regenerator_runtime/babel_plugin_regenerator_runtime_injector.js +11 -35
  11. package/src/babel/regenerator_runtime/regenerator_runtime_client_file_url.js +4 -0
  12. package/src/babel/regenerator_runtime/regenerator_runtime_usage.js +23 -0
  13. package/src/babel/{polyfill_injection_in_babel_ast.js → side_effect_injection_in_babel_ast.js} +8 -8
  14. package/src/import_assertions/jsenv_plugin_import_assertions.js +3 -3
  15. package/src/js_module_fallback/jsenv_plugin_js_module_conversion.js +15 -7
  16. package/src/js_module_fallback/jsenv_plugin_js_module_fallback.js +2 -11
  17. package/src/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +21 -98
  18. package/src/babel/apply_js_transpilation.js +0 -74
  19. package/src/babel/global_this/babel_plugin_global_this_injector.js +0 -56
  20. package/src/babel/global_this/client/global_this_js_classic.js +0 -25
  21. package/src/babel/global_this/client/global_this_js_module.js +0 -21
@@ -20,274 +20,248 @@ import checkInRHS from "../checkInRHS/checkInRHS.js";
20
20
  CLASS = 10; // only used in assertValidReturnValue
21
21
  */
22
22
 
23
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
24
- return function addInitializer(initializer) {
25
- assertNotFinished(decoratorFinishedRef, "addInitializer");
26
- assertCallable(initializer, "An initializer");
27
- initializers.push(initializer);
28
- };
29
- }
30
-
31
- function assertInstanceIfPrivate(has, target) {
32
- if (!has(target)) {
33
- throw new TypeError("Attempted to access private element on non-instance");
23
+ function applyDecs2301Factory() {
24
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
25
+ return function addInitializer(initializer) {
26
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
27
+ assertCallable(initializer, "An initializer");
28
+ initializers.push(initializer);
29
+ };
34
30
  }
35
- }
36
31
 
37
- function memberDec(
38
- dec,
39
- name,
40
- desc,
41
- initializers,
42
- kind,
43
- isStatic,
44
- isPrivate,
45
- value,
46
- hasPrivateBrand
47
- ) {
48
- var kindStr;
49
-
50
- switch (kind) {
51
- case 1 /* ACCESSOR */:
52
- kindStr = "accessor";
53
- break;
54
- case 2 /* METHOD */:
55
- kindStr = "method";
56
- break;
57
- case 3 /* GETTER */:
58
- kindStr = "getter";
59
- break;
60
- case 4 /* SETTER */:
61
- kindStr = "setter";
62
- break;
63
- default:
64
- kindStr = "field";
32
+ function assertInstanceIfPrivate(has, target) {
33
+ if (!has(target)) {
34
+ throw new TypeError(
35
+ "Attempted to access private element on non-instance"
36
+ );
37
+ }
65
38
  }
66
39
 
67
- var ctx = {
68
- kind: kindStr,
69
- name: isPrivate ? "#" + name : name,
70
- static: isStatic,
71
- private: isPrivate,
72
- };
40
+ function memberDec(
41
+ dec,
42
+ name,
43
+ desc,
44
+ initializers,
45
+ kind,
46
+ isStatic,
47
+ isPrivate,
48
+ value,
49
+ hasPrivateBrand
50
+ ) {
51
+ var kindStr;
52
+
53
+ switch (kind) {
54
+ case 1 /* ACCESSOR */:
55
+ kindStr = "accessor";
56
+ break;
57
+ case 2 /* METHOD */:
58
+ kindStr = "method";
59
+ break;
60
+ case 3 /* GETTER */:
61
+ kindStr = "getter";
62
+ break;
63
+ case 4 /* SETTER */:
64
+ kindStr = "setter";
65
+ break;
66
+ default:
67
+ kindStr = "field";
68
+ }
73
69
 
74
- var decoratorFinishedRef = { v: false };
70
+ var ctx = {
71
+ kind: kindStr,
72
+ name: isPrivate ? "#" + name : name,
73
+ static: isStatic,
74
+ private: isPrivate,
75
+ };
75
76
 
76
- if (kind !== 0 /* FIELD */) {
77
- ctx.addInitializer = createAddInitializerMethod(
78
- initializers,
79
- decoratorFinishedRef
80
- );
81
- }
77
+ var decoratorFinishedRef = { v: false };
82
78
 
83
- var get, set;
84
- if (!isPrivate && (kind === 0 /* FIELD */ || kind === 2) /* METHOD */) {
85
- get = function (target) {
86
- return target[name];
87
- };
88
- if (kind === 0 /* FIELD */) {
89
- set = function (target, v) {
90
- target[name] = v;
91
- };
79
+ if (kind !== 0 /* FIELD */) {
80
+ ctx.addInitializer = createAddInitializerMethod(
81
+ initializers,
82
+ decoratorFinishedRef
83
+ );
92
84
  }
93
- } else if (kind === 2 /* METHOD */) {
94
- // Assert: isPrivate is true.
95
- get = function (target) {
96
- assertInstanceIfPrivate(hasPrivateBrand, target);
97
- return desc.value;
98
- };
99
- } else {
100
- // Assert: If kind === 0, then isPrivate is true.
101
- var t = kind === 0 /* FIELD */ || kind === 1; /* ACCESSOR */
102
- if (t || kind === 3 /* GETTER */) {
103
- if (isPrivate) {
104
- get = function (target) {
105
- assertInstanceIfPrivate(hasPrivateBrand, target);
106
- return desc.get.call(target);
107
- };
108
- } else {
109
- get = function (target) {
110
- return desc.get.call(target);
85
+
86
+ var get, set;
87
+ if (!isPrivate && (kind === 0 /* FIELD */ || kind === 2) /* METHOD */) {
88
+ get = function (target) {
89
+ return target[name];
90
+ };
91
+ if (kind === 0 /* FIELD */) {
92
+ set = function (target, v) {
93
+ target[name] = v;
111
94
  };
112
95
  }
96
+ } else if (kind === 2 /* METHOD */) {
97
+ // Assert: isPrivate is true.
98
+ get = function (target) {
99
+ assertInstanceIfPrivate(hasPrivateBrand, target);
100
+ return desc.value;
101
+ };
102
+ } else {
103
+ // Assert: If kind === 0, then isPrivate is true.
104
+ var t = kind === 0 /* FIELD */ || kind === 1; /* ACCESSOR */
105
+ if (t || kind === 3 /* GETTER */) {
106
+ if (isPrivate) {
107
+ get = function (target) {
108
+ assertInstanceIfPrivate(hasPrivateBrand, target);
109
+ return desc.get.call(target);
110
+ };
111
+ } else {
112
+ get = function (target) {
113
+ return desc.get.call(target);
114
+ };
115
+ }
116
+ }
117
+ if (t || kind === 4 /* SETTER */) {
118
+ if (isPrivate) {
119
+ set = function (target, value) {
120
+ assertInstanceIfPrivate(hasPrivateBrand, target);
121
+ desc.set.call(target, value);
122
+ };
123
+ } else {
124
+ set = function (target, value) {
125
+ desc.set.call(target, value);
126
+ };
127
+ }
128
+ }
113
129
  }
114
- if (t || kind === 4 /* SETTER */) {
115
- if (isPrivate) {
116
- set = function (target, value) {
117
- assertInstanceIfPrivate(hasPrivateBrand, target);
118
- desc.set.call(target, value);
119
- };
120
- } else {
121
- set = function (target, value) {
122
- desc.set.call(target, value);
130
+ var has = isPrivate
131
+ ? hasPrivateBrand.bind()
132
+ : function (target) {
133
+ return name in target;
123
134
  };
124
- }
135
+ ctx.access =
136
+ get && set
137
+ ? { get: get, set: set, has: has }
138
+ : get
139
+ ? { get: get, has: has }
140
+ : { set: set, has: has };
141
+
142
+ try {
143
+ return dec(value, ctx);
144
+ } finally {
145
+ decoratorFinishedRef.v = true;
125
146
  }
126
147
  }
127
- var has = isPrivate
128
- ? hasPrivateBrand.bind()
129
- : function (target) {
130
- return name in target;
131
- };
132
- ctx.access =
133
- get && set
134
- ? { get: get, set: set, has: has }
135
- : get
136
- ? { get: get, has: has }
137
- : { set: set, has: has };
138
-
139
- try {
140
- return dec(value, ctx);
141
- } finally {
142
- decoratorFinishedRef.v = true;
143
- }
144
- }
145
148
 
146
- function assertNotFinished(decoratorFinishedRef, fnName) {
147
- if (decoratorFinishedRef.v) {
148
- throw new Error(
149
- "attempted to call " + fnName + " after decoration was finished"
150
- );
149
+ function assertNotFinished(decoratorFinishedRef, fnName) {
150
+ if (decoratorFinishedRef.v) {
151
+ throw new Error(
152
+ "attempted to call " + fnName + " after decoration was finished"
153
+ );
154
+ }
151
155
  }
152
- }
153
156
 
154
- function assertCallable(fn, hint) {
155
- if (typeof fn !== "function") {
156
- throw new TypeError(hint + " must be a function");
157
+ function assertCallable(fn, hint) {
158
+ if (typeof fn !== "function") {
159
+ throw new TypeError(hint + " must be a function");
160
+ }
157
161
  }
158
- }
159
162
 
160
- function assertValidReturnValue(kind, value) {
161
- var type = typeof value;
163
+ function assertValidReturnValue(kind, value) {
164
+ var type = typeof value;
162
165
 
163
- if (kind === 1 /* ACCESSOR */) {
164
- if (type !== "object" || value === null) {
166
+ if (kind === 1 /* ACCESSOR */) {
167
+ if (type !== "object" || value === null) {
168
+ throw new TypeError(
169
+ "accessor decorators must return an object with get, set, or init properties or void 0"
170
+ );
171
+ }
172
+ if (value.get !== undefined) {
173
+ assertCallable(value.get, "accessor.get");
174
+ }
175
+ if (value.set !== undefined) {
176
+ assertCallable(value.set, "accessor.set");
177
+ }
178
+ if (value.init !== undefined) {
179
+ assertCallable(value.init, "accessor.init");
180
+ }
181
+ } else if (type !== "function") {
182
+ var hint;
183
+ if (kind === 0 /* FIELD */) {
184
+ hint = "field";
185
+ } else if (kind === 10 /* CLASS */) {
186
+ hint = "class";
187
+ } else {
188
+ hint = "method";
189
+ }
165
190
  throw new TypeError(
166
- "accessor decorators must return an object with get, set, or init properties or void 0"
191
+ hint + " decorators must return a function or void 0"
167
192
  );
168
193
  }
169
- if (value.get !== undefined) {
170
- assertCallable(value.get, "accessor.get");
171
- }
172
- if (value.set !== undefined) {
173
- assertCallable(value.set, "accessor.set");
174
- }
175
- if (value.init !== undefined) {
176
- assertCallable(value.init, "accessor.init");
177
- }
178
- } else if (type !== "function") {
179
- var hint;
180
- if (kind === 0 /* FIELD */) {
181
- hint = "field";
182
- } else if (kind === 10 /* CLASS */) {
183
- hint = "class";
184
- } else {
185
- hint = "method";
186
- }
187
- throw new TypeError(hint + " decorators must return a function or void 0");
188
194
  }
189
- }
190
195
 
191
- function curryThis1(fn) {
192
- return function () {
193
- return fn(this);
194
- };
195
- }
196
- function curryThis2(fn) {
197
- return function (value) {
198
- fn(this, value);
199
- };
200
- }
201
-
202
- function applyMemberDec(
203
- ret,
204
- base,
205
- decInfo,
206
- name,
207
- kind,
208
- isStatic,
209
- isPrivate,
210
- initializers,
211
- hasPrivateBrand
212
- ) {
213
- var decs = decInfo[0];
196
+ function curryThis1(fn) {
197
+ return function () {
198
+ return fn(this);
199
+ };
200
+ }
201
+ function curryThis2(fn) {
202
+ return function (value) {
203
+ fn(this, value);
204
+ };
205
+ }
214
206
 
215
- var desc, init, value;
207
+ function applyMemberDec(
208
+ ret,
209
+ base,
210
+ decInfo,
211
+ name,
212
+ kind,
213
+ isStatic,
214
+ isPrivate,
215
+ initializers,
216
+ hasPrivateBrand
217
+ ) {
218
+ var decs = decInfo[0];
219
+
220
+ var desc, init, value;
216
221
 
217
- if (isPrivate) {
218
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
219
- desc = {
220
- get: curryThis1(decInfo[3]),
221
- set: curryThis2(decInfo[4]),
222
- };
223
- } else {
224
- if (kind === 3 /* GETTER */) {
225
- desc = {
226
- get: decInfo[3],
227
- };
228
- } else if (kind === 4 /* SETTER */) {
222
+ if (isPrivate) {
223
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
229
224
  desc = {
230
- set: decInfo[3],
225
+ get: curryThis1(decInfo[3]),
226
+ set: curryThis2(decInfo[4]),
231
227
  };
232
228
  } else {
233
- desc = {
234
- value: decInfo[3],
235
- };
229
+ if (kind === 3 /* GETTER */) {
230
+ desc = {
231
+ get: decInfo[3],
232
+ };
233
+ } else if (kind === 4 /* SETTER */) {
234
+ desc = {
235
+ set: decInfo[3],
236
+ };
237
+ } else {
238
+ desc = {
239
+ value: decInfo[3],
240
+ };
241
+ }
236
242
  }
243
+ } else if (kind !== 0 /* FIELD */) {
244
+ desc = Object.getOwnPropertyDescriptor(base, name);
237
245
  }
238
- } else if (kind !== 0 /* FIELD */) {
239
- desc = Object.getOwnPropertyDescriptor(base, name);
240
- }
241
246
 
242
- if (kind === 1 /* ACCESSOR */) {
243
- value = {
244
- get: desc.get,
245
- set: desc.set,
246
- };
247
- } else if (kind === 2 /* METHOD */) {
248
- value = desc.value;
249
- } else if (kind === 3 /* GETTER */) {
250
- value = desc.get;
251
- } else if (kind === 4 /* SETTER */) {
252
- value = desc.set;
253
- }
254
-
255
- var newValue, get, set;
256
-
257
- if (typeof decs === "function") {
258
- newValue = memberDec(
259
- decs,
260
- name,
261
- desc,
262
- initializers,
263
- kind,
264
- isStatic,
265
- isPrivate,
266
- value,
267
- hasPrivateBrand
268
- );
269
-
270
- if (newValue !== void 0) {
271
- assertValidReturnValue(kind, newValue);
272
-
273
- if (kind === 0 /* FIELD */) {
274
- init = newValue;
275
- } else if (kind === 1 /* ACCESSOR */) {
276
- init = newValue.init;
277
- get = newValue.get || value.get;
278
- set = newValue.set || value.set;
279
-
280
- value = { get: get, set: set };
281
- } else {
282
- value = newValue;
283
- }
247
+ if (kind === 1 /* ACCESSOR */) {
248
+ value = {
249
+ get: desc.get,
250
+ set: desc.set,
251
+ };
252
+ } else if (kind === 2 /* METHOD */) {
253
+ value = desc.value;
254
+ } else if (kind === 3 /* GETTER */) {
255
+ value = desc.get;
256
+ } else if (kind === 4 /* SETTER */) {
257
+ value = desc.set;
284
258
  }
285
- } else {
286
- for (var i = decs.length - 1; i >= 0; i--) {
287
- var dec = decs[i];
288
259
 
260
+ var newValue, get, set;
261
+
262
+ if (typeof decs === "function") {
289
263
  newValue = memberDec(
290
- dec,
264
+ decs,
291
265
  name,
292
266
  desc,
293
267
  initializers,
@@ -300,12 +274,11 @@ function applyMemberDec(
300
274
 
301
275
  if (newValue !== void 0) {
302
276
  assertValidReturnValue(kind, newValue);
303
- var newInit;
304
277
 
305
278
  if (kind === 0 /* FIELD */) {
306
- newInit = newValue;
279
+ init = newValue;
307
280
  } else if (kind === 1 /* ACCESSOR */) {
308
- newInit = newValue.init;
281
+ init = newValue.init;
309
282
  get = newValue.get || value.get;
310
283
  set = newValue.set || value.set;
311
284
 
@@ -313,367 +286,414 @@ function applyMemberDec(
313
286
  } else {
314
287
  value = newValue;
315
288
  }
289
+ }
290
+ } else {
291
+ for (var i = decs.length - 1; i >= 0; i--) {
292
+ var dec = decs[i];
293
+
294
+ newValue = memberDec(
295
+ dec,
296
+ name,
297
+ desc,
298
+ initializers,
299
+ kind,
300
+ isStatic,
301
+ isPrivate,
302
+ value,
303
+ hasPrivateBrand
304
+ );
316
305
 
317
- if (newInit !== void 0) {
318
- if (init === void 0) {
319
- init = newInit;
320
- } else if (typeof init === "function") {
321
- init = [init, newInit];
306
+ if (newValue !== void 0) {
307
+ assertValidReturnValue(kind, newValue);
308
+ var newInit;
309
+
310
+ if (kind === 0 /* FIELD */) {
311
+ newInit = newValue;
312
+ } else if (kind === 1 /* ACCESSOR */) {
313
+ newInit = newValue.init;
314
+ get = newValue.get || value.get;
315
+ set = newValue.set || value.set;
316
+
317
+ value = { get: get, set: set };
322
318
  } else {
323
- init.push(newInit);
319
+ value = newValue;
320
+ }
321
+
322
+ if (newInit !== void 0) {
323
+ if (init === void 0) {
324
+ init = newInit;
325
+ } else if (typeof init === "function") {
326
+ init = [init, newInit];
327
+ } else {
328
+ init.push(newInit);
329
+ }
324
330
  }
325
331
  }
326
332
  }
327
333
  }
328
- }
329
-
330
- if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
331
- if (init === void 0) {
332
- // If the initializer was void 0, sub in a dummy initializer
333
- init = function (instance, init) {
334
- return init;
335
- };
336
- } else if (typeof init !== "function") {
337
- var ownInitializers = init;
338
334
 
339
- init = function (instance, init) {
340
- var value = init;
335
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
336
+ if (init === void 0) {
337
+ // If the initializer was void 0, sub in a dummy initializer
338
+ init = function (instance, init) {
339
+ return init;
340
+ };
341
+ } else if (typeof init !== "function") {
342
+ var ownInitializers = init;
341
343
 
342
- for (var i = 0; i < ownInitializers.length; i++) {
343
- value = ownInitializers[i].call(instance, value);
344
- }
344
+ init = function (instance, init) {
345
+ var value = init;
345
346
 
346
- return value;
347
- };
348
- } else {
349
- var originalInitializer = init;
347
+ for (var i = 0; i < ownInitializers.length; i++) {
348
+ value = ownInitializers[i].call(instance, value);
349
+ }
350
350
 
351
- init = function (instance, init) {
352
- return originalInitializer.call(instance, init);
353
- };
354
- }
351
+ return value;
352
+ };
353
+ } else {
354
+ var originalInitializer = init;
355
355
 
356
- ret.push(init);
357
- }
356
+ init = function (instance, init) {
357
+ return originalInitializer.call(instance, init);
358
+ };
359
+ }
358
360
 
359
- if (kind !== 0 /* FIELD */) {
360
- if (kind === 1 /* ACCESSOR */) {
361
- desc.get = value.get;
362
- desc.set = value.set;
363
- } else if (kind === 2 /* METHOD */) {
364
- desc.value = value;
365
- } else if (kind === 3 /* GETTER */) {
366
- desc.get = value;
367
- } else if (kind === 4 /* SETTER */) {
368
- desc.set = value;
361
+ ret.push(init);
369
362
  }
370
363
 
371
- if (isPrivate) {
364
+ if (kind !== 0 /* FIELD */) {
372
365
  if (kind === 1 /* ACCESSOR */) {
373
- ret.push(function (instance, args) {
374
- return value.get.call(instance, args);
375
- });
376
- ret.push(function (instance, args) {
377
- return value.set.call(instance, args);
378
- });
366
+ desc.get = value.get;
367
+ desc.set = value.set;
379
368
  } else if (kind === 2 /* METHOD */) {
380
- ret.push(value);
369
+ desc.value = value;
370
+ } else if (kind === 3 /* GETTER */) {
371
+ desc.get = value;
372
+ } else if (kind === 4 /* SETTER */) {
373
+ desc.set = value;
374
+ }
375
+
376
+ if (isPrivate) {
377
+ if (kind === 1 /* ACCESSOR */) {
378
+ ret.push(function (instance, args) {
379
+ return value.get.call(instance, args);
380
+ });
381
+ ret.push(function (instance, args) {
382
+ return value.set.call(instance, args);
383
+ });
384
+ } else if (kind === 2 /* METHOD */) {
385
+ ret.push(value);
386
+ } else {
387
+ ret.push(function (instance, args) {
388
+ return value.call(instance, args);
389
+ });
390
+ }
381
391
  } else {
382
- ret.push(function (instance, args) {
383
- return value.call(instance, args);
384
- });
392
+ Object.defineProperty(base, name, desc);
385
393
  }
386
- } else {
387
- Object.defineProperty(base, name, desc);
388
394
  }
389
395
  }
390
- }
391
396
 
392
- function applyMemberDecs(Class, decInfos, instanceBrand) {
393
- var ret = [];
394
- var protoInitializers;
395
- var staticInitializers;
396
- var staticBrand;
397
-
398
- var existingProtoNonFields = new Map();
399
- var existingStaticNonFields = new Map();
400
-
401
- for (var i = 0; i < decInfos.length; i++) {
402
- var decInfo = decInfos[i];
403
-
404
- // skip computed property names
405
- if (!Array.isArray(decInfo)) continue;
406
-
407
- var kind = decInfo[1];
408
- var name = decInfo[2];
409
- var isPrivate = decInfo.length > 3;
410
-
411
- var isStatic = kind >= 5; /* STATIC */
412
- var base;
413
- var initializers;
414
- var hasPrivateBrand = instanceBrand;
415
-
416
- if (isStatic) {
417
- base = Class;
418
- kind = kind - 5 /* STATIC */;
419
- // initialize staticInitializers when we see a non-field static member
420
- if (kind !== 0 /* FIELD */) {
421
- staticInitializers = staticInitializers || [];
422
- initializers = staticInitializers;
423
- }
424
- if (isPrivate && !staticBrand) {
425
- staticBrand = function (_) {
426
- return checkInRHS(_) === Class;
427
- };
428
- }
429
- hasPrivateBrand = staticBrand;
430
- } else {
431
- base = Class.prototype;
432
- // initialize protoInitializers when we see a non-field member
433
- if (kind !== 0 /* FIELD */) {
434
- protoInitializers = protoInitializers || [];
435
- initializers = protoInitializers;
397
+ function applyMemberDecs(Class, decInfos, instanceBrand) {
398
+ var ret = [];
399
+ var protoInitializers;
400
+ var staticInitializers;
401
+ var staticBrand;
402
+
403
+ var existingProtoNonFields = new Map();
404
+ var existingStaticNonFields = new Map();
405
+
406
+ for (var i = 0; i < decInfos.length; i++) {
407
+ var decInfo = decInfos[i];
408
+
409
+ // skip computed property names
410
+ if (!Array.isArray(decInfo)) continue;
411
+
412
+ var kind = decInfo[1];
413
+ var name = decInfo[2];
414
+ var isPrivate = decInfo.length > 3;
415
+
416
+ var isStatic = kind >= 5; /* STATIC */
417
+ var base;
418
+ var initializers;
419
+ var hasPrivateBrand = instanceBrand;
420
+
421
+ if (isStatic) {
422
+ base = Class;
423
+ kind = kind - 5 /* STATIC */;
424
+ // initialize staticInitializers when we see a non-field static member
425
+ if (kind !== 0 /* FIELD */) {
426
+ staticInitializers = staticInitializers || [];
427
+ initializers = staticInitializers;
428
+ }
429
+ if (isPrivate && !staticBrand) {
430
+ staticBrand = function (_) {
431
+ return checkInRHS(_) === Class;
432
+ };
433
+ }
434
+ hasPrivateBrand = staticBrand;
435
+ } else {
436
+ base = Class.prototype;
437
+ // initialize protoInitializers when we see a non-field member
438
+ if (kind !== 0 /* FIELD */) {
439
+ protoInitializers = protoInitializers || [];
440
+ initializers = protoInitializers;
441
+ }
436
442
  }
437
- }
438
443
 
439
- if (kind !== 0 /* FIELD */ && !isPrivate) {
440
- var existingNonFields = isStatic
441
- ? existingStaticNonFields
442
- : existingProtoNonFields;
443
-
444
- var existingKind = existingNonFields.get(name) || 0;
445
-
446
- if (
447
- existingKind === true ||
448
- (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ ||
449
- (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */
450
- ) {
451
- throw new Error(
452
- "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: " +
453
- name
454
- );
455
- } else if (!existingKind && kind > 2 /* METHOD */) {
456
- existingNonFields.set(name, kind);
457
- } else {
458
- existingNonFields.set(name, true);
444
+ if (kind !== 0 /* FIELD */ && !isPrivate) {
445
+ var existingNonFields = isStatic
446
+ ? existingStaticNonFields
447
+ : existingProtoNonFields;
448
+
449
+ var existingKind = existingNonFields.get(name) || 0;
450
+
451
+ if (
452
+ existingKind === true ||
453
+ (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ ||
454
+ (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */
455
+ ) {
456
+ throw new Error(
457
+ "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: " +
458
+ name
459
+ );
460
+ } else if (!existingKind && kind > 2 /* METHOD */) {
461
+ existingNonFields.set(name, kind);
462
+ } else {
463
+ existingNonFields.set(name, true);
464
+ }
459
465
  }
466
+
467
+ applyMemberDec(
468
+ ret,
469
+ base,
470
+ decInfo,
471
+ name,
472
+ kind,
473
+ isStatic,
474
+ isPrivate,
475
+ initializers,
476
+ hasPrivateBrand
477
+ );
460
478
  }
461
479
 
462
- applyMemberDec(
463
- ret,
464
- base,
465
- decInfo,
466
- name,
467
- kind,
468
- isStatic,
469
- isPrivate,
470
- initializers,
471
- hasPrivateBrand
472
- );
480
+ pushInitializers(ret, protoInitializers);
481
+ pushInitializers(ret, staticInitializers);
482
+ return ret;
473
483
  }
474
484
 
475
- pushInitializers(ret, protoInitializers);
476
- pushInitializers(ret, staticInitializers);
477
- return ret;
478
- }
479
-
480
- function pushInitializers(ret, initializers) {
481
- if (initializers) {
482
- ret.push(function (instance) {
483
- for (var i = 0; i < initializers.length; i++) {
484
- initializers[i].call(instance);
485
- }
486
- return instance;
487
- });
485
+ function pushInitializers(ret, initializers) {
486
+ if (initializers) {
487
+ ret.push(function (instance) {
488
+ for (var i = 0; i < initializers.length; i++) {
489
+ initializers[i].call(instance);
490
+ }
491
+ return instance;
492
+ });
493
+ }
488
494
  }
489
- }
490
495
 
491
- function applyClassDecs(targetClass, classDecs) {
492
- if (classDecs.length > 0) {
493
- var initializers = [];
494
- var newClass = targetClass;
495
- var name = targetClass.name;
496
-
497
- for (var i = classDecs.length - 1; i >= 0; i--) {
498
- var decoratorFinishedRef = { v: false };
499
-
500
- try {
501
- var nextNewClass = classDecs[i](newClass, {
502
- kind: "class",
503
- name: name,
504
- addInitializer: createAddInitializerMethod(
505
- initializers,
506
- decoratorFinishedRef
507
- ),
508
- });
509
- } finally {
510
- decoratorFinishedRef.v = true;
511
- }
496
+ function applyClassDecs(targetClass, classDecs) {
497
+ if (classDecs.length > 0) {
498
+ var initializers = [];
499
+ var newClass = targetClass;
500
+ var name = targetClass.name;
501
+
502
+ for (var i = classDecs.length - 1; i >= 0; i--) {
503
+ var decoratorFinishedRef = { v: false };
504
+
505
+ try {
506
+ var nextNewClass = classDecs[i](newClass, {
507
+ kind: "class",
508
+ name: name,
509
+ addInitializer: createAddInitializerMethod(
510
+ initializers,
511
+ decoratorFinishedRef
512
+ ),
513
+ });
514
+ } finally {
515
+ decoratorFinishedRef.v = true;
516
+ }
512
517
 
513
- if (nextNewClass !== undefined) {
514
- assertValidReturnValue(10 /* CLASS */, nextNewClass);
515
- newClass = nextNewClass;
518
+ if (nextNewClass !== undefined) {
519
+ assertValidReturnValue(10 /* CLASS */, nextNewClass);
520
+ newClass = nextNewClass;
521
+ }
516
522
  }
517
- }
518
523
 
519
- return [
520
- newClass,
521
- function () {
522
- for (var i = 0; i < initializers.length; i++) {
523
- initializers[i].call(newClass);
524
- }
525
- },
526
- ];
524
+ return [
525
+ newClass,
526
+ function () {
527
+ for (var i = 0; i < initializers.length; i++) {
528
+ initializers[i].call(newClass);
529
+ }
530
+ },
531
+ ];
532
+ }
533
+ // The transformer will not emit assignment when there are no class decorators,
534
+ // so we don't have to return an empty array here.
527
535
  }
528
- // The transformer will not emit assignment when there are no class decorators,
529
- // so we don't have to return an empty array here.
530
- }
531
536
 
532
- /**
533
- Basic usage:
537
+ /**
538
+ Basic usage:
534
539
 
535
- applyDecs(
536
- Class,
537
- [
538
- // member decorators
540
+ applyDecs(
541
+ Class,
542
+ [
543
+ // member decorators
544
+ [
545
+ dec, // dec or array of decs
546
+ 0, // kind of value being decorated
547
+ 'prop', // name of public prop on class containing the value being decorated,
548
+ '#p', // the name of the private property (if is private, void 0 otherwise),
549
+ ]
550
+ ],
539
551
  [
540
- dec, // dec or array of decs
541
- 0, // kind of value being decorated
542
- 'prop', // name of public prop on class containing the value being decorated,
543
- '#p', // the name of the private property (if is private, void 0 otherwise),
552
+ // class decorators
553
+ dec1, dec2
544
554
  ]
545
- ],
546
- [
547
- // class decorators
548
- dec1, dec2
549
- ]
550
- )
551
- ```
552
-
553
- Fully transpiled example:
554
-
555
- ```js
556
- @dec
557
- class Class {
558
- @dec
559
- a = 123;
555
+ )
556
+ ```
560
557
 
561
- @dec
562
- #a = 123;
558
+ Fully transpiled example:
563
559
 
560
+ ```js
564
561
  @dec
565
- @dec2
566
- accessor b = 123;
562
+ class Class {
563
+ @dec
564
+ a = 123;
567
565
 
568
- @dec
569
- accessor #b = 123;
566
+ @dec
567
+ #a = 123;
570
568
 
571
- @dec
572
- c() { console.log('c'); }
569
+ @dec
570
+ @dec2
571
+ accessor b = 123;
573
572
 
574
- @dec
575
- #c() { console.log('privC'); }
573
+ @dec
574
+ accessor #b = 123;
576
575
 
577
- @dec
578
- get d() { console.log('d'); }
576
+ @dec
577
+ c() { console.log('c'); }
579
578
 
580
- @dec
581
- get #d() { console.log('privD'); }
579
+ @dec
580
+ #c() { console.log('privC'); }
582
581
 
583
- @dec
584
- set e(v) { console.log('e'); }
582
+ @dec
583
+ get d() { console.log('d'); }
585
584
 
586
- @dec
587
- set #e(v) { console.log('privE'); }
588
- }
585
+ @dec
586
+ get #d() { console.log('privD'); }
589
587
 
588
+ @dec
589
+ set e(v) { console.log('e'); }
590
590
 
591
- // becomes
592
- let initializeInstance;
593
- let initializeClass;
591
+ @dec
592
+ set #e(v) { console.log('privE'); }
593
+ }
594
594
 
595
- let initA;
596
- let initPrivA;
597
595
 
598
- let initB;
599
- let initPrivB, getPrivB, setPrivB;
596
+ // becomes
597
+ let initializeInstance;
598
+ let initializeClass;
600
599
 
601
- let privC;
602
- let privD;
603
- let privE;
600
+ let initA;
601
+ let initPrivA;
604
602
 
605
- let Class;
606
- class _Class {
607
- static {
608
- let ret = applyDecs(
609
- this,
610
- [
611
- [dec, 0, 'a'],
612
- [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
613
- [[dec, dec2], 1, 'b'],
614
- [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
615
- [dec, 2, 'c'],
616
- [dec, 2, 'c', () => console.log('privC')],
617
- [dec, 3, 'd'],
618
- [dec, 3, 'd', () => console.log('privD')],
619
- [dec, 4, 'e'],
620
- [dec, 4, 'e', () => console.log('privE')],
621
- ],
622
- [
623
- dec
624
- ]
625
- )
603
+ let initB;
604
+ let initPrivB, getPrivB, setPrivB;
626
605
 
627
- initA = ret[0];
606
+ let privC;
607
+ let privD;
608
+ let privE;
628
609
 
629
- initPrivA = ret[1];
610
+ let Class;
611
+ class _Class {
612
+ static {
613
+ let ret = applyDecs(
614
+ this,
615
+ [
616
+ [dec, 0, 'a'],
617
+ [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
618
+ [[dec, dec2], 1, 'b'],
619
+ [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
620
+ [dec, 2, 'c'],
621
+ [dec, 2, 'c', () => console.log('privC')],
622
+ [dec, 3, 'd'],
623
+ [dec, 3, 'd', () => console.log('privD')],
624
+ [dec, 4, 'e'],
625
+ [dec, 4, 'e', () => console.log('privE')],
626
+ ],
627
+ [
628
+ dec
629
+ ]
630
+ )
630
631
 
631
- initB = ret[2];
632
+ initA = ret[0];
632
633
 
633
- initPrivB = ret[3];
634
- getPrivB = ret[4];
635
- setPrivB = ret[5];
634
+ initPrivA = ret[1];
636
635
 
637
- privC = ret[6];
636
+ initB = ret[2];
638
637
 
639
- privD = ret[7];
638
+ initPrivB = ret[3];
639
+ getPrivB = ret[4];
640
+ setPrivB = ret[5];
640
641
 
641
- privE = ret[8];
642
+ privC = ret[6];
642
643
 
643
- initializeInstance = ret[9];
644
+ privD = ret[7];
644
645
 
645
- Class = ret[10]
646
+ privE = ret[8];
646
647
 
647
- initializeClass = ret[11];
648
- }
648
+ initializeInstance = ret[9];
649
+
650
+ Class = ret[10]
649
651
 
650
- a = (initializeInstance(this), initA(this, 123));
652
+ initializeClass = ret[11];
653
+ }
651
654
 
652
- #a = initPrivA(this, 123);
655
+ a = (initializeInstance(this), initA(this, 123));
653
656
 
654
- #bData = initB(this, 123);
655
- get b() { return this.#bData }
656
- set b(v) { this.#bData = v }
657
+ #a = initPrivA(this, 123);
657
658
 
658
- #privBData = initPrivB(this, 123);
659
- get #b() { return getPrivB(this); }
660
- set #b(v) { setPrivB(this, v); }
659
+ #bData = initB(this, 123);
660
+ get b() { return this.#bData }
661
+ set b(v) { this.#bData = v }
661
662
 
662
- c() { console.log('c'); }
663
+ #privBData = initPrivB(this, 123);
664
+ get #b() { return getPrivB(this); }
665
+ set #b(v) { setPrivB(this, v); }
663
666
 
664
- #c(...args) { return privC(this, ...args) }
667
+ c() { console.log('c'); }
665
668
 
666
- get d() { console.log('d'); }
669
+ #c(...args) { return privC(this, ...args) }
667
670
 
668
- get #d() { return privD(this); }
671
+ get d() { console.log('d'); }
669
672
 
670
- set e(v) { console.log('e'); }
673
+ get #d() { return privD(this); }
671
674
 
672
- set #e(v) { privE(this, v); }
673
- }
675
+ set e(v) { console.log('e'); }
676
+
677
+ set #e(v) { privE(this, v); }
678
+ }
674
679
 
675
- initializeClass(Class);
676
- */
680
+ initializeClass(Class);
681
+ */
682
+ return function applyDecs2301(
683
+ targetClass,
684
+ memberDecs,
685
+ classDecs,
686
+ instanceBrand
687
+ ) {
688
+ return {
689
+ e: applyMemberDecs(targetClass, memberDecs, instanceBrand),
690
+ // Lazily apply class decorations so that member init locals can be properly bound.
691
+ get c() {
692
+ return applyClassDecs(targetClass, classDecs);
693
+ },
694
+ };
695
+ };
696
+ }
677
697
 
678
698
  export default function applyDecs2301(
679
699
  targetClass,
@@ -681,11 +701,10 @@ export default function applyDecs2301(
681
701
  classDecs,
682
702
  instanceBrand
683
703
  ) {
684
- return {
685
- e: applyMemberDecs(targetClass, memberDecs, instanceBrand),
686
- // Lazily apply class decorations so that member init locals can be properly bound.
687
- get c() {
688
- return applyClassDecs(targetClass, classDecs);
689
- },
690
- };
704
+ return (applyDecs2301 = applyDecs2301Factory())(
705
+ targetClass,
706
+ memberDecs,
707
+ classDecs,
708
+ instanceBrand
709
+ );
691
710
  }