Skip to content

Commit

Permalink
Support new.target
Browse files Browse the repository at this point in the history
FIX: Add support for `new.target` syntax.

Issue #32
  • Loading branch information
szuend authored Apr 23, 2024
1 parent b7dd6f0 commit 49aefe8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/javascript.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ expressionNoComma {
RegExp |
ArrayExpression |
ObjectExpression { "{" commaSep<Property> ~destructure "}" } |
NewTarget { kw<"new"> "." PropertyName } |
NewExpression { kw<"new"> expressionNoComma (!newArgs TypeArgList? ArgList)? } |
UnaryExpression |
YieldExpression |
Expand Down
15 changes: 15 additions & 0 deletions test/statement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,18 @@ foo()
==>

Script(Hashbang,ExpressionStatement(CallExpression(VariableName,ArgList)))

# new.target

function MyObj() {
if (!new.target) {
throw new Error('Must construct MyObj with new');
}
}

==>

Script(
FunctionDeclaration(function,VariableDefinition,ParamList,Block(
IfStatement(if,ParenthesizedExpression(UnaryExpression(LogicOp,NewTarget(new,PropertyName))), Block(
ThrowStatement(throw,NewExpression(new,VariableName,ArgList(String))))))))

0 comments on commit 49aefe8

Please sign in to comment.