Skip to content

Commit 8e3f6d0

Browse files
committed
Merge branch 'num-prop-fix'
2 parents f21ec7b + 752d157 commit 8e3f6d0

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default function({types: t}){
156156
throw path.buildCodeFrameError('Computed method/property decorators are not yet supported.')
157157
}
158158

159-
const property = t.stringLiteral(node.key.name);
159+
const property = t.isLiteral(node.key) ? node.key : t.stringLiteral(node.key.name);
160160

161161
const target = (path.isClass() && !node.static) ? buildClassPrototype({
162162
CLASS_REF: name,

test/index.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ describe('decorators', function(){
9797
});
9898

9999
describe('prototype methods', function(){
100+
it('should support numeric props', function(){
101+
function dec(target, name, descriptor){
102+
expect(name).to.eql(4);
103+
}
104+
105+
class Example {
106+
@dec
107+
4(){
108+
109+
}
110+
}
111+
});
112+
113+
it('should support string props', function(){
114+
function dec(target, name, descriptor){
115+
expect(name).to.eql("str");
116+
}
117+
118+
class Example {
119+
@dec
120+
"str"(){
121+
122+
}
123+
}
124+
});
125+
100126
it('should allow returning a descriptor', function(){
101127
function dec(target, name, descriptor){
102128
let value = descriptor.value;
@@ -295,6 +321,32 @@ describe('decorators', function(){
295321
});
296322

297323
describe('static methods', function(){
324+
it('should support numeric props', function(){
325+
function dec(target, name, descriptor){
326+
expect(name).to.eql(4);
327+
}
328+
329+
class Example {
330+
@dec
331+
static 4(){
332+
333+
}
334+
}
335+
});
336+
337+
it('should support string props', function(){
338+
function dec(target, name, descriptor){
339+
expect(name).to.eql("str");
340+
}
341+
342+
class Example {
343+
@dec
344+
static "str"(){
345+
346+
}
347+
}
348+
});
349+
298350
it('should allow returning a descriptor', function(){
299351
function dec(target, name, descriptor){
300352
let value = descriptor.value;
@@ -722,6 +774,32 @@ describe('decorators', function(){
722774
});
723775

724776
describe('methods', function(){
777+
it('should support numeric props', function(){
778+
function dec(target, name, descriptor){
779+
expect(name).to.eql(4);
780+
}
781+
782+
const inst = {
783+
@dec
784+
4(){
785+
786+
}
787+
};
788+
});
789+
790+
it('should support string props', function(){
791+
function dec(target, name, descriptor){
792+
expect(name).to.eql("str");
793+
}
794+
795+
const inst = {
796+
@dec
797+
"str"(){
798+
799+
}
800+
};
801+
});
802+
725803
it('should allow returning a descriptor', function(){
726804
function dec(target, name, descriptor){
727805
let value = descriptor.value;
@@ -918,6 +996,28 @@ describe('decorators', function(){
918996
});
919997

920998
describe('properties', function(){
999+
it('should support numeric props', function(){
1000+
function dec(target, name, descriptor){
1001+
expect(name).to.eql(4);
1002+
}
1003+
1004+
const inst = {
1005+
@dec
1006+
4: 1
1007+
};
1008+
});
1009+
1010+
it('should support string props', function(){
1011+
function dec(target, name, descriptor){
1012+
expect(name).to.eql("str");
1013+
}
1014+
1015+
const inst = {
1016+
@dec
1017+
"str": 1
1018+
};
1019+
});
1020+
9211021
it('should allow returning a descriptor', function(){
9221022
function dec(target, name, descriptor){
9231023
let initializer = descriptor.initializer;

0 commit comments

Comments
 (0)