systemjs / plugin-babel

SystemJS Babel Plugin
MIT License
82 stars 33 forks source link

ReferenceError: state is not defined #23

Closed paulwalker closed 8 years ago

paulwalker commented 8 years ago

I am getting an error simply trying to reference a file:

err  ReferenceError: file:///Users/paul/Projects/jspm-test/lib/middleware/response_time.js: state is not defined
    at getRuntimeMarkDecl (file:///Users/paul/Projects/eyecue/jspm-test/jspm_packages/npm/systemjs-plugin-babel@0.0.6/systemjs-babel-node.js:40043:235)

This is the file:

'use strict'

function * responseTime (next) {
  let start = new Date()
  yield next
  var ms = new Date() - start
  this.set('X-Response-Time', ms + 'ms')
}

export default function init (app) {
  app.use(responseTime)
}

This is the import statement:

import responseTime from './response_time'

paulwalker commented 8 years ago

So, it seems to be related to the use of a generator function. I believe this is a bug still, but the use of the following syntax seems to act as a workaround:

const responseTime = function *(next) {

guybedford commented 8 years ago

Thanks, fixed and released in 0.0.7.

ghempton commented 8 years ago

I still seem to be encountering this in 0.0.13. To reproduce, there simply needs to be a file with:

function * eachEntityProp(Component, props, context) {}
guybedford commented 8 years ago

@ghempton thanks for catching this. I've included the fix in the latest build on master for release.

alexisvincent commented 7 years ago

@guybedford hitting this on 0.0.18

alexisvincent commented 7 years ago

I also notice some changes have been made to plugin-babel related to generators since 0.0.17

guybedford commented 7 years ago

@alexisvincent thanks yes this regressed again. I've fixed this up in 0.0.19 and made sure the test is included.

alexisvincent commented 7 years ago

@guybedford Thanks