@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,802 @@
1
+ /* @minVersion 7.17.8 */
2
+
3
+ /**
4
+ * NOTE: This is an old version of the helper, used for 2021-12 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
+
26
+ function old_createMetadataMethodsForProperty(
27
+ metadataMap,
28
+ kind,
29
+ property,
30
+ decoratorFinishedRef
31
+ ) {
32
+ return {
33
+ getMetadata: function (key) {
34
+ old_assertNotFinished(decoratorFinishedRef, "getMetadata");
35
+ old_assertMetadataKey(key);
36
+
37
+ var metadataForKey = metadataMap[key];
38
+
39
+ if (metadataForKey === void 0) return void 0;
40
+
41
+ if (kind === 1 /* PUBLIC */) {
42
+ var pub = metadataForKey.public;
43
+ if (pub !== void 0) {
44
+ return pub[property];
45
+ }
46
+ } else if (kind === 2 /* PRIVATE */) {
47
+ var priv = metadataForKey.private;
48
+ if (priv !== void 0) {
49
+ return priv.get(property);
50
+ }
51
+ } else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) {
52
+ return metadataForKey.constructor;
53
+ }
54
+ },
55
+ setMetadata: function (key, value) {
56
+ old_assertNotFinished(decoratorFinishedRef, "setMetadata");
57
+ old_assertMetadataKey(key);
58
+
59
+ var metadataForKey = metadataMap[key];
60
+
61
+ if (metadataForKey === void 0) {
62
+ metadataForKey = metadataMap[key] = {};
63
+ }
64
+
65
+ if (kind === 1 /* PUBLIC */) {
66
+ var pub = metadataForKey.public;
67
+
68
+ if (pub === void 0) {
69
+ pub = metadataForKey.public = {};
70
+ }
71
+
72
+ pub[property] = value;
73
+ } else if (kind === 2 /* PRIVATE */) {
74
+ var priv = metadataForKey.priv;
75
+
76
+ if (priv === void 0) {
77
+ priv = metadataForKey.private = new Map();
78
+ }
79
+
80
+ priv.set(property, value);
81
+ } else {
82
+ metadataForKey.constructor = value;
83
+ }
84
+ },
85
+ };
86
+ }
87
+
88
+ function old_convertMetadataMapToFinal(obj, metadataMap) {
89
+ var parentMetadataMap = obj[Symbol.metadata || Symbol.for("Symbol.metadata")];
90
+ var metadataKeys = Object.getOwnPropertySymbols(metadataMap);
91
+
92
+ if (metadataKeys.length === 0) return;
93
+
94
+ for (var i = 0; i < metadataKeys.length; i++) {
95
+ var key = metadataKeys[i];
96
+ var metaForKey = metadataMap[key];
97
+ var parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null;
98
+
99
+ var pub = metaForKey.public;
100
+ var parentPub = parentMetaForKey ? parentMetaForKey.public : null;
101
+
102
+ if (pub && parentPub) {
103
+ Object.setPrototypeOf(pub, parentPub);
104
+ }
105
+
106
+ var priv = metaForKey.private;
107
+
108
+ if (priv) {
109
+ var privArr = Array.from(priv.values());
110
+ var parentPriv = parentMetaForKey ? parentMetaForKey.private : null;
111
+
112
+ if (parentPriv) {
113
+ privArr = privArr.concat(parentPriv);
114
+ }
115
+
116
+ metaForKey.private = privArr;
117
+ }
118
+
119
+ if (parentMetaForKey) {
120
+ Object.setPrototypeOf(metaForKey, parentMetaForKey);
121
+ }
122
+ }
123
+
124
+ if (parentMetadataMap) {
125
+ Object.setPrototypeOf(metadataMap, parentMetadataMap);
126
+ }
127
+
128
+ obj[Symbol.metadata || Symbol.for("Symbol.metadata")] = metadataMap;
129
+ }
130
+
131
+ function old_createAddInitializerMethod(initializers, decoratorFinishedRef) {
132
+ return function addInitializer(initializer) {
133
+ old_assertNotFinished(decoratorFinishedRef, "addInitializer");
134
+ old_assertCallable(initializer, "An initializer");
135
+ initializers.push(initializer);
136
+ };
137
+ }
138
+
139
+ function old_memberDec(
140
+ dec,
141
+ name,
142
+ desc,
143
+ metadataMap,
144
+ initializers,
145
+ kind,
146
+ isStatic,
147
+ isPrivate,
148
+ value
149
+ ) {
150
+ var kindStr;
151
+
152
+ switch (kind) {
153
+ case 1 /* ACCESSOR */:
154
+ kindStr = "accessor";
155
+ break;
156
+ case 2 /* METHOD */:
157
+ kindStr = "method";
158
+ break;
159
+ case 3 /* GETTER */:
160
+ kindStr = "getter";
161
+ break;
162
+ case 4 /* SETTER */:
163
+ kindStr = "setter";
164
+ break;
165
+ default:
166
+ kindStr = "field";
167
+ }
168
+
169
+ var ctx = {
170
+ kind: kindStr,
171
+ name: isPrivate ? "#" + name : name,
172
+ isStatic: isStatic,
173
+ isPrivate: isPrivate,
174
+ };
175
+
176
+ var decoratorFinishedRef = { v: false };
177
+
178
+ if (kind !== 0 /* FIELD */) {
179
+ ctx.addInitializer = old_createAddInitializerMethod(
180
+ initializers,
181
+ decoratorFinishedRef
182
+ );
183
+ }
184
+
185
+ var metadataKind, metadataName;
186
+
187
+ if (isPrivate) {
188
+ metadataKind = 2 /* PRIVATE */;
189
+ metadataName = Symbol(name);
190
+
191
+ var access = {};
192
+
193
+ if (kind === 0 /* FIELD */) {
194
+ access.get = desc.get;
195
+ access.set = desc.set;
196
+ } else if (kind === 2 /* METHOD */) {
197
+ access.get = function () {
198
+ return desc.value;
199
+ };
200
+ } else {
201
+ // replace with values that will go through the final getter and setter
202
+ if (kind === 1 /* ACCESSOR */ || kind === 3 /* GETTER */) {
203
+ access.get = function () {
204
+ return desc.get.call(this);
205
+ };
206
+ }
207
+
208
+ if (kind === 1 /* ACCESSOR */ || kind === 4 /* SETTER */) {
209
+ access.set = function (v) {
210
+ desc.set.call(this, v);
211
+ };
212
+ }
213
+ }
214
+
215
+ ctx.access = access;
216
+ } else {
217
+ metadataKind = 1 /* PUBLIC */;
218
+ metadataName = name;
219
+ }
220
+
221
+ try {
222
+ return dec(
223
+ value,
224
+ Object.assign(
225
+ ctx,
226
+ old_createMetadataMethodsForProperty(
227
+ metadataMap,
228
+ metadataKind,
229
+ metadataName,
230
+ decoratorFinishedRef
231
+ )
232
+ )
233
+ );
234
+ } finally {
235
+ decoratorFinishedRef.v = true;
236
+ }
237
+ }
238
+
239
+ function old_assertNotFinished(decoratorFinishedRef, fnName) {
240
+ if (decoratorFinishedRef.v) {
241
+ throw new Error(
242
+ "attempted to call " + fnName + " after decoration was finished"
243
+ );
244
+ }
245
+ }
246
+
247
+ function old_assertMetadataKey(key) {
248
+ if (typeof key !== "symbol") {
249
+ throw new TypeError("Metadata keys must be symbols, received: " + key);
250
+ }
251
+ }
252
+
253
+ function old_assertCallable(fn, hint) {
254
+ if (typeof fn !== "function") {
255
+ throw new TypeError(hint + " must be a function");
256
+ }
257
+ }
258
+
259
+ function old_assertValidReturnValue(kind, value) {
260
+ var type = typeof value;
261
+
262
+ if (kind === 1 /* ACCESSOR */) {
263
+ if (type !== "object" || value === null) {
264
+ throw new TypeError(
265
+ "accessor decorators must return an object with get, set, or init properties or void 0"
266
+ );
267
+ }
268
+ if (value.get !== undefined) {
269
+ old_assertCallable(value.get, "accessor.get");
270
+ }
271
+ if (value.set !== undefined) {
272
+ old_assertCallable(value.set, "accessor.set");
273
+ }
274
+ if (value.init !== undefined) {
275
+ old_assertCallable(value.init, "accessor.init");
276
+ }
277
+ if (value.initializer !== undefined) {
278
+ old_assertCallable(value.initializer, "accessor.initializer");
279
+ }
280
+ } else if (type !== "function") {
281
+ var hint;
282
+ if (kind === 0 /* FIELD */) {
283
+ hint = "field";
284
+ } else if (kind === 10 /* CLASS */) {
285
+ hint = "class";
286
+ } else {
287
+ hint = "method";
288
+ }
289
+ throw new TypeError(hint + " decorators must return a function or void 0");
290
+ }
291
+ }
292
+
293
+ function old_getInit(desc) {
294
+ var initializer;
295
+ if (
296
+ (initializer = desc.init) == null &&
297
+ (initializer = desc.initializer) &&
298
+ typeof console !== "undefined"
299
+ ) {
300
+ console.warn(".initializer has been renamed to .init as of March 2022");
301
+ }
302
+ return initializer;
303
+ }
304
+
305
+ function old_applyMemberDec(
306
+ ret,
307
+ base,
308
+ decInfo,
309
+ name,
310
+ kind,
311
+ isStatic,
312
+ isPrivate,
313
+ metadataMap,
314
+ initializers
315
+ ) {
316
+ var decs = decInfo[0];
317
+
318
+ var desc, initializer, value;
319
+
320
+ if (isPrivate) {
321
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
322
+ desc = {
323
+ get: decInfo[3],
324
+ set: decInfo[4],
325
+ };
326
+ } else if (kind === 3 /* GETTER */) {
327
+ desc = {
328
+ get: decInfo[3],
329
+ };
330
+ } else if (kind === 4 /* SETTER */) {
331
+ desc = {
332
+ set: decInfo[3],
333
+ };
334
+ } else {
335
+ desc = {
336
+ value: decInfo[3],
337
+ };
338
+ }
339
+ } else if (kind !== 0 /* FIELD */) {
340
+ desc = Object.getOwnPropertyDescriptor(base, name);
341
+ }
342
+
343
+ if (kind === 1 /* ACCESSOR */) {
344
+ value = {
345
+ get: desc.get,
346
+ set: desc.set,
347
+ };
348
+ } else if (kind === 2 /* METHOD */) {
349
+ value = desc.value;
350
+ } else if (kind === 3 /* GETTER */) {
351
+ value = desc.get;
352
+ } else if (kind === 4 /* SETTER */) {
353
+ value = desc.set;
354
+ }
355
+
356
+ var newValue, get, set;
357
+
358
+ if (typeof decs === "function") {
359
+ newValue = old_memberDec(
360
+ decs,
361
+ name,
362
+ desc,
363
+ metadataMap,
364
+ initializers,
365
+ kind,
366
+ isStatic,
367
+ isPrivate,
368
+ value
369
+ );
370
+
371
+ if (newValue !== void 0) {
372
+ old_assertValidReturnValue(kind, newValue);
373
+
374
+ if (kind === 0 /* FIELD */) {
375
+ initializer = newValue;
376
+ } else if (kind === 1 /* ACCESSOR */) {
377
+ initializer = old_getInit(newValue);
378
+ get = newValue.get || value.get;
379
+ set = newValue.set || value.set;
380
+
381
+ value = { get: get, set: set };
382
+ } else {
383
+ value = newValue;
384
+ }
385
+ }
386
+ } else {
387
+ for (var i = decs.length - 1; i >= 0; i--) {
388
+ var dec = decs[i];
389
+
390
+ newValue = old_memberDec(
391
+ dec,
392
+ name,
393
+ desc,
394
+ metadataMap,
395
+ initializers,
396
+ kind,
397
+ isStatic,
398
+ isPrivate,
399
+ value
400
+ );
401
+
402
+ if (newValue !== void 0) {
403
+ old_assertValidReturnValue(kind, newValue);
404
+ var newInit;
405
+
406
+ if (kind === 0 /* FIELD */) {
407
+ newInit = newValue;
408
+ } else if (kind === 1 /* ACCESSOR */) {
409
+ newInit = old_getInit(newValue);
410
+ get = newValue.get || value.get;
411
+ set = newValue.set || value.set;
412
+
413
+ value = { get: get, set: set };
414
+ } else {
415
+ value = newValue;
416
+ }
417
+
418
+ if (newInit !== void 0) {
419
+ if (initializer === void 0) {
420
+ initializer = newInit;
421
+ } else if (typeof initializer === "function") {
422
+ initializer = [initializer, newInit];
423
+ } else {
424
+ initializer.push(newInit);
425
+ }
426
+ }
427
+ }
428
+ }
429
+ }
430
+
431
+ if (kind === 0 /* FIELD */ || kind === 1 /* ACCESSOR */) {
432
+ if (initializer === void 0) {
433
+ // If the initializer was void 0, sub in a dummy initializer
434
+ initializer = function (instance, init) {
435
+ return init;
436
+ };
437
+ } else if (typeof initializer !== "function") {
438
+ var ownInitializers = initializer;
439
+
440
+ initializer = function (instance, init) {
441
+ var value = init;
442
+
443
+ for (var i = 0; i < ownInitializers.length; i++) {
444
+ value = ownInitializers[i].call(instance, value);
445
+ }
446
+
447
+ return value;
448
+ };
449
+ } else {
450
+ var originalInitializer = initializer;
451
+
452
+ initializer = function (instance, init) {
453
+ return originalInitializer.call(instance, init);
454
+ };
455
+ }
456
+
457
+ ret.push(initializer);
458
+ }
459
+
460
+ if (kind !== 0 /* FIELD */) {
461
+ if (kind === 1 /* ACCESSOR */) {
462
+ desc.get = value.get;
463
+ desc.set = value.set;
464
+ } else if (kind === 2 /* METHOD */) {
465
+ desc.value = value;
466
+ } else if (kind === 3 /* GETTER */) {
467
+ desc.get = value;
468
+ } else if (kind === 4 /* SETTER */) {
469
+ desc.set = value;
470
+ }
471
+
472
+ if (isPrivate) {
473
+ if (kind === 1 /* ACCESSOR */) {
474
+ ret.push(function (instance, args) {
475
+ return value.get.call(instance, args);
476
+ });
477
+ ret.push(function (instance, args) {
478
+ return value.set.call(instance, args);
479
+ });
480
+ } else if (kind === 2 /* METHOD */) {
481
+ ret.push(value);
482
+ } else {
483
+ ret.push(function (instance, args) {
484
+ return value.call(instance, args);
485
+ });
486
+ }
487
+ } else {
488
+ Object.defineProperty(base, name, desc);
489
+ }
490
+ }
491
+ }
492
+
493
+ function old_applyMemberDecs(
494
+ ret,
495
+ Class,
496
+ protoMetadataMap,
497
+ staticMetadataMap,
498
+ decInfos
499
+ ) {
500
+ var protoInitializers;
501
+ var staticInitializers;
502
+
503
+ var existingProtoNonFields = new Map();
504
+ var existingStaticNonFields = new Map();
505
+
506
+ for (var i = 0; i < decInfos.length; i++) {
507
+ var decInfo = decInfos[i];
508
+
509
+ // skip computed property names
510
+ if (!Array.isArray(decInfo)) continue;
511
+
512
+ var kind = decInfo[1];
513
+ var name = decInfo[2];
514
+ var isPrivate = decInfo.length > 3;
515
+
516
+ var isStatic = kind >= 5; /* STATIC */
517
+ var base;
518
+ var metadataMap;
519
+ var initializers;
520
+
521
+ if (isStatic) {
522
+ base = Class;
523
+ metadataMap = staticMetadataMap;
524
+ kind = kind - 5 /* STATIC */;
525
+ // initialize staticInitializers when we see a non-field static member
526
+ if (kind !== 0 /* FIELD */) {
527
+ staticInitializers = staticInitializers || [];
528
+ initializers = staticInitializers;
529
+ }
530
+ } else {
531
+ base = Class.prototype;
532
+ metadataMap = protoMetadataMap;
533
+ // initialize protoInitializers when we see a non-field member
534
+ if (kind !== 0 /* FIELD */) {
535
+ protoInitializers = protoInitializers || [];
536
+ initializers = protoInitializers;
537
+ }
538
+ }
539
+
540
+ if (kind !== 0 /* FIELD */ && !isPrivate) {
541
+ var existingNonFields = isStatic
542
+ ? existingStaticNonFields
543
+ : existingProtoNonFields;
544
+
545
+ var existingKind = existingNonFields.get(name) || 0;
546
+
547
+ if (
548
+ existingKind === true ||
549
+ (existingKind === 3 /* GETTER */ && kind !== 4) /* SETTER */ ||
550
+ (existingKind === 4 /* SETTER */ && kind !== 3) /* GETTER */
551
+ ) {
552
+ throw new Error(
553
+ "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: " +
554
+ name
555
+ );
556
+ } else if (!existingKind && kind > 2 /* METHOD */) {
557
+ existingNonFields.set(name, kind);
558
+ } else {
559
+ existingNonFields.set(name, true);
560
+ }
561
+ }
562
+
563
+ old_applyMemberDec(
564
+ ret,
565
+ base,
566
+ decInfo,
567
+ name,
568
+ kind,
569
+ isStatic,
570
+ isPrivate,
571
+ metadataMap,
572
+ initializers
573
+ );
574
+ }
575
+
576
+ old_pushInitializers(ret, protoInitializers);
577
+ old_pushInitializers(ret, staticInitializers);
578
+ }
579
+
580
+ function old_pushInitializers(ret, initializers) {
581
+ if (initializers) {
582
+ ret.push(function (instance) {
583
+ for (var i = 0; i < initializers.length; i++) {
584
+ initializers[i].call(instance);
585
+ }
586
+ return instance;
587
+ });
588
+ }
589
+ }
590
+
591
+ function old_applyClassDecs(ret, targetClass, metadataMap, classDecs) {
592
+ if (classDecs.length > 0) {
593
+ var initializers = [];
594
+ var newClass = targetClass;
595
+ var name = targetClass.name;
596
+
597
+ for (var i = classDecs.length - 1; i >= 0; i--) {
598
+ var decoratorFinishedRef = { v: false };
599
+
600
+ try {
601
+ var ctx = Object.assign(
602
+ {
603
+ kind: "class",
604
+ name: name,
605
+ addInitializer: old_createAddInitializerMethod(
606
+ initializers,
607
+ decoratorFinishedRef
608
+ ),
609
+ },
610
+ old_createMetadataMethodsForProperty(
611
+ metadataMap,
612
+ 0 /* CONSTRUCTOR */,
613
+ name,
614
+ decoratorFinishedRef
615
+ )
616
+ );
617
+ var nextNewClass = classDecs[i](newClass, ctx);
618
+ } finally {
619
+ decoratorFinishedRef.v = true;
620
+ }
621
+
622
+ if (nextNewClass !== undefined) {
623
+ old_assertValidReturnValue(10 /* CLASS */, nextNewClass);
624
+ newClass = nextNewClass;
625
+ }
626
+ }
627
+
628
+ ret.push(newClass, function () {
629
+ for (var i = 0; i < initializers.length; i++) {
630
+ initializers[i].call(newClass);
631
+ }
632
+ });
633
+ }
634
+ }
635
+
636
+ /**
637
+ Basic usage:
638
+
639
+ applyDecs(
640
+ Class,
641
+ [
642
+ // member decorators
643
+ [
644
+ dec, // dec or array of decs
645
+ 0, // kind of value being decorated
646
+ 'prop', // name of public prop on class containing the value being decorated,
647
+ '#p', // the name of the private property (if is private, void 0 otherwise),
648
+ ]
649
+ ],
650
+ [
651
+ // class decorators
652
+ dec1, dec2
653
+ ]
654
+ )
655
+ ```
656
+
657
+ Fully transpiled example:
658
+
659
+ ```js
660
+ @dec
661
+ class Class {
662
+ @dec
663
+ a = 123;
664
+
665
+ @dec
666
+ #a = 123;
667
+
668
+ @dec
669
+ @dec2
670
+ accessor b = 123;
671
+
672
+ @dec
673
+ accessor #b = 123;
674
+
675
+ @dec
676
+ c() { console.log('c'); }
677
+
678
+ @dec
679
+ #c() { console.log('privC'); }
680
+
681
+ @dec
682
+ get d() { console.log('d'); }
683
+
684
+ @dec
685
+ get #d() { console.log('privD'); }
686
+
687
+ @dec
688
+ set e(v) { console.log('e'); }
689
+
690
+ @dec
691
+ set #e(v) { console.log('privE'); }
692
+ }
693
+
694
+
695
+ // becomes
696
+ let initializeInstance;
697
+ let initializeClass;
698
+
699
+ let initA;
700
+ let initPrivA;
701
+
702
+ let initB;
703
+ let initPrivB, getPrivB, setPrivB;
704
+
705
+ let privC;
706
+ let privD;
707
+ let privE;
708
+
709
+ let Class;
710
+ class _Class {
711
+ static {
712
+ let ret = applyDecs(
713
+ this,
714
+ [
715
+ [dec, 0, 'a'],
716
+ [dec, 0, 'a', (i) => i.#a, (i, v) => i.#a = v],
717
+ [[dec, dec2], 1, 'b'],
718
+ [dec, 1, 'b', (i) => i.#privBData, (i, v) => i.#privBData = v],
719
+ [dec, 2, 'c'],
720
+ [dec, 2, 'c', () => console.log('privC')],
721
+ [dec, 3, 'd'],
722
+ [dec, 3, 'd', () => console.log('privD')],
723
+ [dec, 4, 'e'],
724
+ [dec, 4, 'e', () => console.log('privE')],
725
+ ],
726
+ [
727
+ dec
728
+ ]
729
+ )
730
+
731
+ initA = ret[0];
732
+
733
+ initPrivA = ret[1];
734
+
735
+ initB = ret[2];
736
+
737
+ initPrivB = ret[3];
738
+ getPrivB = ret[4];
739
+ setPrivB = ret[5];
740
+
741
+ privC = ret[6];
742
+
743
+ privD = ret[7];
744
+
745
+ privE = ret[8];
746
+
747
+ initializeInstance = ret[9];
748
+
749
+ Class = ret[10]
750
+
751
+ initializeClass = ret[11];
752
+ }
753
+
754
+ a = (initializeInstance(this), initA(this, 123));
755
+
756
+ #a = initPrivA(this, 123);
757
+
758
+ #bData = initB(this, 123);
759
+ get b() { return this.#bData }
760
+ set b(v) { this.#bData = v }
761
+
762
+ #privBData = initPrivB(this, 123);
763
+ get #b() { return getPrivB(this); }
764
+ set #b(v) { setPrivB(this, v); }
765
+
766
+ c() { console.log('c'); }
767
+
768
+ #c(...args) { return privC(this, ...args) }
769
+
770
+ get d() { console.log('d'); }
771
+
772
+ get #d() { return privD(this); }
773
+
774
+ set e(v) { console.log('e'); }
775
+
776
+ set #e(v) { privE(this, v); }
777
+ }
778
+
779
+ initializeClass(Class);
780
+ */
781
+ export default function applyDecs(targetClass, memberDecs, classDecs) {
782
+ var ret = [];
783
+ var staticMetadataMap = {};
784
+
785
+ var protoMetadataMap = {};
786
+
787
+ old_applyMemberDecs(
788
+ ret,
789
+ targetClass,
790
+ protoMetadataMap,
791
+ staticMetadataMap,
792
+ memberDecs
793
+ );
794
+
795
+ old_convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
796
+
797
+ old_applyClassDecs(ret, targetClass, staticMetadataMap, classDecs);
798
+
799
+ old_convertMetadataMapToFinal(targetClass, staticMetadataMap);
800
+
801
+ return ret;
802
+ }