-
Notifications
You must be signed in to change notification settings - Fork 30k
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
lib: don't match sourceMappingURL
in strings
#44658
Conversation
09d29a2
to
51f24d5
Compare
51f24d5
to
1c54fff
Compare
1c54fff
to
3e43e1c
Compare
3e43e1c
to
d308119
Compare
d308119
to
15db6d8
Compare
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 found that v8 has been more strict than what Node.js does to parsing the source map magic comments. AFAICT, we don't have a written spec on the magic comment formats. I'll bring this topic to the TC39 tooling discussion to see what can we do to reduce the divergence here.
Anyway, this change looks good to me! Thank you for working on this.
"use strict"; | ||
const content = '/*# sourceMappingURL='; | ||
throw new Error('an exception.'); | ||
//# sourceMappingURL=typescript-sourcemapping_url_string.js.map |
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.
With a deeper dig, I found that this works because of the trailing mark $
in the RegExp: i.e. the search begins from the tail of the source content.
If a statement of a string literal that contains a magic comment is present after the actual source map magic comment, this still matches the string literal instead of the actual magic comment.
But I assume we should always take the last magic comment present in the source content, and the magic comment always comes after the real source content. Maybe we can simply add the $
mark in the RegExp instead.
(sorry for the churn, it's late night and I really need to go to sleep 😴)
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.
Thanks for the feedback. I did go down the root at the beginning but found out that when both sourceMappingURL
and sourceURL
are specified.
Ex:
node/test/fixtures/source-map/tabs.js
Lines 55 to 56 in 85b46e1
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFicy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRhYnMuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBYTtFQUFBO0FB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M6XG5zcXVhcmUgPSAoeCkgLT4geCAqIHhcblxuIyBBcnJheXM6XG5saXN0ID0gWzEsIDIsIDMsIDQsIDVdXG5cbiMgT2JqZWN0czpcbm1hdGggPVxuXHRyb290OiAgIE1hdGguc3FydFxuXHRzcXVhcmU6IHNxdWFyZVxuXHRjdWJlOiAgICh4KSAtPiB4ICogc3F1YXJlIHhcblxuIyBTcGxhdHM6XG5yYWNlID0gKHdpbm5lciwgcnVubmVycy4uLikgLT5cblx0cHJpbnQgd2lubmVyLCBydW5uZXJzXG5cbiMgRXhpc3RlbmNlOlxuaWYgdHJ1ZVxuXHRhbGVydCBcIkkga25ldyBpdCFcIlxuXG4jIEFycmF5IGNvbXByZWhlbnNpb25zOlxuY3ViZXMgPSAobWF0aC5jdWJlIG51bSBmb3IgbnVtIGluIGxpc3QpXG4iXX0= | |
//# sourceURL=/Users/bencoe/oss/coffee-script-test/tabs.coffee |
I did however, go back and amend the RegExp to use the global flag which makes this simpler.
15db6d8
to
098f579
Compare
@alan-agius4 don't hesitate not to force push when pushing more updates, it creates a poor reviewer experience because GitHub is not able to show the diff since the last review, it's a bit frustrating to have to "start over" the review again and again. If instead, you push additional commits to the branch, that would be better for me (and all commits will be squashed into one upon landing anyway). |
Prior to this change `sourceMappingURL` in string where being matched by the RegExp which caused sourcemaps not be loaded when using the `--enable-source-maps` flag. This commit changes the RegExp to match the last occurrence. Fixes: nodejs#44654
098f579
to
680947c
Compare
Oops sorry about that. I will keep this in mind for the next time. |
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.
This deserves some comments as I don't think it would be obvious to future reader why we use a loop.
Added comments. |
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
Anything needed from my end to make this green? As the failures seems unrelated to this change. Should I rebase? |
Please don't, it wouldn't help in this case. CI failures seem indeed to be unrelated, I've resumed the CI, hopefully that'd be enough to turn it green. |
Prior to this change `sourceMappingURL` in string where being matched by the RegExp which caused sourcemaps not be loaded when using the `--enable-source-maps` flag. This commit changes the RegExp to match the last occurrence. Fixes: #44654 PR-URL: #44658 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Landed in e6018e2. Thank you for your contribution! |
Prior to this change `sourceMappingURL` in string where being matched by the RegExp which caused sourcemaps not be loaded when using the `--enable-source-maps` flag. This commit changes the RegExp to match the last occurrence. Fixes: #44654 PR-URL: #44658 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Prior to this change `sourceMappingURL` in string where being matched by the RegExp which caused sourcemaps not be loaded when using the `--enable-source-maps` flag. This commit changes the RegExp to match the last occurrence. Fixes: #44654 PR-URL: #44658 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Prior to this change `sourceMappingURL` in string where being matched by the RegExp which caused sourcemaps not be loaded when using the `--enable-source-maps` flag. This commit changes the RegExp to match the last occurrence. Fixes: #44654 PR-URL: #44658 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This depends on #43875; marking this as "backport-blocked-v16.x" |
Prior to this change
sourceMappingURL
in string where being matched by the RegExp which caused sourcemaps not be loaded when using the--enable-source-maps
flag. This commit changes the RegExp to match the last occurrence.Fixes: #44654