From e854fa776b0f5cd39d8592c7561e11bb946b5a20 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Thu, 6 Oct 2022 06:27:32 +0800 Subject: [PATCH 01/14] feat --- packages/babel-generator/src/buffer.ts | 12 +++--------- .../babel-generator/src/generators/methods.ts | 17 +++++++++++++---- .../babel-generator/src/generators/types.ts | 8 +++++++- packages/babel-generator/src/printer.ts | 7 +++++++ .../sourcemaps/call-identifiers/output.js | 2 +- .../real-world-babel-file1/source-map.json | 8 +++----- .../real-world-babel-file2/source-map.json | 8 +++----- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/packages/babel-generator/src/buffer.ts b/packages/babel-generator/src/buffer.ts index 85e214684c43..a27e2e502bf6 100644 --- a/packages/babel-generator/src/buffer.ts +++ b/packages/babel-generator/src/buffer.ts @@ -8,13 +8,12 @@ export type Pos = { export type Loc = { start?: Pos; end?: Pos; - identifierName?: string; filename?: string; }; type SourcePos = { - identifierName: string | undefined; line: number | undefined; column: number | undefined; + identifierName: string | undefined; filename: string | undefined; }; @@ -23,7 +22,7 @@ type QueueItem = { repeat: number; line: number | undefined; column: number | undefined; - identifierName: string | undefined; + identifierName: undefined; // Not used, it always undefined. filename: string | undefined; }; @@ -73,7 +72,6 @@ export default class Buffer { repeat: number, line: number | undefined, column: number | undefined, - identifierName: string | undefined, filename: string | undefined, ) { const cursor = this._queueCursor; @@ -85,7 +83,6 @@ export default class Buffer { item.repeat = repeat; item.line = line; item.column = column; - item.identifierName = identifierName; item.filename = filename; this._queueCursor++; @@ -173,7 +170,6 @@ export default class Buffer { 1, sourcePosition.line, sourcePosition.column, - sourcePosition.identifierName, sourcePosition.filename, ); } @@ -182,7 +178,7 @@ export default class Buffer { * Same as queue, but this indentation will never have a sourcmap marker. */ queueIndentation(char: number, repeat: number): void { - this._pushQueue(char, repeat, undefined, undefined, undefined, undefined); + this._pushQueue(char, repeat, undefined, undefined, undefined); } _flush(): void { @@ -428,8 +424,6 @@ export default class Buffer { const pos = loc[prop]; const target = this._sourcePosition; - target.identifierName = - (prop === "start" && loc.identifierName) || undefined; if (pos) { target.line = pos.line + lineOffset; target.column = pos.column + columnOffset; diff --git a/packages/babel-generator/src/generators/methods.ts b/packages/babel-generator/src/generators/methods.ts index e8a94da32898..d9228ef02e43 100644 --- a/packages/babel-generator/src/generators/methods.ts +++ b/packages/babel-generator/src/generators/methods.ts @@ -5,9 +5,18 @@ import type * as t from "@babel/types"; export function _params( this: Printer, node: t.Function | t.TSDeclareMethod | t.TSDeclareFunction, + id: t.Expression | t.PrivateName, ) { this.print(node.typeParameters, node); - this.token("("); + if (isIdentifier(id)) { + // @ts-expect-error Undocumented property identifierName + this.withIdentifierName(id.loc?.identifierName || id.name, () => { + this.token("("); + }); + } else { + this.token("("); + } + this._parameters(node.params, node); this.token(")"); @@ -106,7 +115,7 @@ export function _methodHead(this: Printer, node: t.Method | t.TSDeclareMethod) { this.token("?"); } - this._params(node); + this._params(node, key); } export function _predicate( @@ -152,7 +161,7 @@ export function _functionHead( this.print(node.id, node); } - this._params(node); + this._params(node, node.id); if (node.type !== "TSDeclareFunction") { this._predicate(node); } @@ -186,7 +195,7 @@ export function ArrowFunctionExpression( ) { this.print(firstParam, node, true); } else { - this._params(node); + this._params(node, undefined); } this._predicate(node, true); diff --git a/packages/babel-generator/src/generators/types.ts b/packages/babel-generator/src/generators/types.ts index ce9addd525f0..64935cdb2dc6 100644 --- a/packages/babel-generator/src/generators/types.ts +++ b/packages/babel-generator/src/generators/types.ts @@ -4,7 +4,13 @@ import type * as t from "@babel/types"; import jsesc from "jsesc"; export function Identifier(this: Printer, node: t.Identifier) { - this.word(node.name); + this.withIdentifierName( + // @ts-expect-error Undocumented property identifierName + node.loc?.identifierName || node.name, + () => { + this.word(node.name); + }, + ); } export function ArgumentPlaceholder(this: Printer) { diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index 5832e1dfa96b..917ffeb8cbb4 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -364,6 +364,13 @@ class Printer { this._buf.withSource(prop, loc, cb); } + withIdentifierName(identifierName: string, cb: () => void): void { + const pos = this._buf._sourcePosition; + pos.identifierName = identifierName; + cb(); + pos.identifierName = undefined; + } + _space(): void { this._queue(charCodes.space); } diff --git a/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/output.js b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/output.js index 2aa2d3b2b022..f913bd9810df 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/output.js +++ b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/output.js @@ -13,4 +13,4 @@ obj.foo().bar; obj.foo(); obj.foo.bar; obj.foo().bar; -} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json index 7b69685247d6..a5bf61fde148 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json @@ -68,11 +68,9 @@ "err", "error" ], - "sources": [ - "fixtures/sourcemaps/real-world-babel-file1/input.ts" - ], + "sources": ["fixtures/sourcemaps/real-world-babel-file1/input.ts"], "sourcesContent": [ "// From packages\\babel-cli\\src\\babel\\watcher.ts\n\nimport { createRequire } from \"module\";\nimport path from \"path\";\nimport type { WatchOptions, FSWatcher } from \"chokidar\";\n\nconst fileToDeps = new Map>();\nconst depToFiles = new Map>();\n\nlet isWatchMode = false;\nlet watcher: FSWatcher;\nconst watchQueue = new Set();\nlet hasStarted = false;\n\nexport function enable({ enableGlobbing }: { enableGlobbing: boolean }) {\n isWatchMode = true;\n\n const { FSWatcher } = requireChokidar();\n\n const options: WatchOptions = {\n disableGlobbing: !enableGlobbing,\n persistent: true,\n ignoreInitial: true,\n awaitWriteFinish: {\n stabilityThreshold: 50,\n pollInterval: 10,\n },\n };\n watcher = new FSWatcher(options);\n\n watcher.on(\"unlink\", unwatchFile);\n}\n\nexport function startWatcher() {\n hasStarted = true;\n\n for (const dep of watchQueue) {\n watcher.add(dep);\n }\n watchQueue.clear();\n\n watcher.on(\"ready\", () => {\n console.log(\"The watcher is ready.\");\n });\n}\n\nexport function watch(filename: string): void {\n if (!isWatchMode) {\n throw new Error(\n \"Internal Babel error: .watch called when not in watch mode.\",\n );\n }\n\n if (!hasStarted) {\n watchQueue.add(path.resolve(filename));\n } else {\n watcher.add(path.resolve(filename));\n }\n}\n\n/**\n * Call @param callback whenever a dependency (source file)/\n * external dependency (non-source file) changes.\n *\n * Handles mapping external dependencies to their corresponding\n * dependencies.\n */\nexport function onFilesChange(\n callback: (filenames: string[], event: string, cause: string) => void,\n): void {\n if (!isWatchMode) {\n throw new Error(\n \"Internal Babel error: .onFilesChange called when not in watch mode.\",\n );\n }\n\n watcher.on(\"all\", (event, filename) => {\n if (event !== \"change\" && event !== \"add\") return;\n\n const absoluteFile = path.resolve(filename);\n callback(\n [absoluteFile, ...(depToFiles.get(absoluteFile) ?? [])],\n event,\n absoluteFile,\n );\n });\n}\n\nexport function updateExternalDependencies(\n filename: string,\n dependencies: Set,\n) {\n if (!isWatchMode) return;\n\n // Use absolute paths\n const absFilename = path.resolve(filename);\n const absDependencies = new Set(\n Array.from(dependencies, dep => path.resolve(dep)),\n );\n\n const deps = fileToDeps.get(absFilename);\n if (deps) {\n for (const dep of deps) {\n if (!absDependencies.has(dep)) {\n removeFileDependency(absFilename, dep);\n }\n }\n }\n for (const dep of absDependencies) {\n let deps = depToFiles.get(dep);\n if (!deps) {\n depToFiles.set(dep, (deps = new Set()));\n\n if (!hasStarted) {\n watchQueue.add(dep);\n } else {\n watcher.add(dep);\n }\n }\n\n deps.add(absFilename);\n }\n\n fileToDeps.set(absFilename, absDependencies);\n}\n\nfunction removeFileDependency(filename: string, dep: string) {\n const deps = depToFiles.get(dep) as Set;\n deps.delete(filename);\n\n if (deps.size === 0) {\n depToFiles.delete(dep);\n\n if (!hasStarted) {\n watchQueue.delete(dep);\n } else {\n watcher.unwatch(dep);\n }\n }\n}\n\nfunction unwatchFile(filename: string) {\n const deps = fileToDeps.get(filename);\n if (!deps) return;\n\n for (const dep of deps) {\n removeFileDependency(filename, dep);\n }\n fileToDeps.delete(filename);\n}\n\nfunction requireChokidar(): any {\n const require = createRequire(import.meta.url);\n\n try {\n return process.env.BABEL_8_BREAKING\n ? require(\"chokidar\")\n : parseInt(process.versions.node) >= 8\n ? require(\"chokidar\")\n : require(\"@nicolo-ribaudo/chokidar-2\");\n } catch (err) {\n console.error(\n \"The optional dependency chokidar failed to install and is required for \" +\n \"--watch. Chokidar is likely not supported on your platform.\",\n );\n throw err;\n }\n}" ], - "mappings": "AAAA;;AAEA,SAASA,aAAa,QAAQ,QAAQ;AACtC,OAAOC,IAAI,MAAM,MAAM;AACvB,cAAcC,YAAY,EAAEC,SAAS,QAAQ,UAAU;AAEvD,MAAMC,UAAU,GAAG,IAAIC,GAAG,CAAC,MAAM,EAAEC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE;AACjD,MAAMC,UAAU,GAAG,IAAIF,GAAG,CAAC,MAAM,EAAEC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE;AAEjD,IAAIE,WAAW,GAAG,KAAK;AACvB,IAAIC,OAAO,EAAEN,SAAS;AACtB,MAAMO,UAAU,GAAG,IAAIJ,GAAG,CAAC,MAAM,CAAC,EAAE;AACpC,IAAIK,UAAU,GAAG,KAAK;AAEtB,OAAO,SAASC,MAAM,CAAC;EAAEC;AAA4C,CAA5B,EAAE;EAAEA,cAAc,EAAE,OAAO;AAAC,CAAC,EAAE;EACtEL,WAAW,GAAG,IAAI;EAElB,MAAM;IAAEL;EAAU,CAAC,GAAGW,eAAe,EAAE;EAEvC,MAAMC,OAAO,EAAEb,YAAY,GAAG;IAC5Bc,eAAe,EAAE,CAACH,cAAc;IAChCI,UAA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ACqC,KAAK,CACX,yEAAyE,GACvE,6DAA6D,CAChE;IACD,MAAMD,GAAG;EACX;AACF" +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/source-map.json index 9785528535d9..ec06eba70c1f 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/source-map.json +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/source-map.json @@ -247,11 +247,9 @@ "Noop", "GeneratorFunctions" ], - "sources": [ - "fixtures/sourcemaps/real-world-babel-file2/input.ts" - ], + "sources": ["fixtures/sourcemaps/real-world-babel-file2/input.ts"], "sourcesContent": [ "// From packages\\babel-generator\\src\\printer.ts\n\nimport Buffer from \"./buffer\";\nimport type { Loc } from \"./buffer\";\nimport * as n from \"./node\";\nimport type * as t from \"@babel/types\";\nimport type {\n RecordAndTuplePluginOptions,\n PipelineOperatorPluginOptions,\n} from \"@babel/parser\";\nimport type { Opts as jsescOptions } from \"jsesc\";\n\nimport * as generatorFunctions from \"./generators\";\nimport type SourceMap from \"./source-map\";\nimport * as charCodes from \"charcodes\";\n\nconst SCIENTIFIC_NOTATION = /e/i;\nconst ZERO_DECIMAL_INTEGER = /\\.0+$/;\nconst NON_DECIMAL_LITERAL = /^0[box]/;\nconst PURE_ANNOTATION_RE = /^\\s*[@#]__PURE__\\s*$/;\n\nconst { needsParens, needsWhitespaceAfter, needsWhitespaceBefore } = n;\n\nexport type Format = {\n shouldPrintComment: (comment: string) => boolean;\n retainLines: boolean;\n retainFunctionParens: boolean;\n comments: boolean;\n auxiliaryCommentBefore: string;\n auxiliaryCommentAfter: string;\n compact: boolean | \"auto\";\n minified: boolean;\n concise: boolean;\n indent: {\n adjustMultilineComment: boolean;\n style: string;\n };\n recordAndTupleSyntaxType: RecordAndTuplePluginOptions[\"syntaxType\"];\n jsescOption: jsescOptions;\n jsonCompatibleStrings?: boolean;\n /**\n * For use with the Hack-style pipe operator.\n * Changes what token is used for pipe bodies’ topic references.\n */\n topicToken?: PipelineOperatorPluginOptions[\"topicToken\"];\n /**\n * @deprecated Removed in Babel 8\n */\n decoratorsBeforeExport?: boolean;\n};\n\ninterface AddNewlinesOptions {\n addNewlines(leading: boolean, node: t.Node): number;\n}\n\ninterface PrintSequenceOptions extends Partial {\n statement?: boolean;\n indent?: boolean;\n}\n\ninterface PrintListOptions {\n separator?: (this: Printer) => void;\n statement?: boolean;\n indent?: boolean;\n}\n\ntype PrintJoinOptions = PrintListOptions &\n PrintSequenceOptions & {\n iterator?: (node: t.Node, index: number) => void;\n };\nclass Printer {\n constructor(format: Format, map: SourceMap) {\n this.format = format;\n this._buf = new Buffer(map);\n\n this._indentChar = format.indent.style.charCodeAt(0);\n this._indentRepeat = format.indent.style.length;\n }\n\n declare format: Format;\n inForStatementInitCounter: number = 0;\n\n declare _buf: Buffer;\n _printStack: Array = [];\n _indent: number = 0;\n _indentChar: number = 0;\n _indentRepeat: number = 0;\n _insideAux: boolean = false;\n _parenPushNewlineState: { printed: boolean } | null = null;\n _noLineTerminator: boolean = false;\n _printAuxAfterOnNextUserNode: boolean = false;\n _printedComments = new Set();\n _endsWithInteger = false;\n _endsWithWord = false;\n\n generate(ast: t.Node) {\n this.print(ast);\n this._maybeAddAuxComment();\n\n return this._buf.get();\n }\n\n /**\n * Increment indent size.\n */\n\n indent(): void {\n if (this.format.compact || this.format.concise) return;\n\n this._indent++;\n }\n\n /**\n * Decrement indent size.\n */\n\n dedent(): void {\n if (this.format.compact || this.format.concise) return;\n\n this._indent--;\n }\n\n /**\n * Add a semicolon to the buffer.\n */\n\n semicolon(force: boolean = false): void {\n this._maybeAddAuxComment();\n if (force) {\n this._appendChar(charCodes.semicolon);\n } else {\n this._queue(charCodes.semicolon);\n }\n }\n\n /**\n * Add a right brace to the buffer.\n */\n\n rightBrace(): void {\n if (this.format.minified) {\n this._buf.removeLastSemicolon();\n }\n this.token(\"}\");\n }\n\n /**\n * Add a space to the buffer unless it is compact.\n */\n\n space(force: boolean = false): void {\n if (this.format.compact) return;\n\n if (force) {\n this._space();\n } else if (this._buf.hasContent()) {\n const lastCp = this.getLastChar();\n if (lastCp !== charCodes.space && lastCp !== charCodes.lineFeed) {\n this._space();\n }\n }\n }\n\n /**\n * Writes a token that can't be safely parsed without taking whitespace into account.\n */\n\n word(str: string): void {\n // prevent concatenating words and creating // comment out of division and regex\n if (\n this._endsWithWord ||\n (str.charCodeAt(0) === charCodes.slash && this.endsWith(charCodes.slash))\n ) {\n this._space();\n }\n\n this._maybeAddAuxComment();\n this._append(str, false);\n\n this._endsWithWord = true;\n }\n\n /**\n * Writes a number token so that we can validate if it is an integer.\n */\n\n number(str: string): void {\n this.word(str);\n\n // Integer tokens need special handling because they cannot have '.'s inserted\n // immediately after them.\n this._endsWithInteger =\n Number.isInteger(+str) &&\n !NON_DECIMAL_LITERAL.test(str) &&\n !SCIENTIFIC_NOTATION.test(str) &&\n !ZERO_DECIMAL_INTEGER.test(str) &&\n str.charCodeAt(str.length - 1) !== charCodes.dot;\n }\n\n /**\n * Writes a simple token.\n */\n\n token(str: string, maybeNewline = false): void {\n // space is mandatory to avoid outputting \n\n" - ] + ], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFA;EACAA,IAAA;EACAC,KAAA;IACA;MACAC,GAAA;IACA;EACA;AACA,G" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json index 1b9392bc5377..aa80cf5ef409 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json @@ -1,11 +1,13 @@ { "version": 3, - "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", - "names": [], + "names": [ + "foo" + ], "sources": [ "original.js" ], "sourcesContent": [ "var foo = () => 4;" - ] + ], + "mappings": "AAAA,IAAAA,GAAA,GAAU,SAAAA,CAAA,E;SAAM,C;CAAC" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json index 050799fd70f9..a5f1938f9f60 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json @@ -1,13 +1,17 @@ { "version": 3, - "mappings": "AAAC,KAAG;ACAJ,KAAG", "names": [], "sources": [ + "input.tsx", + "source-maps/input-source-map-multiple-output-sources-complete-replace/input.js", "bar.js", "baz.js" ], "sourcesContent": [ + "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}", + "foo(1);\nfunction foo(bar) {\n throw new Error('Intentional.');\n}\n//# sourceMappingURL=input.js.map", "", "baz();" - ] + ], + "mappings": "AAAA,KAAI;AAAJ,KAAG" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json index fd627dac5f6b..2a794dfd9964 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json @@ -1,17 +1,19 @@ { "version": 3, - "mappings": "AAAC,KAAG;ACCJ,SAASA,GAAG,CAACC,GAAW;EACpB,MAAM,IAAIC,KAAK,CAAC,cAAc,CAAC;AACnC", "names": [ "foo", "bar", "Error" ], "sources": [ - "test.js", - "input.tsx" + "input.tsx", + "source-maps/input-source-map-multiple-output-sources/input.js", + "test.js" ], "sourcesContent": [ - "", - "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}" - ] + "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}", + "foo(1);\nfunction foo(bar) {\n throw new Error('Intentional.');\n}\n//# sourceMappingURL=input.js.map", + "" + ], + "mappings": "AAAA,KAAI;AACJ,SAASA,GAAGA,CAACC,GAAW;EACpB,MAAM,IAAIC,KAAK,CAAC,cAAc,CAAC;AACnC" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json index 0dde70b60b7c..c90ac92dd77c 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json @@ -1,11 +1,13 @@ { "version": 3, - "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", - "names": [], + "names": [ + "foo" + ], "sources": [ "source-maps/input-source-map-same-location/input.js" ], "sourcesContent": [ "var foo = () => 4;" - ] + ], + "mappings": "AAAA,IAAAA,GAAA,GAAU,SAAAA,CAAA,E;SAAM,C;CAAC" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json index 4a26e2136a38..eb6d4a8e5c3e 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json @@ -1,11 +1,15 @@ { "version": 3, - "mappings": "AAAC,KAAG", "names": [], "sources": [ + "input.tsx", + "source-maps/input-source-map-sources-complete-replace/input.js", "test.js" ], "sourcesContent": [ + "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}", + "foo(1);\nfunction foo(bar) {\n throw new Error('Intentional.');\n}\n//# sourceMappingURL=input.js.map", "" - ] + ], + "mappings": "AAAA,KAAI" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json index 1b9392bc5377..aa80cf5ef409 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json @@ -1,11 +1,13 @@ { "version": 3, - "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", - "names": [], + "names": [ + "foo" + ], "sources": [ "original.js" ], "sourcesContent": [ "var foo = () => 4;" - ] + ], + "mappings": "AAAA,IAAAA,GAAA,GAAU,SAAAA,CAAA,E;SAAM,C;CAAC" } \ No newline at end of file diff --git a/packages/babel-generator/src/buffer.ts b/packages/babel-generator/src/buffer.ts index 5780920d2481..9637b0da7a19 100644 --- a/packages/babel-generator/src/buffer.ts +++ b/packages/babel-generator/src/buffer.ts @@ -42,6 +42,7 @@ export default class Buffer { _last = 0; _queue: QueueItem[] = []; _queueCursor = 0; + _canMarkIdName = true; _position = { line: 1, @@ -226,8 +227,10 @@ export default class Buffer { this._position.column = 0; } - sourcePos.identifierName = undefined; - sourcePos.identifierNamePos = undefined; + if (this._canMarkIdName) { + sourcePos.identifierName = undefined; + sourcePos.identifierNamePos = undefined; + } } _append( @@ -257,7 +260,10 @@ export default class Buffer { const { column, identifierName, identifierNamePos, filename } = sourcePos; let line = sourcePos.line; - if (identifierName != null || identifierNamePos != null) { + if ( + (identifierName != null || identifierNamePos != null) && + this._canMarkIdName + ) { sourcePos.identifierName = undefined; sourcePos.identifierNamePos = undefined; } @@ -407,9 +413,20 @@ export default class Buffer { if (!this._map) return cb(); this.source("start", loc); - + // @ts-expect-error identifierName is not defined + const identifierName = loc.identifierName; + const sourcePos = this._sourcePosition; + if (identifierName) { + this._canMarkIdName = false; + sourcePos.identifierName = identifierName; + } cb(); + if (identifierName) { + this._canMarkIdName = true; + sourcePos.identifierName = undefined; + sourcePos.identifierNamePos = undefined; + } this.source("end", loc); } diff --git a/packages/babel-generator/src/generators/methods.ts b/packages/babel-generator/src/generators/methods.ts index 1dd9f7b45ac1..e6beb1770440 100644 --- a/packages/babel-generator/src/generators/methods.ts +++ b/packages/babel-generator/src/generators/methods.ts @@ -1,12 +1,15 @@ import type Printer from "../printer"; import type * as t from "@babel/types"; import { isIdentifier } from "@babel/types"; +import type { NodePath } from "@babel/traverse"; export function _params( this: Printer, node: t.Function | t.TSDeclareMethod | t.TSDeclareFunction, - idNode: t.Node, - parentNode: t.Node, + idNode: t.Expression | t.PrivateName, + parentNode: NodePath< + t.Function | t.TSDeclareMethod | t.TSDeclareFunction + >["parent"], ) { this.print(node.typeParameters, node); @@ -141,7 +144,9 @@ export function _predicate( export function _functionHead( this: Printer, node: t.FunctionDeclaration | t.FunctionExpression | t.TSDeclareFunction, - parent: t.Node, + parent: NodePath< + t.FunctionDeclaration | t.FunctionExpression | t.TSDeclareFunction + >["parent"], ) { if (node.async) { this.word("async"); @@ -174,7 +179,7 @@ export function _functionHead( export function FunctionExpression( this: Printer, node: t.FunctionExpression, - parent: t.Node, + parent: NodePath["parent"], ) { this._functionHead(node, parent); this.space(); @@ -186,7 +191,7 @@ export { FunctionExpression as FunctionDeclaration }; export function ArrowFunctionExpression( this: Printer, node: t.ArrowFunctionExpression, - parent: t.Node, + parent: NodePath["parent"], ) { if (node.async) { this.word("async", true); @@ -236,14 +241,25 @@ function hasTypesOrComments( ); } -function _getFuncIdName(this: Printer, idNode: t.Node, parent: t.Node) { - let id = idNode; +function _getFuncIdName( + this: Printer, + idNode: t.Expression | t.PrivateName, + parent: NodePath< + t.Function | t.TSDeclareMethod | t.TSDeclareFunction + >["parent"], +) { + let id: t.Expression | t.PrivateName | t.LVal = idNode; if (!id && parent) { const parentType = parent.type; if (parentType === "VariableDeclarator") { id = parent.id; + } else if ( + parentType === "AssignmentExpression" || + parentType === "AssignmentPattern" + ) { + id = parent.left; } else if ( parentType === "ObjectProperty" || parentType === "ClassProperty" @@ -251,29 +267,35 @@ function _getFuncIdName(this: Printer, idNode: t.Node, parent: t.Node) { if (!parent.computed || parent.key.type === "StringLiteral") { id = parent.key; } + } else if ( + parentType === "ClassPrivateProperty" || + parentType === "ClassAccessorProperty" + ) { + id = parent.key; } } + if (!id) return; + let nameInfo; - if (id) { - if (id.type === "Identifier") { - nameInfo = { - pos: id.loc?.start, - name: - // @ts-expect-error Undocumented property identifierName - id.loc?.identifierName || id.name, - }; - } else if (id.type === "PrivateName") { - nameInfo = { - pos: id.id.loc?.start, - name: id.id.name, - }; - } else if (id.type === "StringLiteral") { - nameInfo = { - pos: id.loc?.start, - name: id.value, - }; - } + + if (id.type === "Identifier") { + nameInfo = { + pos: id.loc?.start, + name: + // @ts-expect-error Undocumented property identifierName + id.loc?.identifierName || id.name, + }; + } else if (id.type === "PrivateName") { + nameInfo = { + pos: id.loc?.start, + name: "#" + id.id.name, + }; + } else if (id.type === "StringLiteral") { + nameInfo = { + pos: id.loc?.start, + name: id.value, + }; } return nameInfo; diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index a84223f89620..c5585c555bd0 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -1,5 +1,6 @@ import type Printer from "../printer"; import type * as t from "@babel/types"; +import type { NodePath } from "@babel/traverse"; export function TSTypeAnnotation(this: Printer, node: t.TSTypeAnnotation) { this.token(":"); @@ -76,7 +77,7 @@ export function TSParameterProperty( export function TSDeclareFunction( this: Printer, node: t.TSDeclareFunction, - parent: t.Node, + parent: NodePath["parent"], ) { if (node.declare) { this.word("declare"); diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index 981f1ffed9d0..582a3452cdc0 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -369,6 +369,8 @@ class Printer { } sourceIdentifierName(identifierName: string, pos?: Pos): void { + if (!this._buf._canMarkIdName) return; + const sourcePosition = this._buf._sourcePosition; sourcePosition.identifierNamePos = pos; sourcePosition.identifierName = identifierName; diff --git a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/input.js b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/input.js index 0dd413c8be1d..5df8f3f4b966 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/input.js +++ b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/input.js @@ -26,6 +26,8 @@ class b { ["fn"]() { }; [function() {}]() { }; [()=> {}]() { }; + #x = function() {}; + accessor y = function() {} } var aa = { @@ -53,3 +55,7 @@ var z = () => {}; var z = x => {}; var z = (x) => {}; var z = (x, y, z) => {}; + +x = function() {}; + +( { x = function() {} } = {}); diff --git a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/options.json b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/options.json index 219de99ead2d..5a346a8a5cf6 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/options.json +++ b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/options.json @@ -1,3 +1,4 @@ { - "sourceMaps": true + "sourceMaps": true, + "plugins": ["decoratorAutoAccessors"] } diff --git a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/output.js b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/output.js index 407046bccecf..5d815fb69740 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/output.js +++ b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/output.js @@ -23,6 +23,8 @@ class b { ["fn"]() {} [function () {}]() {} [() => {}]() {} + #x = function () {}; + accessor y = function () {}; } var aa = { fn: function a() {}, @@ -44,4 +46,8 @@ var x = function () {}; var z = () => {}; var z = x => {}; var z = x => {}; -var z = (x, y, z) => {}; \ No newline at end of file +var z = (x, y, z) => {}; +x = function () {}; +({ + x = function () {} +} = {}); \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/source-map.json index bc36c652b42a..e32aa61af2c3 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/source-map.json +++ b/packages/babel-generator/test/fixtures/sourcemaps/function-identifier-name/source-map.json @@ -4,17 +4,18 @@ "fn", "a", "b", + "x", + "#x", + "y", "aa", "bb", - "x", - "z", - "y" + "z" ], "sources": [ "fixtures/sourcemaps/function-identifier-name/input.js" ], "sourcesContent": [ - "function fn() {}\n\nexport default function () {}\n\nvar a = {\n fn() {},\n fn:function() {},\n [fn]:function() {},\n [\"fn\"]:function() {},\n [function() {}]:function() {},\n [()=> {}]:function() {},\n [fn]() { },\n [\"fn\"]() { },\n [function() {}]() { },\n [()=> {}]() { }\n}\n\nclass b {\n fn() {};\n fn=function() {};\n [fn]=function() {};\n [\"fn\"]=function() {};\n [function() {}]=function() {};\n [()=> {}]=function() {};\n [fn]() { };\n [\"fn\"]() { };\n [function() {}]() { };\n [()=> {}]() { };\n}\n\nvar aa = {\n fn:function a() {},\n [fn]:function a() {},\n [\"fn\"]:function a() {},\n [function() {}]:function a() {},\n [()=> {}]:function a() {},\n}\n\nclass bb {\n fn=function a() {};\n [fn]=function a() {};\n [\"fn\"]=function a() {};\n [function() {}]=function a() {};\n [()=> {}]=function a() {};\n}\n\nvar x = function fn() {};\nvar x = function () {};\n\n(function fn() {});\n\nvar z = () => {};\nvar z = x => {};\nvar z = (x) => {};\nvar z = (x, y, z) => {};" + "function fn() {}\n\nexport default function () {}\n\nvar a = {\n fn() {},\n fn:function() {},\n [fn]:function() {},\n [\"fn\"]:function() {},\n [function() {}]:function() {},\n [()=> {}]:function() {},\n [fn]() { },\n [\"fn\"]() { },\n [function() {}]() { },\n [()=> {}]() { }\n}\n\nclass b {\n fn() {};\n fn=function() {};\n [fn]=function() {};\n [\"fn\"]=function() {};\n [function() {}]=function() {};\n [()=> {}]=function() {};\n [fn]() { };\n [\"fn\"]() { };\n [function() {}]() { };\n [()=> {}]() { };\n #x = function() {};\n accessor y = function() {}\n}\n\nvar aa = {\n fn:function a() {},\n [fn]:function a() {},\n [\"fn\"]:function a() {},\n [function() {}]:function a() {},\n [()=> {}]:function a() {},\n}\n\nclass bb {\n fn=function a() {};\n [fn]=function a() {};\n [\"fn\"]=function a() {};\n [function() {}]=function a() {};\n [()=> {}]=function a() {};\n}\n\nvar x = function fn() {};\nvar x = function () {};\n\n(function fn() {});\n\nvar z = () => {};\nvar z = x => {};\nvar z = (x) => {};\nvar z = (x, y, z) => {};\n\nx = function() {};\n\n( { x = function() {} } = {});" ], - "mappings": "AAAA,SAASA,EAAEA,CAAA,EAAG,CAAC;AAEf,eAAe,YAAY,CAAC;AAE5B,IAAIC,CAAC,GAAG;EACND,EAAEA,CAAA,EAAG,CAAC,CAAC;EACPA,EAAE,EAAC,SAAAA,CAAA,EAAW,CAAC,CAAC;EAChB,CAACA,EAAE,GAAE,YAAW,CAAC,CAAC;EAClB,CAAC,IAAI,GAAE,SAAAA,CAAA,EAAW,CAAC,CAAC;EACpB,CAAC,YAAW,CAAC,CAAC,GAAE,YAAW,CAAC,CAAC;EAC7B,CAAC,MAAK,CAAC,CAAC,GAAE,YAAW,CAAC,CAAC;EACvB,CAACA,EAAE,IAAI,CAAE,CAAC;EACV,CAAC,IAAI,CAAAA,CAAA,EAAI,CAAE,CAAC;EACZ,CAAC,YAAW,CAAC,CAAC,IAAI,CAAE,CAAC;EACrB,CAAC,MAAK,CAAC,CAAC,IAAI,CAAE;AAChB,CAAC;AAED,MAAME,CAAC,CAAC;EACNF,EAAEA,CAAA,EAAG,CAAC;EACNA,EAAE,GAAC,SAAAA,CAAA,EAAW,CAAC,CAAC;EAChB,CAACA,EAAE,IAAE,YAAW,CAAC,CAAC;EAClB,CAAC,IAAI,IAAE,SAAAA,CAAA,EA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W,CAAC,CAAC;AAEjB,CAAE;EAAEA,CAAC,GAAG,SAAAA,CAAA,EAAW,CAAC;AAAE,CAAC,GAAG,CAAC,CAAC" } \ No newline at end of file diff --git a/packages/babel-plugin-transform-destructuring/test/fixtures/sourcemap/declaration-loc/source-map.json b/packages/babel-plugin-transform-destructuring/test/fixtures/sourcemap/declaration-loc/source-map.json index d96b0adc9d41..7fffb459d0b2 100644 --- a/packages/babel-plugin-transform-destructuring/test/fixtures/sourcemap/declaration-loc/source-map.json +++ b/packages/babel-plugin-transform-destructuring/test/fixtures/sourcemap/declaration-loc/source-map.json @@ -3,6 +3,9 @@ "names": [ "fn", "arg", + "_arg", + "babelHelpers", + "slicedToArray", "x", "y" ], @@ -12,5 +15,5 @@ "sourcesContent": [ "const fn = (arg) => {\n var [x, y] = arg;\n}" ], - "mappings": "AAAA,MAAMA,EAAE,GAAIC,GAAG,IAAK;EAClB,sCAAaA,GAAG;IAAXC,CAAC;IAAEC,CAAC;AACX,CAAC" + "mappings": "AAAA,MAAMA,EAAE,GAAIC,GAAG,IAAK;EAClB,IAAAC,IAAA,GAAAC,YAAA,CAAAC,aAAA,CAAaH,GAAG;IAAXI,CAAC,GAAAH,IAAA;IAAEI,CAAC,GAAAJ,IAAA;AACX,CAAC" } \ No newline at end of file diff --git a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/reference-source-map/source-map.json b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/reference-source-map/source-map.json index a9eb1ff49e4c..9d2baa976ddc 100644 --- a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/reference-source-map/source-map.json +++ b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/reference-source-map/source-map.json @@ -1,12 +1,19 @@ { "version": 3, "names": [ + "_one", + "babelHelpers", + "interopRequireDefault", + "require", + "_two", + "_three", + "aNamespace", + "interopRequireWildcard", "console", "log", "aDefault", "aNamed", - "anAliased", - "aNamespace" + "anAliased" ], "sources": [ "misc/reference-source-map/input.mjs" @@ -14,5 +21,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,IAAAA,IAAA,GAAAC,YAAA,CAAAC,qBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAL,YAAA,CAAAM,sBAAA,CAAAJ,OAAA;AAEAK,OAAO,CAACC,GAAG,CAACC,YAAQ,CAAC;AACrBF,OAAO,CAACC,GAAG,CAACE,WAAM,CAAC;AACnBH,OAAO,CAACC,GAAG,CAACG,WAAS,CAAC;AACtBJ,OAAO,CAACC,GAAG,CAACH,UAAU,CAAC;AAEvBE,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,CAACH,UAAU,EAAE,CAAC" } \ No newline at end of file diff --git a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/strict/import/source-map.json b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/strict/import/source-map.json index 1d9088e54ebe..bddb0ee0073b 100644 --- a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/strict/import/source-map.json +++ b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/strict/import/source-map.json @@ -1,6 +1,10 @@ { "version": 3, "names": [ + "foo4", + "babelHelpers", + "interopRequireWildcard", + "require", "foo", "foo2", "foo3" @@ -11,5 +15,5 @@ "sourcesContent": [ "import foo from \"foo\";\nimport { default as foo2 } from \"foo\";\nimport { foo3 } from \"foo\";\nimport * as foo4 from \"foo\";\n\nfoo;\nfoo2;\nfoo3;\nfoo3();\nfoo3``;\nfoo3?.();" ], - "mappings": ";;AAAA;AAKAA,YAAG;AACHC,YAAI;AACJC,SAAI;AACJ,IAAAA,SAAI,GAAE;AACN,IAAAA,SAAI,CAAC,EAAC;AACN,IAAAA,SAAI,KAAI" + "mappings": ";;AAAA,IAAAA,IAAA,GAAAC,YAAA,CAAAC,sBAAA,CAAAC,OAAA;AAKAC,YAAG;AACHC,YAAI;AACJC,SAAI;AACJ,IAAAA,SAAI,GAAE;AACN,IAAAA,SAAI,CAAC,EAAC;AACN,IAAAA,SAAI,KAAI" } \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/sourcemaps/JSXText/source-map.json b/packages/babel-plugin-transform-react-jsx/test/fixtures/sourcemaps/JSXText/source-map.json index 1afb281ac7e1..7b8331ef3b8a 100644 --- a/packages/babel-plugin-transform-react-jsx/test/fixtures/sourcemaps/JSXText/source-map.json +++ b/packages/babel-plugin-transform-react-jsx/test/fixtures/sourcemaps/JSXText/source-map.json @@ -2,7 +2,9 @@ "version": 3, "names": [ "React", - "App" + "App", + "createElement", + "className" ], "sources": [ "sourcemaps/JSXText/input.js" @@ -10,5 +12,5 @@ "sourcesContent": [ "import React from 'react';\n\nexport default function App() {\n return (\n
\n

Welcome to my application!

\n This is my app!\n MINE.\n
\n )\n}" ], - "mappings": "AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,eAAe,SAASC,GAAG,GAAG;EAC5B,oBACE;IAAK,SAAS,EAAC;EAAK,gBAClB,gCAAI,4BAA0B,CAAK,mBAEnC,mDAAQ,OAAK,CAAS,CAClB;AAEV" + "mappings": "AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,eAAe,SAASC,GAAGA,CAAA,EAAG;EAC5B,oBACED,KAAA,CAAAE,aAAA;IAAKC,SAAS,EAAC;EAAK,gBAClBH,KAAA,CAAAE,aAAA,aAAI,4BAA0B,CAAK,mBAEnC,eAAAF,KAAA,CAAAE,aAAA,iBAAQ,OAAK,CAAS,CAClB;AAEV" } \ No newline at end of file diff --git a/packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-map.json b/packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-map.json index 74b54b5bf881..2cbf176f834f 100644 --- a/packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-map.json +++ b/packages/babel-traverse/test/fixtures/conversion/arguments-source-maps/source-map.json @@ -2,10 +2,11 @@ "version": 3, "names": [ "fn", + "_arguments", + "arguments", "inner", "console", - "log", - "arguments" + "log" ], "sources": [ "conversion/arguments-source-maps/input.js" @@ -13,5 +14,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,EAAEA,CAAA,EAAG;EAAA,IAAAC,UAAA,GAAAC,SAAA;EACZ,IAAIC,KAAK,GAAG,SAAAA,CAAA,EAAM;IAChBC,OAAO,CAACC,GAAG,CAACH,UAAS,CAAC;EACxB,CAAC;AACH" } \ No newline at end of file diff --git a/packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-map.json b/packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-map.json index 70fb45953d9e..9b137b64093e 100644 --- a/packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-map.json +++ b/packages/babel-traverse/test/fixtures/conversion/this-source-maps/source-map.json @@ -2,6 +2,7 @@ "version": 3, "names": [ "fn", + "_this", "inner", "console", "log" @@ -12,5 +13,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,EAAEA,CAAA,EAAG;EAAA,IAAAC,KAAA;EACZ,IAAIC,KAAK,GAAG,SAAAA,CAAA,EAAM;IAChBC,OAAO,CAACC,GAAG,CAACH,KAAI,CAAC;EACnB,CAAC;AACH" } \ No newline at end of file From fd9a77e9f0926d2737d47889e90981592303e157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 18 Feb 2023 18:02:39 +0100 Subject: [PATCH 14/14] Temporarily disable failing test --- scripts/integration-tests/e2e-jest.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/integration-tests/e2e-jest.sh b/scripts/integration-tests/e2e-jest.sh index fea1ec390750..bc36056f58ec 100755 --- a/scripts/integration-tests/e2e-jest.sh +++ b/scripts/integration-tests/e2e-jest.sh @@ -61,6 +61,12 @@ sed -i 's/"skipLibCheck": false,/"skipLibCheck": true,/g' tsconfig.json # Speedu yarn build +# Temporarily ignore this test that is failing due to source maps changes in +# Babel 7.21.0. +# Re-enable it once Jest updates their snapshots to the latest Babel version. +rm -f packages/jest-transform/src/__tests__/ScriptTransformer.test.ts +rm -f packages/jest-transform/src/__tests__/__snapshots__/ScriptTransformer.test.ts.snap + # The full test suite takes about 20mins on CircleCI. We run only a few of them # to speed it up. # The goals of this e2e test are: