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
22 changes: 20 additions & 2 deletions common/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function foo<T, U>(this: T[]): U[] {
body: (statement_block (return_statement (array)))))

==================================
Function calls with type arguments
New object with type arguments
==================================

const lines = new Array<DiffLine>()
Expand All @@ -69,7 +69,25 @@ const lines = new Array<DiffLine>()
(lexical_declaration
(variable_declarator
(identifier)
(new_expression (identifier) (type_arguments (type_identifier)) (arguments)))))
(new_expression
(identifier)
(type_arguments (type_identifier))
(arguments)))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some reformatting and new test name.


==================================
Function calls with optional chaining and type arguments
==================================

A?.<B>();

---

(program
(expression_statement
(call_expression
(identifier)
(type_arguments (type_identifier))
(arguments))))

==================================
Arrow functions and generators with call signatures
Expand Down
23 changes: 15 additions & 8 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PREC = {
NEG: 9,
INC: 10,
NON_NULL: 10,
FUNCTION_CALL: 11,
CALL: 11,
NEW: 12,
ARRAY_TYPE: 13,
MEMBER: 14,
Expand Down Expand Up @@ -91,15 +91,23 @@ module.exports = function defineGrammar(dialect) {
optional($._initializer)
),

call_expression: ($, previous) => prec(PREC.FUNCTION_CALL, seq(
field('function', choice($._expression, $.super, $.function)),
field('type_arguments', optional($.type_arguments)),
field('arguments', choice($.arguments, $.template_string))
)),
call_expression: ($, previous) => choice(
prec(PREC.CALL, seq(
field('function', $._expression),
field('type_arguments', optional($.type_arguments)),
field('arguments', choice($.arguments, $.template_string))
)),
prec(PREC.MEMBER, seq(
field('function', $._primary_expression),
'?.',
field('type_arguments', optional($.type_arguments)),
field('arguments', $.arguments)
))
),

new_expression: $ => prec.right(PREC.NEW, seq(
'new',
field('constructor', $._constructable_expression),
field('constructor', $._primary_expression),
field('type_arguments', optional($.type_arguments)),
field('arguments', optional($.arguments))
)),
Expand Down Expand Up @@ -677,7 +685,6 @@ module.exports = function defineGrammar(dialect) {
'boolean',
'string',
'symbol',
'void',
'export',
previous
),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"tree-sitter-cli": "^0.16.9",
"tree-sitter-javascript": "tree-sitter/tree-sitter-javascript"
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#3d54934"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do in terms of dependencies and versioning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This makes sense to me.

},
"scripts": {
"build": "npm run build-typescript && npm run build-tsx",
Expand Down
Loading