@jsenv/plugin-transpilation 1.0.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 (127) hide show
  1. package/README.md +3 -0
  2. package/package.json +60 -0
  3. package/src/as_js_module/convert_js_classic_to_js_module.js +42 -0
  4. package/src/as_js_module/jsenv_plugin_as_js_module.js +89 -0
  5. package/src/babel/apply_js_transpilation.js +74 -0
  6. package/src/babel/babel_helper_directory/README.md +8 -0
  7. package/src/babel/babel_helper_directory/babel_helper_directory.js +35 -0
  8. package/src/babel/babel_helper_directory/babel_helpers/AsyncGenerator/AsyncGenerator.js +112 -0
  9. package/src/babel/babel_helper_directory/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  10. package/src/babel/babel_helper_directory/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +23 -0
  11. package/src/babel/babel_helper_directory/babel_helpers/applyDecs/applyDecs.js +802 -0
  12. package/src/babel/babel_helper_directory/babel_helpers/applyDecs2203/applyDecs2203.js +635 -0
  13. package/src/babel/babel_helper_directory/babel_helpers/applyDecs2203R/applyDecs2203R.js +642 -0
  14. package/src/babel/babel_helper_directory/babel_helpers/applyDecs2301/applyDecs2301.js +691 -0
  15. package/src/babel/babel_helper_directory/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +7 -0
  16. package/src/babel/babel_helper_directory/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  17. package/src/babel/babel_helper_directory/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +6 -0
  18. package/src/babel/babel_helper_directory/babel_helpers/assertThisInitialized/assertThisInitialized.js +7 -0
  19. package/src/babel/babel_helper_directory/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +55 -0
  20. package/src/babel/babel_helper_directory/babel_helpers/asyncIterator/asyncIterator.js +65 -0
  21. package/src/babel/babel_helper_directory/babel_helpers/asyncToGenerator/asyncToGenerator.js +34 -0
  22. package/src/babel/babel_helper_directory/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -0
  23. package/src/babel/babel_helper_directory/babel_helpers/checkInRHS/checkInRHS.js +9 -0
  24. package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -0
  25. package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -0
  26. package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -0
  27. package/src/babel/babel_helper_directory/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  28. package/src/babel/babel_helper_directory/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  29. package/src/babel/babel_helper_directory/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  30. package/src/babel/babel_helper_directory/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -0
  31. package/src/babel/babel_helper_directory/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  32. package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -0
  33. package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +7 -0
  34. package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -0
  35. package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  36. package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +8 -0
  37. package/src/babel/babel_helper_directory/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +6 -0
  38. package/src/babel/babel_helper_directory/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  39. package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -0
  40. package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -0
  41. package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -0
  42. package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  43. package/src/babel/babel_helper_directory/babel_helpers/construct/construct.js +16 -0
  44. package/src/babel/babel_helper_directory/babel_helpers/createClass/createClass.js +17 -0
  45. package/src/babel/babel_helper_directory/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -0
  46. package/src/babel/babel_helper_directory/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -0
  47. package/src/babel/babel_helper_directory/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  48. package/src/babel/babel_helper_directory/babel_helpers/createSuper/createSuper.js +22 -0
  49. package/src/babel/babel_helper_directory/babel_helpers/decorate/decorate.js +403 -0
  50. package/src/babel/babel_helper_directory/babel_helpers/defaults/defaults.js +11 -0
  51. package/src/babel/babel_helper_directory/babel_helpers/defineAccessor/defineAccessor.js +6 -0
  52. package/src/babel/babel_helper_directory/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +23 -0
  53. package/src/babel/babel_helper_directory/babel_helpers/defineProperty/defineProperty.js +21 -0
  54. package/src/babel/babel_helper_directory/babel_helpers/extends/extends.js +14 -0
  55. package/src/babel/babel_helper_directory/babel_helpers/get/get.js +19 -0
  56. package/src/babel/babel_helper_directory/babel_helpers/getPrototypeOf/getPrototypeOf.js +4 -0
  57. package/src/babel/babel_helper_directory/babel_helpers/identity/identity.js +3 -0
  58. package/src/babel/babel_helper_directory/babel_helpers/inherits/inherits.js +19 -0
  59. package/src/babel/babel_helper_directory/babel_helpers/inheritsLoose/inheritsLoose.js +7 -0
  60. package/src/babel/babel_helper_directory/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  61. package/src/babel/babel_helper_directory/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +6 -0
  62. package/src/babel/babel_helper_directory/babel_helpers/instanceof/instanceof.js +6 -0
  63. package/src/babel/babel_helper_directory/babel_helpers/interopRequireDefault/interopRequireDefault.js +3 -0
  64. package/src/babel/babel_helper_directory/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +37 -0
  65. package/src/babel/babel_helper_directory/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  66. package/src/babel/babel_helper_directory/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  67. package/src/babel/babel_helper_directory/babel_helpers/iterableToArray/iterableToArray.js +7 -0
  68. package/src/babel/babel_helper_directory/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +54 -0
  69. package/src/babel/babel_helper_directory/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +16 -0
  70. package/src/babel/babel_helper_directory/babel_helpers/jsx/jsx.js +50 -0
  71. package/src/babel/babel_helper_directory/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  72. package/src/babel/babel_helper_directory/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  73. package/src/babel/babel_helper_directory/babel_helpers/nonIterableRest/nonIterableRest.js +5 -0
  74. package/src/babel/babel_helper_directory/babel_helpers/nonIterableSpread/nonIterableSpread.js +5 -0
  75. package/src/babel/babel_helper_directory/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  76. package/src/babel/babel_helper_directory/babel_helpers/objectSpread/objectSpread.js +23 -0
  77. package/src/babel/babel_helper_directory/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  78. package/src/babel/babel_helper_directory/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +19 -0
  79. package/src/babel/babel_helper_directory/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -0
  80. package/src/babel/babel_helper_directory/babel_helpers/overloadYield/overloadYield.js +11 -0
  81. package/src/babel/babel_helper_directory/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  82. package/src/babel/babel_helper_directory/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  83. package/src/babel/babel_helper_directory/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +702 -0
  84. package/src/babel/babel_helper_directory/babel_helpers/set/set.js +44 -0
  85. package/src/babel/babel_helper_directory/babel_helpers/setPrototypeOf/setPrototypeOf.js +6 -0
  86. package/src/babel/babel_helper_directory/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  87. package/src/babel/babel_helper_directory/babel_helpers/slicedToArray/slicedToArray.js +10 -0
  88. package/src/babel/babel_helper_directory/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +13 -0
  89. package/src/babel/babel_helper_directory/babel_helpers/superPropBase/superPropBase.js +10 -0
  90. package/src/babel/babel_helper_directory/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -0
  91. package/src/babel/babel_helper_directory/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -0
  92. package/src/babel/babel_helper_directory/babel_helpers/tdz/tdz.js +4 -0
  93. package/src/babel/babel_helper_directory/babel_helpers/temporalRef/temporalRef.js +6 -0
  94. package/src/babel/babel_helper_directory/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  95. package/src/babel/babel_helper_directory/babel_helpers/toArray/toArray.js +10 -0
  96. package/src/babel/babel_helper_directory/babel_helpers/toConsumableArray/toConsumableArray.js +10 -0
  97. package/src/babel/babel_helper_directory/babel_helpers/toPrimitive/toPrimitive.js +10 -0
  98. package/src/babel/babel_helper_directory/babel_helpers/toPropertyKey/toPropertyKey.js +6 -0
  99. package/src/babel/babel_helper_directory/babel_helpers/typeof/typeof.js +14 -0
  100. package/src/babel/babel_helper_directory/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -0
  101. package/src/babel/babel_helper_directory/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -0
  102. package/src/babel/babel_helper_directory/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +30 -0
  103. package/src/babel/babel_helper_directory/babel_helpers/wrapRegExp/wrapRegExp.js +77 -0
  104. package/src/babel/babel_helper_directory/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  105. package/src/babel/babel_plugin_babel_helpers_as_jsenv_imports.js +53 -0
  106. package/src/babel/babel_plugin_structure.js +176 -0
  107. package/src/babel/babel_plugins_compatibility.js +432 -0
  108. package/src/babel/global_this/babel_plugin_global_this_injector.js +56 -0
  109. package/src/babel/global_this/client/global_this_js_classic.js +25 -0
  110. package/src/babel/global_this/client/global_this_js_module.js +21 -0
  111. package/src/babel/jsenv_plugin_babel.js +35 -0
  112. package/src/babel/new_stylesheet/babel_plugin_new_stylesheet_injector.js +149 -0
  113. package/src/babel/new_stylesheet/client/new_stylesheet.js +381 -0
  114. package/src/babel/polyfill_injection_in_babel_ast.js +41 -0
  115. package/src/babel/regenerator_runtime/babel_plugin_regenerator_runtime_injector.js +49 -0
  116. package/src/babel/regenerator_runtime/client/regenerator_runtime.js +748 -0
  117. package/src/css/apply_css_transpilation.js +41 -0
  118. package/src/css/jsenv_plugin_css_transpilation.js +17 -0
  119. package/src/import_assertions/jsenv_plugin_import_assertions.js +244 -0
  120. package/src/import_meta_resolve/jsenv_plugin_import_meta_resolve.js +48 -0
  121. package/src/js_module_fallback/jsenv_plugin_js_module_conversion.js +136 -0
  122. package/src/js_module_fallback/jsenv_plugin_js_module_fallback.js +46 -0
  123. package/src/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +240 -0
  124. package/src/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +62 -0
  125. package/src/jsenv_plugin_transpilation.js +54 -0
  126. package/src/main.js +2 -0
  127. package/src/top_level_await/jsenv_plugin_top_level_await.js +94 -0
@@ -0,0 +1,691 @@
1
+ /* @minVersion 7.21.0 */
2
+
3
+ import checkInRHS from "../checkInRHS/checkInRHS.js";
4
+
5
+ /**
6
+ Enums are used in this file, but not assigned to vars to avoid non-hoistable values
7
+
8
+ CONSTRUCTOR = 0;
9
+ PUBLIC = 1;
10
+ PRIVATE = 2;
11
+
12
+ FIELD = 0;
13
+ ACCESSOR = 1;
14
+ METHOD = 2;
15
+ GETTER = 3;
16
+ SETTER = 4;
17
+
18
+ STATIC = 5;
19
+
20
+ CLASS = 10; // only used in assertValidReturnValue
21
+ */
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");
34
+ }
35
+ }
36
+
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";
65
+ }
66
+
67
+ var ctx = {
68
+ kind: kindStr,
69
+ name: isPrivate ? "#" + name : name,
70
+ static: isStatic,
71
+ private: isPrivate,
72
+ };
73
+
74
+ var decoratorFinishedRef = { v: false };
75
+
76
+ if (kind !== 0 /* FIELD */) {
77
+ ctx.addInitializer = createAddInitializerMethod(
78
+ initializers,
79
+ decoratorFinishedRef
80
+ );
81
+ }
82
+
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
+ };
92
+ }
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);
111
+ };
112
+ }
113
+ }
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);
123
+ };
124
+ }
125
+ }
126
+ }
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
+
146
+ function assertNotFinished(decoratorFinishedRef, fnName) {
147
+ if (decoratorFinishedRef.v) {
148
+ throw new Error(
149
+ "attempted to call " + fnName + " after decoration was finished"
150
+ );
151
+ }
152
+ }
153
+
154
+ function assertCallable(fn, hint) {
155
+ if (typeof fn !== "function") {
156
+ throw new TypeError(hint + " must be a function");
157
+ }
158
+ }
159
+
160
+ function assertValidReturnValue(kind, value) {
161
+ var type = typeof value;
162
+
163
+ if (kind === 1 /* ACCESSOR */) {
164
+ if (type !== "object" || value === null) {
165
+ throw new TypeError(
166
+ "accessor decorators must return an object with get, set, or init properties or void 0"
167
+ );
168
+ }
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
+ }
189
+ }
190
+
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];
214
+
215
+ var desc, init, value;
216
+
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 */) {
229
+ desc = {
230
+ set: decInfo[3],
231
+ };
232
+ } else {
233
+ desc = {
234
+ value: decInfo[3],
235
+ };
236
+ }
237
+ }
238
+ } else if (kind !== 0 /* FIELD */) {
239
+ desc = Object.getOwnPropertyDescriptor(base, name);
240
+ }
241
+
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
+ }
284
+ }
285
+ } else {
286
+ for (var i = decs.length - 1; i >= 0; i--) {
287
+ var dec = decs[i];
288
+
289
+ newValue = memberDec(
290
+ dec,
291
+ name,
292
+ desc,
293
+ initializers,
294
+ kind,
295
+ isStatic,
296
+ isPrivate,
297
+ value,
298
+ hasPrivateBrand
299
+ );
300
+
301
+ if (newValue !== void 0) {
302
+ assertValidReturnValue(kind, newValue);
303
+ var newInit;
304
+
305
+ if (kind === 0 /* FIELD */) {
306
+ newInit = newValue;
307
+ } else if (kind === 1 /* ACCESSOR */) {
308
+ newInit = newValue.init;
309
+ get = newValue.get || value.get;
310
+ set = newValue.set || value.set;
311
+
312
+ value = { get: get, set: set };
313
+ } else {
314
+ value = newValue;
315
+ }
316
+
317
+ if (newInit !== void 0) {
318
+ if (init === void 0) {
319
+ init = newInit;
320
+ } else if (typeof init === "function") {
321
+ init = [init, newInit];
322
+ } else {
323
+ init.push(newInit);
324
+ }
325
+ }
326
+ }
327
+ }
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
+
339
+ init = function (instance, init) {
340
+ var value = init;
341
+
342
+ for (var i = 0; i < ownInitializers.length; i++) {
343
+ value = ownInitializers[i].call(instance, value);
344
+ }
345
+
346
+ return value;
347
+ };
348
+ } else {
349
+ var originalInitializer = init;
350
+
351
+ init = function (instance, init) {
352
+ return originalInitializer.call(instance, init);
353
+ };
354
+ }
355
+
356
+ ret.push(init);
357
+ }
358
+
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;
369
+ }
370
+
371
+ if (isPrivate) {
372
+ 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
+ });
379
+ } else if (kind === 2 /* METHOD */) {
380
+ ret.push(value);
381
+ } else {
382
+ ret.push(function (instance, args) {
383
+ return value.call(instance, args);
384
+ });
385
+ }
386
+ } else {
387
+ Object.defineProperty(base, name, desc);
388
+ }
389
+ }
390
+ }
391
+
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;
436
+ }
437
+ }
438
+
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);
459
+ }
460
+ }
461
+
462
+ applyMemberDec(
463
+ ret,
464
+ base,
465
+ decInfo,
466
+ name,
467
+ kind,
468
+ isStatic,
469
+ isPrivate,
470
+ initializers,
471
+ hasPrivateBrand
472
+ );
473
+ }
474
+
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
+ });
488
+ }
489
+ }
490
+
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
+ }
512
+
513
+ if (nextNewClass !== undefined) {
514
+ assertValidReturnValue(10 /* CLASS */, nextNewClass);
515
+ newClass = nextNewClass;
516
+ }
517
+ }
518
+
519
+ return [
520
+ newClass,
521
+ function () {
522
+ for (var i = 0; i < initializers.length; i++) {
523
+ initializers[i].call(newClass);
524
+ }
525
+ },
526
+ ];
527
+ }
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
+
532
+ /**
533
+ Basic usage:
534
+
535
+ applyDecs(
536
+ Class,
537
+ [
538
+ // member decorators
539
+ [
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),
544
+ ]
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;
560
+
561
+ @dec
562
+ #a = 123;
563
+
564
+ @dec
565
+ @dec2
566
+ accessor b = 123;
567
+
568
+ @dec
569
+ accessor #b = 123;
570
+
571
+ @dec
572
+ c() { console.log('c'); }
573
+
574
+ @dec
575
+ #c() { console.log('privC'); }
576
+
577
+ @dec
578
+ get d() { console.log('d'); }
579
+
580
+ @dec
581
+ get #d() { console.log('privD'); }
582
+
583
+ @dec
584
+ set e(v) { console.log('e'); }
585
+
586
+ @dec
587
+ set #e(v) { console.log('privE'); }
588
+ }
589
+
590
+
591
+ // becomes
592
+ let initializeInstance;
593
+ let initializeClass;
594
+
595
+ let initA;
596
+ let initPrivA;
597
+
598
+ let initB;
599
+ let initPrivB, getPrivB, setPrivB;
600
+
601
+ let privC;
602
+ let privD;
603
+ let privE;
604
+
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
+ )
626
+
627
+ initA = ret[0];
628
+
629
+ initPrivA = ret[1];
630
+
631
+ initB = ret[2];
632
+
633
+ initPrivB = ret[3];
634
+ getPrivB = ret[4];
635
+ setPrivB = ret[5];
636
+
637
+ privC = ret[6];
638
+
639
+ privD = ret[7];
640
+
641
+ privE = ret[8];
642
+
643
+ initializeInstance = ret[9];
644
+
645
+ Class = ret[10]
646
+
647
+ initializeClass = ret[11];
648
+ }
649
+
650
+ a = (initializeInstance(this), initA(this, 123));
651
+
652
+ #a = initPrivA(this, 123);
653
+
654
+ #bData = initB(this, 123);
655
+ get b() { return this.#bData }
656
+ set b(v) { this.#bData = v }
657
+
658
+ #privBData = initPrivB(this, 123);
659
+ get #b() { return getPrivB(this); }
660
+ set #b(v) { setPrivB(this, v); }
661
+
662
+ c() { console.log('c'); }
663
+
664
+ #c(...args) { return privC(this, ...args) }
665
+
666
+ get d() { console.log('d'); }
667
+
668
+ get #d() { return privD(this); }
669
+
670
+ set e(v) { console.log('e'); }
671
+
672
+ set #e(v) { privE(this, v); }
673
+ }
674
+
675
+ initializeClass(Class);
676
+ */
677
+
678
+ export default function applyDecs2301(
679
+ targetClass,
680
+ memberDecs,
681
+ classDecs,
682
+ instanceBrand
683
+ ) {
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
+ };
691
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable no-eq-null, eqeqeq */
2
+ export default function arrayLikeToArray(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length
4
+ var arr2 = new Array(len)
5
+ for (var i = 0; i < len; i++) arr2[i] = arr[i]
6
+ return arr2
7
+ }
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line consistent-return
2
+ export default (arr) => {
3
+ if (Array.isArray(arr)) return arr
4
+ }
@@ -0,0 +1,6 @@
1
+ import arrayLikeToArray from "../arrayLikeToArray/arrayLikeToArray.js"
2
+
3
+ // eslint-disable-next-line consistent-return
4
+ export default (arr) => {
5
+ if (Array.isArray(arr)) return arrayLikeToArray(arr)
6
+ }
@@ -0,0 +1,7 @@
1
+ export default (self) => {
2
+ // eslint-disable-next-line no-void
3
+ if (self === void 0) {
4
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
5
+ }
6
+ return self
7
+ }