Skip to content

Commit

Permalink
Reuse getter/setter template
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-mc committed Jul 22, 2019
1 parent 6ab7fb8 commit ee9364e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
38 changes: 9 additions & 29 deletions packages/babel-helper-create-class-features-plugin/src/fields.js
Expand Up @@ -314,35 +314,15 @@ function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) {
initAdded: true,
});

if (getId && setId) {
return template.statement.ast`
var ${id.name} = {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId.name},
set: ${setId.name}
}
`;
} else if (getId && !setId) {
return template.statement.ast`
var ${id.name} = {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId.name}
}
`;
} else if (!getId && setId) {
return template.statement.ast`
var ${id.name} = {
// configurable is false by default
// enumerable is false by default
// writable is false by default
set: ${setId.name}
}
`;
}
return template.statement.ast`
var ${id.name} = {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId ? getId.name : "null"},
set: ${setId ? setId.name : "null"}
}
`;
}

const value = prop.node.value || prop.scope.buildUndefinedNode();
Expand Down
Expand Up @@ -14,5 +14,6 @@ var _PRIVATE_STATIC_FIELD = {
value: 0
};
var _privateStaticFieldValue = {
get: null,
set: _set_privateStaticFieldValue
};
Expand Up @@ -14,5 +14,6 @@ var _PRIVATE_STATIC_FIELD = {
value: 0
};
var _privateStaticFieldValue = {
get: _get_privateStaticFieldValue
get: _get_privateStaticFieldValue,
set: null
};

0 comments on commit ee9364e

Please sign in to comment.