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

feat(parser/ts): support optional variance annotations #4008

Merged
merged 12 commits into from
Mar 23, 2022
  •  
  •  
  •  
1 change: 1 addition & 0 deletions crates/swc_atoms/words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ object
of
only
or
out
override
package
private
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_ast/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub struct TsTypeParam {
pub span: Span,
pub name: Ident,

#[serde(default, rename = "in")]
pub is_in: bool,

#[serde(default, rename = "out")]
pub is_out: bool,

#[serde(default)]
pub constraint: Option<Box<TsType>>,

Expand Down
10 changes: 10 additions & 0 deletions crates/swc_ecma_codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,16 @@ where
fn emit_ts_type_param(&mut self, n: &TsTypeParam) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

if n.is_in {
keyword!("in");
space!();
}

if n.is_out {
keyword!("out");
space!();
}

emit!(n.name);

if let Some(constraints) = &n.constraint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58662,7 +58662,7 @@ TestSnapshot {
),
(
(
Atom('out' type=inline),
Atom('out' type=static),
#5,
),
VarUsageInfo {
Expand Down Expand Up @@ -58702,7 +58702,7 @@ TestSnapshot {
),
(
(
Atom('out' type=inline),
Atom('out' type=static),
#8,
),
VarUsageInfo {
Expand Down Expand Up @@ -58742,7 +58742,7 @@ TestSnapshot {
),
(
(
Atom('out' type=inline),
Atom('out' type=static),
#116,
),
VarUsageInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37494,7 +37494,7 @@ TestSnapshot {
),
(
(
Atom('out' type=inline),
Atom('out' type=static),
#275,
),
VarUsageInfo {
Expand Down Expand Up @@ -37534,7 +37534,7 @@ TestSnapshot {
),
(
(
Atom('out' type=inline),
Atom('out' type=static),
#276,
),
VarUsageInfo {
Expand Down
Loading