-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44e688e
commit db6bcbe
Showing
6 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const setGoldsteinIf = (node) => { | ||
node.goldsteinIf = true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {types} from 'putout'; | ||
|
||
const { | ||
isAwaitExpression, | ||
isCallExpression, | ||
} = types; | ||
|
||
export function createGoldsteinTry({async, callee, args}) { | ||
return { | ||
type: 'TryStatement', | ||
expression: true, | ||
async, | ||
argument: { | ||
type: 'CallExpression', | ||
callee, | ||
arguments: args, | ||
}, | ||
}; | ||
} | ||
|
||
export const setGoldsteinTry = (node) => { | ||
if (!isCallExpression(node) && !isAwaitExpression(node)) | ||
return; | ||
|
||
node.goldstein = createGoldsteinTry(parseExpression(node)); | ||
}; | ||
|
||
const parseExpression = (node) => { | ||
const {argument, arguments: allArgs} = node; | ||
|
||
const async = isAwaitExpression(node); | ||
|
||
if (!async) { | ||
const [callee, ...args] = allArgs; | ||
|
||
return { | ||
async, | ||
args, | ||
callee, | ||
}; | ||
} | ||
|
||
const [callee, ...args] = argument.arguments; | ||
|
||
return { | ||
async, | ||
args, | ||
callee, | ||
}; | ||
}; |