diff --git a/SHA256SUMS b/SHA256SUMS index 63e2aaf..9f2214d 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1 +1 @@ -10826257b222e4d6b430b3a38f05b8c89042eaabc95cd26316fefd8a50e06857 vm2_nesting_check.py +263eb1d334f7fb60ad9c2e0439245e3fac661becd51c3747e43e13061682bec1 vm2_nesting_check.py diff --git a/test_source.py b/test_source.py index 7b3e8c5..de9b499 100644 --- a/test_source.py +++ b/test_source.py @@ -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"), diff --git a/vm2_nesting_check.py b/vm2_nesting_check.py index d98b71d..71586b2 100644 --- a/vm2_nesting_check.py +++ b/vm2_nesting_check.py @@ -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):