Treat regex literals and template string literals as atoms in JS/TS

Fixes #64
pull/70/head
Wilfred Hughes 2021-12-04 18:19:15 +07:00
parent 4f0fa617df
commit aab3e7f2cc
2 changed files with 5 additions and 2 deletions

@ -8,6 +8,9 @@ Updated the C, CSS and JSON parsers to the latest upstream versions.
Expanded filename associations, so difftastic recognises more files. Expanded filename associations, so difftastic recognises more files.
Improved parsing for regex and template string literals in JavaScript
and TypeScript.
Improved word diffing on punctuation in comments. Improved word diffing on punctuation in comments.
When logging is enabled (e.g. `RUST_LOG=warn`), difftastic now warns When logging is enabled (e.g. `RUST_LOG=warn`), difftastic now warns

@ -186,7 +186,7 @@ pub fn from_extension(extension: &OsStr) -> Option<TreeSitterConfig> {
"cjs" | "js" | "jsx" | "mjs" => Some(TreeSitterConfig { "cjs" | "js" | "jsx" | "mjs" => Some(TreeSitterConfig {
name: "JavaScript", name: "JavaScript",
language: unsafe { tree_sitter_javascript() }, language: unsafe { tree_sitter_javascript() },
atom_nodes: (vec!["string"]).into_iter().collect(), atom_nodes: (vec!["string", "template_string", "regex"]).into_iter().collect(),
delimiter_tokens: (vec![ delimiter_tokens: (vec![
("[", "]"), ("[", "]"),
("(", ")"), ("(", ")"),
@ -263,7 +263,7 @@ pub fn from_extension(extension: &OsStr) -> Option<TreeSitterConfig> {
"ts" => Some(TreeSitterConfig { "ts" => Some(TreeSitterConfig {
name: "TypeScript", name: "TypeScript",
language: unsafe { tree_sitter_typescript() }, language: unsafe { tree_sitter_typescript() },
atom_nodes: (vec!["string", "template_string"]).into_iter().collect(), atom_nodes: (vec!["string", "template_string", "regex"]).into_iter().collect(),
delimiter_tokens: (vec![("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")]), delimiter_tokens: (vec![("{", "}"), ("(", ")"), ("[", "]"), ("<", ">")]),
highlight_queries: include_str!("../vendor/highlights/typescript.scm"), highlight_queries: include_str!("../vendor/highlights/typescript.scm"),
}), }),