GithubHelp home page GithubHelp logo

tree-sitter / tree-sitter-typescript Goto Github PK

View Code? Open in Web Editor NEW
312.0 14.0 99.0 136.23 MB

TypeScript grammar for tree-sitter

License: MIT License

Python 0.83% JavaScript 65.71% Shell 3.86% C 16.49% C++ 3.03% Scheme 2.49% Rust 6.02% TypeScript 0.05% Swift 1.52%
typescript tree-sitter parser

tree-sitter-typescript's Introduction

tree-sitter-typescript

CI discord matrix crates npm

TypeScript and TSX grammars for tree-sitter.

Because TSX and TypeScript are actually two different dialects, this module defines two grammars. Require them as follows:

require("tree-sitter-typescript").typescript; // TypeScript grammar
require("tree-sitter-typescript").tsx; // TSX grammar

For Javascript files with flow type annotations you can use the the tsx parser.

References

tree-sitter-typescript's People

Contributors

314eter avatar ahlinc avatar amaanq avatar aryx avatar darangi avatar daviwil avatar dcreager avatar guillaumebrunerie avatar hendrikvanantwerpen avatar herringtondarkholme avatar iwanabethatguy avatar joshvera avatar kevinsawicki avatar kraftwerk28 avatar luni-4 avatar mattmassicotte avatar maxbrunsfeld avatar mjambon avatar nbrahms avatar nmote avatar nullvoxpopuli avatar patrickt avatar rattrayalex avatar resolritter avatar rewinfrey avatar rmagatti avatar rtsao avatar ruricolist avatar shraymonks avatar tclem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tree-sitter-typescript's Issues

Support non-null assertion operator after array dereference

This code was found in the wild:

lastDstToken.parts[0]! += token.parts[0];

The parser is confused by the exclamation mark. A simpler test case that also fails is:

a[0]! += 2

and also

a[0]! = 2

This feature would be useful if the typescript type checker could show a warning when a[0] could be unset, causing an error when adding something to it. I haven't managed to obtain such warning in the typescript playground, so I wonder if this syntax is widely used.

Optional chaining is not supported

This was introduced in TS3.7 (and javascript... not sure which spec version).

test?.value
program [0, 0] - [1, 0])
  expression_statement [0, 0] - [0, 11])
    member_expression [0, 0] - [0, 11])
      object: identifier [0, 0] - [0, 4])
      ERROR [0, 4] - [0, 5])
      property: property_identifier [0, 6] - [0, 11])

Is this on the road map?

Split parser into JSX and non-JSX versions

Currently, code with lots of type assertions leads to a lot of ambiguity during parsing:

switch (node.kind) {
    case SyntaxKind.QualifiedName:
        return visitNode(cbNode, (<QualifiedName>node).left) ||
            visitNode(cbNode, (<QualifiedName>node).right);
    case SyntaxKind.TypeParameter:
        return visitNode(cbNode, (<TypeParameterDeclaration>node).name) ||
            visitNode(cbNode, (<TypeParameterDeclaration>node).constraint) ||
            visitNode(cbNode, (<TypeParameterDeclaration>node).default) ||
            visitNode(cbNode, (<TypeParameterDeclaration>node).expression);
    case SyntaxKind.ShorthandPropertyAssignment:
        return visitNodes(cbNode, cbNodes, node.decorators) ||
            visitNodes(cbNode, cbNodes, node.modifiers) ||
            visitNode(cbNode, (<ShorthandPropertyAssignment>node).name) ||
            visitNode(cbNode, (<ShorthandPropertyAssignment>node).questionToken) ||
            visitNode(cbNode, (<ShorthandPropertyAssignment>node).equalsToken) ||
            visitNode(cbNode, (<ShorthandPropertyAssignment>node).objectAssignmentInitializer);
    case SyntaxKind.SpreadAssignment:
        return visitNode(cbNode, (<SpreadAssignment>node).expression);
}

This is because JSX uses angle brackets as well.

The TypeScript compiler avoids this ambiguity by requiring you to use the .tsx extension if you want to use JSX in TypeScript, and forbidding these types of type assertions in .tsx files.

Similarly, Flow allows JSX but does not support the angle bracket type assertion syntax.

We should probably do the same for the sake of editing performance in Atom.

Disable automatic colon insertion before function body

This is something I noticed while testing the fix for #93.

The following code is parsed correctly by tree-sitter-javascript parser but incorrectly by tree-sitter-typescript:

function f()
{}

tree-sitter-typescript sees a function_signature followed by a statement_block:

(program [0, 0] - [2, 0]
  (function_signature [0, 0] - [0, 12]
    name: (identifier [0, 9] - [0, 10])
    parameters: (formal_parameters [0, 10] - [0, 12]))
  (statement_block [1, 0] - [1, 2]))

