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

fix: add support for classes with decorators #7

Merged
merged 3 commits into from Apr 14, 2020
Merged

Conversation

homer0
Copy link
Owner

@homer0 homer0 commented Apr 14, 2020

What does this PR do?

When using decorators with Babel, Babel creates a sequence wrapper in order to apply the decorators, something like this:

let Hello = (_class = (_temp = (_temp2 = class Hello {
  constructor(someService) {
    'inject';

    _initializerDefineProperty(this, "random", _descriptor, this);
  }
}, _temp2), _temp), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "random", [aurelia_framework__WEBPACK_IMPORTED_MODULE_0__["bindable"]], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function () {
    return 'something';
  }
})), _class);

And when this plugin tries to add the inject property, it ends up between the class expression and _temp2, making the code invalid and breaking the execution.

The solution I implemented here is that, when working with a class, if the class is inside a sequence expression, the plugin will crawl all the way up until the top path is the program itself, and then add the definition:

})), _class);
+ Hello.inject = ['something'];

Yes, I'm not good at working with Babel ASTs :P.

How should it be tested manually?

  1. Try using the current release on a class with a decorator, it should break.
  2. Use this branch and everything should go back like it was before.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling fa84f6e on homer0_decoratorsFix into 1c1e1c8 on master.

@homer0 homer0 merged commit 9dd3de6 into master Apr 14, 2020
@homer0 homer0 deleted the homer0_decoratorsFix branch April 14, 2020 11:51
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

Successfully merging this pull request may close these issues.

None yet

2 participants