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

fix(es/compat): Apply transforms for explicit resource management #7881

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ use swc_ecma_transforms::{
modules::{path::NodeImportResolver, rewriter::import_rewriter},
optimization::{const_modules, json_parse, simplifier},
pass::{noop, Optional},
proposals::{decorators, export_default_from, import_assertions},
proposals::{
decorators, explicit_resource_management::explicit_resource_management,
export_default_from, import_assertions,
},
react::{self, default_pragma, default_pragma_frag},
resolver,
typescript::{self, TsEnumConfig, TsImportExportAssignConfig},
Expand Down Expand Up @@ -792,6 +795,10 @@ impl Options {
},
syntax.decorators()
),
Optional::new(
explicit_resource_management(),
syntax.explicit_resource_management()
),
// The transform strips import assertions, so it's only enabled if
// keep_import_assertions is false.
Optional::new(import_assertions(), !keep_import_assertions),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl Syntax {
}
}

fn using_decl(&self) -> bool {
pub fn explicit_resource_management(&self) -> bool {
match self {
Syntax::Es(EsConfig { using_decl, .. }) => *using_decl,
Syntax::Typescript(_) => true,
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl<'a, I: Tokens> Parser<I> {
decls.push(self.parse_var_declarator(false, VarDeclKind::Var)?);
}

if !self.syntax().using_decl() {
if !self.syntax().explicit_resource_management() {
self.emit_err(span!(self, start), SyntaxError::UsingDeclNotEnabled);
}

Expand Down Expand Up @@ -1272,7 +1272,7 @@ impl<'a, I: Tokens> Parser<I> {
let start = cur_pos!(self);
let init = self.include_in_expr(false).parse_for_head_prefix()?;

let is_using_decl = self.input.syntax().using_decl()
let is_using_decl = self.input.syntax().explicit_resource_management()
&& match *init {
Expr::Ident(Ident {
sym: js_word!("using"),
Expand Down