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
[bug] Literal strings are matched generically #1057
Labels
bug
Something isn't working
Comments
This is fixed in tree-sitter/tree-sitter-rust#218 But it is blocked by https://github.com/tree-sitter/tree-sitter-typescript/blob/master/Cargo.toml#L29 More context: tree-sitter/tree-sitter-typescript#289 |
You can use this workaround rule:
pattern: $E.with_meaning($D, $STR)
constraints:
STR: { regex: '^"meaning"$'} |
1 task
Thanks for the explanation, @HerringtonDarkholme |
I have created a new issue to track the fix #1104 . Closing this now. |
This was referenced May 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
⏯ Playground Link
https://ast-grep.github.io/playground.html#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoicnVzdCIsInF1ZXJ5IjoiJEUud2l0aF9tZWFuaW5nKCRELCBcIm1lYW5pbmdcIikiLCJyZXdyaXRlIjoiJEUud2l0aF9tZWFuaW5nKCRELCBtZWFuaW5nOjpNRVNTQUdFKSIsImNvbmZpZyI6IiMgWUFNTCBSdWxlIGlzIG1vcmUgcG93ZXJmdWwhXG4jIGh0dHBzOi8vYXN0LWdyZXAuZ2l0aHViLmlvL2d1aWRlL3J1bGUtY29uZmlnLmh0bWwjcnVsZVxucnVsZTpcbiAgYW55OlxuICAgIC0gcGF0dGVybjogY29uc29sZS5sb2coJEEpXG4gICAgLSBwYXR0ZXJuOiBjb25zb2xlLmRlYnVnKCRBKVxuZml4OlxuICBsb2dnZXIubG9nKCRBKSIsInNvdXJjZSI6ImZuIHRlc3QoKSB7XG4gICAgc2NoZW1hLndpdGhfbWVhbmluZyhGT08sIFwibWVhbmluZ1wiKTtcbiAgICBzY2hlbWEud2l0aF9tZWFuaW5nKEZPTywgXCJzZXJ2aWNlXCIpO1xufSJ9
💻 Code
Pattern:
$E.with_meaning($D, "meaning")
🙁 Actual behavior
The pattern matches both of the calls in the above code snippet, with
"meaning"
matching"service"
in the second.🙂 Expected behavior
I expected that it would only match the first one, since the constant literal string is different from the pattern. My use case is to replace a literal string with a predefined constant, but the pattern is matching the wrong strings to be useful.
The text was updated successfully, but these errors were encountered: