@meteorjs/babel 7.19.0-beta.1 → 7.19.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/options.js CHANGED
@@ -186,18 +186,14 @@ function getDefaultsForNode8(features) {
186
186
  require("@babel/plugin-syntax-object-rest-spread"),
187
187
  require("@babel/plugin-proposal-object-rest-spread")
188
188
  );
189
- // TODO [fibers]: instead of removing the code below, consider this comment:
190
- // https://github.com/meteor/meteor/pull/12471/files#r1089610144
191
- const isFiberDisabled = process.env.DISABLE_FIBERS === '1';
192
- const ignoreAsyncPlugin = process.env.IGNORE_ASYNC_PLUGIN === '1';
193
189
 
194
- if (!ignoreAsyncPlugin) {
190
+ if (features.useNativeAsyncAwait === false) {
195
191
  combined.plugins.push([
196
192
  require('./plugins/async-await.js'),
197
193
  {
198
- // Do not transform `await x` to `Promise.await(x)`, since Node
199
- // 8 has native support for await expressions.
200
- useNativeAsyncAwait: isFiberDisabled,
194
+ // Even though Node 8 supports native async/await, it is not
195
+ // compatible with fibers.
196
+ useNativeAsyncAwait: false,
201
197
  },
202
198
  ]);
203
199
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meteorjs/babel",
3
3
  "author": "Meteor <dev@meteor.com>",
4
- "version": "7.19.0-beta.1",
4
+ "version": "7.19.0-beta.3",
5
5
  "license": "MIT",
6
6
  "description": "Babel wrapper package for use with Meteor",
7
7
  "keywords": [
@@ -41,13 +41,13 @@
41
41
  "@babel/template": "^7.16.7",
42
42
  "@babel/traverse": "^7.17.0",
43
43
  "@babel/types": "^7.17.0",
44
- "@meteorjs/reify": "https://github.com/meteor/reify/tarball/5078da9d0827cc17741504762f3a7f71c3b01448",
44
+ "@meteorjs/reify": "https://github.com/meteor/reify/tarball/cf61c57c6c4fefcbf164bf63d3c12fda1924b3d2",
45
45
  "babel-preset-meteor": "^7.10.0",
46
46
  "babel-preset-minify": "^0.5.1",
47
47
  "convert-source-map": "^1.6.0",
48
48
  "lodash": "^4.17.21",
49
49
  "meteor-babel-helpers": "0.0.3",
50
- "typescript": "~4.7.4"
50
+ "typescript": "~4.9.4"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@babel/plugin-proposal-decorators": "7.14.5",
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ module.exports = function (babel) {
4
+ const t = babel.types;
5
+
6
+ return {
7
+ name: "transform-meteor-async-await",
8
+ visitor: {
9
+ Function: {
10
+ exit: function (path) {
11
+ if (this.opts.useNativeAsyncAwait !== false) {
12
+ return;
13
+ }
14
+
15
+ const node = path.node;
16
+ if (!node.async) {
17
+ return;
18
+ }
19
+
20
+ // The original function becomes a non-async function that
21
+ // returns a Promise.
22
+ node.async = false;
23
+
24
+ // The inner function should inherit lexical environment items
25
+ // like `this`, `super`, and `arguments` from the outer
26
+ // function, and arrow functions provide exactly that behavior.
27
+ const innerFn = t.arrowFunctionExpression(
28
+ // The inner function has no parameters of its own, but can
29
+ // refer to the outer parameters of the original function.
30
+ [],
31
+ node.body,
32
+ // The inner function called by Promise.asyncApply should be
33
+ // async if we have native async/await support.
34
+ !!this.opts.useNativeAsyncAwait
35
+ );
36
+
37
+ const promiseResultExpression = t.callExpression(
38
+ t.memberExpression(
39
+ t.identifier("Promise"),
40
+ t.identifier("asyncApply"),
41
+ false
42
+ ), [innerFn]
43
+ );
44
+
45
+ // Calling the async function with Promise.asyncApply is
46
+ // important to ensure that the part before the first await
47
+ // expression runs synchronously in its own Fiber, even when
48
+ // there is native support for async/await.
49
+ if (node.type === "ArrowFunctionExpression") {
50
+ node.body = promiseResultExpression;
51
+ } else {
52
+ node.body = t.blockStatement([
53
+ t.returnStatement(promiseResultExpression)
54
+ ]);
55
+ }
56
+ }
57
+ },
58
+
59
+ AwaitExpression: function (path) {
60
+ if (this.opts.useNativeAsyncAwait !== false) {
61
+ // No need to transform await expressions if we have native
62
+ // support for them.
63
+ return;
64
+ }
65
+
66
+ const node = path.node;
67
+ path.replaceWith(t.callExpression(
68
+ t.memberExpression(
69
+ t.identifier("Promise"),
70
+ t.identifier(node.all ? "awaitAll" : "await"),
71
+ false
72
+ ),
73
+ [node.argument]
74
+ ));
75
+ }
76
+ }
77
+ };
78
+ };