add test and fix for string literal case (#10578)
This commit is contained in:
parent
fe258dec04
commit
5b40845afe
@ -281,7 +281,10 @@ export default {
|
|||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
t.callExpression(state.addHelper("initializerDefineProperty"), [
|
t.callExpression(state.addHelper("initializerDefineProperty"), [
|
||||||
t.cloneNode(path.get("left.object").node),
|
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")[0].node),
|
||||||
t.cloneNode(path.get("right.arguments")[1].node),
|
t.cloneNode(path.get("right.arguments")[1].node),
|
||||||
]),
|
]),
|
||||||
|
|||||||
@ -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();
|
||||||
Loading…
x
Reference in New Issue
Block a user