Skip to content

Commit 8be3f3a

Browse files
committed
Add AllowNewTargetOutsideFunction option
1 parent 9c9b12e commit 8be3f3a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Acornima/Parser.State.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ private bool AllowNewDotTarget()
298298
{
299299
// https://github.com/acornjs/acorn/blob/8.11.3/acorn/src/state.js > `get allowNewDotTarget`
300300

301-
return (CurrentThisScope(out _).Flags & (ScopeFlags.Function | ScopeFlags.ClassStaticBlock | ScopeFlags.InClassFieldInit)) != 0;
301+
return _options.AllowNewTargetOutsideFunction
302+
|| (CurrentThisScope(out _).Flags & (ScopeFlags.Function | ScopeFlags.ClassStaticBlock | ScopeFlags.InClassFieldInit)) != 0;
302303
}
303304

304305
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Acornima/ParserOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public EcmaVersion EcmaVersion
8787
/// </remarks>
8888
public bool AllowAwaitOutsideFunction { get => _allowAwaitOutsideFunction; init => _allowAwaitOutsideFunction = value; }
8989

90+
internal readonly bool _allowNewTargetOutsideFunction;
91+
/// <summary>
92+
/// Gets or sets whether to allow new.target meta-properties in the top-level scope.
93+
/// Defaults to <see langword="false"/>.
94+
/// </summary>
95+
public bool AllowNewTargetOutsideFunction { get => _allowNewTargetOutsideFunction; init => _allowNewTargetOutsideFunction = value; }
96+
9097
internal readonly bool _allowSuperOutsideMethod;
9198
/// <summary>
9299
/// Gets or sets whether to allow super identifiers to appear outside methods.

0 commit comments

Comments
 (0)