Skip to content
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
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = off

[*.{cc,h}]
max_line_length = 120

[*.js]
max_line_length = 120
40 changes: 40 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: ci
labels: [dependencies]
open-pull-requests-limit: 1
groups:
actions:
patterns: ["*"]

- package-ecosystem: gitsubmodule
directory: /
schedule:
interval: weekly
day: friday
commit-message:
prefix: build
labels: [dependencies]
open-pull-requests-limit: 1
groups:
submodules:
patterns: ["*"]

- package-ecosystem: npm
directory: /
schedule:
interval: weekly
day: saturday
commit-message:
prefix: build
labels: [dependencies]
open-pull-requests-limit: 1
groups:
npm:
patterns: ["*"]
55 changes: 22 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: CI

on:
push:
branches:
- master
branches: [master]
pull_request:
branches:
- master
branches: [master]
workflow_call:

concurrency:
Expand All @@ -18,58 +16,49 @@ jobs:
strategy:
matrix:
os:
- windows-latest
- macos-latest
- windows-2022
- windows-11-arm
- macos-15
- macos-13
- ubuntu-22.04
- ubuntu-22.04-arm
node:
- 18
- 20
- 22
- 20.19.5
- 22.19.0
- 24.7.0
fail-fast: false
name: Test Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
name: Test Node ${{matrix.node}} on ${{matrix.os}}
runs-on: ${{matrix.os}}
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
submodules: true
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node }}

- name: Install dependencies
run: npm ci --legacy-peer-deps
node-version: ${{matrix.node}}

- name: Set npm_config_target
run: echo "CONFIG_TARGET=${{ matrix.node == 22 && '22.12.0' || '20.9.0' }}" >> $GITHUB_ENV
run: printf 'npm_config_target=${{matrix.node}}\n' >> "$GITHUB_ENV"

- name: Build x64 binary
run: npm_config_target=${{ env.CONFIG_TARGET }} npm x -- prebuildify --napi --arch x64 -t 20.9.0

- name: Set up cross-compilation
if: runner.os == 'Linux'
run: |-
sudo apt-get update
sudo apt-get install g++-aarch64-linux-gnu
printf '%s\n' >> "$GITHUB_ENV" \
'CC=aarch64-linux-gnu-gcc' 'CXX=aarch64-linux-gnu-g++'
- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Build arm64 binary
run: npm_config_target=${{ env.CONFIG_TARGET }} npm x -- prebuildify --napi --arch arm64 -t 20.9.0
- name: Build binary
run: npm x -- prebuildify --napi

- name: Run tests
run: npm test

- name: Upload prebuilds
uses: actions/upload-artifact@v4
if: github.ref_type == 'tag' && matrix.node == 20
if: github.ref_type == 'tag' && startsWith(matrix.node, '20')
with:
path: prebuilds/**
name: prebuilds-${{matrix.os}}
name: prebuilds-${{runner.os}}-${{runner.arch}}
retention-days: 2
7 changes: 3 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ jobs:
url: ${{steps.deployment.outputs.page_url}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
submodules: true
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: 20
cache: 'npm'
Expand All @@ -40,7 +39,7 @@ jobs:
- name: Generate documentation
run: npm run docs
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v4
with:
path: docs/api
- name: Deploy to GitHub Pages
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: 20
registry-url: https://registry.npmjs.org

- name: Download prebuilds
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
path: prebuilds
pattern: prebuilds-*
Expand All @@ -42,7 +41,7 @@ jobs:
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Prepare release artifacts
run: |
Expand All @@ -54,7 +53,6 @@ jobs:
ls -l dist

- name: Create release
run: |-
gh release create ${{ github.ref_name }} --generate-notes dist/*
run: gh release create "$GITHUB_REF_NAME" --generate-notes dist/*
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{github.token}}
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "vendor/tree-sitter"]
path = vendor/tree-sitter
url = https://github.com/tree-sitter/tree-sitter.git
branch = release-0.25
12 changes: 0 additions & 12 deletions .npmignore

This file was deleted.

28 changes: 18 additions & 10 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@
"defines": [
"NAPI_VERSION=<(napi_build_version)",
],
"cflags_cc": [
"-std=c++17"
],
"conditions": [
["OS=='mac'", {
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES", # -fvisibility=hidden
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"CLANG_CXX_LANGUAGE_STANDARD": "<(cxxstd)",
"MACOSX_DEPLOYMENT_TARGET": "10.9",
},
}],
["OS=='win'", {
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [
"/std:c++17",
"/std:<(cxxstd)",
],
"RuntimeLibrary": 0,
},
},
}],
["OS == 'linux'", {
"cflags_cc": [
"-Wno-cast-function-type"
"-std=<(cxxstd)",
"-fvisibility=hidden",
"-Wno-cast-function-type",
]
}],
]
Expand All @@ -62,19 +61,28 @@
"vendor/tree-sitter/lib/src",
"vendor/tree-sitter/lib/include",
],
"cflags": [
"-std=c11"
],
"defines": [
"_POSIX_C_SOURCE=200112L",
"_DEFAULT_SOURCE",
]
],
"conditions": [
["OS!='win'", {
"cflags_c": [
"-std=c11",
],
}, { # OS == "win"
"cflags_c": [
"/std:c11",
],
}],
],
}
],
"variables": {
"runtime%": "node",
"openssl_fips": "",
"v8_enable_pointer_compression%": 0,
"v8_enable_31bit_smis_on_64bit_arch%": 0,
"cxxstd%": "<!(node -p \"parseInt(process.env.npm_config_target ?? process.versions.node) > 22 ? 'c++20' : 'c++17'\")",
}
}
32 changes: 26 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Object.defineProperty(Tree.prototype, 'rootNode', {
Due to a race condition arising from Jest's worker pool, "this"
has no knowledge of the native extension if the extension has not
yet loaded when multiple Jest tests are being run simultaneously.
If the extension has correctly loaded, "this" should be an instance
If the extension has correctly loaded, "this" should be an instance
of the class whose prototype we are acting on (in this case, Tree).
Furthermore, the race condition sometimes results in the function in
question being undefined even when the context is correct, so we also
Furthermore, the race condition sometimes results in the function in
question being undefined even when the context is correct, so we also
perform a null function check.
*/
if (this instanceof Tree && rootNode) {
Expand Down Expand Up @@ -61,7 +61,10 @@ Tree.prototype.walk = function() {

class SyntaxNode {
constructor(tree) {
this.tree = tree;
Object.defineProperty(this, 'tree', {
value: tree,
enumerable: true
});
}

[util.inspect.custom]() {
Expand Down Expand Up @@ -239,6 +242,15 @@ class SyntaxNode {
return NodeMethods.toString(this.tree);
}

toJSON() {
return {
type: this.type,
startPosition: this.startPosition,
endPosition: this.endPosition,
childCount: this.childCount,
}
}

child(index) {
marshalNode(this);
return unmarshalNode(NodeMethods.child(this.tree, index), this.tree);
Expand Down Expand Up @@ -894,8 +906,16 @@ function initializeLanguageNodeClasses(language) {

const className = camelCase(typeName, true) + 'Node';
const nodeSubclass = eval(`class ${className} extends SyntaxNode {${classBody}}; ${className}`);
nodeSubclass.prototype.type = typeName;
nodeSubclass.prototype.fields = Object.freeze(fieldNames.sort())
Object.defineProperties(nodeSubclass.prototype, {
type: {
value: typeName,
enumerable: true
},
fields: {
value: Object.freeze(fieldNames.sort()),
enumerable: true
}
});
nodeSubclasses[id] = nodeSubclass;
}

Expand Down
3 changes: 2 additions & 1 deletion test/lookahead_iterable_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {typeof import('tree-sitter')} */
/// <reference path="../tree-sitter.d.ts" />
/** @type {typeof import("tree-sitter")} */
const Parser = require("../index.js");
const Rust = require("tree-sitter-rust");
const assert = require('node:assert');
Expand Down
Loading
Loading