@babel/eslint-parser: Fix ClassPrivateMethods (#10913)
This commit is contained in:
parent
daaa2063bb
commit
9f832c2716
@ -34,6 +34,7 @@
|
|||||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
|
||||||
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
|
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
|
||||||
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
|
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
|
||||||
|
"@babel/plugin-proposal-private-methods": "^7.7.4",
|
||||||
"@babel/plugin-syntax-bigint": "^7.7.4",
|
"@babel/plugin-syntax-bigint": "^7.7.4",
|
||||||
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
||||||
"@babel/plugin-syntax-export-default-from": "^7.0.0",
|
"@babel/plugin-syntax-export-default-from": "^7.0.0",
|
||||||
|
|||||||
@ -16,16 +16,16 @@ const flowFlippedAliasKeys = t.FLIPPED_ALIAS_KEYS.Flow.concat([
|
|||||||
"ObjectPattern",
|
"ObjectPattern",
|
||||||
"RestElement",
|
"RestElement",
|
||||||
]);
|
]);
|
||||||
const visitorKeysMap = Object.entries(t.VISITOR_KEYS).reduce(function(
|
|
||||||
acc,
|
const visitorKeysMap = Object.entries(t.VISITOR_KEYS).reduce(
|
||||||
[key, value],
|
(acc, [key, value]) => {
|
||||||
) {
|
if (!flowFlippedAliasKeys.includes(value)) {
|
||||||
if (flowFlippedAliasKeys.indexOf(value) === -1) {
|
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{});
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
const propertyTypes = {
|
const propertyTypes = {
|
||||||
// loops
|
// loops
|
||||||
@ -166,6 +166,11 @@ class Referencer extends OriginalReferencer {
|
|||||||
this._visitClassProperty(node);
|
this._visitClassProperty(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Update to visit type annotations when TypeScript/Flow support this syntax.
|
||||||
|
ClassPrivateMethod(node) {
|
||||||
|
super.MethodDefinition(node);
|
||||||
|
}
|
||||||
|
|
||||||
DeclareModule(node) {
|
DeclareModule(node) {
|
||||||
this._visitDeclareX(node);
|
this._visitDeclareX(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -270,7 +270,7 @@ describe("babylon-to-espree", () => {
|
|||||||
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
|
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Espree doesn't support the private fields yet
|
// Espree doesn't support private fields yet
|
||||||
it("hash (token)", () => {
|
it("hash (token)", () => {
|
||||||
const code = "class A { #x }";
|
const code = "class A { #x }";
|
||||||
const babylonAST = parseForESLint(code, {
|
const babylonAST = parseForESLint(code, {
|
||||||
|
|||||||
@ -18,5 +18,6 @@ module.exports = {
|
|||||||
["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: false }],
|
["@babel/plugin-proposal-decorators", { decoratorsBeforeExport: false }],
|
||||||
["@babel/plugin-proposal-pipeline-operator", { proposal: "minimal" }],
|
["@babel/plugin-proposal-pipeline-operator", { proposal: "minimal" }],
|
||||||
"@babel/plugin-syntax-bigint",
|
"@babel/plugin-syntax-bigint",
|
||||||
|
"@babel/plugin-proposal-private-methods",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1763,7 +1763,32 @@ describe("verify", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("private class properties", () => {
|
describe("class field declarations", () => {
|
||||||
|
describe("field declarations", () => {
|
||||||
|
it("should not be undefined", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
class C {
|
||||||
|
d = 1;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ "no-undef": 1 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not be unused", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
export class C {
|
||||||
|
d = 1;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ "no-unused-vars": 1 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("private field declarations", () => {
|
||||||
it("should not be undefined", () => {
|
it("should not be undefined", () => {
|
||||||
verifyAndAssertMessages(
|
verifyAndAssertMessages(
|
||||||
`
|
`
|
||||||
@ -1787,6 +1812,31 @@ describe("verify", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("private methods", () => {
|
||||||
|
it("should not be undefined", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
class C {
|
||||||
|
#d() {};
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ "no-undef": 1 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not be unused", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
export class C {
|
||||||
|
#d() {};
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{ "no-unused-vars": 1 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("optional chaining operator", () => {
|
describe("optional chaining operator", () => {
|
||||||
it("should not be undefined #595", () => {
|
it("should not be undefined #595", () => {
|
||||||
verifyAndAssertMessages(
|
verifyAndAssertMessages(
|
||||||
@ -1853,6 +1903,22 @@ describe("verify", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("works with classPrivateMethods", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
class A { #a(b, c) {} }
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("works with arrow function classPrivateProperties", () => {
|
||||||
|
verifyAndAssertMessages(
|
||||||
|
`
|
||||||
|
class A { #a = (a, b) => {}; }
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("works with optionalCatchBinding", () => {
|
it("works with optionalCatchBinding", () => {
|
||||||
verifyAndAssertMessages(
|
verifyAndAssertMessages(
|
||||||
`
|
`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user