Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect flag(s) generated for createVariableDeclarationList #152

Open
joshuaavalon opened this issue Jun 5, 2024 · 0 comments
Open

Incorrect flag(s) generated for createVariableDeclarationList #152

joshuaavalon opened this issue Jun 5, 2024 · 0 comments

Comments

@joshuaavalon
Copy link

joshuaavalon commented Jun 5, 2024

Example code

export interface Options {
    a: number;
    b: string
}

export function addSchema(opts: Options): void {
    const { a } = opts;
}

Result AST

[
  factory.createInterfaceDeclaration(
    [factory.createToken(ts.SyntaxKind.ExportKeyword)],
    factory.createIdentifier("Options"),
    undefined,
    undefined,
    [
      factory.createPropertySignature(
        undefined,
        factory.createIdentifier("a"),
        undefined,
        factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)
      ),
      factory.createPropertySignature(
        undefined,
        factory.createIdentifier("b"),
        undefined,
        factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
      )
    ]
  ),
  factory.createFunctionDeclaration(
    [factory.createToken(ts.SyntaxKind.ExportKeyword)],
    undefined,
    factory.createIdentifier("addSchema"),
    undefined,
    [factory.createParameterDeclaration(
      undefined,
      undefined,
      factory.createIdentifier("opts"),
      undefined,
      factory.createTypeReferenceNode(
        factory.createIdentifier("Options"),
        undefined
      ),
      undefined
    )],
    factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),
    factory.createBlock(
      [factory.createVariableStatement(
        undefined,
        factory.createVariableDeclarationList(
          [factory.createVariableDeclaration(
            factory.createObjectBindingPattern([factory.createBindingElement(
              undefined,
              undefined,
              factory.createIdentifier("a"),
              undefined
            )]),
            undefined,
            undefined,
            factory.createIdentifier("opts")
          )],
          ts.NodeFlags.Const | ts.NodeFlags.Constant | ts.NodeFlags.Constant
        )
      )],
      true
    )
  )
];

You can see it generated ts.NodeFlags.Const | ts.NodeFlags.Constant | ts.NodeFlags.Constant when it should be ts.NodeFlags.Const.

When you use the generated AST, it generates

await using { a } = opts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant