Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined variable #344

Open
tomascharad opened this issue Nov 2, 2016 · 1 comment
Open

Undefined variable #344

tomascharad opened this issue Nov 2, 2016 · 1 comment

Comments

@tomascharad
Copy link

tomascharad commented Nov 2, 2016

I have the following code:

...
if(movementId) {
  movementDetails = (<Dialog
  ...
  <div className="row">
    <div className="col-md-12">
      <Temp origin={origin} destiny={destiny} actions={actions} map={map} google={google} />
    </div>
  </div>
  ...
}
....

And by some reason the row div gets declared outside de if scope, and so at runtime I get

3.96a4658….chunk.js:192 Uncaught (in promise) ReferenceError: origin is not defined

The code after transpilation looks something like this:

var _ref10 = _jsx('div', {
        className: 'row'
      }, void 0, _jsx('div', {
        className: 'col-md-12'
      }, void 0, _jsx(__WEBPACK_IMPORTED_MODULE_16__components_MapTemplate_index_js__["a" /* default */], {
        origin: origin,
        destiny: destiny,
        actions: actions,
        map: map,
        google: google
      })));

      if (movementId) {
        (function () {
          var _jsx2;

          var movement = env.Movement.findBy('id', movementId);
          var origin = movement.origin();
          var destiny = movement.destiny();
          var transport = movement.transport();
          var driver = transport.driver();

Please note how _ref10 is declared outside the if statement.

I don't understand why a new variable is created for this in first place (might it be because of the nesting?).

This doesn't happen while using webpack-dev-server.

I'm using webpack 2.1.0-beta.12 and react 15.3.2

@alex-kinokon
Copy link

You are in the wrong repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants