diff --git a/__tests__/async-await-test.js b/__tests__/async-await-test.js index e99725c..e8314e1 100755 --- a/__tests__/async-await-test.js +++ b/__tests__/async-await-test.js @@ -658,4 +658,26 @@ describe('async-await', () => { } ); }); + + describe('es6 getter and setter should be unchanged', function() { + defineTestFromFunctions( + () => { + class A { + method() {return a().then(b => 'convert')} + get prop() {return a().then(b => 'getter')} + set prop(val) {return a(val).then(b => 'setter')} + } + }, + () => { + class A { + async method() { + const b = await a(); + return 'convert'; + } + get prop() {return a().then(b => 'getter')} + set prop(val) {return a(val).then(b => 'setter')} + } + }, + ); + }); }); diff --git a/async-await.js b/async-await.js index 1c36b2c..0bef8e5 100755 --- a/async-await.js +++ b/async-await.js @@ -104,6 +104,14 @@ module.exports = function transformer(file, api) { return; } + // Don't transform get x() {…} into async get x() {…}; that would generate invalid syntax + if ( + p.parent.node.type === 'MethodDefinition' && + (p.parent.node.kind === 'get' || p.parent.node.kind === 'set') + ) { + return; + } + // Set function to async node.async = true;