However, the tree-sitter-javascript implementation works fine and gives us a single function_declaration:

(program [0, 0] - [2, 0]
  (function_declaration [0, 0] - [1, 2]
    name: (identifier [0, 9] - [0, 10])
    parameters: (formal_parameters [0, 10] - [0, 12])
    body: (statement_block [1, 0] - [1, 2])))

Add support for type imports

example:

import type { MyType } from '...path...';

Today, the type is red with my editor theme, but then so is the rest of the file. It's like the parser just gives up?

Here is the playground syntax for this:

import_statement [4, 0] - [4, 85]
  import_clause [4, 12] - [4, 26]
    named_imports [4, 12] - [4, 26]
      import_specifier [4, 14] - [4, 24]
        name: identifier [4, 14] - [4, 24]
  source: string [4, 32] - [4, 84]

it looks like it doesn't actually identity the type?

Why or why not a rule for a single keyword like `readonly`?

In define-grammar.js, we have:

        choice(
          seq(optional('static'), optional($.readonly)),
          seq(optional('abstract'), optional($.readonly)),
          seq(optional($.readonly), optional('abstract')),
        ),

while the readonly rule is just defined as follows:

      readonly: $ => 'readonly',

The readonly rule is not declared as inline. Does it make a difference? Or do we use a rule for readonly because it appears in more places than static or abstract?

Support for enum union cast.

Typescript introduced a feature that lets you cast a enum into a union type which breaks all highlighting in ts typescript

issue example:

enum Currency {
  EUR = "EUR"
  DOLLAR = "DOLLAR"
}

interface SomeApiPayload {
  id: string
  currency: `${Currency}` // this is the enum to union cast feature
}

const someApiCall = () => {
 // do api call
}

the highlight should be broken at the function and everything should be displayed green under the interface now

Unable to build on Node 12+

tree-sitter-typescript fails to build for me both when I try to use it as a dependency and when I clone the repository. I have tried on both Ubuntu 19.10 with Node 13 and MacOS Catalina with Node 12.12

Build log
[5/5] ๐Ÿ”จ  Building fresh packages...
[-/8] โข€ waiting...
[-/8] โ   waiting...
[-/8] โ   waiting...
[7/8] โ   oniguruma
error /Users/nicholas/Development/blueprint/node_modules/tree-sitter-typescript: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /Users/nicholas/Development/blueprint/node_modules/tree-sitter-typescript
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn /usr/local/bin/python2
gyp info spawn args [
gyp info spawn args   '/Users/nicholas/Development/blueprint/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nicholas/Development/blueprint/node_modules/tree-sitter-typescript/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nicholas/Development/blueprint/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nicholas/.node-gyp/12.12.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/nicholas/.node-gyp/12.12.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/nicholas/Development/blueprint/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/nicholas/.node-gyp/12.12.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/nicholas/Development/blueprint/node_modules/tree-sitter-typescript',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/tree_sitter_tsx_binding/tsx/src/parser.o
  CC(target) Release/obj.target/tree_sitter_tsx_binding/tsx/src/scanner.o
  CXX(target) Release/obj.target/tree_sitter_tsx_binding/tsx/src/binding.o
../tsx/src/binding.cc:13:6: error: variable has incomplete type 'void'
void Init(Handle<Object> exports, Handle<Object> module) {
     ^
../tsx/src/binding.cc:13:11: error: use of undeclared identifier 'Handle'
void Init(Handle<Object> exports, Handle<Object> module) {
          ^
../tsx/src/binding.cc:13:18: error: 'Object' does not refer to a value
void Init(Handle<Object> exports, Handle<Object> module) {
                 ^
/Users/nicholas/.node-gyp/12.12.0/include/node/v8.h:3400:17: note: declared here
class V8_EXPORT Object : public Value {
                ^
../tsx/src/binding.cc:13:26: error: use of undeclared identifier 'exports'
void Init(Handle<Object> exports, Handle<Object> module) {
                         ^
../tsx/src/binding.cc:13:35: error: use of undeclared identifier 'Handle'
void Init(Handle<Object> exports, Handle<Object> module) {
                                  ^
../tsx/src/binding.cc:13:42: error: 'Object' does not refer to a value
void Init(Handle<Object> exports, Handle<Object> module) {
                                         ^
/Users/nicholas/.node-gyp/12.12.0/include/node/v8.h:3400:17: note: declared here
class V8_EXPORT Object : public Value {
                ^
../tsx/src/binding.cc:13:50: error: use of undeclared identifier 'module'
void Init(Handle<Object> exports, Handle<Object> module) {
                                                 ^
../tsx/src/binding.cc:13:57: error: expected ';' after top level declarator
void Init(Handle<Object> exports, Handle<Object> module) {
                                                        ^
                                                        ;
8 errors generated.
make: *** [Release/obj.target/tree_sitter_tsx_binding/tsx/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/nicholas/Development/blueprint/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.0.0
gyp ERR! command "/usr/local/Cellar/node/12.12.0/bin/node" "/Users/nicholas/Development/blueprint/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/nicholas/Development/blueprint/node_modules/tree-sitter-typescript

palantir/blueprint#3799

User-defined type guards don't allow 'this'

The following code is valid, but the parser doesn't like the this in this is Foo<number>:

class Foo<T> {
    bar = 42;
    test(): this is Foo<number> {
      return typeof this.bar === 'number';
  }
}

view in typescript playground

For comparison, the following works:

class Foo<T> {
    bar = 42;
    test(): baz is Foo<number> {
        //  ^^^
      return typeof this.bar === 'number';
  }
}

[Question] Should we reuse `highlights.scm`?

I know people are able to write javascript inside a typescript file. Should people load JavaScript's hightlights.scm file for a TypeScript file? Or should we just load scheme file separately for each language?

  • file.ts -> load ts/highlights.scm and js/highlights.scm
  • file.js -> load js/highlights.scm

or

  • file.ts -> load ts/highlights.scm
  • file.js -> load js/highlights.scm

Parse error with a special kind of function

When I parsed this code with tree-sitter-typescript v0.19

  close(): Promise {
    if (this._closed) return Promise.resolve();
    if (this._tempDirectory) {
      this.kill();
    } else if (this.connection) {
      // Attempt to close the browser gracefully
      this.connection.send('Browser.close').catch((error) => {
        debugError(error);
        this.kill();
      });
    }
    // Cleanup this listener last, as that makes sure the full callback runs. If we
    // perform this earlier, then the previous function calls would not happen.
    helper.removeEventListeners(this._listeners);
    return this._processClosing;
  };

I got this AST:

(program [0, 2] - [16, 0]
  (ERROR [0, 2] - [0, 18]
    (call_expression [0, 2] - [0, 9]
      function: (identifier [0, 2] - [0, 7])
      arguments: (arguments [0, 7] - [0, 9]))
    (identifier [0, 11] - [0, 18]))
  (statement_block [0, 19] - [15, 3]
    (if_statement [1, 4] - [1, 47]
      condition: (parenthesized_expression [1, 7] - [1, 21]
        (member_expression [1, 8] - [1, 20]
          object: (this [1, 8] - [1, 12])
          property: (property_identifier [1, 13] - [1, 20])))
      consequence: (return_statement [1, 22] - [1, 47]
        (call_expression [1, 29] - [1, 46]
          function: (member_expression [1, 29] - [1, 44]
            object: (identifier [1, 29] - [1, 36])
            property: (property_identifier [1, 37] - [1, 44]))
          arguments: (arguments [1, 44] - [1, 46]))))
    (if_statement [2, 4] - [10, 5]
      condition: (parenthesized_expression [2, 7] - [2, 28]
        (member_expression [2, 8] - [2, 27]
          object: (this [2, 8] - [2, 12])
          property: (property_identifier [2, 13] - [2, 27])))
      consequence: (statement_block [2, 29] - [4, 5]
        (expression_statement [3, 6] - [3, 18]
          (call_expression [3, 6] - [3, 17]
            function: (member_expression [3, 6] - [3, 15]
              object: (this [3, 6] - [3, 10])
              property: (property_identifier [3, 11] - [3, 15]))
            arguments: (arguments [3, 15] - [3, 17]))))
      alternative: (else_clause [4, 6] - [10, 5]
        (if_statement [4, 11] - [10, 5]
          condition: (parenthesized_expression [4, 14] - [4, 31]
            (member_expression [4, 15] - [4, 30]
              object: (this [4, 15] - [4, 19])
              property: (property_identifier [4, 20] - [4, 30])))
          consequence: (statement_block [4, 32] - [10, 5]
            (comment [5, 6] - [5, 48])
            (expression_statement [6, 6] - [9, 9]
              (call_expression [6, 6] - [9, 8]
                function: (member_expression [6, 6] - [6, 49]
                  object: (call_expression [6, 6] - [6, 43]
                    function: (member_expression [6, 6] - [6, 26]
                      object: (member_expression [6, 6] - [6, 21]
                        object: (this [6, 6] - [6, 10])
                        property: (property_identifier [6, 11] - [6, 21]))
                      property: (property_identifier [6, 22] - [6, 26]))
                    arguments: (arguments [6, 26] - [6, 43]
                      (string [6, 27] - [6, 42])))
                  property: (property_identifier [6, 44] - [6, 49]))
                arguments: (arguments [6, 49] - [9, 8]
                  (arrow_function [6, 50] - [9, 7]
                    parameters: (formal_parameters [6, 50] - [6, 57]
                      (required_parameter [6, 51] - [6, 56]
                        (identifier [6, 51] - [6, 56])))
                    body: (statement_block [6, 61] - [9, 7]
                      (expression_statement [7, 8] - [7, 26]
                        (call_expression [7, 8] - [7, 25]
                          function: (identifier [7, 8] - [7, 18])
                          arguments: (arguments [7, 18] - [7, 25]
                            (identifier [7, 19] - [7, 24]))))
                      (expression_statement [8, 8] - [8, 20]
                        (call_expression [8, 8] - [8, 19]
                          function: (member_expression [8, 8] - [8, 17]
                            object: (this [8, 8] - [8, 12])
                            property: (property_identifier [8, 13] - [8, 17]))
                          arguments: (arguments [8, 17] - [8, 19]))))))))))))
    (comment [11, 4] - [11, 83])
    (comment [12, 4] - [12, 79])
    (expression_statement [13, 4] - [13, 49]
      (call_expression [13, 4] - [13, 48]
        function: (member_expression [13, 4] - [13, 31]
          object: (identifier [13, 4] - [13, 10])
          property: (property_identifier [13, 11] - [13, 31]))
        arguments: (arguments [13, 31] - [13, 48]
          (member_expression [13, 32] - [13, 47]
            object: (this [13, 32] - [13, 36])
            property: (property_identifier [13, 37] - [13, 47])))))
    (return_statement [14, 4] - [14, 32]
      (member_expression [14, 11] - [14, 31]
        object: (this [14, 11] - [14, 15])
        property: (property_identifier [14, 16] - [14, 31])))))

`jsx_opening_element` with if-else inside of it can't be queried properly

Example code

export function Button() {
  return (
    <button
      className={style.className}
      onClick={function () {
        if (activeTheme == "light") {
          updateTheme(themes.dark)
        } else {
          updateTheme(themes.light)
        }
      }}
    >
      Change the theme
    </button>
    </>
  )
}

Given the following query

(jsx_opening_element
 "<" @operator
 ">" @operator)

The query weirdly yields no matches for the <button> element due to the if-else function inside of the onClick attribute. Removing the else statement seems to fix the problem.

EDIT: Seems to be a more general problem with any two or more expressions inside of the function's body.

i.e.

      onClick={function () {
        const activeTheme = getActiveTheme()
        if (activeTheme == "light") {
          updateTheme(themes.dark)
        }
      }}

also reproduces in the same problem

Support for readonly array types

Readonly arrays appear to be popular, and they're not supported by tree-sitter-typescript. See this page where I gathered various parse errors and tried to identify the most frequent ones.

type matrix = readonly number[][]

is equivalent to

type matrix = readonly (number[])[]

I gave it a try yesterday and ran into difficulties with precedences.

keyof [generic_type] not covered

Given the following valid TypeScript code

export type Extracted = keyof Pick<Base, "id">

Yields the s-expression below

(program [0, 0] - [1, 0])
  export_statement [0, 0] - [0, 34])
    declaration: type_alias_declaration [0, 7] - [0, 34])
      name: type_identifier [0, 12] - [0, 21])
      value: index_type_query [0, 24] - [0, 34])
        type_identifier [0, 30] - [0, 34])
      MISSING ; [0, 34] - [0, 34])
  ERROR [0, 34] - [0, 46])
    type_arguments [0, 34] - [0, 46])
      type_identifier [0, 35] - [0, 39])
      literal_type [0, 41] - [0, 45])
        string [0, 41] - [0, 45])

My idea for fixing it is as follows

      index_type_query: $ => seq(
        'keyof',
        choice($.generic_type, $._type_identifier, $.nested_type_identifier)
      ),

which generates a conflict. Between the two possible interpretations

Possible interpretations:

  1:  _expression  'as'  'keyof'  (generic_type  identifier  โ€ข  type_arguments)
  2:  _expression  'as'  (index_type_query  'keyof'  identifier)  โ€ข  '<'  โ€ฆ

I believe the second one is invalid, as I don't think keys can be parameterized further.

JSX parse error with multi-line attribute

@UltimateBeaver pointed out on a Semantic issue that we have problems with multi-line attribute spans in TSX tags. An example:

export default function SelectionEvents() {
  return (
    <FixtureSet
      title="Selection Restoration"
      description="selection state before commits and then restoring it afterwards.">
      <ReorderedInputsTestCase />
      <OnSelectEventTestCase />
    </FixtureSet>
  );
}

Incorrect precedence in 'typeof' indexed access type

The type expression typeof ar[number] should be parsed as (typeof ar)[number], not as typeof (ar[number]).
Here's a valid typescript snippet according to the typescript playground:

const ar = ['a', 'b'] as const;
type Elt = typeof ar[number];
const x: Elt = 'a';

The following snippet gets parsed incorrectly by tree-sitter-typescript:

type Elt = typeof ar[number];

It gives:

(program
  (comment)
  (type_alias_declaration
    (type_identifier)
    (type_query (subscript_expression (identifier) (identifier)))))

The last line should be more like:

    (subscript_expression (type_query (identifier)) (identifier)))))

