Skip to content

Commit

Permalink
Fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 19, 2021
1 parent afbde46 commit b6c8589
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 20 deletions.
19 changes: 4 additions & 15 deletions packages/babel-helper-create-class-features-plugin/src/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,18 +636,12 @@ const thisContextVisitor = traverse.visitors.merge([
environmentVisitor,
]);

function replaceThisContext(
path,
ref,
superRef,
file,
privateFieldsAsProperties,
) {
function replaceThisContext(path, ref, superRef, file, loose) {
const state = { classRef: ref, needsClassRef: false };

const replacer = new ReplaceSupers({
methodPath: path,
isLoose: privateFieldsAsProperties,
isLoose: loose,
superRef,
file,
refToPreserve: ref,
Expand All @@ -673,6 +667,7 @@ export function buildFieldsInitNodes(
state,
setPublicClassFields,
privateFieldsAsProperties,
loose,
) {
const staticNodes = [];
const instanceNodes = [];
Expand All @@ -689,13 +684,7 @@ export function buildFieldsInitNodes(
const isMethod = !isField;

if (isStatic || (isMethod && isPrivate)) {
const replaced = replaceThisContext(
prop,
ref,
superRef,
state,
privateFieldsAsProperties,
);
const replaced = replaceThisContext(prop, ref, superRef, state, loose);
needsClassRef = needsClassRef || replaced;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export function createClassFeaturePlugin({
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
loose,
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class A {
static prop = 1;
}

class B extends A {
static prop = 2;
static propA = super.prop;
static getPropA = () => super.prop;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"validateLogs": true,
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
["proposal-class-properties", { "loose": true }],
"syntax-class-properties"
],
"assumptions": {
"setPublicClassFields": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class A {}

A.prop = 1;

class B extends A {}

B.prop = 2;
B.propA = A.prop;

B.getPropA = () => A.prop;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[proposal-class-properties]: You are using the "loose: true" option and you are explicitly setting a value for the "setPublicClassFields" assumption. The "loose" option can cause incompatibilities with the other class features plugins, so it's recommended that you replace it with the following top-level option:
"assumptions": {
"setPublicClassFields": true,
"privateFieldsAsProperties": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ A.prop = 1;
class B extends A {}

B.prop = 2;
B.propA = A.prop;
B.propA = babelHelpers.get(babelHelpers.getPrototypeOf(B), "prop", B);

B.getPropA = () => A.prop;
B.getPropA = () => babelHelpers.get(babelHelpers.getPrototypeOf(B), "prop", B);
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class Sub extends Base {
}

var _privateMethod2 = function _privateMethod2() {
return Base.prototype.superMethod.call(this);
return babelHelpers.get(babelHelpers.getPrototypeOf(Sub.prototype), "superMethod", this).call(this);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Sub extends Base {
}

var _subStaticPrivateMethod2 = function _subStaticPrivateMethod2() {
return Base.basePublicStaticMethod.call(this);
return babelHelpers.get(babelHelpers.getPrototypeOf(Sub), "basePublicStaticMethod", this).call(this);
};

Object.defineProperty(Sub, _subStaticPrivateMethod, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _getB2 = function _getB2() {
};

var _getA2 = function _getA2() {
return A.a;
return babelHelpers.get(babelHelpers.getPrototypeOf(B), "a", this);
};

Object.defineProperty(B, _getA, {
Expand Down

0 comments on commit b6c8589

Please sign in to comment.