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

Import typescript files with bring #6042

Open
MarkMcCulloh opened this issue Mar 24, 2024 · 1 comment
Open

Import typescript files with bring #6042

MarkMcCulloh opened this issue Mar 24, 2024 · 1 comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl

Comments

@MarkMcCulloh
Copy link
Contributor

Use Case

The current mechanism to import javascript/typescript is extern. Among several DX issues, a primary difficulty is that it forces the user to declare types for the module upfront within the consuming wing file. This takes the source of truth for types away from the implementation. Instead, we can import typescript files like wing files to allow them to be the source of truth:

bring "helper.ts" as helper;

Proposed Solution

To limit the implementation difficulty, I would propose the following limitations/simplifications:

  • ESM only (either implicitly or only allowing .mts)
    • Parsing ESM to find exports is much simpler than CJS
  • Named exports only
  • async translates to inflight
  • exports can be classes, functions, interfaces, or enums
  • Extremely limited types:
    • primitives with equivalent wing types
    • No re-exporting of imported types
    • No builtin global types
    • classes and interfaces (no references to imported types)
      • Classes are always inflight
    • arrays of supported types
    • literal objects of supported types

Ideally, the naive implementation of

  1. Parse single typescript file
  2. Visit all exports to build up a wing SymbolEnv with type info

The above restrictions basically already match existing extern restrictions.

Implementation Notes

Depends on #3013 to run ESM+typescript in preflight.

https://docs.rs/oxc_parser/latest/oxc_parser/ and https://docs.rs/oxc_semantic/latest/oxc_semantic/ could be invaluable here

Component

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@MarkMcCulloh MarkMcCulloh added ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl labels Mar 24, 2024
@monadabot monadabot added this to Wing Mar 24, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Mar 24, 2024
@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Mar 28, 2024
Copy link

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

2 participants