Skip to content

Commit

Permalink
fix: source maps for manually added multi-line content (#15365)
Browse files Browse the repository at this point in the history
Fixes #15363
  • Loading branch information
liuxingbaoyu committed Jan 25, 2023
1 parent 112169c commit 6de6d58
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sourceMap": "inline"
}
"sourceMaps": "inline"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
line1
line2
*/
const myConst = 'ANY CODE OR NO CODE AT ALL';
export { myConst };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sourceType": "module",
"inputSourceMap": true,
"plugins": ["./plugin.js"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*line1
line2*/
/*
line1
line2
*/
const myConst = 'ANY CODE OR NO CODE AT ALL';
export { myConst };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function () {
return {
visitor: {
Program(path) {
path.addComment("leading", "line1\nline2");
},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 3,
"names": [
"myConst"
],
"sources": [
"source-maps/add-multi-line-comments/input.js"
],
"sourcesContent": [
"/*\nline1\nline2\n*/\nconst myConst = 'ANY CODE OR NO CODE AT ALL';\nexport { myConst };"
],
"mappings": ";;AAAA;AACA;AACA;AACA;AACA,MAAMA,OAAO,GAAG,4BAA4B;AAC5C,SAASA,OAAO"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-arrow-functions", "transform-function-name"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-classes", "transform-block-scoping"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"sourcesContent": [
"class Test {\n get bar() {\n throw new Error(\"wow\");\n }\n}\n\nvar test = new Test;\ntest.bar;"
],
"mappings": "IAAMA,IAAI;EAAA;;EAAA;IAAA;EAAA;;EAAA;IAAA;IAAA,KACR,YAAU;MACR,MAAM,IAAIC,KAAK,CAAC,KAAK,CAAC;IACxB;EAAC;EAAA;AAAA;;AAGH,IAAIC,IAAI,GAAG,IAAIF,IAAI;AACnBE,IAAI,CAACC,GAAG"
"mappings": "IAAMA,IAAI;EAAA;;EAAA;IAAA;EAAA;EAAA;IAAA;IAAA,KACR,YAAU;MACR,MAAM,IAAIC,KAAK,CAAC,KAAK,CAAC;IACxB;EAAC;EAAA;AAAA;AAGH,IAAIC,IAAI,GAAG,IAAIF,IAAI;AACnBE,IAAI,CAACC,GAAG"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-arrow-functions"],
"sourceMap": "inline"
"sourceMaps": "inline"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-modules-commonjs"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 3,
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFA;EACAA;;EACAC;IACA;MACAC;IACA;EACA;;AACA",
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFA;EACAA;EACAC;IACA;MACAC;IACA;EACA;AACA",
"names": [
"name",
"data",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 3,
"mappings": "AAAC,KAAG;;ACCJ,SAASA,GAAG,CAACC,GAAW;EACpB,MAAM,IAAIC,KAAK,CAAC,cAAc,CAAC;AACnC",
"mappings": "AAAC,KAAG;ACCJ,SAASA,GAAG,CAACC,GAAW;EACpB,MAAM,IAAIC,KAAK,CAAC,cAAc,CAAC;AACnC",
"names": [
"foo",
"bar",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sourceMap": true
"sourceMaps": true
}
3 changes: 2 additions & 1 deletion packages/babel-generator/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ export default class Buffer {

// We mark the start of each line, which happens directly after this newline char
// unless this is the last char.
if (last < len) {
// When manually adding multi-line content (such as a comment), `line` will be `undefined`.
if (last < len && line !== undefined) {
this._mark(++line, 0, identifierName, filename);
}
i = str.indexOf("\n", last);
Expand Down
11 changes: 9 additions & 2 deletions packages/babel-helper-transform-fixture-test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,15 @@ export default function (

async function () {
const runTask = () => run(task);
if ("sourceMap" in task.options === false) {
task.options.sourceMap = !!task.sourceMap;

if ("sourceMap" in task.options) {
throw new Error(
"`sourceMap` option is deprecated. Use `sourceMaps` instead.",
);
}

if ("sourceMaps" in task.options === false) {
task.options.sourceMaps = !!task.sourceMap;
}

Object.assign(task.options, taskOpts);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-destructuring"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"sourcesContent": [
"const fn = (arg) => {\n var [x, y] = arg;\n}"
],
"mappings": "AAAA,MAAMA,EAAE,GAAIC,GAAG,IAAK;EAClB,sCAAaA,GAAG;EAAA,IAAXC,CAAC;EAAA,IAAEC,CAAC;AACX,CAAC"
"mappings": "AAAA,MAAMA,EAAE,GAAIC,GAAG,IAAK;EAClB,sCAAaA,GAAG;IAAXC,CAAC;IAAEC,CAAC;AACX,CAAC"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"externalHelpers": true,
"plugins": ["transform-modules-commonjs"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"sourcesContent": [
"import aDefault from \"one\";\nimport { aNamed } from \"two\";\nimport { orig as anAliased } from \"three\";\nimport * as aNamespace from \"four\";\n\nconsole.log(aDefault);\nconsole.log(aNamed);\nconsole.log(anAliased);\nconsole.log(aNamespace);\n\nconsole.log(aDefault());\nconsole.log(aNamed());\nconsole.log(anAliased());\nconsole.log(aNamespace());"
],
"mappings": ";;AAAA;;AACA;;AACA;;AACA;AAEAA,OAAO,CAACC,GAAG,CAACC,YAAQ,CAAC;AACrBF,OAAO,CAACC,GAAG,CAACE,WAAM,CAAC;AACnBH,OAAO,CAACC,GAAG,CAACG,WAAS,CAAC;AACtBJ,OAAO,CAACC,GAAG,CAACI,UAAU,CAAC;AAEvBL,OAAO,CAACC,GAAG,CAAC,IAAAC,YAAQ,GAAE,CAAC;AACvBF,OAAO,CAACC,GAAG,CAAC,IAAAE,WAAM,GAAE,CAAC;AACrBH,OAAO,CAACC,GAAG,CAAC,IAAAG,WAAS,GAAE,CAAC;AACxBJ,OAAO,CAACC,GAAG,CAACI,UAAU,EAAE,CAAC"
"mappings": ";;AAAA;AACA;AACA;AACA;AAEAA,OAAO,CAACC,GAAG,CAACC,YAAQ,CAAC;AACrBF,OAAO,CAACC,GAAG,CAACE,WAAM,CAAC;AACnBH,OAAO,CAACC,GAAG,CAACG,WAAS,CAAC;AACtBJ,OAAO,CAACC,GAAG,CAACI,UAAU,CAAC;AAEvBL,OAAO,CAACC,GAAG,CAAC,IAAAC,YAAQ,GAAE,CAAC;AACvBF,OAAO,CAACC,GAAG,CAAC,IAAAE,WAAM,GAAE,CAAC;AACrBH,OAAO,CAACC,GAAG,CAAC,IAAAG,WAAS,GAAE,CAAC;AACxBJ,OAAO,CAACC,GAAG,CAACI,UAAU,EAAE,CAAC"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "sourceMap": true }
{ "sourceMaps": true }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sourceType": "module",
"plugins": [["transform-react-jsx", { "runtime": "classic" }]],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-arrow-functions"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"sourcesContent": [
"function fn() {\n var inner = () => {\n console.log(arguments);\n };\n}"
],
"mappings": "AAAA,SAASA,EAAE,GAAG;EAAA;;EACZ,IAAIC,KAAK,GAAG,YAAM;IAChBC,OAAO,CAACC,GAAG,CAACC,UAAS,CAAC;EACxB,CAAC;AACH"
"mappings": "AAAA,SAASA,EAAE,GAAG;EAAA;EACZ,IAAIC,KAAK,GAAG,YAAM;IAChBC,OAAO,CAACC,GAAG,CAACC,UAAS,CAAC;EACxB,CAAC;AACH"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["transform-arrow-functions"],
"sourceMap": true
"sourceMaps": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"sourcesContent": [
"function fn() {\n var inner = () => {\n console.log(this);\n };\n}"
],
"mappings": "AAAA,SAASA,EAAE,GAAG;EAAA;;EACZ,IAAIC,KAAK,GAAG,YAAM;IAChBC,OAAO,CAACC,GAAG,CAAC,KAAI,CAAC;EACnB,CAAC;AACH"
"mappings": "AAAA,SAASA,EAAE,GAAG;EAAA;EACZ,IAAIC,KAAK,GAAG,YAAM;IAChBC,OAAO,CAACC,GAAG,CAAC,KAAI,CAAC;EACnB,CAAC;AACH"
}

0 comments on commit 6de6d58

Please sign in to comment.