Skip to content

Commit

Permalink
fix(typescript): Scoping strings no longer includes quotes
Browse files Browse the repository at this point in the history
That was never intended or useful.

See the changed snapshots in this diff for what
the changes look like.

Similar to 2a743c8.
  • Loading branch information
alexpovel committed Jul 23, 2024
1 parent 5d99fcb commit f1626d7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ Language scopes:

Possible values:
- comments: Comments
- strings: Strings (literal, template; includes quote characters)
- strings: Strings (literal, template)
- imports: Imports (module specifiers)

--typescript-query <TYPESCRIPT_QUERY>
Expand Down
17 changes: 3 additions & 14 deletions src/scoping/langs/typescript.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::{CodeQuery, Find, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::scoping::{langs::IGNORE, scope::RangesWithContext, Scoper};
use crate::scoping::{scope::RangesWithContext, Scoper};
use clap::ValueEnum;
use const_format::formatcp;
use std::{fmt::Debug, str::FromStr};
use tree_sitter::QueryError;

Expand All @@ -14,7 +13,7 @@ pub type TypeScriptQuery = CodeQuery<CustomTypeScriptQuery, PreparedTypeScriptQu
pub enum PreparedTypeScriptQuery {
/// Comments.
Comments,
/// Strings (literal, template; includes quote characters).
/// Strings (literal, template).
Strings,
/// Imports (module specifiers).
Imports,
Expand All @@ -29,17 +28,7 @@ impl From<PreparedTypeScriptQuery> for TSQuery {
PreparedTypeScriptQuery::Imports => {
r"(import_statement source: (string (string_fragment) @sf))"
}
PreparedTypeScriptQuery::Strings => {
formatcp!(
r"
[
(string)
(template_string (template_substitution) @{0})
]
@string",
IGNORE
)
}
PreparedTypeScriptQuery::Strings => "(string_fragment) @string",
},
)
.expect("Prepared queries to be valid")
Expand Down
99 changes: 45 additions & 54 deletions tests/langs/snapshots/r#mod__langs__base.ts_strings.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,55 @@ expression: inscope_parts
---
- n: 2
l: "import * as fs from \"fs\";\n"
m: " ^^^^^^ "
m: " ^^ "
- n: 3
l: "import 'some/package';\n"
m: " ^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^ "
- n: 4
l: "import { promisify } from \"util\";\n"
m: " ^^^^^^^^ "
m: " ^^^^ "
- n: 18
l: " console.log(`Global testVar is now ${testVar}`);\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 18
l: " console.log(`Global testVar is now ${testVar}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^ "
- n: 24
l: " console.log(\"Function decorator called\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 31
l: " console.log(\"Inside decorated function\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 36
l: " static classVar: string = \"Class variable\";\n"
m: " ^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^ "
- n: 41
l: " this.classVar += \" updated\";\n"
m: " ^^^^^^^^^^^^ "
- n: 42
l: " console.log(`Class variable is now ${this.classVar}`);\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^ "
- n: 42
l: " console.log(`Class variable is now ${this.classVar}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^ "
- n: 46
l: " this.instanceVar = 'Instance variable'; // Single quotes\n"
m: " ^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^ "
- n: 47
l: " console.log(`Instance variable is ${this.instanceVar}`);\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^ "
- n: 47
l: " console.log(`Instance variable is ${this.instanceVar}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^^^^^^^ "
- n: 51
l: " console.log(\"Inside static method\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^ "
- n: 80
l: "const multiLineStr: string = `\n"
m: " ^^"
- n: 81
l: "This is a\n"
m: ^^^^^^^^^^^
- n: 82
l: "multi-line string\n"
m: ^^^^^^^^^^^^^^^^^^^
- n: 83
l: "for testing purposes.\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^
- n: 86
l: "const multilineFString: string = `This is a\n"
m: " ^^^^^^^^^^^^"
m: " ^^^^^^^^^^^"
- n: 87
l: "multiline ${multiLineStr} string\n"
m: "^^^^^^^^^^ "
Expand All @@ -59,63 +62,51 @@ expression: inscope_parts
- n: 88
l: "spanning several lines\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^
- n: 89
l: "`;\n"
m: "^ "
- n: 91
l: "const rawString: string = `This is a raw string with no special treatment for \\\\n`;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 91
l: "const rawString: string = `This is a raw string with no special treatment for \\\\n`;\n"
m: " ^ "
- n: 94
l: "const squaredNumbers: string[] = Array.from(Array(10).keys()).map(x => \"x\" + square(x));\n"
m: " ^^^^^ "
m: " ^ "
- n: 104
l: " throw new Error(\"Negative value\");\n"
m: " ^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^ "
- n: 106
l: " throw new Error(\"Division by zero\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^ "
- n: 110
l: " console.error(`Caught an exception: ${e.message}`);\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^ "
- n: 110
l: " console.error(`Caught an exception: ${e.message}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^^^^^^^ "
- n: 112
l: " console.log(\"This will always be printed\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 123
l: " console.log(`Inplace operations result: ${x}`);\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 123
l: " console.log(`Inplace operations result: ${x}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 129
l: " console.log(\"testVar is greater than 5\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 131
l: " console.log(\"testVar is 5 or less\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 136
l: " console.log(`Counter is ${counter}`);\n"
m: " ^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^ "
- n: 136
l: " console.log(`Counter is ${counter}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^ "
- n: 141
l: " console.log(`Loop iteration ${i}`);\n"
m: " ^^^^^^^^^^^^^^^^ "
- n: 141
l: " console.log(`Loop iteration ${i}`);\n"
m: " ^ "
m: " ^^^^^^^^^^^^^^^ "
- n: 146
l: " const content = fs.readFileSync(__filename, 'utf8');\n"
m: " ^^^^^^^^ "
- n: 147
l: " console.log(\"Read from file:\", content.split('\\n')[0]);\n"
m: " ^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^ "
- n: 147
l: " console.log(\"Read from file:\", content.split('\\n')[0]);\n"
m: " ^^^^^^^ "
m: " ^^^^^^^^^^^^^^^ "
- n: 149
l: " console.error(\"Failed to read file\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^ "
- n: 156
l: " console.log(\"Async function executed\");\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
m: " ^^^^^^^^^^^^^^^^^^^^^^^ "

0 comments on commit f1626d7

Please sign in to comment.