-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Wasp TS SDK (TypeScript-based Wasp AST generation) #551
Comments
A quick go on pros/cons as I see it:
Btw looping, conditionals, no-name declarations -> we can implement all of those in the Wasp lang if/when we will need them. We do get them out of the box in TS, but it is not super hard to do in Wasp. So with all this, it is a very attractive option to explore this more. With current state of Wasp, it makes sense to keep the Wasp DSL we have and focus on web framework features, but as we progress, it would be wise to do more experimentation with TS SDK and see how far can we get with it, what can we achieve. If we get to the point where we see that TS SDK is a better option than Wasp DSL, and it makes no sense to maintain both, we can even drop Wasp DSL as a compiler frontend. It would be interesting to first just get TS SDK to the level where it can do exactly the same thing as current Wasp DSL does. So, generate equivalent AppSpec. |
If we had a way to import the appspec from JSON we could open up the ground for more experiments. You could then create some custom build command that uses the ingested JSON. |
Yes this is an exciting idea! If we make AppSpec serializable to JSON, which shouldn't be super hard, then we can as you said both have other tools generate that JSON, but also other tools consume that JSON. It does limit us a bit in the sense that AppSpec needs to be JSON serializable, but restrictions are also good, at least it is worth giving them a try. |
This initiative is getting started now with #2047 ! |
Description
Wasp has its own DSL. This DSL lets you declare how a Wasp app goes together.
The DSL has the benefit that it makes very clear what is being configured, and lets you configure an entire full stack web app as a whole.
The DSL has some drawbacks:
No default editor support, it needs to be built
Need to maintain parser, typechecker
It integrates JS/TypeScript code, but has no understanding of TypeScript types. To bring those we need to invent something like a TS DSL anyway and somehow integrate them with a language server that does TS compiles and interprets its feedback (see also https://www.notion.so/wasp-lang/TypeScript-cf20d4648b1e4dda99a422a2eea59a05)
No access to programming features like conditionals or looping
For better feedback, we need to create and maintain our own language server for the DSL
As an alternative we could make available a TypeScript based frontend. This would generate the same appspec, but from TS. Advantages:
Quite easy to implement, enabling rapid prototyping of DSL features and type-driven thinking about how things go together
Programming features are available
Instead of giving everything an explicit name, you can assign to constants and get it typechecked too
People write JS/TS code anyway to build a Wasp app, so language is already familiar
Knows about TypeScript code. Lots of advanced typechecking features are in relatively easy reach (including typed routes)
Drawbacks:
Integration of other languages may appear less natural
We give up a sense of the Wasp DSL as it own language
Technical challenges
While the TS implementation isn't particularly complex mostly, to enable inline functions and natural imports we actually need access to the source code of what's included later on in the generation process. To do this may require parsing the TypeScript and extracting that information into its own module (which can then be used by the generator).
As an intermediary solution to reach parity with existing Wasp we can make the user do this explicitly (and not allow any inline code) through a "jsRef" construct:
To allow type checking an optional third argument may be supplied that is the JS entity to refer to:
Later on we may introduce a facility to analyze imports and allow jsRefs to be generated automatically.
The text was updated successfully, but these errors were encountered: