Read JavaScript as TypeScript without the types

Why: gtd-inbox-pull's Plan 6 runs the dryer over the swipe page's
JavaScript, and the dryer skipped .js files. This is for BJ's mirror only.

What changed: .js, .jsx, .mjs and .cjs are discovered as "javascript";
their .test and .spec forms are test files. extract.py gains a
"javascript" picker that parses with the JavaScript grammar and reuses
_typescript_nodes, since the tree is TypeScript's without type nodes.
No other code is keyed on the language name. README, pyproject, the CLI
help and the package docstring name JavaScript.

Proof: four tests written first and seen to fail on their own
assertions (language detection, test-file names, the language-set
tests with a JS pair, and the method and nested-function rule), then
the full suite passed (81 tests).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015GF1LYr5V3zY3815Nt6KwR
This commit is contained in:
bj
2026-11-15 16:45:46 +02:00
co-authored by Claude Sonnet 5.5
parent 66ff6d21a4
commit f48bd0c60f
8 changed files with 93 additions and 9 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""Find structural duplicates in Clojure, Java, Go, TypeScript, Rust, and Python."""
"""Find structural duplicates in Clojure, Java, Go, TypeScript, JavaScript, Rust, and Python."""
__version__ = "0.1.0"
+4 -3
View File
@@ -21,8 +21,8 @@ def _skipped_directory_text() -> str:
HELP = f"""\
Usage: dryer [options] [path-or-filter ...]
Find candidate duplicate code in Clojure, Java, Go, TypeScript, Rust, and
Python. Each form is normalized — call and method names, operators, and
Find candidate duplicate code in Clojure, Java, Go, TypeScript, JavaScript,
Rust, and Python. Each form is normalized — call and method names, operators, and
tree shape stay; local names, field names, and literals do not — and compared
with the other forms of the same language. The score is Jaccard similarity of
those structural fingerprints, the same score as dry4clj.
@@ -30,7 +30,8 @@ those structural fingerprints, the same score as dry4clj.
Prints a report and writes .metrics/dry.edn.
Languages: Clojure (.clj .cljc .cljs .cljd .bb), Java (.java), Go (.go),
TypeScript (.ts .tsx .mts .cts), Rust (.rs), Python (.py).
TypeScript (.ts .tsx .mts .cts), JavaScript (.js .jsx .mjs .cjs),
Rust (.rs), Python (.py).
Options:
-h, --help Print this help and exit.
+12
View File
@@ -19,6 +19,10 @@ EXTENSIONS = {
".tsx": "typescript",
".mts": "typescript",
".cts": "typescript",
".js": "javascript",
".jsx": "javascript",
".mjs": "javascript",
".cjs": "javascript",
".rs": "rust",
".py": "python",
}
@@ -71,6 +75,14 @@ def is_test_file(path: str | Path) -> bool:
".spec.mts",
".test.cts",
".spec.cts",
".test.js",
".spec.js",
".test.jsx",
".spec.jsx",
".test.mjs",
".spec.mjs",
".test.cjs",
".spec.cjs",
)
):
return True
+1
View File
@@ -148,6 +148,7 @@ _PICKERS = {
"go": ("go", _go_nodes),
"python": ("python", _python_nodes),
"typescript": (_grammar, _typescript_nodes),
"javascript": ("javascript", _typescript_nodes),
"rust": ("rust", _rust_nodes),
}