Пример #1
0
    def test_jquery(self):
        source, minified, min_map = self.get_fixtures('jquery')

        source_lines = source.splitlines()

        assert sourcemap.discover(minified) == 'jquery.min.map'

        index = sourcemap.loads(min_map)
        assert index.raw == json.loads(min_map)
        for token in index:
            # Ignore tokens that are None.
            # There's no simple way to verify they're correct
            if token.name is None:
                continue
            source_line = source_lines[token.src_line]
            start = token.src_col
            end = start + len(token.name)
            substring = source_line[start:end]

            # jQuery's sourcemap has a few tokens that are identified
            # incorrectly.
            # For example, they have a token for 'embed', and
            # it maps to '"embe', which is wrong. This only happened
            # for a few strings, so we ignore
            if substring[0] == '"':
                continue
            assert token.name == substring
Пример #2
0
def sourcemap_from_url(url):
    js = fetch_url(url)
    if js.status_code != 200:
        raise UnableToFetchMinified(url)
    make_absolute = partial(urljoin, url)
    smap_url = discover_sourcemap(js)
    if smap_url is None:
        raise SourceMapNotFound(url)
    smap_url = make_absolute(smap_url)
    smap = fetch_url(smap_url)
    if smap.status_code != 200:
        raise UnableToFetchSourceMap(smap_url)
    try:
        return SourceMap(js, smap_url, sourcemap.loads(smap.body))
    except ValueError:
        raise InvalidSourceMapFormat(smap_url)
    except sourcemap.SourceMapDecodeError:
        raise UnknownSourceMapError(smap_url)
Пример #3
0
    def test_coolstuff(self):
        source, minified, min_map = self.get_fixtures('coolstuff')

        source_lines = source.splitlines()

        assert sourcemap.discover(minified) == 'tests/fixtures/coolstuff.min.map'

        index = sourcemap.loads(min_map)
        assert index.raw == json.loads(min_map)
        for token in index:
            if token.name is None:
                continue

            source_line = source_lines[token.src_line]
            start = token.src_col
            end = start + len(token.name)
            substring = source_line[start:end]
            assert token.name == substring
Пример #4
0
    def test_unicode_names(self):
        _, _, min_map = self.get_fixtures('unicode')

        # This shouldn't blow up
        sourcemap.loads(min_map)