add support for object literal decorators - fixes #1154
This commit is contained in:
@@ -10,11 +10,11 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {
|
||||
return "Bar";
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
}], null, _instanceInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -9,12 +9,12 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, null, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {
|
||||
return "Bar";
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
}], null, _staticInitializers);
|
||||
Foo.foo = _staticInitializers.foo.call(Foo);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -10,9 +10,9 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {}
|
||||
initializer: function () {},
|
||||
enumerable: true
|
||||
}], null, _instanceInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -9,10 +9,10 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, null, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {}
|
||||
initializer: function () {},
|
||||
enumerable: true
|
||||
}], null, _staticInitializers);
|
||||
Foo.foo = _staticInitializers.foo.call(Foo);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
var autobind = function (target, name, descriptor) {
|
||||
var fn = descriptor.value;
|
||||
delete descriptor.value;
|
||||
delete descriptor.writable;
|
||||
descriptor.get = function () {
|
||||
return fn.bind(this);
|
||||
};
|
||||
};
|
||||
|
||||
var person = {
|
||||
first: "Sebastian",
|
||||
last: "McKenzie",
|
||||
|
||||
@autobind
|
||||
getName() {
|
||||
return `${this.first} ${this.last}`;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(person.getName.call(null), "Sebastian McKenzie")
|
||||
@@ -0,0 +1,11 @@
|
||||
var obj = {
|
||||
@foo
|
||||
get foo() {
|
||||
|
||||
},
|
||||
|
||||
@foo
|
||||
set foo() {
|
||||
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo, foo],
|
||||
get: function get() {},
|
||||
set: function set() {}
|
||||
}]);
|
||||
@@ -0,0 +1,6 @@
|
||||
var obj = {
|
||||
@foo
|
||||
get foo() {
|
||||
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo],
|
||||
get: function get() {}
|
||||
}]);
|
||||
@@ -0,0 +1,6 @@
|
||||
var obj = {
|
||||
@foo
|
||||
set foo() {
|
||||
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo],
|
||||
set: function set() {}
|
||||
}]);
|
||||
@@ -0,0 +1,11 @@
|
||||
var obj = {
|
||||
@foo
|
||||
bar() {
|
||||
|
||||
},
|
||||
|
||||
@bar
|
||||
foo: "lol",
|
||||
|
||||
yes: "wow"
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "bar",
|
||||
decorators: [foo],
|
||||
value: function value() {}
|
||||
}, {
|
||||
key: "foo",
|
||||
decorators: [bar],
|
||||
value: "lol"
|
||||
}, {
|
||||
key: "yes",
|
||||
value: "wow"
|
||||
}]);
|
||||
Reference in New Issue
Block a user