-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
AST standardisation: remove undefined
/optional from node properties unless it really makes sense
#5020
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
Comments
For the Sent two draft PRs for comparison:
What do you think? |
In regards to making the AST smaller - does it hugely matter? Booleans are the smallest sized value in any language (usually at most 1 byte), so we're not talking a whole lot of space allocated ( There's a whole thing about "hidden classes" with objects that JS runtimes do to reduce memory usage and improve property access when objects have a shared shape - so I think using optional properties could actually have the inverse effect because the shape changes - leading to multiple "hidden classes"? We wouldn't know one way or the other without in-depth testing. Personally I'd prefer to have a property there always because consistency and then you can reasonably do duck-typing checks like |
For posterity this TS change microsoft/TypeScript#51682 suggest I wasn't too far off the mark with regards to optionality in the objects. Having a standard shape should help V8 optimise things at the (allbeit small) memory impact of additional "useless" values. |
#6274 was merged into the |
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:boolean
properties 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 emits
true
orundefined
(and neverfalse
), and in some rarer cases it emitstrue
, and then usesfalse
orundefined
interchangeably depending on some internal, obfuscated criteria.undefined
.[Foo, ...Foo[]]
)We should standardise the AST to remove
undefined
/optional from all places, unless there is a very good reason for it to be optional.The text was updated successfully, but these errors were encountered: