File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,14 @@ private bool CanAwait
272272 }
273273 }
274274
275+ private bool AllowReturn
276+ {
277+ // https://github.com/acornjs/acorn/blob/2e1550534005a8d02030df99e20f06c0392ac28b/acorn/src/state.js > `get allowReturn`
278+
279+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
280+ get => InFunction || ( _options . AllowReturnOutsideFunction && ( CurrentVarScope . _flags & ScopeFlags . Top ) != 0 ) ;
281+ }
282+
275283 private bool AllowSuper
276284 {
277285 // https://github.com/acornjs/acorn/blob/8.11.3/acorn/src/state.js > `get allowSuper`
Original file line number Diff line number Diff line change @@ -743,7 +743,7 @@ private ReturnStatement ParseReturnStatement(in Marker startMarker)
743743 {
744744 // https://github.com/acornjs/acorn/blob/8.11.3/acorn/src/statement.js > `pp.parseReturnStatement = function`
745745
746- if ( ! _options . _allowReturnOutsideFunction && ! InFunction )
746+ if ( ! AllowReturn )
747747 {
748748 // Raise(_tokenizer._start, "'return' outside of function"); // original acornjs error reporting
749749 Raise ( _tokenizer . _start , IllegalReturn ) ;
Original file line number Diff line number Diff line change @@ -2278,6 +2278,18 @@ public void ShouldDisallowImportKeywordInYieldExpression(string sourceType)
22782278 Assert . Throws < SyntaxErrorException > ( ( ) => parseAction ( parser , code ) ) ;
22792279 }
22802280
2281+ [ Fact ]
2282+ public void ShouldDisallowReturnInClassStaticBlock ( )
2283+ {
2284+ var parser = new Parser ( new ParserOptions
2285+ {
2286+ AllowReturnOutsideFunction = true ,
2287+ } ) ;
2288+
2289+ var ex = Assert . Throws < SyntaxErrorException > ( ( ) => parser . ParseScript ( "class X { static { return; } }" ) ) ;
2290+ Assert . Equal ( "Illegal return statement" , ex . Description ) ;
2291+ }
2292+
22812293 [ Theory ]
22822294 [ InlineData ( "as" ) ]
22832295 [ InlineData ( "do" ) ]
You can’t perform that action at this time.
0 commit comments