Skip to content

Commit

Permalink
fix(es/quote): Allow variables typed AssignTarget (#8602)
Browse files Browse the repository at this point in the history
**Description:**

This is required to fix vercel/turborepo#7272


**Related issue:**

 - vercel/turborepo#7272
  • Loading branch information
kdy1 committed Feb 5, 2024
1 parent 5fe45db commit 6a48be4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/swc_ecma_quote/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod clone;
///
/// - `Expr`
/// - `Pat`
/// - `AssignTarget`
/// - `Stmt`
/// - `ModuleItem`
///
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_quote_macros/src/ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum VarPos {
Ident,
Expr,
Pat,
AssignTarget,
Str,
}

Expand Down Expand Up @@ -138,6 +139,7 @@ pub(super) fn prepare_vars(
VarPos::Ident => "Ident",
VarPos::Expr => "Expr",
VarPos::Pat => "Pat",
VarPos::AssignTarget => "AssignTarget",
VarPos::Str => "Str",
},
call_site(),
Expand Down
8 changes: 7 additions & 1 deletion crates/swc_ecma_quote_macros/src/ret_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::any::type_name;

use anyhow::{anyhow, bail, Context, Error};
use swc_common::{sync::Lrc, FileName, SourceMap};
use swc_ecma_ast::EsVersion;
use swc_ecma_ast::{AssignTarget, EsVersion};
use swc_ecma_parser::{lexer::Lexer, PResult, Parser, StringInput};
use syn::{GenericArgument, PathArguments, Type};

Expand Down Expand Up @@ -39,6 +39,12 @@ pub(crate) fn parse_input_type(input_str: &str, ty: &Type) -> Result<BoxWrapper,
"Expr" => return parse(input_str, &mut |p| p.parse_expr().map(|v| *v)),
"Pat" => return parse(input_str, &mut |p| p.parse_pat()),
"Stmt" => return parse(input_str, &mut |p| p.parse_stmt_list_item(true)),
"AssignTarget" => {
return parse(input_str, &mut |p| {
Ok(AssignTarget::try_from(p.parse_pat()?)
.expect("failed to parse AssignTarget"))
})
}
"ModuleItem" => return parse(input_str, &mut |p| p.parse_module_item()),
_ => {}
}
Expand Down

0 comments on commit 6a48be4

Please sign in to comment.