wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
13.64k stars 1.18k forks source link

[Analyzer] Support nameless declarations #309

Open Martinsos opened 3 years ago

Martinsos commented 3 years ago

Some declarations, like route or dependencies, don't need a name, there is no purpose in them being named.

Therefore, we should allow them being nameless:

route { path: "/", page: HomePage }

dependencies {=json
  mylib: "1.0.0"
json=}

Right now, this is not supported!

What do we need to support it?

  1. We need to modify Analyzer.Parser so it allows for declarations without a name (or maybe it already allows that? I don't think so).
  2. We need to modify Analyzer.Evaluator.Decl so it doesn't always expect a name to be associated with a declaration
  3. Something else? But I think things above are main places and the rest of the changes will stem from there.
craigmc08 commented 3 years ago

I thought we decided to remove nameless declarations from the new version? In https://github.com/wasp-lang/wasp/issues/109#issuecomment-846094357

route was given a name so you can't refer to non-existent routes, and we decided dependencies and auth to be part of app. It might be worth discussing this again though:

There are several things that don't make sense to have names: app, dependencies, auth, server, db. The reason is that it's invalid to have more than one, and there's no need to refer to them in a .wasp file. So it's worth considering how to design this to only allow one (nameless) instance of each of these.

The original idea for this implementation was to a have third statement type that's an unnamed decl (we didn't settle on a good name. inst for instance or maybe sing for singleton?). The type checking an evaluation would be identical to decl.

Martinsos commented 3 years ago

@craigmc08 makes sense I forgot about that! That is a good analysis -> let's keep it at this for now and we can revisit this in the future, this is certainly not urgent right now. I think it will make sense at some point to have these nameless declarations, but as you said for now we can either just make them part of the app, and then we can figure it out as we go.