Skip to content

tree-sitter-javascript does not parse import-assertions. #239

Closed as not planned
@josteink

Description

@josteink

The following piece of code is valid but it is parsed incorrectly:

import testData from './testData.json' assert { type: "json" };

Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDApgZxgEQIYw3AZlCEOAcgDoB6JVTbUgK2QgDti4NllFY4BvBATzCIAXHABEDZmLgBfANwAoIA

The output of tree-sitter parse is the following:

(program [0, 0] - [1, 0]
  (import_statement [0, 0] - [0, 63]
    (import_clause [0, 7] - [0, 15]
      (identifier [0, 7] - [0, 15]))
    source: (string [0, 21] - [0, 38]
      (string_fragment [0, 22] - [0, 37]))
    (ERROR [0, 39] - [0, 62]
      (identifier [0, 39] - [0, 45])
      (identifier [0, 48] - [0, 52])
      (identifier [0, 55] - [0, 59]))))

Specification for this syntax can be found here: https://nodejs.org/api/esm.html#node-imports

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions