-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
must visit decorators before enter_node
and enter_scope
if have decorators
field
#4142
Comments
@rzvxa cc |
We already have the /// Class Definitions
#[visited_node]
#[scope(flags(ScopeFlags::StrictMode))]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub struct Class<'a> {
pub r#type: ClassType,
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
#[scope(enter_before)]
pub id: Option<BindingIdentifier<'a>>,
// ...
} Which generates this: pub fn walk_class<'a, V: Visit<'a>>(visitor: &mut V, it: &Class<'a>) {
let kind = AstKind::Class(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_decorators(&it.decorators);
visitor.enter_scope(ScopeFlags::StrictMode);
if let Some(id) = &it.id {
visitor.visit_binding_identifier(id);
}
// ...
visitor.leave_node(kind);
visitor.leave_scope();
} I'll add the support for a similar mechanism to mark the |
I understand why |
Won't fix #4142 It is similar to #3994 but for those types that weren't relying on this order. It seems to be the right order. technically speaking it is a breaking change but I know as a fact that it won't have a big difference on our downstream. If you want it to be chronically correct feel free to merge as a breaking change.
You are right. There is an incorrect behavior here. See #4156 (comment) We shouldn't visit decorators before |
Closes #4142 I can split it into 2 PRs but it seems pointless. Let me know if you guys disagree with me.
…ons (#4156) related: #4142 (comment) Although we called `enter_node(Class)`, that doesn't mean we're in the `class` scope. It causes our must to visit decorators before `enter_node`. Let's look at this case. It causes a syntax error if we don't visit decorators before `enter_node` ```js // This file was procedurally generated from the following sources: // - src/decorator/decorator-call-expr-identifier-reference-yield.case // - src/decorator/syntax/valid/cls-expr-decorators-valid-syntax.template /*--- description: Decorator @ DecoratorCallExpression (Valid syntax for decorator on class expression) esid: prod-ClassExpression features: [class, decorators] flags: [generated, noStrict] info: | ClassExpression[Yield, Await] : DecoratorList[?Yield, ?Await]opt class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await] DecoratorList[Yield, Await] : DecoratorList[?Yield, ?Await]opt Decorator[?Yield, ?Await] Decorator[Yield, Await] : @ DecoratorMemberExpression[?Yield, ?Await] @ DecoratorParenthesizedExpression[?Yield, ?Await] @ DecoratorCallExpression[?Yield, ?Await] ... DecoratorCallExpression[Yield, Await] : DecoratorMemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await] DecoratorMemberExpression[Yield, Await] : IdentifierReference[?Yield, ?Await] DecoratorMemberExpression[?Yield, ?Await] . IdentifierName DecoratorMemberExpression[?Yield, ?Await] . PrivateIdentifier IdentifierReference[Yield, Await] : [~Yield] yield ... ---*/ function decorator() { return () => {}; } var yield = decorator; var C = @yield() class {}; ``` Errors: ```shell × The keyword 'yield' is reserved ╭─[language/statements/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js:45:2] 44 │ 45 │ @yield() class C {} · ───── ╰──── ``` The changed code makes more sense. Only if we call `enter_scope` for class, the flags will contain `StrictMode`. Also, we can get the exact `flags` of the `scope` in the `class` at the transformer For example: ``` class A { B() { // Before: flags is `Function` // After: flags is `Function | StrictMode` } } ``` The regression tests will be fixed in follow-up PRs
Please see:
oxc/crates/oxc_semantic/src/builder.rs
Lines 1502 to 1506 in daea29c
The text was updated successfully, but these errors were encountered: