-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
ASTPRs and Issues about the AST structurePRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedThis change will require a new major version to be releasedenhancementNew feature or requestNew feature or request
Milestone
Description
Across the AST we have a lot of cases where we've made properties optional.
I think there were various reasons for why it was done this way (not that I can find the comments any more).
From the perspective of an AST consumer, undefined can create some very weird states. Two examples of this:
- There are a number of
booleanproperties that are optional. On the surface this makes it look like the property with 3 meaningful states (true,false, orundefined), even though in reality it only ever actually represents 2 states.
Usually in these cases the parser emitstrueorundefined(and neverfalse), and in some rarer cases it emitstrue, and then usesfalseorundefinedinterchangeably depending on some internal, obfuscated criteria. - There are a few cases where an array property is optional. In these cases usually the parser will never emit an empty array, and will instead emit
undefined.- From a memory-usage perspective, this could be justified (an empty array is really a heavy "empty" marker). But if that is our goal then these cases should be typed so that it is clear that there are never 0 elements (eg by defining
[Foo, ...Foo[]])
- From a memory-usage perspective, this could be justified (an empty array is really a heavy "empty" marker). But if that is our goal then these cases should be typed so that it is clear that there are never 0 elements (eg by defining
We should standardise the AST to remove undefined/optional from all places, unless there is a very good reason for it to be optional.
Metadata
Metadata
Assignees
Labels
ASTPRs and Issues about the AST structurePRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedThis change will require a new major version to be releasedenhancementNew feature or requestNew feature or request