Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Node 19 and 20 #127

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
environment:
NODEJS_VERSION: "10"
NODEJS_VERSION: "16"
PREBUILD_UPLOAD:
secure: oNyyLE7/Oq3TUGZPz6DkLFPUuQzc8FiFS1iuPp7LZ2fyOP/UF4Np4NzJmWcXVyY/

platform:
- x64
- x86

image: Ubuntu

stack: node 16, python 3.10

install:
- ps: Install-Product node $env:NODEJS_VERSION $env:Platform
- git submodule update --init --recursive
- npm install

Expand Down
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
]
}
],
'variables': { 'runtime%': 'node' },
'variables': {
'runtime%': 'node',
'openssl_fips': '',
},
'conditions': [
['runtime=="electron"', { 'defines': ['NODE_RUNTIME_ELECTRON=1'] }],
]
Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@
"main": "index.js",
"types": "tree-sitter.d.ts",
"dependencies": {
"nan": "^2.14.0",
"prebuild-install": "^6.0.1"
"nan": "^2.17.0",
"prebuild-install": "^7.1.1"
},
"devDependencies": {
"@types/node": "^14.14.31",
"chai": "^4.3.3",
"mocha": "^8.3.1",
"prebuild": "^10.0.1",
"superstring": "^2.4.2",
"@types/node": "^18.14.6",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"node-gyp": "9.3.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't strictly necessary but it lets you run the project with Python 3.11

See prebuild/prebuild#286 (comment)

"prebuild": "^11.0.4",
"superstring": "^2.4.4",
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
},
"overrides": {
"prebuild": {
"node-gyp": "$node-gyp"
}
},
"scripts": {
"install": "prebuild-install || node-gyp rebuild",
"build": "node-gyp build",
"prebuild": "prebuild -r electron -t 3.0.0 -t 4.0.0 -t 4.0.4 -t 5.0.0 --strip && prebuild -t 10.12.0 -t 12.13.0 --strip",
"prebuild": "prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 23.0.0 --strip && prebuild -t 14.0.0 -t 16.0.0 -t 18.0.0 -t 20.0.0 --strip",
"prebuild:upload": "prebuild --upload-all",
"test": "mocha"
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void InitConversions(Local<Object> exports) {
v8::Local<v8::Object> bufferView;
bufferView = node::Buffer::New(Isolate::GetCurrent(), point_transfer_buffer, 0, 2 * sizeof(uint32_t)).ToLocalChecked();
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
#elif V8_MAJOR_VERSION >= 8
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced in 8.3.9 v8/v8@5cf02f0

auto backing_store = ArrayBuffer::NewBackingStore(point_transfer_buffer, 2 * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
Expand Down
14 changes: 12 additions & 2 deletions src/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) {

Local<Value> argv[3] = { name, params, type_name };
TryCatch try_catch(Isolate::GetCurrent());
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);

#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Nan::Call(fn, fn->GetCreationContext().ToLocalChecked()->Global(), 3, argv);
#else
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
#endif
if (try_catch.HasCaught()) {
Local<Value> log_argv[2] = {
Nan::New("Error in debug callback:").ToLocalChecked(),
try_catch.Exception()
};

Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());

#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->GetCreationContext().ToLocalChecked()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
#else
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
#endif
Local<Function> error_fn = Local<Function>::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked());
Nan::Call(error_fn, console, 2, log_argv);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static inline void setup_transfer_buffer(uint32_t node_count) {
v8::Local<v8::Object> bufferView;
bufferView = node::Buffer::New(Isolate::GetCurrent(), transfer_buffer, 0, transfer_buffer_length * sizeof(uint32_t)).ToLocalChecked();
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
#elif V8_MAJOR_VERSION >= 8
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
auto backing_store = ArrayBuffer::NewBackingStore(transfer_buffer, transfer_buffer_length * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
Expand Down
12 changes: 10 additions & 2 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class CallbackInput {
uint32_t utf16_unit = byte / 2;
Local<Value> argv[2] = { Nan::New<Number>(utf16_unit), PointToJS(position) };
TryCatch try_catch(Isolate::GetCurrent());
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
auto maybe_result_value = Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv);
#else
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
#endif
if (try_catch.HasCaught()) return nullptr;

Local<Value> result_value;
Expand Down Expand Up @@ -364,7 +368,11 @@ void Parser::ParseTextBuffer(const Nan::FunctionCallbackInfo<Value> &info) {
delete input;
Local<Value> argv[] = {Tree::NewInstance(result)};
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 1, argv);
#else
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
#endif
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Tree::GetEditedRange(const Nan::FunctionCallbackInfo<Value> &info) {

void Tree::PrintDotGraph(const Nan::FunctionCallbackInfo<Value> &info) {
Tree *tree = ObjectWrap::Unwrap<Tree>(info.This());
ts_tree_print_dot_graph(tree->tree_, stderr);
ts_tree_print_dot_graph(tree->tree_, 2);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens because of updating vendor/tree-sitter:

../src/tree.cc:199:3: error: no matching function for call to 'ts_tree_print_dot_graph'
  ts_tree_print_dot_graph(tree->tree_, stderr);
  ^~~~~~~~~~~~~~~~~~~~~~~
../vendor/tree-sitter/lib/include/tree_sitter/api.h:423:6: note: candidate function not viable: no known conversion from 'FILE *' (aka '__sFILE *') to 'int' for 2nd argument
void ts_tree_print_dot_graph(const TSTree *, int file_descriptor);
     ^

introduced in tree-sitter/tree-sitter@97fd990

info.GetReturnValue().Set(info.This());
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/tree-sitter
Submodule tree-sitter updated 187 files