facebook / fbjs

A collection of utility libraries used by other Meta JS projects.
MIT License
1.95k stars 313 forks source link

[babel-preset-fbjs] Avoid generating duplicate references to the same node #440

Closed motiz88 closed 3 years ago

motiz88 commented 3 years ago

Babel does not deal well with multiple references to the same node in a single AST. Specifically it can lead to NodePaths not being unique and therefore to incorrect scope analyses - see https://github.com/babel/babel/issues/6375 for pointers to manifestations of this in Babel.

These days, Babel's test suite ensures that Babel's first-party plugins do not emit such duplicates (https://github.com/babel/babel/pull/7149) but there is no such guarantee for third-party plugins.

This PR:

  1. fixes the logic in inline-requires to avoid emitting repeated nodes.
  2. adds tests to all the Babel plugins in this repo asserting that there are no repeated nodes in the resulting ASTs.