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

Update to 0.24 #229

Merged
merged 5 commits into from
Oct 26, 2024
Merged
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
44 changes: 10 additions & 34 deletions .github/workflows/build.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
name: build
name: Build

on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
workflow_call:

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true


jobs:
test:
strategy:
matrix:
os:
- windows-2022
- macos-14
- ubuntu-20.04
- windows-latest
- macos-latest
- ubuntu-latest
node:
- 18
- 20
- 22
fail-fast: false
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -37,38 +36,15 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- run: npm install
- run: npm run build -- --arch x64
- run: npm run build -- --arch arm64
- run: npm run build_x64
- run: npm run build_arm64
- run: npm test

- uses: actions/upload-artifact@v4
if: github.ref_type == 'tag' && matrix.node == 20
with:
path: prebuilds/**
name: prebuilds-${{matrix.os}}
retention-days: 2

publish:
if: github.ref_type == 'tag'
name: Publish to npm
runs-on: ubuntu-20.04
needs: [test]
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- uses: actions/download-artifact@v4
with:
path: prebuilds
pattern: prebuilds-*
merge-multiple: true
- run: tree prebuilds
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:
build:
uses: "./.github/workflows/ci.yml"

publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- uses: actions/download-artifact@v4
with:
path: prebuilds
pattern: prebuilds-*
merge-multiple: true
- run: tree prebuilds
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cache
*.pyc
*.log
lib-cov
Expand Down
13 changes: 7 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@
"defines": [
"NAPI_VERSION=<(napi_build_version)",
],
"cflags": [
"-std=c++17"
],
"cflags_cc": [
"-std=c++17"
"-std=c++20"
],
"conditions": [
["OS=='mac'", {
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES", # -fvisibility=hidden
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"CLANG_CXX_LANGUAGE_STANDARD": "c++20",
"MACOSX_DEPLOYMENT_TARGET": "10.9",
},
}],
["OS=='win'", {
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [
"/std:c++17",
"/std:c++20",
],
"RuntimeLibrary": 0,
},
Expand All @@ -67,6 +64,10 @@
],
"cflags": [
"-std=c11"
],
"defines": [
"_POSIX_C_SOURCE=200112L",
"_DEFAULT_SOURCE",
]
}
],
Expand Down
38 changes: 28 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ class SyntaxNode {
return NodeMethods.fieldNameForChild(this.tree, childIndex);
}

fieldNameForNamedChild(namedChildIndex) {
marshalNode(this);
return NodeMethods.fieldNameForNamedChild(this.tree, namedChildIndex);
}

childrenForFieldName(fieldName) {
marshalNode(this);
return unmarshalNodes(NodeMethods.childrenForFieldName(this.tree, fieldName), this.tree);
Expand All @@ -281,6 +286,11 @@ class SyntaxNode {
return unmarshalNode(NodeMethods.firstNamedChildForIndex(this.tree, index), this.tree);
}

childWithDescendant(descendant) {
marshalNodes([this, descendant]);
return unmarshalNode(NodeMethods.childWithDescendant(this.tree, descendant.tree), this.tree);
}

namedDescendantForIndex(start, end) {
marshalNode(this);
if (end == null) end = start;
Expand Down Expand Up @@ -545,7 +555,7 @@ Query.prototype._init = function() {
return matchAll
? nodes.every(text => test(text, isPositive))
: nodes.some(text => test(text, isPositive))
});
});
break;

case 'set!':
Expand Down Expand Up @@ -581,7 +591,7 @@ Query.prototype._init = function() {
if (steps[SECOND] !== PREDICATE_STEP_TYPE.CAPTURE) throw new Error(
`First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
);
stringValues = [];
const stringValues = [];
for (let k = THIRD; k < 2 * stepsLength; k += 2) {
if (steps[k] !== PREDICATE_STEP_TYPE.STRING) throw new Error(
`Arguments to \`#${operator}\` predicate must be a strings.".`
Expand Down Expand Up @@ -619,14 +629,15 @@ Query.prototype.matches = function(
startIndex = 0,
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF
maxStartDepth = 0xFFFFFFFF,
timeoutMicros = 0
} = {}
) {
marshalNode(node);
const [returnedMatches, returnedNodes] = _matches.call(this, node.tree,
startPosition.row, startPosition.column,
endPosition.row, endPosition.column,
startIndex, endIndex, matchLimit, maxStartDepth
startIndex, endIndex, matchLimit, maxStartDepth, timeoutMicros
);
const nodes = unmarshalNodes(returnedNodes, node.tree);
const results = [];
Expand Down Expand Up @@ -668,14 +679,15 @@ Query.prototype.captures = function(
startIndex = 0,
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF
maxStartDepth = 0xFFFFFFFF,
timeoutMicros = 0,
} = {}
) {
marshalNode(node);
const [returnedMatches, returnedNodes] = _captures.call(this, node.tree,
startPosition.row, startPosition.column,
endPosition.row, endPosition.column,
startIndex, endIndex, matchLimit, maxStartDepth
startIndex, endIndex, matchLimit, maxStartDepth, timeoutMicros
);
const nodes = unmarshalNodes(returnedNodes, node.tree);
const results = [];
Expand Down Expand Up @@ -810,13 +822,19 @@ function unmarshalNodes(nodes, tree) {
return nodes;
}

function marshalNode(node) {
if (!(node.tree instanceof Tree)){
function marshalNode(node, offset = 0) {
if (!(node.tree instanceof Tree)) {
throw new TypeError("SyntaxNode must belong to a Tree")
}
const {nodeTransferArray} = binding;
const { nodeTransferArray } = binding;
for (let i = 0; i < NODE_FIELD_COUNT; i++) {
nodeTransferArray[i] = node[i];
nodeTransferArray[offset * NODE_FIELD_COUNT + i] = node[i];
}
}

function marshalNodes(nodes) {
for (let i = 0, { length } = nodes; i < length; i++) {
marshalNode(nodes[i], i);
}
}

Expand Down
10 changes: 0 additions & 10 deletions jest-tests/constants.js

This file was deleted.

9 changes: 0 additions & 9 deletions jest-tests/parse_input.js

This file was deleted.

9 changes: 0 additions & 9 deletions jest-tests/runit.js

This file was deleted.

Loading