Merge pull request #3135 from loganfsmyth/loose-async-gen-T6755
Ensure that the async/generator flags carry over when converting class methods - fixes T6755
This commit is contained in:
commit
333dc8dcda
@ -16,7 +16,7 @@ export default class LooseClassTransformer extends VanillaTransformer {
|
|||||||
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
||||||
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
|
||||||
|
|
||||||
let func = t.functionExpression(null, node.params, node.body);
|
let func = t.functionExpression(null, node.params, node.body, node.generator, node.async);
|
||||||
let key = t.toComputedKey(node, node.key);
|
let key = t.toComputedKey(node, node.key);
|
||||||
if (t.isStringLiteral(key)) {
|
if (t.isStringLiteral(key)) {
|
||||||
func = nameFunction({
|
func = nameFunction({
|
||||||
|
|||||||
9
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/actual.js
vendored
Normal file
9
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/actual.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class Example {
|
||||||
|
async test1(){
|
||||||
|
await Promise.resolve(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
*test2(){
|
||||||
|
yield 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js
vendored
Normal file
30
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/expected.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
var Example = (function () {
|
||||||
|
function Example() {
|
||||||
|
_classCallCheck(this, Example);
|
||||||
|
}
|
||||||
|
|
||||||
|
Example.prototype.test1 = async function test1() {
|
||||||
|
await Promise.resolve(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
Example.prototype.test2 = regeneratorRuntime.mark(function test2() {
|
||||||
|
return regeneratorRuntime.wrap(function test2$(_context) {
|
||||||
|
while (1) {
|
||||||
|
switch (_context.prev = _context.next) {
|
||||||
|
case 0:
|
||||||
|
_context.next = 2;
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case "end":
|
||||||
|
return _context.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, test2, this);
|
||||||
|
});
|
||||||
|
return Example;
|
||||||
|
})();
|
||||||
6
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/options.json
vendored
Normal file
6
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T6755/options.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"syntax-async-functions",
|
||||||
|
["transform-es2015-classes", { "loose": true }]
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user