Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS2] Don’t require async/await support to run coffee #4679

Merged
merged 3 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ runTests = (CoffeeScript) ->
description: description if description?
source: fn.toString() if fn.toString?

global.supportsAsync = if global.testingBrowser
Copy link
Collaborator

@connec connec Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this if? Could we not just always feature test it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not. See the comment at the top of test/async.coffee. Even with a feature test at the top of that file, and a return if it fails, a runtime that doesn't support async will throw an error just from trying to parse the file. Also there's an async test in repl.coffee now, so I want to feature test this once and cache the result rather than having it in two places.

try
new Function('async () => {}')()
yes
catch exception
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception isn't used here so you could just as well remove it.

no
else
[major, minor, build] = process.versions.node.split('.').map (version) ->
parseInt version, 10
major >= 8 or (major is 7 and minor >= 6)

helpers.extend global, require './test/support/helpers'

# When all the tests have run, collect and print errors.
Expand All @@ -428,6 +439,8 @@ runTests = (CoffeeScript) ->

# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
unless global.supportsAsync # Except for async tests, if async isn’t supported.
files = files.filter (filename) -> filename isnt 'async.coffee'

for file in files when helpers.isCoffee file
literate = helpers.isLiterate file
Expand Down
11 changes: 6 additions & 5 deletions lib/coffeescript/repl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ replDefaults =
result = runInContext js, context, filename
# Await an async result, if necessary
if isAsync
result = await result
cb null, result unless sawSIGINT
sawSIGINT = false
result.then (resolvedResult) ->
cb null, resolvedResult unless sawSIGINT
sawSIGINT = no
else
cb null, result
catch err
Expand Down
7 changes: 7 additions & 0 deletions test/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ testRepl "keeps running after runtime error", (input, output) ->
input.emitLine 'a'
eq 'undefined', output.lastWrite()

testRepl "#4604: wraps an async function", (input, output) ->
return unless global.supportsAsync
input.emitLine 'await new Promise (resolve) -> setTimeout (-> resolve 33), 10'
setTimeout ->
eq '33', output.lastWrite()
, 20

process.on 'exit', ->
try
fs.unlinkSync historyFile
Expand Down