Skip to content

Commit

Permalink
🐛 code fixed for not wrapping object expression inside try catch and …
Browse files Browse the repository at this point in the history
…tests updated
  • Loading branch information
vivek12345 committed Feb 1, 2019
1 parent 7d19a11 commit 4fc1059
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions transforms/__testfixtures__/async-await-with-try-catch.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ async function testData() {
const a = async function(req, res) {
const tasks = await repository.get();
};

async function testReturnAwaitData() {
return await getData();
}
// ObjectExpression
const CompaniesController = {
verifySubDomain: async request => {
const company = await Company.findOne({
where: {
id: request.params.id
}
});
}
}
22 changes: 22 additions & 0 deletions transforms/__testfixtures__/async-await-with-try-catch.output.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,25 @@ const a = async function(req, res) {
console.log(e);
}
};

async function testReturnAwaitData() {
try {
return await getData();
} catch (e) {
console.log(e);
}
}
// ObjectExpression
const CompaniesController = {
verifySubDomain: async request => {
try {
const company = await Company.findOne({
where: {
id: request.params.id
}
});
} catch (e) {
console.log(e);
}
}
}
2 changes: 1 addition & 1 deletion transforms/async-await-with-try-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const ExpressionTypes = ['BinaryExpression', 'LogicalExpression', 'NewExpression', 'ObjectExpression'];
const DisAllowedFunctionExpressionTypes = ['ArrowFunctionExpression', 'FunctionExpression'];
const DisAllowedFunctionExpressionTypes = ['ArrowFunctionExpression', 'FunctionExpression', 'ObjectExpression'];
function isAlreadyInsideTryBlock(path) {
return j(path).closest(j.TryStatement).length;
}
Expand Down

0 comments on commit 4fc1059

Please sign in to comment.