-
-
Notifications
You must be signed in to change notification settings - Fork 146
Description
I tried updating to tree-sitter 0.21 for our project https://github.com/dodona-edu/dolos/tree/main/parsers which builds a collection of parsers to be used in our tool. We do this by importing each parser as a submodule and using a simple binding.gyp including the gyp-files of each parser.
This worked fine with the node package of tree-sitter 0.20.6. With the latest release 0.21.0, building using node-gyp succeeds, but actually using the parser fails.
Consider the following snippet:
import { java } from "@dodona/dolos-parsers";
import { default as Parser } from "tree-sitter";
const parser = new Parser();
parser.setLanguage(java);
// throws Uncaught TypeError: Invalid language object
// at Parser.setLanguage (/home/rien/repos/dolos/node_modules/tree-sitter/index.js:338:17)Which is thrown on line 338 in index.js, calling the setLanguage function from the native tree-sitter_runtime binding:
Lines 329 to 345 in 2bdc76a
| /* | |
| * Parser | |
| */ | |
| const {parse, setLanguage} = Parser.prototype; | |
| const languageSymbol = Symbol('parser.language'); | |
| Parser.prototype.setLanguage = function(language) { | |
| if (this instanceof Parser && setLanguage) { | |
| setLanguage.call(this, language); | |
| } | |
| this[languageSymbol] = language; | |
| if (!language.nodeSubclasses) { | |
| initializeLanguageNodeClasses(language) | |
| } | |
| return this; | |
| }; |
I noticed in the commits between v0.20.6...v0.21.0 that the bindings were changed to NAPI instead of Node. I guess this might be caused by this refactor?
Does anything need to be changed to the parsers themselves to work with NAPI? Is this something that I could fix in my binding.gyp or will this require changes in the parsers?