loganfsmyth / babel-plugin-transform-decorators-legacy

A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5
MIT License
817 stars 57 forks source link

Error: Cannot read property of undefined. Static properties #67

Closed Smert closed 7 years ago

Smert commented 7 years ago

Problem

class Test {
  static foo = 1;
  static bar = Test.foo + 1;
}

transforms to

"use strict";

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _class, _temp;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Test = (_temp = _class = function Test() {
  (0, _classCallCheck3.default)(this, Test);
}, _class.foo = 1, _class.bar = Test.foo + 1, _temp);

Error:

Cannot read property 'foo' of undefined


Why Test is undefined?

var _class = function Test() {};
_class.foo = 1;
_class.bar = Test.foo + 1; // Test is not defined

My Babel config

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ],
  "plugins": [
    "transform-runtime",
    "transform-decorators-legacy"
  ]
}

latest versions

oMaten commented 7 years ago

Maybe you can find answer here #17

Smert commented 7 years ago

Thanks!

chebotiuk commented 7 years ago

@Smert Hello. HAVE YOU FOUND A SOLUTION?

Smert commented 7 years ago

@chebotiuk hi. Change order of plugins: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy#installation--usage (NOTE)