Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions __tests__/async-await-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
}
},
);
});
});
8 changes: 8 additions & 0 deletions async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down