forked from benjamn/reify
-
Notifications
You must be signed in to change notification settings - Fork 3
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
4ab165b
commit af9490c
Showing
4 changed files
with
83 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const FUNCTION_TYPES = [ | ||
'FunctionDeclaration', | ||
'FunctionExpression', | ||
'ArrowFunctionExpression', | ||
'ClassMethod', | ||
'ObjectMethod', | ||
'ClassPrivateMethod', | ||
] | ||
|
||
function isTopLevelAwait(ancestors) { | ||
for (let ancestor of ancestors) { | ||
if (FUNCTION_TYPES.includes(ancestor.type)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
module.exports = { isTopLevelAwait } |
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,54 @@ | ||
// FunctionDeclaration | ||
async function functionDeclaration() { | ||
const result = await Promise.resolve("This is a function declaration"); | ||
return result; | ||
} | ||
|
||
// FunctionExpression | ||
var functionExpression = async function() { | ||
const result = await Promise.resolve("This is a function expression"); | ||
return result; | ||
}; | ||
|
||
// ArrowFunctionExpression | ||
var arrowFunctionExpression = async () => { | ||
const result = await Promise.resolve("This is an arrow function expression"); | ||
return result; | ||
}; | ||
|
||
// ClassMethod | ||
class MyClass { | ||
async classMethod() { | ||
const result = await Promise.resolve("This is a class method"); | ||
return result; | ||
} | ||
} | ||
|
||
// ObjectMethod | ||
var myObject = { | ||
objectMethod: async function() { | ||
const result = await Promise.resolve("This is an object method"); | ||
return result; | ||
} | ||
}; | ||
|
||
// ClassPrivateMethod | ||
class MyClassWithPrivateMethod { | ||
async #privateMethod() { | ||
const result = await Promise.resolve("This is a private class method"); | ||
return result; | ||
} | ||
|
||
async callPrivateMethod() { | ||
return this.#privateMethod(); | ||
} | ||
} | ||
|
||
module.exports = { | ||
functionDeclaration, | ||
functionExpression, | ||
arrowFunctionExpression, | ||
MyClass, | ||
myObject, | ||
MyClassWithPrivateMethod | ||
}; |
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