Skip to content

Commit

Permalink
Fields without initalizer don't have the initializer function
Browse files Browse the repository at this point in the history
(Review by @littledan)
  • Loading branch information
nicolo-ribaudo committed Aug 17, 2018
1 parent ccd7725 commit b6d3081
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/babel-plugin-proposal-decorators/src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getKey(node) {
}

function getSingleElementDefinition(path, superRef, classRef, file) {
const { node } = path;
const { node, scope } = path;
const isMethod = path.isClassMethod();

if (path.isPrivate()) {
Expand All @@ -61,10 +61,10 @@ function getSingleElementDefinition(path, superRef, classRef, file) {
methodPath: path,
methodNode: node,
objectRef: classRef,
superRef: superRef,
isStatic: node.static,
scope: path.scope,
file: file,
superRef,
scope,
file,
},
true,
).replace();
Expand All @@ -76,7 +76,9 @@ function getSingleElementDefinition(path, superRef, classRef, file) {
prop("key", getKey(node)),
isMethod
? value(node.body, node.params)
: value(template.ast`{ return ${node.value} }`),
: node.value
? value(template.ast`{ return ${node.value} }`)
: prop("value", scope.buildUndefinedNode()),
].filter(Boolean);

return t.objectExpression(properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var el = null;

class A {
@(_ => el = _)
foo;
}

expect(el).toEqual(Object.defineProperty({
kind: "field",
key: "foo",
placement: "own",
descriptor: {
enumerable: false,
configurable: true,
writable: true,
},
initializer: undefined,
}, Symbol.toStringTag, { value: "Descriptor" }));

0 comments on commit b6d3081

Please sign in to comment.