Skip to content

Commit

Permalink
fix: avoid duplicate loop and do not skip for decorated class
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 22, 2021
1 parent a65c8bf commit ad66f65
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/babel-helper-create-class-features-plugin/src/index.js
Expand Up @@ -99,19 +99,6 @@ export function createClassFeaturePlugin({
const computedPaths = [];
const privateNames = new Set();
const classElements = path.get("body").get("body");
const isPublicClassFieldsTransformRequired = isRequired(
"public_class_fields",
targets,
{ compatData },
);
if (
!isPublicClassFieldsTransformRequired &&
classElements.every(
element => element.isClassMethod() || element.isClassProperty(),
)
) {
return;
}

for (const path of classElements) {
verifyUsedFeatures(path, this.file);
Expand Down Expand Up @@ -182,7 +169,17 @@ export function createClassFeaturePlugin({
}
}

if (!props.length && !isDecorated) return;
if (!isDecorated) {
if (!props.length) return;
const isPublicClassFieldsTransformRequired = isRequired(
"public_class_fields",
targets,
{ compatData },
);
if (!isPublicClassFieldsTransformRequired && !privateNames.size) {
return;
}
}

let ref;

Expand Down
@@ -0,0 +1,6 @@
class C {
@dec p = 1;
static P = 2;
m() {}
static M() {}
}
@@ -0,0 +1,6 @@
{
"targets": {
"node": "12"
},
"plugins": ["proposal-class-properties", ["proposal-decorators", { "decoratorsBeforeExport": true }], ["external-helpers", { "helperVersion": "7.100.0" }]]
}
@@ -0,0 +1,42 @@
let C = babelHelpers.decorate(null, function (_initialize) {
"use strict";

class C {
constructor() {
_initialize(this);
}

}

return {
F: C,
d: [{
kind: "field",
decorators: [dec],
key: "p",

value() {
return 1;
}

}, {
kind: "field",
static: true,
key: "P",

value() {
return 2;
}

}, {
kind: "method",
key: "m",
value: function m() {}
}, {
kind: "method",
static: true,
key: "M",
value: function M() {}
}]
};
});

0 comments on commit ad66f65

Please sign in to comment.