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
2 changes: 1 addition & 1 deletion SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10826257b222e4d6b430b3a38f05b8c89042eaabc95cd26316fefd8a50e06857 vm2_nesting_check.py
263eb1d334f7fb60ad9c2e0439245e3fac661becd51c3747e43e13061682bec1 vm2_nesting_check.py
7 changes: 7 additions & 0 deletions test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def cli(self, *args):
code = c.main(list(args))
return code, out.getvalue(), err.getvalue()

def test_javascript_line_terminators_preserve_comment_boundaries(self):
for ending in ("\n", "\r\n", "\r", "\u2028", "\u2029"):
with self.subTest(ending=repr(ending)):
rows = self.scan(("// comment\n" + "import {NodeVM} from 'vm2';\nnew NodeVM({nesting:true});").replace("\n", ending))
self.assertEqual("lexical_source_candidate", rows[0]["evidence_type"])
self.assertEqual(3, rows[0]["source_line"])

def test_import_bound_aliases_and_namespace_imports(self):
for binding, constructor in [
("const {NodeVM} = require('vm2');", "NodeVM"),
Expand Down
1 change: 1 addition & 0 deletions vm2_nesting_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def _read_bounded(path):

def _js_tokens(text):
"""Bounded lexical hints, not a JavaScript parser. Never retain source strings."""
text = text.replace("\r\n", "\n").replace("\r", "\n").replace("\u2028", "\n").replace("\u2029", "\n")
tokens = []
index, line = 0, 1
while index < len(text):
Expand Down
Loading