Skip to content

[AST] shape of Param, Pat and VarDeclarator #5416

@magic-akari

Description

@magic-akari

Describe the bug

I don't think the typeAnnotation should be attached on pat.

1. VarDeclarator

The typeAnnotation should always be attached on the VarDeclarator, not the pat.

const a: number = 1, [b]: [number] = 2, { c }: { c: number } = { c: 3 };

Expect:

VarDeclarator {
    name: Pat,
    init: Expr,
    type_ann: TsTypeAnn,
};

Actual:
the type_ann is in the name.

2. Param

There should be a type_ann in the Param like VarDeclarator.

3. init in the Param

function foo(a = 1) { }

function bar(a: number = 1) { }

Expect :

Param {
    pat: Pat,
    init: Expr,
    type_ann: TsTypeAnn
}

Actual:
got AssignPat

image


It's better to remove typeAnnotation from Pat and add it to other AST struct like Param, VarDeclarator.

Input code

No response

Config

No response

Playground link

No response

Expected behavior

/

Actual behavior

No response

Version

N/A

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions