Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gitgalaxy/core/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2940,7 +2940,9 @@ def _slice_by_braces(
# arrow-function properties. JavaScript shares the same regex
# branch and the same ambiguity, so the gate covers both.
if lang_id in ("typescript", "javascript"):
p = start_idx - 2 # start_idx - 1 is the line's own \n
name_start = match.start(match.lastindex) if match.lastindex else start_idx
line_start = safe_code.rfind("\n", 0, name_start) + 1
p = line_start - 2 # line_start - 1 is the line's own \n
while p >= 0 and safe_code[p] in " \t":
p -= 1
if p >= 0 and safe_code[p] == "(":
Expand All @@ -2957,7 +2959,9 @@ def _slice_by_braces(
# way #1221's Invocation Shield rules out bare call statements.
# JavaScript and TypeScript share the branch, so the gate covers both.
if lang_id in ("typescript", "javascript"):
p = start_idx - 1
name_start = match.start(match.lastindex) if match.lastindex else start_idx
line_start = safe_code.rfind("\n", 0, name_start) + 1
p = line_start - 1
back_steps = 0
while p >= 0 and back_steps < 200 and safe_code[p] in " \t\n\r":
p -= 1
Expand Down
11 changes: 7 additions & 4 deletions gitgalaxy/standards/language_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
| Solidity | 100.0% | 94.3% | 100.0% | 100.0% |
| Swift | 100.0% | 99.2% | 100.0% | 100.0% |
| Tcl | 98.6% | 99.3% | N/A | N/A |
| Typescript | 99.5% | 99.5% | 100.0% | 100.0% |
| Typescript | 99.6% | 99.6% | 100.0% | 100.0% |
| Zig | 100.0% | 100.0% | 100.0% | 100.0% |
<!-- TREE_SITTER_ACCURACY_TABLE:END -->
"""
Expand Down Expand Up @@ -1197,7 +1197,7 @@ class PrismConfigSchema(TypedDict):
# with the function-TYPE-signature case the rest of this
# alternation is busy disambiguating against.
r"(?=[ \t\n]*=[ \t\n]*(?:async\s*)?(?:<(?:[^<>]|<[^<>]*>)*>\s*)?(?:function(?:\s*\*)?\b|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)(?:[^=;{()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)|[a-zA-Z_$][\w$]*[ \t\n]*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)))|"
r"^[ \t]*(\[[^\]]+\]|[#]?[a-zA-Z_$][\w$]*)(?=[ \t\n]*:[ \t\n]*(?:async\s*)?(?:<(?:[^<>]|<[^<>]*>)*>\s*)?(?:function(?:\s*\*)?\b|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)(?:[^=;{()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)|[a-zA-Z_$][\w$]*[ \t\n]*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)))|"
r"(?:^[ \t]*|(?<=[,{])[ \t\n]*)(\[[^\]]+\]|[#]?[a-zA-Z_$][\w$]*)(?=[ \t\n]*:[ \t\n]*(?:async\s*)?(?:<(?:[^<>]|<[^<>]*>)*>\s*)?(?:function(?:\s*\*)?\b|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)(?:[^=;{()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)|[a-zA-Z_$][\w$]*[ \t\n]*=>[ \t\n]*(?:[{<]|\(|!|$|[a-zA-Z_$][\w$]*(?=[ \t\n]*\()|(?!(?:void|string|number|boolean|any|unknown|never|object|symbol|bigint|undefined|null)\b)[a-z_][\w$]*)))|"
# #1221: the trailing lookahead used to be just
# `(?=[ \t\n]{0,50}(?:<...>)?[ \t\n]{0,50}\()` -- proof a
# `(` follows, nothing more -- so any bare call statement
Expand Down Expand Up @@ -1355,8 +1355,11 @@ class PrismConfigSchema(TypedDict):
# BUG FIX (issue #2276): same conditional-exclusion fix as
# Branch A above, mirrored here since this branch carries
# its own copy of the same reserved-keyword shield -- see
# that branch's comment for the full rationale.
r"^[ \t]*(?!(?:class|interface|enum|if|for|while|switch|new|typeof|jQuery|function|yield|await|void)\b|type\b(?![ \t\n]*\()|\$|(?:catch|return|throw)\b[ \t\n]+(?:\(|<))(\[[^\]]+\]|[#]?[a-zA-Z_$][\w$]*)(?=\??[ \t\n]{0,50}(?:<(?:[^<>]|<[^<>]*>)*>)?[ \t\n]{0,50}\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)[ \t\n]{0,50}(?:(?::[^{;]{0,200})?[ \t\n]{0,50}(?:=>[ \t\n]{0,50})?\{|:[^{;]{0,200}[ \t\n]{0,50};))"
# that branch's comment for the full rationale. Combined
# with #2277's widened anchor (below) during that PR's
# merge conflict with #2276 -- both changes apply to the
# same branch, independently of each other.
r"(?:^[ \t]*|(?<=[,{])[ \t\n]*)(?!(?:class|interface|enum|if|for|while|switch|new|typeof|jQuery|function|yield|await|void)\b|type\b(?![ \t\n]*\()|\$|(?:catch|return|throw)\b[ \t\n]+(?:\(|<))(\[[^\]]+\]|[#]?[a-zA-Z_$][\w$]*)(?=\??[ \t\n]{0,50}(?:<(?:[^<>]|<[^<>]*>)*>)?[ \t\n]{0,50}\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)[ \t\n]{0,50}(?:(?::[^{;]{0,200})?[ \t\n]{0,50}(?:=>[ \t\n]{0,50})?\{|:[^{;]{0,200}[ \t\n]{0,50};))"
r")",
re.M,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/extraction/languages/test_typescript_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
("func_start", "export const myFunc: React.FC<Props> = (props) => {", "type MyFunc = (a: number) => void;"),
("func_start", "public async *myGenerator<T>(arg: T) {", " return foo();"),
("func_start", "const f = function <T>(x: T) {", " typeof foo();"),
("func_start", " #myPrivateMethod(a: number) {", "class A { #myPrivateMethod(a) {} }"),
("func_start", " #myPrivateMethod(a: number) {", None),
("func_start", " [Symbol.iterator]() {", None),
("func_start", " * myGenerator () {", None),

Expand Down
Loading
Loading