|
1 |
| -#include "tree_sitter/parser.h" |
2 |
| -#include <node.h> |
3 |
| -#include "nan.h" |
| 1 | +#include <napi.h> |
4 | 2 |
|
5 |
| -using namespace v8; |
| 3 | +typedef struct TSLanguage TSLanguage; |
6 | 4 |
|
7 |
| -extern "C" TSLanguage * tree_sitter_elixir(); |
| 5 | +extern "C" TSLanguage *tree_sitter_elixir(); |
8 | 6 |
|
9 |
| -namespace { |
| 7 | +// "tree-sitter", "language" hashed with BLAKE2 |
| 8 | +const napi_type_tag LANGUAGE_TYPE_TAG = { |
| 9 | + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 |
| 10 | +}; |
10 | 11 |
|
11 |
| -NAN_METHOD(New) {} |
12 |
| - |
13 |
| -void Init(Local<Object> exports, Local<Object> module) { |
14 |
| - Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); |
15 |
| - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); |
16 |
| - tpl->InstanceTemplate()->SetInternalFieldCount(1); |
17 |
| - |
18 |
| - Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked(); |
19 |
| - Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); |
20 |
| - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_elixir()); |
21 |
| - |
22 |
| - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("elixir").ToLocalChecked()); |
23 |
| - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); |
| 12 | +Napi::Object Init(Napi::Env env, Napi::Object exports) { |
| 13 | + exports["name"] = Napi::String::New(env, "elixir"); |
| 14 | + auto language = Napi::External<TSLanguage>::New(env, tree_sitter_elixir()); |
| 15 | + language.TypeTag(&LANGUAGE_TYPE_TAG); |
| 16 | + exports["language"] = language; |
| 17 | + return exports; |
24 | 18 | }
|
25 | 19 |
|
26 |
| -NODE_MODULE(tree_sitter_elixir_binding, Init) |
27 |
| - |
28 |
| -} // namespace |
| 20 | +NODE_API_MODULE(tree_sitter_elixir_binding, Init) |
0 commit comments