Skip to content

Commit

Permalink
Node 6 compat in the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 7, 2024
1 parent a38dff4 commit 1f310fb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions scripts/babel-plugin-bit-decorator/plugin.cjs
Expand Up @@ -16,7 +16,8 @@ function pluginBabelBitDecorator({ types: t, template }) {
for (const element of path.get("body.body")) {
if (
(element.isClassProperty() || element.isClassPrivateProperty()) &&
element.node.decorators?.some(dec =>
element.node.decorators &&
element.node.decorators.some(dec =>
t.matchesPattern(dec.expression, "bit.storage")
)
) {
Expand All @@ -36,14 +37,16 @@ function pluginBabelBitDecorator({ types: t, template }) {
let dec;
if (
element.isClassAccessorProperty() &&
(dec = element
.get("decorators")
?.find(
({ node: dec }) =>
t.isIdentifier(dec.expression, { name: "bit" }) ||
(t.isCallExpression(dec.expression) &&
t.isIdentifier(dec.expression.callee, { name: "bit" }))
))
(dec =
element.node.decorators &&
element
.get("decorators")
.find(
({ node: dec }) =>
t.isIdentifier(dec.expression, { name: "bit" }) ||
(t.isCallExpression(dec.expression) &&
t.isIdentifier(dec.expression.callee, { name: "bit" }))
))
) {
if (element.node.static || t.isPrivateName(element.node.key)) {
throw element.buildCodeFrameError(
Expand Down Expand Up @@ -80,7 +83,7 @@ function pluginBabelBitDecorator({ types: t, template }) {
nextMask
) {
throw dec.buildCodeFrameError(
`Bit mask is ${nextMask.toString(2)}, but found ${val?.toString(2)} (or couldn't evaluate)`
`Bit mask is ${nextMask.toString(2)}, but found ${val.toString(2)} (or couldn't evaluate)`
);
}

Expand Down

0 comments on commit 1f310fb

Please sign in to comment.