Skip to content

Commit

Permalink
Add AllowNewTargetOutsideFunction option
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Mar 29, 2024
1 parent 9c9b12e commit 8be3f3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Acornima/Parser.State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ private bool AllowNewDotTarget()
{
// https://github.com/acornjs/acorn/blob/8.11.3/acorn/src/state.js > `get allowNewDotTarget`

return (CurrentThisScope(out _).Flags & (ScopeFlags.Function | ScopeFlags.ClassStaticBlock | ScopeFlags.InClassFieldInit)) != 0;
return _options.AllowNewTargetOutsideFunction
|| (CurrentThisScope(out _).Flags & (ScopeFlags.Function | ScopeFlags.ClassStaticBlock | ScopeFlags.InClassFieldInit)) != 0;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
7 changes: 7 additions & 0 deletions src/Acornima/ParserOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public EcmaVersion EcmaVersion
/// </remarks>
public bool AllowAwaitOutsideFunction { get => _allowAwaitOutsideFunction; init => _allowAwaitOutsideFunction = value; }

internal readonly bool _allowNewTargetOutsideFunction;
/// <summary>
/// Gets or sets whether to allow new.target meta-properties in the top-level scope.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool AllowNewTargetOutsideFunction { get => _allowNewTargetOutsideFunction; init => _allowNewTargetOutsideFunction = value; }

internal readonly bool _allowSuperOutsideMethod;
/// <summary>
/// Gets or sets whether to allow super identifiers to appear outside methods.
Expand Down

0 comments on commit 8be3f3a

Please sign in to comment.