From 6a48be4b6b91c71687c2edc1cf9db9538d9f5650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 5 Feb 2024 19:50:03 +0900 Subject: [PATCH] fix(es/quote): Allow variables typed `AssignTarget` (#8602) **Description:** This is required to fix https://github.com/vercel/turbo/pull/7272 **Related issue:** - https://github.com/vercel/turbo/pull/7272 --- crates/swc_ecma_quote/src/lib.rs | 1 + crates/swc_ecma_quote_macros/src/ctxt.rs | 2 ++ crates/swc_ecma_quote_macros/src/ret_type.rs | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_quote/src/lib.rs b/crates/swc_ecma_quote/src/lib.rs index a7cf6dd5e08e..726a50c81e80 100644 --- a/crates/swc_ecma_quote/src/lib.rs +++ b/crates/swc_ecma_quote/src/lib.rs @@ -17,6 +17,7 @@ mod clone; /// /// - `Expr` /// - `Pat` +/// - `AssignTarget` /// - `Stmt` /// - `ModuleItem` /// diff --git a/crates/swc_ecma_quote_macros/src/ctxt.rs b/crates/swc_ecma_quote_macros/src/ctxt.rs index bb46ec775f39..45e1f6d5c46f 100644 --- a/crates/swc_ecma_quote_macros/src/ctxt.rs +++ b/crates/swc_ecma_quote_macros/src/ctxt.rs @@ -24,6 +24,7 @@ pub enum VarPos { Ident, Expr, Pat, + AssignTarget, Str, } @@ -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(), diff --git a/crates/swc_ecma_quote_macros/src/ret_type.rs b/crates/swc_ecma_quote_macros/src/ret_type.rs index ad4b5ed3d7cd..fa081627df3b 100644 --- a/crates/swc_ecma_quote_macros/src/ret_type.rs +++ b/crates/swc_ecma_quote_macros/src/ret_type.rs @@ -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}; @@ -39,6 +39,12 @@ pub(crate) fn parse_input_type(input_str: &str, ty: &Type) -> Result 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()), _ => {} }