Skip to content

Commit

Permalink
fix: Handling source maps without sourcesContent (#15445)
Browse files Browse the repository at this point in the history
* fix

* improve
  • Loading branch information
liuxingbaoyu committed Feb 20, 2023
1 parent 49e4855 commit dd776da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-generator/src/source-map.ts
Expand Up @@ -58,7 +58,7 @@ export default class SourceMap {
setSourceContent(
map,
resolvedSources[i],
this._inputMap.sourcesContent[i],
this._inputMap.sourcesContent?.[i],
);
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -880,6 +880,40 @@ describe("generation", function () {
});"
`);
});

it("inputSourceMap without sourcesContent", () => {
const ast = parse("var t = x => x * x;");

expect(
generate(ast, {
sourceMaps: true,
inputSourceMap: {
version: 3,
names: ["t", "x"],
sources: ["source-maps/arrow-function/input.js"],
mappings:
"AAAA,IAAIA,CAAC,GAAG,SAAJA,CAACA,CAAGC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAC;AAAA",
},
}).map,
).toMatchInlineSnapshot(`
Object {
"file": undefined,
"mappings": "AAAA,IAAIA,CAAC,GAAGC,CAAA,IAAAA,CAAA,GAAJA,CAAC",
"names": Array [
"t",
"x",
],
"sourceRoot": undefined,
"sources": Array [
"source-maps/arrow-function/input.js",
],
"sourcesContent": Array [
undefined,
],
"version": 3,
}
`);
});
});

describe("programmatic generation", function () {
Expand Down

0 comments on commit dd776da

Please sign in to comment.