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

TsConstructSignatureDecl type_params is not output #7079

Closed
narumincho opened this issue Mar 14, 2023 · 1 comment · Fixed by #7080
Closed

TsConstructSignatureDecl type_params is not output #7079

narumincho opened this issue Mar 14, 2023 · 1 comment · Fixed by #7080
Labels
Milestone

Comments

@narumincho
Copy link

narumincho commented Mar 14, 2023

Describe the bug

The type specified by type_params of TsConstructSignatureDecl is not output in swc_ecma_codegen

Input code

#[test]
fn output_construct_signature_with_type_params() {
    let type_parameter_t_ident =
        swc_ecma_ast::Ident::new(string_cache::Atom::from("T"), swc_common::Span::default());
    let type_decl = swc_ecma_ast::TsTypeLit {
        span: swc_common::Span::default(),
        members: vec![swc_ecma_ast::TsTypeElement::TsConstructSignatureDecl(
            swc_ecma_ast::TsConstructSignatureDecl {
                span: swc_common::Span::default(),
                params: vec![swc_ecma_ast::TsFnParam::Ident(swc_ecma_ast::BindingIdent {
                    id: swc_ecma_ast::Ident::new(
                        string_cache::Atom::from("value"),
                        swc_common::Span::default(),
                    ),
                    type_ann: Some(Box::new(swc_ecma_ast::TsTypeAnn {
                        span: swc_common::Span::default(),
                        type_ann: Box::new(swc_ecma_ast::TsType::TsTypeRef(
                            swc_ecma_ast::TsTypeRef {
                                span: swc_common::Span::default(),
                                type_name: swc_ecma_ast::TsEntityName::Ident(
                                    type_parameter_t_ident.clone(),
                                ),
                                type_params: None,
                            },
                        )),
                    })),
                })],
                type_ann: Some(Box::new(swc_ecma_ast::TsTypeAnn {
                    span: swc_common::Span::default(),
                    type_ann: Box::new(swc_ecma_ast::TsType::TsTypeRef(swc_ecma_ast::TsTypeRef {
                        span: swc_common::Span::default(),
                        type_name: swc_ecma_ast::TsEntityName::Ident(swc_ecma_ast::Ident::new(
                            string_cache::Atom::from("Obj"),
                            swc_common::Span::default(),
                        )),
                        type_params: Some(Box::new(swc_ecma_ast::TsTypeParamInstantiation {
                            span: swc_common::Span::default(),
                            params: vec![Box::new(swc_ecma_ast::TsType::TsTypeRef(
                                swc_ecma_ast::TsTypeRef {
                                    span: swc_common::Span::default(),
                                    type_name: swc_ecma_ast::TsEntityName::Ident(
                                        type_parameter_t_ident.clone(),
                                    ),
                                    type_params: None,
                                },
                            ))],
                        })),
                    })),
                })),
                // ignored ?
                type_params: Some(Box::new(swc_ecma_ast::TsTypeParamDecl {
                    span: swc_common::Span::default(),
                    params: vec![swc_ecma_ast::TsTypeParam {
                        span: swc_common::Span::default(),
                        name: type_parameter_t_ident.clone(),
                        is_in: false,
                        is_out: false,
                        is_const: false,
                        constraint: None,
                        default: None,
                    }],
                })),
            },
        )],
    };

    let cm = swc_common::sync::Lrc::<swc_common::SourceMap>::default();
    let mut buf = vec![];
    let writer = swc_ecma_codegen::text_writer::JsWriter::new(cm.clone(), "\n", &mut buf, None);

    let mut emitter = swc_ecma_codegen::Emitter {
        cfg: Default::default(),
        comments: None,
        cm: cm.clone(),
        wr: writer,
    };

    swc_ecma_codegen::Node::emit_with(&type_decl, &mut emitter).unwrap();

    let code = String::from_utf8(buf).unwrap();
    println!("{}", code);
}

Config

No response

Playground link

No response

Expected behavior

{
    new<T>(value: T): Obj<T>;
}

Actual behavior

{
    new(value: T): Obj<T>;
}

Version

[dependencies]
swc_atoms = "0.4.39"
swc_common = "0.29.37"
swc_ecma_parser = "0.130.2"
swc_ecma_ast = "0.100.1"
swc_ecma_codegen = "0.135.2"
string_cache = "0.8.7"

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Mar 14, 2023
kdy1 pushed a commit that referenced this issue Mar 17, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.41 Mar 17, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 16, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants