Open overlookmotel opened 1 month ago
Also calculate and cache the hash of the var name we're going to be repeatedly searching for in hash tables (i.e. React
). Can even make it a const
for the default pragma, if hash function is const.
Some other possible optimizations to JSX transform commented here: https://github.com/oxc-project/oxc/commit/10dcc779b8ddb4d977fe4389c3c62089aa1e1e08
React JSX transform in classic mode currently performs a scope lookup on every JSX node, to find the binding
React
inReact.createElement
expressions which transform creates.In classic mode, the binding for
React
can be anywhere, so we have to perform scope lookup every time to ensure correct scopes tree for weird cases like this:However, this is of course a very uncommon case. 99% of the time
React
is bound toimport React from 'react';
in top level scope.Scope tree lookups are fairly expensive. While traversing the AST, we should cache scope tree lookups to optimize for the common case.