-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add a couple new source map features #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8651372
3d46140
0d716f8
bfdfe1f
0ee28cf
02b92a8
48433a5
c08d391
b27c192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
|
|
||
| SourceMap = namedtuple('SourceMap', ['dst_line', 'dst_col', 'src', 'src_line', 'src_col', 'name']) | ||
| SourceMapIndex = namedtuple('SourceMapIndex', ['states', 'keys', 'sources']) | ||
| SourceMapIndex = namedtuple('SourceMapIndex', ['states', 'keys', 'sources', 'content']) | ||
|
|
||
| # Mapping of base64 letter -> integer value. | ||
| B64 = dict( | ||
|
|
@@ -59,12 +59,10 @@ def parse_vlq(segment): | |
| return values | ||
|
|
||
|
|
||
| def parse_sourcemap(sourcemap): | ||
| def parse_sourcemap(smap): | ||
| """ | ||
| Given a file-like object, yield SourceMap objects as they are read from it. | ||
| Given a sourcemap json object, yield SourceMap objects as they are read from it. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "file-like object" has meaning in the python community. It means it adheres to some subset of the python File API and can be treated like a file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that makes sense, the reason I changed the doc string was cecause the function now takes the source map after it has already been parsed to json instead of taking the raw source map which is what I thought file-like object was referring to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation and terminology are not my strong suite, if you have a suggestion for a better doc string I'd be happy to use it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes total sense. I didn't realize the api was actually changing. :)
|
||
| """ | ||
|
|
||
| smap = json.loads(sourcemap) | ||
| sources = smap['sources'] | ||
| sourceRoot = smap.get('sourceRoot') | ||
| names = smap['names'] | ||
|
|
@@ -108,16 +106,27 @@ def parse_sourcemap(sourcemap): | |
|
|
||
|
|
||
| def sourcemap_to_index(sourcemap): | ||
| smap = json.loads(sourcemap) | ||
|
|
||
| state_list = [] | ||
| key_list = [] | ||
| src_list = set() | ||
| content = None | ||
|
|
||
| if 'sourcesContent' in smap: | ||
| content = {} | ||
| for idx, source in enumerate(smap['sources']): | ||
| if smap['sourcesContent'][idx]: | ||
| content[source] = smap['sourcesContent'][idx].splitlines() | ||
| else: | ||
| content[source] = [] | ||
|
|
||
| for state in parse_sourcemap(sourcemap): | ||
| for state in parse_sourcemap(smap): | ||
| state_list.append(state) | ||
| key_list.append((state.dst_line, state.dst_col)) | ||
| src_list.add(state.src) | ||
|
|
||
| return SourceMapIndex(state_list, key_list, src_list) | ||
| return SourceMapIndex(state_list, key_list, src_list, content) | ||
|
|
||
|
|
||
| def find_source(indexed_sourcemap, lineno, colno): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will leave this to the maintainers to finally decide, but python folks tend to appreciate longer, clearer variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to prefer longer more explicit variable names as well, my reason for changing this was to maintain the relationship between the variable names and what the represent. In both the old and new version
smaprepresents the source map after it hasbeen parsed, and
sourcemaprepresents the unprocessed sourcemap, but I would be more than happy to use more explicit names. I was just trying to change things as little as possible