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

Playground eval #941

Merged
merged 4 commits into from
Feb 5, 2024
Merged

Playground eval #941

merged 4 commits into from
Feb 5, 2024

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Feb 4, 2024

Playground "Run" button now supports:

  • Running code like 1+2 now outputs [EVAL] 3, without the need for wrapping in console.log. Like most REPLs, outputs nothing if the eval'd value is undefined.
  • console.error, console.warn, etc. (prefixing output with [ERROR] , [WARN] , etc.). console.timeEnd etc. don't currently work well (but they still work in the actual console); this could be fixed later.
  • console commands now work from async functions too (fixes civet.dev/playground - Displaying console output from async functions #938). This is done by modifying the output AST to replace all console identifiers with civetconsole. (Note: if you run async code twice in rapid succession, you may get output from the first run in the second run.)
  • Top-level await, by wrapping the Civet code in an async do block (or do -> block in CoffeeScript mode). I did this at the Civet level so that we still get implicit return of the last value, which (once resolved) gets printed with [EVAL] prefix like the sync case.

@edemaine
Copy link
Collaborator Author

edemaine commented Feb 4, 2024

Ugh, yarn test fails with my attempt to export lib from the main Civet bundle. The issue is:

  • parser.hera and lib.civet are in CJS. I think this is necessary until Hera is fully ESM?
  • main.civet is ESM, and wants to export from lib.civet

esbuild can build these fine, but running in actual ESM mode as in yarn test fails, because ESM isn't supposed to import CJS. Any ideas for a workaround?

@STRd6
Copy link
Contributor

STRd6 commented Feb 4, 2024

I think this branch in Hera is maybe 90% of the way to emitting ESM. I recall leaving it though because I encountered an issue with the latest NPM loaders API and I couldn't find a way to actually get Node to load ESM using the new API. Maybe the examples and documentation are better now and I can continue it soon.

@STRd6 STRd6 mentioned this pull request Feb 5, 2024
@edemaine
Copy link
Collaborator Author

edemaine commented Feb 5, 2024

#942 fixed the build here! So this is ready for review.

@edemaine edemaine merged commit 9476dfe into main Feb 5, 2024
3 checks passed
@edemaine edemaine deleted the playground-eval branch February 5, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

civet.dev/playground - Displaying console output from async functions
2 participants