facebook / fbjs

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

inline-requires handles Identifiers declared before CallExpressions #236

Closed bvaughn closed 7 years ago

bvaughn commented 7 years ago

While syncing the latest React release to fbsource I discovered an improperly handled inlining case.

Essentially this:

function foo() {
  bar();
}
var bar = require('baz');
foo();

Became this (and errored because bar was undefined):

function foo() {
  bar();
}
foo();

After this bugfix it becomes:

function foo() {
  require("baz")();
}
foo();
bvaughn commented 7 years ago

cc @spicyj for a code review 😄

sophiebits commented 7 years ago

Published babel-preset-fbjs@2.1.1.

bvaughn commented 7 years ago

Nice! Thanks!