Skip to content

Undefined variable #344

@tomascharad

Description

@tomascharad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions