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

query result inconsistency between cli and lib #111

Open
cdmistman opened this issue Jun 1, 2023 · 1 comment
Open

query result inconsistency between cli and lib #111

cdmistman opened this issue Jun 1, 2023 · 1 comment

Comments

@cdmistman
Copy link

cdmistman commented Jun 1, 2023

given the following query with the JS language:

(import_statement
	source: (string [
		("'" . (_) @import . "'")
		("\"" . (_) @import . "\"")]))

(
	(call_expression
		function: (identifier) @function
		arguments:
			(arguments
				((_) @other-imports)?
				((string [
					("'" . (_) @import . "'")
					("\"" . (_) @import . "\"")
				]))
				.))
	(#eq? @function "require"))

i get 0 results due to the string destructuring pattern. for example, changing the query to be:

(import_statement
	source: (string) @import)

(
	(call_expression
		function: (identifier) @function
		arguments: (arguments ((_) @other-imports)? ((string) @import) .))
	(#eq? @function "require"))

results in 6 results given this input:

import * as fs from 'fs';
import 'assert';
import { isAbsolute } from 'path';
import nan from "nan";
const foo = require('buffer');
const foo2 = require("console");
require("cluster", "crypto");
require('async_hooks', 'constants');

foo('bar');

fs.doThing();

process.exit(1);

the first query works with the tree-sitter CLI

@cdmistman
Copy link
Author

cdmistman commented Jun 1, 2023

for clarity, i expect there to be 6 matches when given the input to the first query: (looking only at the @import capture) fs, assert, path, nan, buffer, and console. However, 0 results are returned.

with the second query, i get 'fs', 'assert', 'path', "nan", 'buffer', and "console"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant