test: widen window-collision classifier to recognize long bare-identifier exports
The #2715/#2771 brick-guard (test_window_function_collision) capped the window.X=RHS capture at 32 chars and required a trailing terminator to classify a bare identifier, so a very long function name (e.g. _renderLiveAnchorActivitySceneSnapshotForStream, 47 chars) was misclassified as 'other' → false positive on the now-correct direct-assignment exports. Widen capture to 80 chars + recognize an identifier running to end-of-window. Still flags the real object/number/other bug shapes.
This commit is contained in:
1 parent
6c1fe51ca6
commit
54818261e1
1 file changed
+7
-1
@@ -40,7 +40,7 @@ TOP_LEVEL_FN_RE = re.compile(r"^function\s+([A-Za-z_\$][A-Za-z_\$0-9]*)\s*\(", r
|
||||
# to see `function(` (8 chars) even after some whitespace; we use 32 chars to
|
||||
# be safe against newlines and odd indenting.
|
||||
WINDOW_ASSIGN_RE = re.compile(
|
||||
r"window\.([A-Za-z_\$][A-Za-z_\$0-9]*)\s*=\s*([^=].{0,32})",
|
||||
r"window\.([A-Za-z_\$][A-Za-z_\$0-9]*)\s*=\s*([^=].{0,80})",
|
||||
re.DOTALL,
|
||||
)
|
||||
|
||||
@@ -74,6 +74,12 @@ def _classify_rhs(rhs: str) -> str:
|
||||
# Allow ||, &&, ? chains too (e.g. `window.X = window.X || false;`).
|
||||
if re.match(r"[A-Za-z_\$][A-Za-z_\$0-9]*[\s;,)|&?.]", rhs):
|
||||
return "identifier"
|
||||
# Bare identifier that runs to the end of the (length-capped) capture window
|
||||
# with no trailing terminator visible — e.g. a very long function name like
|
||||
# `_renderLiveAnchorActivitySceneSnapshotForStream;` whose terminator falls
|
||||
# outside the captured snippet. Still a benign function reference.
|
||||
if re.fullmatch(r"[A-Za-z_\$][A-Za-z_\$0-9]*", rhs.rstrip()):
|
||||
return "identifier"
|
||||
return "other"
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user