Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(semantic): add strict mode in scope flags for class definiti…
…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
- Loading branch information