Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ new Thing;
---

(program
(expression_statement (new_expression (call_expression
(expression_statement (new_expression
(member_expression (identifier) (property_identifier))
(arguments (number) (string)))))
(arguments (number) (string))))
(expression_statement (new_expression
(identifier))))

Expand Down Expand Up @@ -999,7 +999,7 @@ typeof a == b && c instanceof d
(expression_statement (binary_expression
(binary_expression
(identifier)
(new_expression (call_expression (identifier) (arguments (identifier)))))
(new_expression (identifier) (arguments (identifier))))
(identifier)))
(expression_statement (binary_expression
(binary_expression
Expand Down
8 changes: 4 additions & 4 deletions corpus/semicolon_insertion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ var a = new A()
(program
(variable_declaration (variable_declarator
(identifier)
(new_expression (call_expression
(call_expression
(member_expression
(call_expression
(member_expression
(call_expression (identifier) (arguments))
(new_expression (identifier) (arguments))
(property_identifier))
(arguments (object (pair (property_identifier) (string)))))
(property_identifier))
(arguments))))))
(arguments)))))

==============================================
if/for/while/do statements without semicolons
Expand Down Expand Up @@ -280,4 +280,4 @@ let d
(comment)
(comment)
(comment)
(lexical_declaration (variable_declarator (identifier))))
(lexical_declaration (variable_declarator (identifier))))
2 changes: 1 addition & 1 deletion corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ throw new Error("uh oh");

(program
(throw_statement
(new_expression (call_expression (identifier) (arguments (string))))))
(new_expression (identifier) (arguments (string)))))

============================================
Throw statements with sequence expressions
Expand Down
68 changes: 41 additions & 27 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const PREC = {
NOT: 8,
NEG: 9,
INC: 10,
NEW: 11,
CALL: 12,
CALL: 11,
NEW: 12,
MEMBER: 13
};

Expand All @@ -37,6 +37,7 @@ module.exports = grammar({
],

inline: $ => [
$._constructable_expression,
$._statement,
$._expressions,
$._semicolon,
Expand All @@ -57,6 +58,7 @@ module.exports = grammar({
[$._expression, $.arrow_function],
[$._expression, $.method_definition],
[$._expression, $.formal_parameters],
[$._expression, $.rest_parameter],
[$.labeled_statement, $._property_name],
[$.assignment_pattern, $.assignment_expression],
[$.computed_property_name, $.array],
Expand Down Expand Up @@ -386,15 +388,9 @@ module.exports = grammar({
),

_expression: $ => choice(
$.object,
$.array,
$._constructable_expression,
$._jsx_element,
$.jsx_fragment,
$.class,
$.anonymous_class,
$.function,
$.arrow_function,
$.generator_function,

$.assignment_expression,
$.augmented_assignment_expression,
Expand All @@ -404,23 +400,7 @@ module.exports = grammar({
$.ternary_expression,
$.update_expression,
$.call_expression,
$.member_expression,
$.new_expression,
$.parenthesized_expression,
$.subscript_expression,
$.yield_expression,
$.this,

$.number,
$.string,
$.template_string,
$.regex,
$.true,
$.false,
$.null,
$.undefined,
$.identifier,
alias($._reserved_identifier, $.identifier)
),

yield_expression: $ => prec.right(seq(
Expand Down Expand Up @@ -586,11 +566,43 @@ module.exports = grammar({
choice($.arguments, $.template_string)
)),

new_expression: $ => prec(PREC.NEW, seq(
new_expression: $ => prec.right(PREC.NEW, seq(
'new',
$._expression

$._constructable_expression,

optional($.arguments)
)),

_constructable_expression: $ => choice(
// Primary Expression
$.this,
$.identifier,
alias($._reserved_identifier, $.identifier),
$.number,
$.string,
$.template_string,
$.regex,
$.true,
$.false,
$.null,
$.undefined,
$.object,
$.array,
$.function,
$.arrow_function,
$.generator_function,
$.class,
$.anonymous_class,
$.parenthesized_expression,

$.subscript_expression,
$.member_expression,
$.meta_property,
$.new_expression,
),


await_expression: $ => seq(
'await',
$._expression
Expand Down Expand Up @@ -830,6 +842,8 @@ module.exports = grammar({
return token(seq(alpha, repeat(alpha_numeric)))
},

meta_property: $ => seq('new', '.', 'target'),

this: $ => 'this',
super: $ => 'super',
true: $ => 'true',
Expand Down
Loading