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 Dec 14, 2020
1 parent acd82be commit 1864522
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/validation/options.js
Expand Up @@ -334,8 +334,8 @@ export type NestingPath = RootPath | OverridesPath | EnvPath;
export const assumptionsNames = new Set<string>([
"ignoreFunctionLength",
"ignoreToPrimitiveHint",
"noDocumentAll",
"mutableTemplateObject",
"noDocumentAll",
"privateFieldsAsProperties",
"setClassMethods",
"setComputedProperties",
Expand Down
19 changes: 4 additions & 15 deletions packages/babel-helper-create-class-features-plugin/src/fields.js
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,
getObjectRef() {
Expand All @@ -672,6 +666,7 @@ export function buildFieldsInitNodes(
state,
setPublicClassFields,
privateFieldsAsProperties,
loose,
) {
const staticNodes = [];
const instanceNodes = [];
Expand All @@ -688,13 +683,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
Expand Up @@ -213,6 +213,7 @@ export function createClassFeaturePlugin({
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
loose,
));
}

Expand Down
@@ -0,0 +1,9 @@
class A {
static prop = 1;
}

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

A.prop = 1;

class B extends A {}

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

B.getPropA = () => A.prop;
@@ -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
}
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);
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);
};
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
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 1864522

Please sign in to comment.