Skip to content

Commit

Permalink
Only allow TSParameterProperty in ClassMethod parameters (#13349)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 23, 2021
1 parent d6a5f61 commit b1f57e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
10 changes: 5 additions & 5 deletions packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -481,7 +481,7 @@ export interface ForStatement extends BaseNode {
export interface FunctionDeclaration extends BaseNode {
type: "FunctionDeclaration";
id?: Identifier | null;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
params: Array<Identifier | Pattern | RestElement>;
body: BlockStatement;
generator?: boolean;
async?: boolean;
Expand All @@ -497,7 +497,7 @@ export interface FunctionDeclaration extends BaseNode {
export interface FunctionExpression extends BaseNode {
type: "FunctionExpression";
id?: Identifier | null;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
params: Array<Identifier | Pattern | RestElement>;
body: BlockStatement;
generator?: boolean;
async?: boolean;
Expand Down Expand Up @@ -616,7 +616,7 @@ export interface ObjectMethod extends BaseNode {
type: "ObjectMethod";
kind: "method" | "get" | "set";
key: Expression | Identifier | StringLiteral | NumericLiteral;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
params: Array<Identifier | Pattern | RestElement>;
body: BlockStatement;
computed: boolean;
generator?: boolean;
Expand Down Expand Up @@ -756,7 +756,7 @@ export interface ArrayPattern extends BaseNode {

export interface ArrowFunctionExpression extends BaseNode {
type: "ArrowFunctionExpression";
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
params: Array<Identifier | Pattern | RestElement>;
body: BlockStatement | Expression;
async?: boolean;
expression: boolean;
Expand Down Expand Up @@ -1658,7 +1658,7 @@ export interface TSDeclareFunction extends BaseNode {
type: "TSDeclareFunction";
id?: Identifier | null;
typeParameters?: TSTypeParameterDeclaration | Noop | null;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
params: Array<Identifier | Pattern | RestElement>;
returnType?: TSTypeAnnotation | Noop | null;
async?: boolean;
declare?: boolean | null;
Expand Down
20 changes: 5 additions & 15 deletions packages/babel-types/src/builders/generated/index.ts
Expand Up @@ -133,9 +133,7 @@ export function forStatement(
}
export function functionDeclaration(
id: t.Identifier | null | undefined,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
body: t.BlockStatement,
generator?: boolean,
async?: boolean,
Expand All @@ -144,9 +142,7 @@ export function functionDeclaration(
}
export function functionExpression(
id: t.Identifier | null | undefined,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
body: t.BlockStatement,
generator?: boolean,
async?: boolean,
Expand Down Expand Up @@ -226,9 +222,7 @@ export function objectExpression(
export function objectMethod(
kind: "method" | "get" | "set" | undefined,
key: t.Expression | t.Identifier | t.StringLiteral | t.NumericLiteral,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
body: t.BlockStatement,
computed?: boolean,
generator?: boolean,
Expand Down Expand Up @@ -338,9 +332,7 @@ export function arrayPattern(
return builder("ArrayPattern", ...arguments);
}
export function arrowFunctionExpression(
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
body: t.BlockStatement | t.Expression,
async?: boolean,
): t.ArrowFunctionExpression {
Expand Down Expand Up @@ -1093,9 +1085,7 @@ export { tsParameterProperty as tSParameterProperty };
export function tsDeclareFunction(
id: t.Identifier | null | undefined,
typeParameters: t.TSTypeParameterDeclaration | t.Noop | null | undefined,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
returnType?: t.TSTypeAnnotation | t.Noop | null,
): t.TSDeclareFunction {
return builder("TSDeclareFunction", ...arguments);
Expand Down
22 changes: 14 additions & 8 deletions packages/babel-types/src/definitions/core.ts
Expand Up @@ -353,14 +353,7 @@ export const functionCommon = {
params: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"Identifier",
"Pattern",
"RestElement",
"TSParameterProperty",
),
),
assertEach(assertNodeType("Identifier", "Pattern", "RestElement")),
),
},
generator: {
Expand Down Expand Up @@ -1743,6 +1736,19 @@ export const classMethodOrPropertyCommon = {
export const classMethodOrDeclareMethodCommon = {
...functionCommon,
...classMethodOrPropertyCommon,
params: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"Identifier",
"Pattern",
"RestElement",
"TSParameterProperty",
),
),
),
},
kind: {
validate: assertOneOf("get", "set", "method", "constructor"),
default: "method",
Expand Down

0 comments on commit b1f57e5

Please sign in to comment.