|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
-from libsourcemap import from_json as view_from_json, Token
|
|
|
+from symbolic import SourceMapView, SourceMapTokenMatch
|
|
|
from sentry.testutils import TestCase
|
|
|
|
|
|
from sentry.utils import json
|
|
@@ -66,10 +66,10 @@ indexed_sourcemap_example = json.dumps(
|
|
|
|
|
|
class FindSourceTest(TestCase):
|
|
|
def test_simple(self):
|
|
|
- smap_view = view_from_json(sourcemap)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(sourcemap)
|
|
|
|
|
|
- result = smap_view.lookup_token(0, 56)
|
|
|
- assert result == Token(
|
|
|
+ result = smap_view.lookup(0, 56)
|
|
|
+ assert result == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=50,
|
|
|
src='foo/file2.js',
|
|
@@ -80,33 +80,33 @@ class FindSourceTest(TestCase):
|
|
|
)
|
|
|
|
|
|
# Start of minified file (exact match first line/col tuple)
|
|
|
- result = smap_view.lookup_token(0, 0)
|
|
|
- assert result == Token(
|
|
|
+ result = smap_view.lookup(0, 0)
|
|
|
+ assert result == SourceMapTokenMatch(
|
|
|
dst_line=0, dst_col=0, src='foo/file1.js', src_line=0, src_col=0, src_id=0, name=None
|
|
|
)
|
|
|
|
|
|
# Last character in mapping
|
|
|
- result = smap_view.lookup_token(0, 36)
|
|
|
- assert result == Token(
|
|
|
+ result = smap_view.lookup(0, 36)
|
|
|
+ assert result == SourceMapTokenMatch(
|
|
|
dst_line=0, dst_col=30, src='foo/file1.js', src_line=2, src_col=1, src_id=0, name=None
|
|
|
)
|
|
|
|
|
|
# First character in mapping (exact match line/col tuple)
|
|
|
- result = smap_view.lookup_token(0, 37)
|
|
|
- assert result == Token(
|
|
|
+ result = smap_view.lookup(0, 37)
|
|
|
+ assert result == SourceMapTokenMatch(
|
|
|
dst_line=0, dst_col=37, src='foo/file1.js', src_line=2, src_col=8, src_id=0, name='a'
|
|
|
)
|
|
|
|
|
|
# End of minified file (character *beyond* last line/col tuple)
|
|
|
- result = smap_view.lookup_token(0, 192)
|
|
|
- assert result == Token(
|
|
|
+ result = smap_view.lookup(0, 192)
|
|
|
+ assert result == SourceMapTokenMatch(
|
|
|
dst_line=0, dst_col=191, src='foo/file2.js', src_line=9, src_col=25, src_id=1, name='e'
|
|
|
)
|
|
|
|
|
|
|
|
|
class IterSourcesTest(TestCase):
|
|
|
def test_basic(self):
|
|
|
- smap_view = view_from_json(sourcemap)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(sourcemap)
|
|
|
assert list(smap_view.iter_sources()) == [
|
|
|
(0, 'foo/file1.js'),
|
|
|
(1, 'foo/file2.js'),
|
|
@@ -116,28 +116,28 @@ class IterSourcesTest(TestCase):
|
|
|
class GetSourceContentsTest(TestCase):
|
|
|
def test_no_inline(self):
|
|
|
# basic sourcemap fixture has no inlined sources, so expect None
|
|
|
- smap_view = view_from_json(sourcemap)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(sourcemap)
|
|
|
|
|
|
- source = smap_view.get_source_contents(0)
|
|
|
+ source = smap_view.get_sourceview(0)
|
|
|
assert source is None
|
|
|
|
|
|
def test_indexed_inline(self):
|
|
|
- smap_view = view_from_json(indexed_sourcemap_example)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(indexed_sourcemap_example)
|
|
|
|
|
|
- assert smap_view.get_source_contents(0) == (
|
|
|
- ' ONE.foo = function (bar) {\n' + ' return baz(bar);\n' + ' };'
|
|
|
+ assert smap_view.get_sourceview(0).get_source() == (
|
|
|
+ u' ONE.foo = function (bar) {\n' + ' return baz(bar);\n' + ' };'
|
|
|
)
|
|
|
- assert smap_view.get_source_contents(1) == (
|
|
|
- ' TWO.inc = function (n) {\n' + ' return n + 1;\n' + ' };'
|
|
|
+ assert smap_view.get_sourceview(1).get_source() == (
|
|
|
+ u' TWO.inc = function (n) {\n' + ' return n + 1;\n' + ' };'
|
|
|
)
|
|
|
|
|
|
|
|
|
class ParseSourcemapTest(TestCase):
|
|
|
def test_basic(self):
|
|
|
- index = view_from_json(sourcemap)
|
|
|
+ index = SourceMapView.from_json_bytes(sourcemap)
|
|
|
|
|
|
assert list(index) == [
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=0,
|
|
|
src='foo/file1.js',
|
|
@@ -146,7 +146,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=8,
|
|
|
src='foo/file1.js',
|
|
@@ -155,7 +155,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='add'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=13,
|
|
|
src='foo/file1.js',
|
|
@@ -164,7 +164,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=15,
|
|
|
src='foo/file1.js',
|
|
@@ -173,7 +173,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=18,
|
|
|
src='foo/file1.js',
|
|
@@ -182,7 +182,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=30,
|
|
|
src='foo/file1.js',
|
|
@@ -191,7 +191,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=37,
|
|
|
src='foo/file1.js',
|
|
@@ -200,7 +200,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=40,
|
|
|
src='foo/file1.js',
|
|
@@ -209,7 +209,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=42,
|
|
|
src='foo/file2.js',
|
|
@@ -218,7 +218,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=50,
|
|
|
src='foo/file2.js',
|
|
@@ -227,7 +227,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='multiply'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=60,
|
|
|
src='foo/file2.js',
|
|
@@ -236,7 +236,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=62,
|
|
|
src='foo/file2.js',
|
|
@@ -245,7 +245,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=65,
|
|
|
src='foo/file2.js',
|
|
@@ -254,7 +254,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=77,
|
|
|
src='foo/file2.js',
|
|
@@ -263,7 +263,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=84,
|
|
|
src='foo/file2.js',
|
|
@@ -272,7 +272,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=87,
|
|
|
src='foo/file2.js',
|
|
@@ -281,7 +281,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=89,
|
|
|
src='foo/file2.js',
|
|
@@ -290,7 +290,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=97,
|
|
|
src='foo/file2.js',
|
|
@@ -299,7 +299,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='divide'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=105,
|
|
|
src='foo/file2.js',
|
|
@@ -308,7 +308,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=107,
|
|
|
src='foo/file2.js',
|
|
@@ -317,7 +317,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=110,
|
|
|
src='foo/file2.js',
|
|
@@ -326,7 +326,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=122,
|
|
|
src='foo/file2.js',
|
|
@@ -335,7 +335,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=127,
|
|
|
src='foo/file2.js',
|
|
@@ -344,7 +344,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=133,
|
|
|
src='foo/file2.js',
|
|
@@ -353,7 +353,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='multiply'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=143,
|
|
|
src='foo/file2.js',
|
|
@@ -362,7 +362,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='add'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=147,
|
|
|
src='foo/file2.js',
|
|
@@ -371,7 +371,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=149,
|
|
|
src='foo/file2.js',
|
|
@@ -380,7 +380,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=152,
|
|
|
src='foo/file2.js',
|
|
@@ -389,7 +389,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='a'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=154,
|
|
|
src='foo/file2.js',
|
|
@@ -398,7 +398,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='b'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=157,
|
|
|
src='foo/file2.js',
|
|
@@ -407,7 +407,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='c'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=159,
|
|
|
src='foo/file2.js',
|
|
@@ -416,7 +416,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=165,
|
|
|
src='foo/file2.js',
|
|
@@ -425,7 +425,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='e'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=168,
|
|
|
src='foo/file2.js',
|
|
@@ -434,7 +434,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='Raven'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=174,
|
|
|
src='foo/file2.js',
|
|
@@ -443,7 +443,7 @@ class ParseSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='captureException'
|
|
|
),
|
|
|
- Token(
|
|
|
+ SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=191,
|
|
|
src='foo/file2.js',
|
|
@@ -459,10 +459,10 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
# Tests lookups that fall exactly on source map token boundaries
|
|
|
# https://github.com/mozilla/source-map/blob/master/test/test-source-map-consumer.js#138
|
|
|
def test_exact_mappings(self):
|
|
|
- smap_view = view_from_json(indexed_sourcemap_example)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(indexed_sourcemap_example)
|
|
|
|
|
|
# one.js
|
|
|
- assert smap_view.lookup_token(0, 1) == Token(
|
|
|
+ assert smap_view.lookup(0, 1) == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=1,
|
|
|
src='/the/root/one.js',
|
|
@@ -471,7 +471,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name=None
|
|
|
)
|
|
|
- assert smap_view.lookup_token(0, 18) == Token(
|
|
|
+ assert smap_view.lookup(0, 18) == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=18,
|
|
|
src='/the/root/one.js',
|
|
@@ -480,7 +480,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='bar'
|
|
|
)
|
|
|
- assert smap_view.lookup_token(0, 28) == Token(
|
|
|
+ assert smap_view.lookup(0, 28) == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=28,
|
|
|
src='/the/root/one.js',
|
|
@@ -491,7 +491,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
)
|
|
|
|
|
|
# two.js
|
|
|
- assert smap_view.lookup_token(1, 18) == Token(
|
|
|
+ assert smap_view.lookup(1, 18) == SourceMapTokenMatch(
|
|
|
dst_line=1,
|
|
|
dst_col=18,
|
|
|
src='/the/root/two.js',
|
|
@@ -500,7 +500,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name='n'
|
|
|
)
|
|
|
- assert smap_view.lookup_token(1, 21) == Token(
|
|
|
+ assert smap_view.lookup(1, 21) == SourceMapTokenMatch(
|
|
|
dst_line=1,
|
|
|
dst_col=21,
|
|
|
src='/the/root/two.js',
|
|
@@ -509,7 +509,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=1,
|
|
|
name=None
|
|
|
)
|
|
|
- assert smap_view.lookup_token(1, 21) == Token(
|
|
|
+ assert smap_view.lookup(1, 21) == SourceMapTokenMatch(
|
|
|
dst_line=1,
|
|
|
dst_col=21,
|
|
|
src='/the/root/two.js',
|
|
@@ -522,10 +522,10 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
# Tests lookups that fall inside source map token boundaries
|
|
|
# https://github.com/mozilla/source-map/blob/master/test/test-source-map-consumer.js#181
|
|
|
def test_fuzzy_mapping(self):
|
|
|
- smap_view = view_from_json(indexed_sourcemap_example)
|
|
|
+ smap_view = SourceMapView.from_json_bytes(indexed_sourcemap_example)
|
|
|
|
|
|
# one.js
|
|
|
- assert smap_view.lookup_token(0, 20) == Token(
|
|
|
+ assert smap_view.lookup(0, 20) == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=18,
|
|
|
src='/the/root/one.js',
|
|
@@ -534,7 +534,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='bar'
|
|
|
)
|
|
|
- assert smap_view.lookup_token(0, 30) == Token(
|
|
|
+ assert smap_view.lookup(0, 30) == SourceMapTokenMatch(
|
|
|
dst_line=0,
|
|
|
dst_col=28,
|
|
|
src='/the/root/one.js',
|
|
@@ -543,7 +543,7 @@ class ParseIndexedSourcemapTest(TestCase):
|
|
|
src_id=0,
|
|
|
name='baz'
|
|
|
)
|
|
|
- assert smap_view.lookup_token(1, 12) == Token(
|
|
|
+ assert smap_view.lookup(1, 12) == SourceMapTokenMatch(
|
|
|
dst_line=1,
|
|
|
dst_col=9,
|
|
|
src='/the/root/two.js',
|