@babel/generator
Advanced tools
Comparing version 7.20.14 to 7.21.0
@@ -16,2 +16,3 @@ "use strict"; | ||
this._queueCursor = 0; | ||
this._canMarkIdName = true; | ||
this._position = { | ||
@@ -23,2 +24,3 @@ line: 1, | ||
identifierName: undefined, | ||
identifierNamePos: undefined, | ||
line: undefined, | ||
@@ -40,2 +42,3 @@ column: undefined, | ||
identifierName: undefined, | ||
identifierNamePos: undefined, | ||
filename: "" | ||
@@ -45,3 +48,3 @@ }); | ||
} | ||
_pushQueue(char, repeat, line, column, identifierName, filename) { | ||
_pushQueue(char, repeat, line, column, filename) { | ||
const cursor = this._queueCursor; | ||
@@ -56,3 +59,2 @@ if (cursor === this._queue.length) { | ||
item.column = column; | ||
item.identifierName = identifierName; | ||
item.filename = filename; | ||
@@ -73,2 +75,5 @@ this._queueCursor++; | ||
decodedMap: map == null ? void 0 : map.getDecoded(), | ||
get __mergedMap() { | ||
return this.map; | ||
}, | ||
get map() { | ||
@@ -118,6 +123,6 @@ const resultMap = map ? map.get() : null; | ||
const sourcePosition = this._sourcePosition; | ||
this._pushQueue(char, 1, sourcePosition.line, sourcePosition.column, sourcePosition.identifierName, sourcePosition.filename); | ||
this._pushQueue(char, 1, sourcePosition.line, sourcePosition.column, sourcePosition.filename); | ||
} | ||
queueIndentation(char, repeat) { | ||
this._pushQueue(char, repeat, undefined, undefined, undefined, undefined); | ||
this._pushQueue(char, repeat, undefined, undefined, undefined); | ||
} | ||
@@ -137,3 +142,3 @@ _flush() { | ||
if (char !== 10) { | ||
this._mark(sourcePos.line, sourcePos.column, sourcePos.identifierName, sourcePos.filename); | ||
this._mark(sourcePos.line, sourcePos.column, sourcePos.identifierName, sourcePos.identifierNamePos, sourcePos.filename); | ||
this._position.column += repeat; | ||
@@ -144,2 +149,6 @@ } else { | ||
} | ||
if (this._canMarkIdName) { | ||
sourcePos.identifierName = undefined; | ||
sourcePos.identifierNamePos = undefined; | ||
} | ||
} | ||
@@ -165,9 +174,14 @@ _append(str, sourcePos, maybeNewline) { | ||
identifierName, | ||
identifierNamePos, | ||
filename | ||
} = sourcePos; | ||
let line = sourcePos.line; | ||
if ((identifierName != null || identifierNamePos != null) && this._canMarkIdName) { | ||
sourcePos.identifierName = undefined; | ||
sourcePos.identifierNamePos = undefined; | ||
} | ||
let i = str.indexOf("\n"); | ||
let last = 0; | ||
if (i !== 0) { | ||
this._mark(line, column, identifierName, filename); | ||
this._mark(line, column, identifierName, identifierNamePos, filename); | ||
} | ||
@@ -179,3 +193,3 @@ while (i !== -1) { | ||
if (last < len && line !== undefined) { | ||
this._mark(++line, 0, identifierName, filename); | ||
this._mark(++line, 0, null, null, filename); | ||
} | ||
@@ -186,5 +200,5 @@ i = str.indexOf("\n", last); | ||
} | ||
_mark(line, column, identifierName, filename) { | ||
_mark(line, column, identifierName, identifierNamePos, filename) { | ||
var _this$_map; | ||
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position, line, column, identifierName, filename); | ||
(_this$_map = this._map) == null ? void 0 : _this$_map.mark(this._position, line, column, identifierName, identifierNamePos, filename); | ||
} | ||
@@ -238,3 +252,14 @@ removeTrailingNewline() { | ||
this.source("start", loc); | ||
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); | ||
@@ -258,3 +283,2 @@ } | ||
const target = this._sourcePosition; | ||
target.identifierName = prop === "start" && loc.identifierName || undefined; | ||
if (pos) { | ||
@@ -261,0 +285,0 @@ target.line = pos.line + lineOffset; |
@@ -21,6 +21,5 @@ "use strict"; | ||
function ClassDeclaration(node, parent) { | ||
{ | ||
if (!this.format.decoratorsBeforeExport || !isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent)) { | ||
this.printJoin(node.decorators, node); | ||
} | ||
const inExport = isExportDefaultDeclaration(parent) || isExportNamedDeclaration(parent); | ||
if (!inExport || !this._shouldPrintDecoratorsBeforeExport(parent)) { | ||
this.printJoin(node.decorators, node); | ||
} | ||
@@ -27,0 +26,0 @@ if (node.declare) { |
@@ -32,2 +32,3 @@ "use strict"; | ||
exports.YieldExpression = YieldExpression; | ||
exports._shouldPrintDecoratorsBeforeExport = _shouldPrintDecoratorsBeforeExport; | ||
var _t = require("@babel/types"); | ||
@@ -127,2 +128,8 @@ var n = require("../node"); | ||
} | ||
function _shouldPrintDecoratorsBeforeExport(node) { | ||
if (typeof this.format.decoratorsBeforeExport === "boolean") { | ||
return this.format.decoratorsBeforeExport; | ||
} | ||
return typeof node.start === "number" && node.start === node.declaration.start; | ||
} | ||
function Decorator(node) { | ||
@@ -129,0 +136,0 @@ this.tokenChar(64); |
@@ -18,4 +18,8 @@ "use strict"; | ||
} = _t; | ||
function _params(node) { | ||
function _params(node, idNode, parentNode) { | ||
this.print(node.typeParameters, node); | ||
const nameInfo = _getFuncIdName.call(this, idNode, parentNode); | ||
if (nameInfo) { | ||
this.sourceIdentifierName(nameInfo.name, nameInfo.pos); | ||
} | ||
this.tokenChar(40); | ||
@@ -72,3 +76,3 @@ this._parameters(node.params, node); | ||
} | ||
this._params(node); | ||
this._params(node, node.computed && node.key.type !== "StringLiteral" ? undefined : node.key, undefined); | ||
} | ||
@@ -84,3 +88,3 @@ function _predicate(node, noLineTerminatorAfter) { | ||
} | ||
function _functionHead(node) { | ||
function _functionHead(node, parent) { | ||
if (node.async) { | ||
@@ -100,3 +104,3 @@ this.word("async"); | ||
} | ||
this._params(node); | ||
this._params(node, node.id, parent); | ||
if (node.type !== "TSDeclareFunction") { | ||
@@ -106,8 +110,8 @@ this._predicate(node); | ||
} | ||
function FunctionExpression(node) { | ||
this._functionHead(node); | ||
function FunctionExpression(node, parent) { | ||
this._functionHead(node, parent); | ||
this.space(); | ||
this.print(node.body, node); | ||
} | ||
function ArrowFunctionExpression(node) { | ||
function ArrowFunctionExpression(node, parent) { | ||
if (node.async) { | ||
@@ -121,3 +125,3 @@ this.word("async", true); | ||
} else { | ||
this._params(node); | ||
this._params(node, undefined, parent); | ||
} | ||
@@ -135,3 +139,42 @@ this._predicate(node, true); | ||
} | ||
function _getFuncIdName(idNode, parent) { | ||
let id = 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") { | ||
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.type === "Identifier") { | ||
var _id$loc, _id$loc2; | ||
nameInfo = { | ||
pos: (_id$loc = id.loc) == null ? void 0 : _id$loc.start, | ||
name: ((_id$loc2 = id.loc) == null ? void 0 : _id$loc2.identifierName) || id.name | ||
}; | ||
} else if (id.type === "PrivateName") { | ||
var _id$loc3; | ||
nameInfo = { | ||
pos: (_id$loc3 = id.loc) == null ? void 0 : _id$loc3.start, | ||
name: "#" + id.id.name | ||
}; | ||
} else if (id.type === "StringLiteral") { | ||
var _id$loc4; | ||
nameInfo = { | ||
pos: (_id$loc4 = id.loc) == null ? void 0 : _id$loc4.start, | ||
name: id.value | ||
}; | ||
} | ||
return nameInfo; | ||
} | ||
//# sourceMappingURL=methods.js.map |
@@ -96,8 +96,9 @@ "use strict"; | ||
} | ||
function maybePrintDecoratorsBeforeExport(printer, node) { | ||
if (isClassDeclaration(node.declaration) && printer._shouldPrintDecoratorsBeforeExport(node)) { | ||
printer.printJoin(node.declaration.decorators, node); | ||
} | ||
} | ||
function ExportNamedDeclaration(node) { | ||
{ | ||
if (this.format.decoratorsBeforeExport && isClassDeclaration(node.declaration)) { | ||
this.printJoin(node.declaration.decorators, node); | ||
} | ||
} | ||
maybePrintDecoratorsBeforeExport(this, node); | ||
this.word("export"); | ||
@@ -155,7 +156,3 @@ this.space(); | ||
function ExportDefaultDeclaration(node) { | ||
{ | ||
if (this.format.decoratorsBeforeExport && isClassDeclaration(node.declaration)) { | ||
this.printJoin(node.declaration.decorators, node); | ||
} | ||
} | ||
maybePrintDecoratorsBeforeExport(this, node); | ||
this.word("export"); | ||
@@ -162,0 +159,0 @@ this.noIndentInnerCommentsHere(); |
@@ -33,2 +33,4 @@ "use strict"; | ||
function Identifier(node) { | ||
var _node$loc; | ||
this.sourceIdentifierName(((_node$loc = node.loc) == null ? void 0 : _node$loc.identifierName) || node.name); | ||
this.word(node.name); | ||
@@ -35,0 +37,0 @@ } |
@@ -122,3 +122,3 @@ "use strict"; | ||
} | ||
function TSDeclareFunction(node) { | ||
function TSDeclareFunction(node, parent) { | ||
if (node.declare) { | ||
@@ -128,3 +128,3 @@ this.word("declare"); | ||
} | ||
this._functionHead(node); | ||
this._functionHead(node, parent); | ||
this.tokenChar(59); | ||
@@ -131,0 +131,0 @@ } |
@@ -46,3 +46,3 @@ "use strict"; | ||
{ | ||
format.decoratorsBeforeExport = !!opts.decoratorsBeforeExport; | ||
format.decoratorsBeforeExport = opts.decoratorsBeforeExport; | ||
format.jsonCompatibleStrings = opts.jsonCompatibleStrings; | ||
@@ -49,0 +49,0 @@ } |
@@ -48,2 +48,3 @@ "use strict"; | ||
this._indentRepeat = format.indent.style.length; | ||
this._inputMap = map == null ? void 0 : map._inputMap; | ||
} | ||
@@ -172,2 +173,8 @@ generate(ast) { | ||
} | ||
sourceIdentifierName(identifierName, pos) { | ||
if (!this._buf._canMarkIdName) return; | ||
const sourcePosition = this._buf._sourcePosition; | ||
sourcePosition.identifierNamePos = pos; | ||
sourcePosition.identifierName = identifierName; | ||
} | ||
_space() { | ||
@@ -174,0 +181,0 @@ this._queue(32); |
@@ -8,2 +8,3 @@ "use strict"; | ||
var _genMapping = require("@jridgewell/gen-mapping"); | ||
var _traceMapping = require("@jridgewell/trace-mapping"); | ||
class SourceMap { | ||
@@ -18,2 +19,3 @@ constructor(opts, code) { | ||
this._lastSourceColumn = 0; | ||
this._inputMap = void 0; | ||
const map = this._map = new _genMapping.GenMapping({ | ||
@@ -24,8 +26,17 @@ sourceRoot: opts.sourceRoot | ||
this._rawMappings = undefined; | ||
if (typeof code === "string") { | ||
if (opts.inputSourceMap) { | ||
this._inputMap = new _traceMapping.TraceMap(opts.inputSourceMap); | ||
const resolvedSources = this._inputMap.resolvedSources; | ||
if (resolvedSources.length) { | ||
for (let i = 0; i < resolvedSources.length; i++) { | ||
(0, _genMapping.setSourceContent)(map, resolvedSources[i], this._inputMap.sourcesContent[i]); | ||
} | ||
} | ||
} | ||
if (typeof code === "string" && !opts.inputSourceMap) { | ||
(0, _genMapping.setSourceContent)(map, this._sourceFileName, code); | ||
} else if (typeof code === "object") { | ||
Object.keys(code).forEach(sourceFileName => { | ||
for (const sourceFileName of Object.keys(code)) { | ||
(0, _genMapping.setSourceContent)(map, sourceFileName.replace(/\\/g, "/"), code[sourceFileName]); | ||
}); | ||
} | ||
} | ||
@@ -42,12 +53,31 @@ } | ||
} | ||
mark(generated, line, column, identifierName, filename) { | ||
mark(generated, line, column, identifierName, identifierNamePos, filename) { | ||
var _originalMapping; | ||
this._rawMappings = undefined; | ||
let originalMapping; | ||
if (line != null) { | ||
if (this._inputMap) { | ||
originalMapping = (0, _traceMapping.originalPositionFor)(this._inputMap, { | ||
line, | ||
column | ||
}); | ||
if (!originalMapping.name && identifierNamePos) { | ||
const originalIdentifierMapping = (0, _traceMapping.originalPositionFor)(this._inputMap, identifierNamePos); | ||
if (originalIdentifierMapping.name) { | ||
identifierName = originalIdentifierMapping.name; | ||
} | ||
} | ||
} else { | ||
originalMapping = { | ||
source: (filename == null ? void 0 : filename.replace(/\\/g, "/")) || this._sourceFileName, | ||
line: line, | ||
column: column | ||
}; | ||
} | ||
} | ||
(0, _genMapping.maybeAddMapping)(this._map, { | ||
name: identifierName, | ||
generated, | ||
source: line == null ? undefined : (filename == null ? void 0 : filename.replace(/\\/g, "/")) || this._sourceFileName, | ||
original: line == null ? undefined : { | ||
line: line, | ||
column: column | ||
} | ||
source: (_originalMapping = originalMapping) == null ? void 0 : _originalMapping.source, | ||
original: originalMapping | ||
}); | ||
@@ -54,0 +84,0 @@ } |
{ | ||
"name": "@babel/generator", | ||
"version": "7.20.14", | ||
"version": "7.21.0", | ||
"description": "Turns an AST into code.", | ||
@@ -22,10 +22,10 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/types": "^7.20.7", | ||
"@babel/types": "^7.21.0", | ||
"@jridgewell/gen-mapping": "^0.3.2", | ||
"@jridgewell/trace-mapping": "^0.3.17", | ||
"jsesc": "^2.5.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/helper-fixtures": "^7.19.4", | ||
"@babel/parser": "^7.20.13", | ||
"@jridgewell/trace-mapping": "^0.3.8", | ||
"@babel/helper-fixtures": "^7.21.0", | ||
"@babel/parser": "^7.21.0", | ||
"@types/jsesc": "^2.5.0", | ||
@@ -32,0 +32,0 @@ "charcodes": "^0.2.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
470825
4
4728
4
Updated@babel/types@^7.21.0