I think the expected output is this, based on what we get when using parentheses:

(program
  (comment)
  (type_alias_declaration
    (type_identifier)
    (lookup_type
      (type_query (identifier))
      (predefined_type))))

newline before leading brace breaks function_declaration

With tree-sitter-typescript version 0.16.1 parses this as a (function_declaration):

function foo() {}

But does not parse as a (function_declaration):

function foo()
{}

Does not occur with (function) or (method_definition)

Screen Shot 2021-01-28 at 7 09 52 PM

Can't parse `keyof (ObjectType[Lookup])`

Typescript exhibits the following behavior:

type O = { [key: number]: { [key: string]: boolean } }
type NA = keyof (O[number]);          // Returns "string | number"
type NB = (keyof O)[number];          // Throws errors

But tree-sitter succeeds in parsing only the second "keyof" line:

$ tree-sitter parse <(echo 'type Foo = keyof (my_obj[number]);')
(program [0, 0] - [1, 0]
  (type_alias_declaration [0, 0] - [0, 34]
    name: (type_identifier [0, 5] - [0, 8])
    (ERROR [0, 11] - [0, 16])
    value: (parenthesized_type [0, 17] - [0, 33]
      (lookup_type [0, 18] - [0, 32]
        (type_identifier [0, 18] - [0, 24])
        (predefined_type [0, 25] - [0, 31])))))
