fix(es): Allow extra comments after sourceMappingURL (#7262)

This commit is contained in:
limerick 2023-04-15 08:35:04 +08:00 committed by GitHub
parent 5f0660667f
commit 219a738a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 1 deletions

View File

@ -309,7 +309,15 @@ impl Compiler {
let read_sourcemap = || -> Result<Option<sourcemap::SourceMap>, Error> {
let s = "sourceMappingURL=";
let idx = fm.src.rfind(s);
let data_url = idx.map(|idx| &fm.src[idx + s.len()..]);
let data_url = idx.map(|idx| {
let data_idx = idx + s.len();
if let Some(end) = fm.src[data_idx..].find('\n').map(|i| i + data_idx + 1) {
&fm.src[data_idx..end]
} else {
&fm.src[data_idx..]
}
});
match read_inline_sourcemap(data_url) {
Ok(r) => Ok(r),

View File

@ -74,6 +74,11 @@ fn case_inline() {
inline("tests/srcmap/case-inline/index.js");
}
#[test]
fn case_inline_extra_content() {
inline("tests/srcmap/case-inline-extra-content/index.js");
}
#[test]
fn issue_622() {
file("tests/srcmap/issue-622/index.js", Default::default()).unwrap();

View File

@ -0,0 +1,3 @@
{
"inputSourceMap": true,
}

View File

@ -0,0 +1,27 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Foo = /** @class */ (function () {
function Foo() {
}
return Foo;
}());
var Bar = /** @class */ (function (_super) {
__extends(Bar, _super);
function Bar() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Bar;
}(Foo));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7O0FBQUE7SUFBQTtJQUVBLENBQUM7SUFBRCxVQUFDO0FBQUQsQ0FBQyxBQUZELElBRUM7QUFFRDtJQUFrQix1QkFBRztJQUFyQjs7SUFFQSxDQUFDO0lBQUQsVUFBQztBQUFELENBQUMsQUFGRCxDQUFrQixHQUFHLEdBRXBCIn0=
// extra content