You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GatherNodeParts is used for generating unique identifiers based on an AST node. e.g. the MemberExpressionfoo.bar results in a UID _foo$bar.
Currently GatherNodeParts::gather calls a callback with &str slices which are assembled into a string.
We then:
Cut name down to 20 bytes max.
Sanitize the string to remove illegal characters (foo["bar-qux"] becomes _foo$barQux).
Trim off leading _s.
Add a leading _ on start.
Add a number to the end if necessary to make it unique.
This algorithm is directly ported from Babel.
There are various ways we can optimize this:
Pass a mutable &mut String / &mut CompactString into gather to append to (or maybe could be a &mut str referencing a str on the stack, since we have a static max length anyway).
Stop adding to that string when hit 20 bytes max (since it'll be cut down to 20 bytes anyway).
Skip sanitizing parts which we know cannot contain invalid characters (e.g. IdentifierReference, IdentifierName - common case).
Avoid calling is_identifier_name at start of to_identifier. This involves iterating over the string twice if is_identifier_name returns false.
Avoid Chars iterator - iterate over bytes instead.
When the output is going to be minified anyway, there's also no point in generating these "sensible" var names at all. Just _10 would suffice.
The text was updated successfully, but these errors were encountered:
GatherNodeParts
is used for generating unique identifiers based on an AST node. e.g. theMemberExpression
foo.bar
results in a UID_foo$bar
.Currently
GatherNodeParts::gather
calls a callback with&str
slices which are assembled into a string.We then:
foo["bar-qux"]
becomes_foo$barQux
)._
s._
on start.This algorithm is directly ported from Babel.
There are various ways we can optimize this:
&mut String
/&mut CompactString
intogather
to append to (or maybe could be a&mut str
referencing astr
on the stack, since we have a static max length anyway).IdentifierReference
,IdentifierName
- common case).is_identifier_name
at start ofto_identifier
. This involves iterating over the string twice ifis_identifier_name
returns false.Chars
iterator - iterate over bytes instead.When the output is going to be minified anyway, there's also no point in generating these "sensible" var names at all. Just
_10
would suffice.The text was updated successfully, but these errors were encountered: