Skip to content

Commit

Permalink
refactor(traverse): improve parsing attrs in traverse codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jun 24, 2024
1 parent 7f1266a commit b6cb0ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tsify::Tsify;

#[visited_node(
scope(ScopeFlags::Top),
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict))
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict)),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down Expand Up @@ -1101,7 +1101,7 @@ pub struct WhileStatement<'a> {
/// For Statement
#[visited_node(
scope(ScopeFlags::empty()),
scope_if(self.init.as_ref().is_some_and(ForStatementInit::is_lexical_declaration))
scope_if(self.init.as_ref().is_some_and(ForStatementInit::is_lexical_declaration)),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down Expand Up @@ -1426,7 +1426,7 @@ pub struct BindingRestElement<'a> {
#[visited_node(
// TODO: `ScopeFlags::Function` is not correct if this is a `MethodDefinition`
scope(ScopeFlags::Function),
strict_if(self.body.as_ref().is_some_and(|body| body.has_use_strict_directive()))
strict_if(self.body.as_ref().is_some_and(|body| body.has_use_strict_directive())),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down Expand Up @@ -1533,7 +1533,7 @@ pub struct FunctionBody<'a> {
/// Arrow Function Definitions
#[visited_node(
scope(ScopeFlags::Function | ScopeFlags::Arrow),
strict_if(self.body.has_use_strict_directive())
strict_if(self.body.has_use_strict_directive()),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ pub enum TSTypePredicateName<'a> {
#[visited_node(
scope(ScopeFlags::TsModuleBlock),
enter_scope_before(body),
strict_if(self.body.as_ref().is_some_and(|body| body.is_strict()))
strict_if(self.body.as_ref().is_some_and(|body| body.is_strict())),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_traverse/scripts/lib/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function parseFile(code, filename, types) {
line = lines[++lineIndex];
}
scopeArgsStr += ` ${line.slice(0, -2)}`;
scopeArgsStr = scopeArgsStr.trim().replace(/ +/g, ' ');
scopeArgsStr = scopeArgsStr.trim().replace(/ +/g, ' ').replace(/,$/, '');

scopeArgs = parseScopeArgs(scopeArgsStr, filename, lineIndex);
}
Expand Down

0 comments on commit b6cb0ec

Please sign in to comment.