/dev/fd/11	0 ms	(ERROR [0, 11] - [0, 16])
$ tree-sitter parse <(echo 'type Foo = (keyof my_obj)[number];')
(program [0, 0] - [1, 0]
  (type_alias_declaration [0, 0] - [0, 34]
    name: (type_identifier [0, 5] - [0, 8])
    value: (lookup_type [0, 11] - [0, 33]
      (parenthesized_type [0, 11] - [0, 25]
        (index_type_query [0, 12] - [0, 24]
          (type_identifier [0, 18] - [0, 24])))
      (predefined_type [0, 26] - [0, 32]))))

TSX Todo and JSDOC Params not highlighted

On a TSX file the JSDOC params are not highlighted

example:

/**
 * TODO im not highlighted
 * @see im also not highlighted
 * @param not highlighted :(
 */
const Component = () => {
 return <>broken</>
}

Parenthesized casted expression gets misinterpreted as JSX tag in TSX grammar

Code

const foo = (<any>1)

Output

(program [0, 0] - [3, 0]
  (comment [0, 0] - [0, 10])
  (ERROR [2, 0] - [3, 0]
    (identifier [2, 4] - [2, 5])
    (jsx_opening_element [2, 9] - [2, 14]
      name: (identifier [2, 10] - [2, 13]))
    (jsx_text [2, 14] - [3, 0])))
foo.tsx	0 ms	(ERROR [2, 0] - [3, 0])

Expectation

Should parse correctly, as the TypeScript grammar does

Improve TypeScript ?

Hello,

