Skip to content

Commit

Permalink
Merge pull request #815 from DanielXMoore/promise-void-non-async
Browse files Browse the repository at this point in the history
Fix Promise<void> in non-async function
  • Loading branch information
edemaine authored Nov 23, 2023
2 parents 2bcb609 + dbcd0a0 commit 61c8f2d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -1603,8 +1603,8 @@ FunctionSignature
async,
generator,
modifier: {
async: !async.length,
generator: !generator.length,
async: !!async.length,
generator: !!generator.length,
},
block: null,
children: !parameters.implicit
Expand All @@ -1629,10 +1629,12 @@ FunctionExpression

if (hasAwait(block) && !signature.async.length) {
signature.async.push("async ")
signature.modifier.async = true
}

if (hasYield(block) && !signature.generator.length) {
signature.generator.push("*")
signature.modifier.generator = true
}

// Attach the block
Expand Down
33 changes: 33 additions & 0 deletions test/function.civet
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ describe "function", ->
})
"""

testCase """
implicit generator longhand
---
function
yield 5
---
(function*() {
return yield 5
})
"""

testCase """
explicit generator doesn't get double added
---
Expand Down Expand Up @@ -1228,6 +1239,28 @@ describe "function", ->
})
"""

testCase """
no async Promise<void>
---
(x): Promise<void> ->
fetch x
---
(function(x): Promise<void> {
return fetch(x)
})
"""

testCase """
no async Promise<void> longhand
---
function(x): Promise<void>
fetch x
---
(function(x): Promise<void> {
return fetch(x)
})
"""

testCase """
nested anonymous function
---
Expand Down

0 comments on commit 61c8f2d

Please sign in to comment.