-
-
Notifications
You must be signed in to change notification settings - Fork 466
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
refactor(semantic): add strict mode in scope flags for class definitions #4156
refactor(semantic): add strict mode in scope flags for class definitions #4156
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #4156 will not alter performanceComparing Summary
|
45430cd
to
df02c40
Compare
I can't keep up with who should review this anymore, can you request the right person to review? |
df02c40
to
f676841
Compare
I'm afraid I don't have time this week to get into this properly, but a few thoughts:
// Sloppy mode
var yield = class {};
class X extends yield {}
// SyntaxError: Unexpected strict mode reserved word
// Sloppy mode
var C = @yield() class {}; i.e. is the decorator considered part of the class itself, or just sugar for: var C = yield()(class {}); |
Oh, I just saw this issue and this PR would solve the second point of #3862 (comment). The first point I can create another PR to fix
Yes
Should not be a syntax error. Because
You can think of it as sugar |
In that case, Babel's decorator transform is incorrect (Babel REPL). Should we raise an issue on Babel? |
Looks correct in the latest version Babel REPL |
Ah ha yes you're right. |
f676841
to
e88e957
Compare
e88e957
to
e9192fb
Compare
cbb7bfd
to
520d1f1
Compare
e9192fb
to
2f41660
Compare
Merge activity
|
2f41660
to
f171c7e
Compare
…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
f171c7e
to
dc2b3c4
Compare
## [0.21.0] - 2024-07-18 - d7ab0b8 semantic: [**BREAKING**] Simplify node creation (#4226) (lucab) ### Features - af4dc01 ast: Align ts ast scope with typescript (#4253) (Dunqing) - 83c2c62 codegen: Add option for choosing quotes; remove slow `choose_quot` method (#4219) (Boshen) - 5d17675 mangler: Add debug mode (#4314) (Boshen) - e3e663b mangler: Initialize crate and integrate into minifier (#4197) (Boshen) - c818472 minifier: Dce conditional expression `&&` or `||` (#4190) (Boshen) - 8a190eb oxc: Export `oxc_mangler` (Boshen) - 20cdb1f semantic: Align class scope with typescript (#4195) (Dunqing) - 92ee774 semantic: Add `ScopeFlags::CatchClause` for use in CatchClause (#4205) (Dunqing) - 205c259 sourcemap: Support SourceMapBuilder#token_chunks (#4220) (underfin) - 7eb960d transformer: Decode xml character entity `&#xhhhh` and `&#nnnn;` (#4235) (Boshen) ### Bug Fixes - bf3d8d3 codegen: Print annotation comment inside parens for new and call expressions (#4290) (Boshen) - 084ab76 codegen: Use `ryu-js` for f64 to string (Boshen) - e167ef7 codegen: Print parenthesis properly (#4245) (Boshen) - c65198f codegen: Choose the right quote for jsx attribute string (#4236) (Boshen) - be82c28 codegen: Print `JSXAttributeValue::StringLiteral` directly (#4231) (Boshen) - 3df9e69 mangler: No shorthand `BindingProperty`; handle var hoisting and export variables (#4319) (Boshen) - f144082 minifier: RemoveDeadCode should visit nested expression (#4268) (underfin) - 66b455a oxc_codegen: Avoid print same pure comments multiple time (#4230) (IWANABETHATGUY) - 9a87e41 parser: Avoid crashing on invalid const modifier (#4267) (lucab) - 641a78b parser: Fix tests for number parsing (#4254) (overlookmotel) - 9badac0 semantic: Avoid var hosting insert the var variable to the `CatchClause` scope (#4337) (Dunqing) - 95e15b6 semantic: Incorrect resolve references for `ExportSpecifier` (#4320) (Dunqing) - c362bf7 semantic: Incorrect resolve references for `TSInterfaceHeritage` (#4311) (Dunqing) - 351ecf2 semantic: Incorrect resolve references for `TSTypeQuery` (#4310) (Dunqing) - 1108f2a semantic: Resolve references to the incorrect symbol (#4280) (Dunqing) - 22d56bd semantic: Do not resolve references after `FormalParameters` in TS type (#4241) (overlookmotel)- 1c117eb Avoid print extra semicolon after accessor property (#4199) (IWANABETHATGUY) ### Performance - a8dc4f3 parser: Speed up parsing numbers with `_` separators (#4259) (overlookmotel) - b94540d parser: Speed up parsing octal literals (#4258) (overlookmotel) - a7b328c parser: Faster parsing decimal numbers (#4257) (overlookmotel) - f9d3f2e semantic: Inline ast record functions (#4272) (overlookmotel) - 8fad7db semantic: Reduce `AstNodeId` to `u32` (#4264) (overlookmotel) - 23743db semantic: Do not record ast nodes for cfg if cfg disabled (#4263) (overlookmotel) - da69076 semantic: Reduce overhead of cfg recording ast nodes (#4262) (overlookmotel) - cb15303 semantic: Reduce memory copies (#4216) (overlookmotel) - ef4c1f4 semantic: Reduce lookups (#4214) (overlookmotel) - f23e54f semantic: Recycle unresolved references hash maps (#4213) (overlookmotel) - 2602ce2 semantic: Reuse existing map of unresolved refs (#4206) (lucab) ### Refactor - 2c7bb9f ast: Pass final `ScopeFlags` into `visit_function` (#4283) (overlookmotel) - 3e099fe ast: Move `enter_scope` after `visit_binding_identifier` (#4246) (Dunqing) - aab7aaa ast/visit: Fire node events as the outermost one. (#4203) (rzvxa) - d1c4be0 codegen: Clean up annotation_comment (Boshen) - 06197b8 codegen: Separate tests (Boshen) - aa22073 codegen: Improve print API (#4196) (Boshen) - c5731a5 semantic: Remove defunct code setting ScopeFlags twice (#4286) (overlookmotel) - 16698bc semantic: Move function/class-specific code into specific visitors (#4278) (overlookmotel) - ee16668 semantic: Rename function param (#4277) (overlookmotel) - 25f0771 semantic: Alter syntax of `control_flow!` macro (#4275) (overlookmotel) - 639fd48 semantic: Comment why extra CFG enabled check (#4274) (overlookmotel) - c418bf5 semantic: Directly record `current_node_id` when adding a scope (#4265) (Dunqing) - ace4f1f semantic: Update the order of `visit_function` and `Visit` fields in the builder to be consistent (#4248) (Dunqing) - 8bfeabf semantic: Simplify adding `SymbolFlags::Export` (#4249) (Dunqing) - dc2b3c4 semantic: Add strict mode in scope flags for class definitions (#4156) (Dunqing) - 81ed588 semantic: Convert scope fields to IndexVecs (#4208) (lucab) - bbe5ded semantic: Set `current_scope_id` to `scope_id` in `enter_scope` (#4193) (Dunqing) - 7f1addd semantic: Correct scope in CatchClause (#4192) (Dunqing) - fc0b17d syntax: Turn the `AstNodeId::dummy` into a constant field. (#4308) (rzvxa) - a197e01 transformer/typescript: Remove unnecessary code (#4321) (Dunqing) - 1458d81 visit: Add `#[inline]` to empty functions (#4330) (overlookmotel) Co-authored-by: Boshen <[email protected]>
## [0.21.0] - 2024-07-18 - d7ab0b8 semantic: [**BREAKING**] Simplify node creation (#4226) (lucab) ### Features - af4dc01 ast: Align ts ast scope with typescript (#4253) (Dunqing) - 83c2c62 codegen: Add option for choosing quotes; remove slow `choose_quot` method (#4219) (Boshen) - 5d17675 mangler: Add debug mode (#4314) (Boshen) - e3e663b mangler: Initialize crate and integrate into minifier (#4197) (Boshen) - c818472 minifier: Dce conditional expression `&&` or `||` (#4190) (Boshen) - 8a190eb oxc: Export `oxc_mangler` (Boshen) - 20cdb1f semantic: Align class scope with typescript (#4195) (Dunqing) - 92ee774 semantic: Add `ScopeFlags::CatchClause` for use in CatchClause (#4205) (Dunqing) - 205c259 sourcemap: Support SourceMapBuilder#token_chunks (#4220) (underfin) - 7eb960d transformer: Decode xml character entity `&#xhhhh` and `&#nnnn;` (#4235) (Boshen) ### Bug Fixes - bf3d8d3 codegen: Print annotation comment inside parens for new and call expressions (#4290) (Boshen) - 084ab76 codegen: Use `ryu-js` for f64 to string (Boshen) - e167ef7 codegen: Print parenthesis properly (#4245) (Boshen) - c65198f codegen: Choose the right quote for jsx attribute string (#4236) (Boshen) - be82c28 codegen: Print `JSXAttributeValue::StringLiteral` directly (#4231) (Boshen) - 3df9e69 mangler: No shorthand `BindingProperty`; handle var hoisting and export variables (#4319) (Boshen) - f144082 minifier: RemoveDeadCode should visit nested expression (#4268) (underfin) - 66b455a oxc_codegen: Avoid print same pure comments multiple time (#4230) (IWANABETHATGUY) - 9a87e41 parser: Avoid crashing on invalid const modifier (#4267) (lucab) - 641a78b parser: Fix tests for number parsing (#4254) (overlookmotel) - 9badac0 semantic: Avoid var hosting insert the var variable to the `CatchClause` scope (#4337) (Dunqing) - 95e15b6 semantic: Incorrect resolve references for `ExportSpecifier` (#4320) (Dunqing) - c362bf7 semantic: Incorrect resolve references for `TSInterfaceHeritage` (#4311) (Dunqing) - 351ecf2 semantic: Incorrect resolve references for `TSTypeQuery` (#4310) (Dunqing) - 1108f2a semantic: Resolve references to the incorrect symbol (#4280) (Dunqing) - 22d56bd semantic: Do not resolve references after `FormalParameters` in TS type (#4241) (overlookmotel)- 1c117eb Avoid print extra semicolon after accessor property (#4199) (IWANABETHATGUY) ### Performance - a8dc4f3 parser: Speed up parsing numbers with `_` separators (#4259) (overlookmotel) - b94540d parser: Speed up parsing octal literals (#4258) (overlookmotel) - a7b328c parser: Faster parsing decimal numbers (#4257) (overlookmotel) - f9d3f2e semantic: Inline ast record functions (#4272) (overlookmotel) - 8fad7db semantic: Reduce `AstNodeId` to `u32` (#4264) (overlookmotel) - 23743db semantic: Do not record ast nodes for cfg if cfg disabled (#4263) (overlookmotel) - da69076 semantic: Reduce overhead of cfg recording ast nodes (#4262) (overlookmotel) - cb15303 semantic: Reduce memory copies (#4216) (overlookmotel) - ef4c1f4 semantic: Reduce lookups (#4214) (overlookmotel) - f23e54f semantic: Recycle unresolved references hash maps (#4213) (overlookmotel) - 2602ce2 semantic: Reuse existing map of unresolved refs (#4206) (lucab) ### Refactor - 2c7bb9f ast: Pass final `ScopeFlags` into `visit_function` (#4283) (overlookmotel) - 3e099fe ast: Move `enter_scope` after `visit_binding_identifier` (#4246) (Dunqing) - aab7aaa ast/visit: Fire node events as the outermost one. (#4203) (rzvxa) - d1c4be0 codegen: Clean up annotation_comment (Boshen) - 06197b8 codegen: Separate tests (Boshen) - aa22073 codegen: Improve print API (#4196) (Boshen) - c5731a5 semantic: Remove defunct code setting ScopeFlags twice (#4286) (overlookmotel) - 16698bc semantic: Move function/class-specific code into specific visitors (#4278) (overlookmotel) - ee16668 semantic: Rename function param (#4277) (overlookmotel) - 25f0771 semantic: Alter syntax of `control_flow!` macro (#4275) (overlookmotel) - 639fd48 semantic: Comment why extra CFG enabled check (#4274) (overlookmotel) - c418bf5 semantic: Directly record `current_node_id` when adding a scope (#4265) (Dunqing) - ace4f1f semantic: Update the order of `visit_function` and `Visit` fields in the builder to be consistent (#4248) (Dunqing) - 8bfeabf semantic: Simplify adding `SymbolFlags::Export` (#4249) (Dunqing) - dc2b3c4 semantic: Add strict mode in scope flags for class definitions (#4156) (Dunqing) - 81ed588 semantic: Convert scope fields to IndexVecs (#4208) (lucab) - bbe5ded semantic: Set `current_scope_id` to `scope_id` in `enter_scope` (#4193) (Dunqing) - 7f1addd semantic: Correct scope in CatchClause (#4192) (Dunqing) - fc0b17d syntax: Turn the `AstNodeId::dummy` into a constant field. (#4308) (rzvxa) - a197e01 transformer/typescript: Remove unnecessary code (#4321) (Dunqing) - 1458d81 visit: Add `#[inline]` to empty functions (#4330) (overlookmotel) Co-authored-by: Boshen <[email protected]>
related: #4142 (comment)
Although we called
enter_node(Class)
, that doesn't mean we're in theclass
scope. It causes our must to visit decorators beforeenter_node
.Let's look at this case. It causes a syntax error if we don't visit decorators before
enter_node
Errors:
The changed code makes more sense. Only if we call
enter_scope
for class, the flags will containStrictMode
. Also, we can get the exactflags
of thescope
in theclass
at the transformerFor example:
The regression tests will be fixed in follow-up PRs