I've been trying to use tree-sitter with One Monokai theme.
Basically, what I do, is turn tree-sitter on, my colors are gone, and I turn it off. I don't know if there are too many tokens/scopes not being reported or if the theme doesn't support them ("one monokai" doesn't support variable scope - I added one locally but then almost everything turned that color).

Here is a screenshot what TS in tree-sitter looks like:

Bildschirmfoto 2019-08-10 um 11 45 36

Things that make me odd:

  • The boolean and nullish constants are in a color, that one monokai is using for either invalid or numeric scopes
  • property names and method names receive no highlighting, which makes navigating with visual cues quite hard

"Abstract classes" test fails on master branch + how can I help?

Hey @maxbrunsfeld and team + @resolritter,

I see that @resolritter has made many contributions in the last quarter, thank you, this will be of great value to us in semgrep! I would like to help make further progress as well. I noticed the following:

  • the master branch fails to pass the test "Abstract classes" despite using a recent tree-sitter-javascript.
  • several PRs made by @resolritter would be very valuable once merged but haven't been reviewed yet (#115, #124, #125, #126).

I can help with any of these, I have a couple of days. Please let me know if there's something I can be most helpful with. Otherwise I'll start with looking into the broken build/test.

Martin

Incorrect semicolon insertion for method with brace on separate line

One of the dev teams I work with has identified an issue when tree-sitter attempts to parse typescript. If an opening curly brace is on the next line for a class method declaration, there are parsing errors:

class Foo {
  public bar()
  {
  }
}

Once the team switched to using :

class Foo {
    public bar() {
    }
}

Parser struggles to parse object_type in interface_declaration

I don't think it's a major issue, but it seems that if a call_signature is used after another type. The parser cannot recognize that a call_signature exists.

For example,

interface A {
  /**
   * description
   */
  func (x: string): void
  /**
   * description
   */
  (x: string): void
}

outputs

[ SyntaxNode {
  type: comment,
  startPosition: {row: 9, column: 2},
  endPosition: {row: 11, column: 5},
  childCount: 0,
},
  SyntaxNode {
  type: method_signature,
  startPosition: {row: 12, column: 2},
  endPosition: {row: 12, column: 24},
  childCount: 2,
},
  SyntaxNode {
  type: comment,
  startPosition: {row: 13, column: 2},
  endPosition: {row: 15, column: 5},
  childCount: 0,
} ]

If the call_signature is defined first then the parser would parse correctly:

interface A {
  /**
   * description
   */
  (x: string): void
  /**
   * description
   */
  func (x: string): void

}

outputs

[ SyntaxNode {
  type: comment,
  startPosition: {row: 9, column: 2},
  endPosition: {row: 11, column: 5},
  childCount: 0,
},
  SyntaxNode {
  type: call_signature,
  startPosition: {row: 12, column: 2},
  endPosition: {row: 12, column: 19},
  childCount: 2,
},
  SyntaxNode {
  type: comment,
  startPosition: {row: 13, column: 2},
  endPosition: {row: 15, column: 5},
  childCount: 0,
},
  SyntaxNode {
  type: method_signature,
  startPosition: {row: 16, column: 2},
  endPosition: {row: 16, column: 24},
  childCount: 2,
} ]

Another interesting thing to note is that if a comma was added after the method_definition, then the parser would parse correctly.

I'm currently using VSCode and it doesn't warn me about the order properties are defined so I'm sure its syntactically correct.

Support labeled tuple elements

Labeled tuple elements are a feature of typescript 4.0.

type t = [a: string, b: number]

Labels are for documentation purposes only. If I understand correctly, they're not used to create or destructure tuple values.

All tuple elements must have a label, but we can be more flexible and accept some unlabeled elements if that makes the grammar simpler.

Conditional types fail to parse

Given this piece of code

type A<T, B> = T extends B ? B : never 

I get this resulting tree

program [0, 0] - [1, 0])
  type_alias_declaration [0, 0] - [0, 16])
    name: type_identifier [0, 5] - [0, 6])
    type_parameters: type_parameters [0, 6] - [0, 12])
      type_parameter [0, 7] - [0, 8])
        type_identifier [0, 7] - [0, 8])
      type_parameter [0, 10] - [0, 11])
        type_identifier [0, 10] - [0, 11])
    value: type_identifier [0, 15] - [0, 16])
    MISSING ; [0, 16] - [0, 16])
  expression_statement [0, 17] - [0, 38])
    ternary_expression [0, 17] - [0, 38])
      condition: identifier [0, 17] - [0, 24])
      ERROR [0, 25] - [0, 26])
        identifier [0, 25] - [0, 26])
      consequence: identifier [0, 29] - [0, 30])
      alternative: identifier [0, 33] - [0, 38])

Is this feature unsupported and need to be implemented? If so, I can take a stab at adding it.

Support types of the form 'keyof typeof foo'

The parser fails on the combination of keyof and typeof below:

const obj = { a: 42, b: "abc" }
type keys = keyof typeof obj

A simpler keyof works:

type t = { a: number, b: string }
type keys = keyof t

A simple typeof also works:

const obj = { a: 42, b: "abc" }
type t = typeof obj

TSX Attribute Interpolation On Newline Causes Parse Issue

When writing a React component using TSX if you have an attribute on a newline and use interpolation it seems to cause issues with the parser. I have found that backticks without interpolation are fine, as is using interpolation on an inline attribute. The variable inside the interpolated string is not highlighted correctly as is the rest of the file.

This style is common especially if using ESLint rules that force line length limitations and consistent attribute formatting. Furthermore interpolation in an attribute like this can be correctly compiled so it should be highlighted correctly.

Let me know if you need more information about this issue happy to provide any info you like.

