add test and fix for string literal case (#10578)

This commit is contained in:
Matthew Whitworth 2019-10-21 16:39:03 +01:00 committed by Nicolò Ribaudo
parent fe258dec04
commit 5b40845afe
2 changed files with 33 additions and 1 deletions

View File

@ -281,7 +281,10 @@ export default {
path.replaceWith(
t.callExpression(state.addHelper("initializerDefineProperty"), [
t.cloneNode(path.get("left.object").node),
t.stringLiteral(path.get("left.property").node.name),
t.stringLiteral(
path.get("left.property").node.name ||
path.get("left.property").node.value,
),
t.cloneNode(path.get("right.arguments")[0].node),
t.cloneNode(path.get("right.arguments")[1].node),
]),

View File

@ -0,0 +1,29 @@
function dec(target, name, descriptor) {
expect(target).toBeTruthy();
expect(typeof name).toBe("string");
expect(typeof descriptor).toBe("object");
target.decoratedProps = (target.decoratedProps || []).concat([name]);
return descriptor;
}
class Example {
@dec "a-prop";
}
let inst = new Example();
expect(Example.prototype).toHaveProperty("decoratedProps");
expect(inst.decoratedProps).toEqual([
"a-prop"
]);
expect(inst).toHaveProperty("a-prop");
expect(inst["a-prop"]).toBeUndefined();
const descs = Object.getOwnPropertyDescriptors(inst);
expect(descs["a-prop"].enumerable).toBeTruthy();
expect(descs["a-prop"].writable).toBeTruthy();
expect(descs["a-prop"].configurable).toBeTruthy();