-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
GatherNodeParts is used for generating unique identifiers based on an AST node. e.g. the MemberExpression 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:
- 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 CompactStringintogatherto append to (or maybe could be a&mut strreferencing astron 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_nameat start ofto_identifier. This involves iterating over the string twice ifis_identifier_namereturns false. - Avoid
Charsiterator - 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels