@meteorjs/babel 7.19.0-beta.1 → 7.19.0-beta.2
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 +4 -5
- package/package.json +3 -3
- package/plugins/async-await.js +74 -0
package/options.js
CHANGED
|
@@ -188,16 +188,15 @@ function getDefaultsForNode8(features) {
|
|
|
188
188
|
);
|
|
189
189
|
// TODO [fibers]: instead of removing the code below, consider this comment:
|
|
190
190
|
// https://github.com/meteor/meteor/pull/12471/files#r1089610144
|
|
191
|
-
const isFiberDisabled = process.env.DISABLE_FIBERS === '1';
|
|
192
191
|
const ignoreAsyncPlugin = process.env.IGNORE_ASYNC_PLUGIN === '1';
|
|
193
192
|
|
|
194
|
-
if (!ignoreAsyncPlugin) {
|
|
193
|
+
if (!features.useNativeAsyncAwait && !ignoreAsyncPlugin) {
|
|
195
194
|
combined.plugins.push([
|
|
196
195
|
require('./plugins/async-await.js'),
|
|
197
196
|
{
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
useNativeAsyncAwait:
|
|
197
|
+
// Even though Node 8 supports native async/await, it is not
|
|
198
|
+
// compatible with fibers.
|
|
199
|
+
useNativeAsyncAwait: false,
|
|
201
200
|
},
|
|
202
201
|
]);
|
|
203
202
|
}
|
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.
|
|
4
|
+
"version": "7.19.0-beta.2",
|
|
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/
|
|
44
|
+
"@meteorjs/reify": "https://github.com/meteor/reify/tarball/ee36898798645097948258eb9106dd0af60cec64",
|
|
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.
|
|
50
|
+
"typescript": "~4.9.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/plugin-proposal-decorators": "7.14.5",
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
const node = path.node;
|
|
12
|
+
if (!node.async) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The original function becomes a non-async function that
|
|
17
|
+
// returns a Promise.
|
|
18
|
+
node.async = false;
|
|
19
|
+
|
|
20
|
+
// The inner function should inherit lexical environment items
|
|
21
|
+
// like `this`, `super`, and `arguments` from the outer
|
|
22
|
+
// function, and arrow functions provide exactly that behavior.
|
|
23
|
+
const innerFn = t.arrowFunctionExpression(
|
|
24
|
+
// The inner function has no parameters of its own, but can
|
|
25
|
+
// refer to the outer parameters of the original function.
|
|
26
|
+
[],
|
|
27
|
+
node.body,
|
|
28
|
+
// The inner function called by Promise.asyncApply should be
|
|
29
|
+
// async if we have native async/await support.
|
|
30
|
+
!!this.opts.useNativeAsyncAwait
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const promiseResultExpression = t.callExpression(
|
|
34
|
+
t.memberExpression(
|
|
35
|
+
t.identifier("Promise"),
|
|
36
|
+
t.identifier("asyncApply"),
|
|
37
|
+
false
|
|
38
|
+
), [innerFn]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Calling the async function with Promise.asyncApply is
|
|
42
|
+
// important to ensure that the part before the first await
|
|
43
|
+
// expression runs synchronously in its own Fiber, even when
|
|
44
|
+
// there is native support for async/await.
|
|
45
|
+
if (node.type === "ArrowFunctionExpression") {
|
|
46
|
+
node.body = promiseResultExpression;
|
|
47
|
+
} else {
|
|
48
|
+
node.body = t.blockStatement([
|
|
49
|
+
t.returnStatement(promiseResultExpression)
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
AwaitExpression: function (path) {
|
|
56
|
+
if (this.opts.useNativeAsyncAwait) {
|
|
57
|
+
// No need to transform await expressions if we have native
|
|
58
|
+
// support for them.
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const node = path.node;
|
|
63
|
+
path.replaceWith(t.callExpression(
|
|
64
|
+
t.memberExpression(
|
|
65
|
+
t.identifier("Promise"),
|
|
66
|
+
t.identifier(node.all ? "awaitAll" : "await"),
|
|
67
|
+
false
|
|
68
|
+
),
|
|
69
|
+
[node.argument]
|
|
70
|
+
));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|