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

Invalid code "class exports.Foo" emitted for TypeScript's decorators #626

Closed
IgorMinar opened this issue Apr 26, 2016 · 2 comments
Closed

Comments

@IgorMinar
Copy link

IgorMinar commented Apr 26, 2016

Given this code with decorators:

@Injectable()
class Testability() {}

Typescript transpiles this into a more verbose version of this es6 code:

export let Testability = class Testability {};
Testability = __decorate([
    Injectable(),
], Testability);

function __decorate(decorators, target) {
  return target;
}

function Injectable() {}

If code like this is processed by rollup, rollup will emit invalid code that looks like:

(function (exports) {
  'use strict';

  exports.Testability = class exports.Testability {};
  exports.Testability = __decorate([
      Injectable(),
  ], exports.Testability);

  function __decorate(decorators, target) {
    return target;
  }

  function Injectable() {}

}((this.rollbug = this.rollbug || {})));
//# sourceMappingURL=rollbug.umd.js.map

Note the class exports.Testability part which is syntactically invalid es6 code.

I'd expect the class to be emitted as exports.Testability = class Testability{ ...

rollup config:

export default {
  entry: 'rollbug.js',
  dest: 'rollbug.umd.js',
  sourceMap: true,
  format: 'iife',
  moduleName: 'rollbug'
}

rollup version: 0.26.0

@Rich-Harris
Copy link
Contributor

Simpler repro:

export let Foo = class Foo {}
Foo = lol( Foo );

Results in:

'use strict';

exports.Foo = class exports.Foo {}
exports.Foo = lol( exports.Foo );

@Rich-Harris
Copy link
Contributor

Thanks @IgorMinar – have opened #628 to address this

Rich-Harris added a commit that referenced this issue Apr 28, 2016
create new scope for classes, with class expression ID (if any) as sole name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants