Open
Description
The following piece of code is valid but it is parsed incorrectly:
{
using resource = getResource();
}
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:
The output of tree-sitter parse
is the following:
(program [0, 0] - [3, 0]
(statement_block [0, 0] - [2, 1]
(ERROR [1, 1] - [1, 6]
(identifier [1, 1] - [1, 6]))
(expression_statement [1, 7] - [1, 32]
(assignment_expression [1, 7] - [1, 31]
left: (identifier [1, 7] - [1, 15])
right: (call_expression [1, 18] - [1, 31]
function: (identifier [1, 18] - [1, 29])
arguments: (arguments [1, 29] - [1, 31]))))))
Support for the using
keyword was added to tree-sitter-typescript in tree-sitter/tree-sitter-typescript#262, but it’s a JavaScript feature, not something TypeScript-specific, so I think it should have been added here directly instead.
ECMAScript proposal: https://github.com/tc39/proposal-explicit-resource-management
It is currently stage 3, so native support in web browsers is quite limited for now, but it is coming in Chrome 134 for instance (https://chromestatus.com/feature/5071680358842368).