Attribute on newline:
image

Inline attribute
image

Query time is much worse if grammar is generated with tree-sitter-cli > 0.16.9

I'm opening the issue here, specifically, because I'm not seeing such drastic slowdown with other grammars (i.e. they apparently have similar query performance regardless of the version).

I have this huge and really repetitive query which I use for querying identifiers inside specific constructs. When generating the grammar with tree-sitter-cli > 0.16.9, the timings get much worse. I've observed that it's not related to the file size, nor due to how complex the file is, nor due to recent commits in this repository... After experimenting a bit, my gut impression is that "query optimization" got worse > 0.16.9 - the timings stay pretty much the same between different versions if I remove the deeply-nested s-expressions.

ts_query
(function_declaration
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (shorthand_property_identifier) @identifier))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter ((array_pattern
      (identifier) @identifier)))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter ((array_pattern
      (identifier) @identifier)))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter ((array_pattern
      (identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter ((array_pattern
      (identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter ((array_pattern
      (identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* ((identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter ((array_pattern
      (identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* ((identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* ((identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* ((identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (array_pattern (* (* (* (* ((identifier) @identifier)))))))))
(function_declaration
    parameters: (formal_parameters
      (required_parameter (identifier) @identifier)))
(function_declaration
    parameters: (formal_parameters
      (optional_parameter (identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters
      (required_parameter (identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters
      (optional_parameter (identifier) @identifier)))
(for_in_statement
  left: (object_pattern
  (shorthand_property_identifier) @identifier))
(for_in_statement
  left: (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))
(for_in_statement
  left: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))
(for_in_statement
  left: (identifier) @identifier)
(assignment_expression
  left: (identifier) @identifier)
(import_statement
  (import_clause
    (named_imports
      (import_specifier
        name: (identifier) @identifier))))
(import_statement
  (import_clause
    (named_imports
      (import_specifier
        alias: (identifier) @identifier))))
(import_statement
  (import_clause
    (identifier) @identifier))
(variable_declarator
  name: (object_pattern
  (shorthand_property_identifier) @identifier))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (identifier) @identifier)))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (identifier) @identifier)))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (identifier) @identifier)))))))
(variable_declarator
  name: ((array_pattern
      (identifier) @identifier)))
(variable_declarator
  name: (array_pattern (* ((shorthand_property_identifier) @identifier))))
(variable_declarator
  name: (array_pattern (* ((identifier) @identifier))))
(variable_declarator
  name: (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))
(variable_declarator
  name: (array_pattern (* (* ((identifier) @identifier)))))
(variable_declarator
  name: (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))
(variable_declarator
  name: (array_pattern (* (* (* ((identifier) @identifier))))))
(variable_declarator
  name: (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))
(variable_declarator
  name: (array_pattern (* (* (* (* ((identifier) @identifier)))))))
(variable_declarator
  name: (identifier) @identifier)
(function_declaration name: (identifier) @identifier)
(namespace_import (identifier) @identifier)
((type_identifier) @identifier)
(object_pattern
  (pair
    value: (identifier) @identifier))
(labeled_statement
  label: (statement_identifier) @identifier)

For the following timings, I'm running the above query against the React Typings (source) which has 3169 lines.

If it's generated with tree-sitter 0.16.9 (12341dbbc03075e0b3bdcbf05191efbac78731fe)

time ../node_modules/.bin/tree-sitter query ts_query react.d.ts
real	0m0.068s
user 0m0.053s
sys	0m0.014s

If it's generated with tree-sitter 0.17.0 (b6fba7ca4c32207fa9b387b594a8da2ff66ee4be) (and above)

time ../node_modules/.bin/tree-sitter query ts_query react.d.ts
real	0m0.492s
user 0m0.473s
sys	0m0.017s

Earlier it was mentioned

I'm not seeing such drastic slowdown with other grammars (i.e. they apparently behave up to par regardless of the version).

On that note, I here's a query very similar to the one posted above, but for JavaScript instead

js_query
(function_declaration
    parameters: (formal_parameters (object_pattern
  (shorthand_property_identifier) @identifier)))
(function_declaration
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier)))))
(function_declaration
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier)))))))))
(function
    parameters: (formal_parameters (object_pattern
  (shorthand_property_identifier) @identifier)))
(function
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier)))))
(function
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier)))))))))
(arrow_function
    parameters: (formal_parameters (object_pattern
  (shorthand_property_identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier)))))))))
