Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.
Draft
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
25 changes: 0 additions & 25 deletions .appveyor.yml

This file was deleted.

132 changes: 132 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: build

on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types:
- released

jobs:

test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
node:
- 14
- 16
- 18
# These fail with a useless error message
exclude:
- os: windows-latest
node: 16
- os: windows-latest
node: 18
fail-fast: false
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Update node-gyp
if: ${{ matrix.os == 'windows-latest' && matrix.node == '14' }}
run: |
$WhereNode = Get-Command node | Select-Object -ExpandProperty Definition
$NodeDirPath = Split-Path $WhereNode -Parent
$NodeModulesPath = $NodeDirPath + "\node_modules\npm\node_modules\npm-lifecycle"
cd $NodeModulesPath
npm install [email protected]
- run: npm install
- run: npm test

prebuild-testing:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
fail-fast: false
name: Prebuild on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install --ignore-scripts
- run: npx --no-install prebuild -r node -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0
# Prebuilding for Electron 13+ on Windows fails with
# win_delay_load_hook.cc
# conversions.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class v8::Local<class v8::ArrayBuffer> __cdecl v8::ArrayBuffer::New(class v8::Isolate *,class std::shared_ptr<class v8::BackingStore>)" (__imp_?New@ArrayBuffer@v8@@SA?AV?$Local@VArrayBuffer@v8@@@2@PEAVIsolate@2@V?$shared_ptr@VBackingStore@v8@@@std@@@Z) referenced in function "void __cdecl node_tree_sitter::InitConversions(class v8::Local<class v8::Object>)" (?InitConversions@node_tree_sitter@@YAXV?$Local@VObject@v8@@@v8@@@Z) [D:\a\node-tree-sitter\node-tree-sitter\build\tree_sitter_runtime_binding.vcxproj]
- if: matrix.os != 'windows-latest'
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0
# - if: matrix.os == 'windows-latest'
# run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch ia32
- if: matrix.os == 'macos-latest'
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch arm64

publish:
if: ${{ github.event_name == 'release' }}
name: Publishing to NPM
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

prebuild:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
fail-fast: false
name: Prebuild on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: publish
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install --ignore-scripts
- run: npx --no-install prebuild -r node -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 -u ${{ secrets.GH_TOKEN }}
# Prebuilding for Electron 13+ on Windows fails with
# win_delay_load_hook.cc
# conversions.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class v8::Local<class v8::ArrayBuffer> __cdecl v8::ArrayBuffer::New(class v8::Isolate *,class std::shared_ptr<class v8::BackingStore>)" (__imp_?New@ArrayBuffer@v8@@SA?AV?$Local@VArrayBuffer@v8@@@2@PEAVIsolate@2@V?$shared_ptr@VBackingStore@v8@@@std@@@Z) referenced in function "void __cdecl node_tree_sitter::InitConversions(class v8::Local<class v8::Object>)" (?InitConversions@node_tree_sitter@@YAXV?$Local@VObject@v8@@@v8@@@Z) [D:\a\node-tree-sitter\node-tree-sitter\build\tree_sitter_runtime_binding.vcxproj]
- if: matrix.os != 'windows-latest'
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 -u ${{ secrets.GH_TOKEN }}
# - if: matrix.os == 'windows-latest'
# run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch ia32 -u ${{ secrets.GH_TOKEN }}
- if: matrix.os == 'macos-latest'
run: npx --no-install prebuild -r electron -t 21.0.0 -t 22.0.0 -t 23.0.0 --arch arm64 -u ${{ secrets.GH_TOKEN }}
29 changes: 16 additions & 13 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
"vendor/superstring",
"<!(node -e \"require('nan')\")",
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.9',
},
}]
],
"cflags": [
"-std=c++17",
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
"cflags_cc": ["-std=c++17"],
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET": "10.7",
"OTHER_CPLUSPLUSFLAGS": ["-std=c++17", "-stdlib=libc++"],
},
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [
"/std:c++17",
],
"RuntimeLibrary": 0,
},
},
},
{
Expand All @@ -49,7 +49,10 @@
]
}
],
'variables': { 'runtime%': 'node' },
'variables': {
'runtime%': 'node',
'openssl_fips': '',
},
'conditions': [
['runtime=="electron"', { 'defines': ['NODE_RUNTIME_ELECTRON=1'] }],
]
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
let binding;
try {
binding = require('./build/Release/tree_sitter_runtime_binding');
binding = require('./build/Release/tree_sitter_runtime_binding.node');
} catch (e) {
try {
binding = require('./build/Debug/tree_sitter_runtime_binding');
binding = require('./build/Debug/tree_sitter_runtime_binding.node');
} catch (_) {
throw e;
}
Expand Down
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "tree-sitter",
"version": "0.20.1",
"name": "@curlconverter/tree-sitter",
"version": "0.0.7",
"description": "Incremental parsers for node",
"author": "Max Brunsfeld",
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/tree-sitter/node-tree-sitter.git"
"url": "http://github.com/curlconverter/node-tree-sitter.git"
},
"keywords": [
"parser",
Expand All @@ -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",
"prebuild": "^11.0.4",
"@curlconverter/superstring": "^0.0.1",
"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 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -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 --strip && prebuild -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.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 >= 9
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 >= 9
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);
info.GetReturnValue().Set(info.This());
}

Expand Down
2 changes: 1 addition & 1 deletion test/node_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Parser = require("..");
const JavaScript = require('tree-sitter-javascript');
const { assert } = require("chai");
const { TextBuffer } = require("superstring");
const { TextBuffer } = require("@curlconverter/superstring");

describe("Node", () => {
let parser;
Expand Down
2 changes: 1 addition & 1 deletion test/parser_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Parser = require("..");
const JavaScript = require('tree-sitter-javascript');
const { assert } = require("chai");
const {TextBuffer} = require('superstring');
const {TextBuffer} = require('@curlconverter/superstring');

describe("Parser", () => {
let parser;
Expand Down
2 changes: 1 addition & 1 deletion tree-sitter.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "tree-sitter" {
declare module "@curlconverter/tree-sitter" {
class Parser {
parse(input: string | Parser.Input | Parser.InputReader, oldTree?: Parser.Tree, options?: { bufferSize?: number, includedRanges?: Parser.Range[] }): Parser.Tree;
parseTextBuffer(buffer: Parser.TextBuffer, oldTree?: Parser.Tree, options?: { syncTimeoutMicros?: number, includedRanges?: Parser.Range[] }): Parser.Tree | Promise<Parser.Tree>;
Expand Down
2 changes: 1 addition & 1 deletion vendor/tree-sitter
Submodule tree-sitter updated 187 files