(function_declaration
    parameters: (formal_parameters ((array_pattern
      (identifier) @identifier))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* ((shorthand_property_identifier) @identifier)))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* ((identifier) @identifier)))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* ((shorthand_property_identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* ((identifier) @identifier))))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* (* ((shorthand_property_identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* (* ((identifier) @identifier)))))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters (array_pattern (* (* (* (* ((identifier) @identifier))))))))
(function
    parameters: (formal_parameters ((array_pattern
      (identifier) @identifier))))
(function
    parameters: (formal_parameters (array_pattern (* ((shorthand_property_identifier) @identifier)))))
(function
    parameters: (formal_parameters (array_pattern (* ((identifier) @identifier)))))
(function
    parameters: (formal_parameters (array_pattern (* (* ((shorthand_property_identifier) @identifier))))))
(function
    parameters: (formal_parameters (array_pattern (* (* ((identifier) @identifier))))))
(function
    parameters: (formal_parameters (array_pattern (* (* (* ((shorthand_property_identifier) @identifier)))))))
(function
    parameters: (formal_parameters (array_pattern (* (* (* ((identifier) @identifier)))))))
(function
    parameters: (formal_parameters (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier))))))))
(function
    parameters: (formal_parameters (array_pattern (* (* (* (* ((identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters ((array_pattern
      (identifier) @identifier))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* ((shorthand_property_identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* ((identifier) @identifier)))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* ((shorthand_property_identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* ((identifier) @identifier))))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* (* ((shorthand_property_identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* (* ((identifier) @identifier)))))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier))))))))
(arrow_function
    parameters: (formal_parameters (array_pattern (* (* (* (* ((identifier) @identifier))))))))
(function_declaration
    parameters: (formal_parameters (identifier) @identifier))
(function
    parameters: (formal_parameters (identifier) @identifier))
(arrow_function
    parameters: (formal_parameters (identifier) @identifier))
(function_declaration
    parameters: (formal_parameters (rest_parameter
  (identifier) @identifier)))
(function
    parameters: (formal_parameters (rest_parameter
  (identifier) @identifier)))
(arrow_function
    parameters: (formal_parameters (rest_parameter
  (identifier) @identifier)))
(for_in_statement
  left: (object_pattern
  (shorthand_property_identifier) @identifier))
(for_in_statement
  left: (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))
(for_in_statement
  left: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))
(for_in_statement
  left: (identifier) @identifier)
(assignment_expression
  left: (identifier) @identifier)
(import_statement
  (import_clause
    (named_imports
      (import_specifier
        name: (identifier) @identifier))))
(import_statement
  (import_clause
    (named_imports
      (import_specifier
        alias: (identifier) @identifier))))
(import_statement
  (import_clause
    (identifier) @identifier))
(variable_declarator
  name: (object_pattern
  (shorthand_property_identifier) @identifier))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (shorthand_property_identifier) @identifier))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (object
              (shorthand_property_identifier) @identifier))))))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (identifier) @identifier)))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (identifier) @identifier)))))
(variable_declarator
  name: (object_pattern
  (pair
    value: (object
      (pair
        value: (object
          (pair
            value: (identifier) @identifier)))))))
(variable_declarator
  name: ((array_pattern
      (identifier) @identifier)))
(variable_declarator
  name: (array_pattern (* ((shorthand_property_identifier) @identifier))))
(variable_declarator
  name: (array_pattern (* ((identifier) @identifier))))
(variable_declarator
  name: (array_pattern (* (* ((shorthand_property_identifier) @identifier)))))
(variable_declarator
  name: (array_pattern (* (* ((identifier) @identifier)))))
(variable_declarator
  name: (array_pattern (* (* (* ((shorthand_property_identifier) @identifier))))))
(variable_declarator
  name: (array_pattern (* (* (* ((identifier) @identifier))))))
(variable_declarator
  name: (array_pattern (* (* (* (* ((shorthand_property_identifier) @identifier)))))))
(variable_declarator
  name: (array_pattern (* (* (* (* ((identifier) @identifier)))))))
(variable_declarator
  name: (identifier) @identifier)
(class_declaration name: (identifier) @identifier)
(function_declaration name: (identifier) @identifier)
(namespace_import (identifier) @identifier)
(object_pattern
  (pair
    value: (identifier) @identifier))
(labeled_statement
  label: (statement_identifier) @identifier)

I did the same experiment running js_query against d3.js' source code (source) which has 19540 lines. In this case, regardless of the tree-sitter-cli version used, the timings are pretty much the same.

time ./node_modules/.bin/tree-sitter query js_query d3.js

real	0m0.252s
user 0m0.211s
sys	0m0.040s

To summarize, I'm noticing a strange behavior where (apparently only) this grammar, specifically, runs queries much slower if it's generated with tree-sitter-cli > 0.16.9.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.