Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/@babel/generator/lib/generators/methods.js.map
rd565449 r0c6b92a 1 {"version":3,"names":["_t","require","_index","isIdentifier","_params","node","idNode","parentNode","print","typeParameters","nameInfo","_getFuncIdName","call","sourceIdentifierName","name","pos","token","_parameters","params","noLineTerminator","type","returnType","_noLineTerminator","parameters"," parent","exit","enterForStatementInit","paramLength","length","i","_param","space","parameter","printJoin","decorators","optional","typeAnnotation","_methodHead","kind","key","word","async","generator","computed","undefined","_predicate","noLineTerminatorAfter","predicate","_functionHead","_endsWithInnerRaw","id","FunctionExpression","body","ArrowFunctionExpression","firstParam","format","retainLines","hasTypesOrComments","printInnerComments","tokenContext","TokenContext","arrowBody","param","_param$leadingComment","_param$trailingCommen","leadingComments","trailingComments","parentType","left","_id$loc","_id$loc2","loc","start","identifierName","_id$loc3","_id$loc4","value"],"sources":["../../src/generators/methods.ts"],"sourcesContent":["import type Printer from \"../printer.ts\";\nimport type * as t from \"@babel/types\";\nimport { isIdentifier, type ParentMaps } from \"@babel/types\";\nimport { TokenContext } from \"../node/index.ts\";\n\ntype ParentsOf<T extends t.Node> = ParentMaps[T[\"type\"]];\n\nexport function _params(\n this: Printer,\n node: t.Function | t.TSDeclareMethod | t.TSDeclareFunction,\n idNode: t.Expression | t.PrivateName,\n parentNode: ParentsOf<typeof node>,\n) {\n this.print(node.typeParameters, node);\n\n const nameInfo = _getFuncIdName.call(this, idNode, parentNode);\n if (nameInfo) {\n this.sourceIdentifierName(nameInfo.name, nameInfo.pos);\n }\n\n this.token(\"(\");\n this._parameters(node.params, node);\n this.token(\")\");\n\n const noLineTerminator = node.type === \"ArrowFunctionExpression\";\n this.print(node.returnType, node, noLineTerminator);\n\n this._noLineTerminator = noLineTerminator;\n}\n\nexport function _parameters(\n this: Printer,\n parameters: t.Function[\"params\"],\n parent:\n | t.Function\n | t.TSIndexSignature\n | t.TSDeclareMethod\n | t.TSDeclareFunction\n | t.TSFunctionType\n | t.TSConstructorType,\n) {\n const exit = this.enterForStatementInit(false);\n\n const paramLength = parameters.length;\n for (let i = 0; i < paramLength; i++) {\n this._param(parameters[i], parent);\n\n if (i < parameters.length - 1) {\n this.token(\",\");\n this.space();\n }\n }\n\n exit();\n}\n\nexport function _param(\n this: Printer,\n parameter: t.Identifier | t.RestElement | t.Pattern | t.TSParameterProperty,\n parent?:\n | t.Function\n | t.TSIndexSignature\n | t.TSDeclareMethod\n | t.TSDeclareFunction\n | t.TSFunctionType\n | t.TSConstructorType,\n) {\n this.printJoin(parameter.decorators, parameter);\n this.print(parameter, parent);\n if (\n // @ts-expect-error optional is not in TSParameterProperty\n parameter.optional\n ) {\n this.token(\"?\"); // TS / flow\n }\n\n this.print(\n // @ts-expect-error typeAnnotation is not in TSParameterProperty\n parameter.typeAnnotation,\n parameter,\n ); // TS / flow\n}\n\nexport function _methodHead(this: Printer, node: t.Method | t.TSDeclareMethod) {\n const kind = node.kind;\n const key = node.key;\n\n if (kind === \"get\" || kind === \"set\") {\n this.word(kind);\n this.space();\n }\n\n if (node.async) {\n this.word(\"async\", true);\n this.space();\n }\n\n if (\n kind === \"method\" ||\n // @ts-expect-error Fixme: kind: \"init\" is not defined\n kind === \"init\"\n ) {\n if (node.generator) {\n this.token(\"*\");\n }\n }\n\n if (node.computed) {\n this.token(\"[\");\n this.print(key, node);\n this.token(\"]\");\n } else {\n this.print(key, node);\n }\n\n if (\n // @ts-expect-error optional is not in ObjectMethod\n node.optional\n ) {\n // TS\n this.token(\"?\");\n }\n\n this._params(\n node,\n node.computed && node.key.type !== \"StringLiteral\" ? undefined : node.key,\n undefined,\n );\n}\n\nexport function _predicate(\n this: Printer,\n node:\n | t.FunctionDeclaration\n | t.FunctionExpression\n | t.ArrowFunctionExpression,\n noLineTerminatorAfter?: boolean,\n) {\n if (node.predicate) {\n if (!node.returnType) {\n this.token(\":\");\n }\n this.space();\n this.print(node.predicate, node, noLineTerminatorAfter);\n }\n}\n\nexport function _functionHead(\n this: Printer,\n node: t.FunctionDeclaration | t.FunctionExpression | t.TSDeclareFunction,\n parent: ParentsOf<typeof node>,\n) {\n if (node.async) {\n this.word(\"async\");\n // We prevent inner comments from being printed here,\n // so that they are always consistently printed in the\n // same place regardless of the function type.\n this._endsWithInnerRaw = false;\n this.space();\n }\n this.word(\"function\");\n if (node.generator) {\n // We prevent inner comments from being printed here,\n // so that they are always consistently printed in the\n // same place regardless of the function type.\n this._endsWithInnerRaw = false;\n this.token(\"*\");\n }\n\n this.space();\n if (node.id) {\n this.print(node.id, node);\n }\n\n this._params(node, node.id, parent);\n if (node.type !== \"TSDeclareFunction\") {\n this._predicate(node);\n }\n}\n\nexport function FunctionExpression(\n this: Printer,\n node: t.FunctionExpression,\n parent: ParentsOf<typeof node>,\n) {\n this._functionHead(node, parent);\n this.space();\n this.print(node.body, node);\n}\n\nexport { FunctionExpression as FunctionDeclaration };\n\nexport function ArrowFunctionExpression(\n this: Printer,\n node: t.ArrowFunctionExpression,\n parent: ParentsOf<typeof node>,\n) {\n if (node.async) {\n this.word(\"async\", true);\n this.space();\n }\n\n // Try to avoid printing parens in simple cases, but only if we're pretty\n // sure that they aren't needed by type annotations or potential newlines.\n let firstParam;\n if (\n !this.format.retainLines &&\n node.params.length === 1 &&\n isIdentifier((firstParam = node.params[0])) &&\n !hasTypesOrComments(node, firstParam)\n ) {\n this.print(firstParam, node, true);\n } else {\n this._params(node, undefined, parent);\n }\n\n this._predicate(node, true);\n this.space();\n // When printing (x)/*1*/=>{}, we remove the parentheses\n // and thus there aren't two contiguous inner tokens.\n // We forcefully print inner comments here.\n this.printInnerComments();\n this.token(\"=>\");\n\n this.space();\n\n this.tokenContext |= TokenContext.arrowBody;\n this.print(node.body, node);\n}\n\nfunction hasTypesOrComments(\n node: t.ArrowFunctionExpression,\n param: t.Identifier,\n): boolean {\n return !!(\n node.typeParameters ||\n node.returnType ||\n node.predicate ||\n param.typeAnnotation ||\n param.optional ||\n // Flow does not support `foo /*: string*/ => {};`\n param.leadingComments?.length ||\n param.trailingComments?.length\n );\n}\n\nfunction _getFuncIdName(\n this: Printer,\n idNode: t.Expression | t.PrivateName,\n parent: ParentsOf<t.Function | t.TSDeclareMethod | t.TSDeclareFunction>,\n) {\n let id: t.Expression | t.PrivateName | t.LVal = idNode;\n\n if (!id && parent) {\n const parentType = parent.type;\n\n if (parentType === \"VariableDeclarator\") {\n id = parent.id;\n } else if (\n parentType === \"AssignmentExpression\" ||\n parentType === \"AssignmentPattern\"\n ) {\n id = parent.left;\n } else if (\n parentType === \"ObjectProperty\" ||\n parentType === \"ClassProperty\"\n ) {\n if (!parent.computed || parent.key.type === \"StringLiteral\") {\n id = parent.key;\n }\n } else if (\n parentType === \"ClassPrivateProperty\" ||\n parentType === \"ClassAccessorProperty\"\n ) {\n id = parent.key;\n }\n }\n\n if (!id) return;\n\n let nameInfo;\n\n if (id.type === \"Identifier\") {\n nameInfo = {\n pos: id.loc?.start,\n name: id.loc?.identifierName || id.name,\n };\n } else if (id.type === \"PrivateName\") {\n nameInfo = {\n pos: id.loc?.start,\n name: \"#\" + id.id.name,\n };\n } else if (id.type === \"StringLiteral\") {\n nameInfo = {\n pos: id.loc?.start,\n name: id.value,\n };\n }\n\n return nameInfo;\n}\n"],"mappings":";;;;;;;;;;;;;AAEA,IAAAA,EAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAgD;EADvCE;AAAY,IAAAH,EAAA;AAKd,SAASI,OAAOA,CAErBC,IAA0D,EAC1DC,MAAoC,EACpCC,UAAkC,EAClC;EACA,IAAI,CAACC,KAAK,CAACH,IAAI,CAACI,cAAc,EAAEJ,IAAI,CAAC;EAErC,MAAMK,QAAQ,GAAGC,cAAc,CAACC,IAAI,CAAC,IAAI,EAAEN,MAAM,EAAEC,UAAU,CAAC;EAC9D,IAAIG,QAAQ,EAAE;IACZ,IAAI,CAACG,oBAAoB,CAACH,QAAQ,CAACI,IAAI,EAAEJ,QAAQ,CAACK,GAAG,CAAC;EACxD;EAEA,IAA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A,GAAExB,EAAE,CAACqB,GAAG,qBAANG,QAAA,CAAQF,KAAK;MAClB1D,IAAI,EAAE,GAAG,GAAGoC,EAAE,CAACA,EAAE,CAACpC;IACpB,CAAC;EACH,CAAC,MAAM,IAAIoC,EAAE,CAAC9B,IAAI,KAAK,eAAe,EAAE;IAAA,IAAAuD,QAAA;IACtCjE,QAAQ,GAAG;MACTK,GAAG,GAAA4D,QAAA,GAAEzB,EAAE,CAACqB,GAAG,qBAANI,QAAA,CAAQH,KAAK;MAClB1D,IAAI,EAAEoC,EAAE,CAAC0B;IACX,CAAC;EACH;EAEA,OAAOlE,QAAQ;AACjB","ignoreList":[]}1 {"version":3,"names":["_t","require","_index","isIdentifier","_params","node","idNode","parentNode","print","typeParameters","nameInfo","_getFuncIdName","call","sourceIdentifierName","name","pos","token","_parameters","params","noLineTerminator","type","returnType","_noLineTerminator","parameters","endToken","exit","enterDelimited","trailingComma","shouldPrintTrailingComma","paramLength","length","i","_param","space","parameter","printJoin","decorators","optional","typeAnnotation","_methodHead","kind","key","word","async","generator","computed","undefined","_predicate","noLineTerminatorAfter","predicate","_functionHead","parent","format","preserveFormat","_endsWithInnerRaw","id","FunctionExpression","body","ArrowFunctionExpression","_shouldPrintArrowParamsParens","printInnerComments","tokenContext","TokenContext","arrowBody","_firstParam$leadingCo","_firstParam$trailingC","firstParam","leadingComments","trailingComments","tokenMap","loc","findMatching","arrowToken","start","line","retainLines","parentType","left","_id$loc","_id$loc2","identifierName","_id$loc3","_id$loc4","value"],"sources":["../../src/generators/methods.ts"],"sourcesContent":["import type Printer from \"../printer.ts\";\nimport type * as t from \"@babel/types\";\nimport { isIdentifier, type ParentMaps } from \"@babel/types\";\nimport { TokenContext } from \"../node/index.ts\";\n\ntype ParentsOf<T extends t.Node> = ParentMaps[T[\"type\"]];\n\nexport function _params(\n this: Printer,\n node: t.Function | t.TSDeclareMethod | t.TSDeclareFunction,\n idNode: t.Expression | t.PrivateName,\n parentNode: ParentsOf<typeof node>,\n) {\n this.print(node.typeParameters);\n\n const nameInfo = _getFuncIdName.call(this, idNode, parentNode);\n if (nameInfo) {\n this.sourceIdentifierName(nameInfo.name, nameInfo.pos);\n }\n\n this.token(\"(\");\n this._parameters(node.params, \")\");\n\n const noLineTerminator = node.type === \"ArrowFunctionExpression\";\n this.print(node.returnType, noLineTerminator);\n\n this._noLineTerminator = noLineTerminator;\n}\n\nexport function _parameters(\n this: Printer,\n parameters: t.Function[\"params\"],\n endToken: string,\n) {\n const exit = this.enterDelimited();\n\n const trailingComma = this.shouldPrintTrailingComma(endToken);\n\n const paramLength = parameters.length;\n for (let i = 0; i < paramLength; i++) {\n this._param(parameters[i]);\n\n if (trailingComma || i < paramLength - 1) {\n this.token(\",\", null, i);\n this.space();\n }\n }\n\n this.token(endToken);\n exit();\n}\n\nexport function _param(\n this: Printer,\n parameter: t.Identifier | t.RestElement | t.Pattern | t.TSParameterProperty,\n) {\n this.printJoin(parameter.decorators);\n this.print(parameter);\n if (\n // @ts-expect-error optional is not in TSParameterProperty\n parameter.optional\n ) {\n this.token(\"?\"); // TS / flow\n }\n\n this.print(\n // @ts-expect-error typeAnnotation is not in TSParameterProperty\n parameter.typeAnnotation,\n ); // TS / flow\n}\n\nexport function _methodHead(this: Printer, node: t.Method | t.TSDeclareMethod) {\n const kind = node.kind;\n const key = node.key;\n\n if (kind === \"get\" || kind === \"set\") {\n this.word(kind);\n this.space();\n }\n\n if (node.async) {\n this.word(\"async\", true);\n this.space();\n }\n\n if (\n kind === \"method\" ||\n // @ts-expect-error Fixme: kind: \"init\" is not defined\n kind === \"init\"\n ) {\n if (node.generator) {\n this.token(\"*\");\n }\n }\n\n if (node.computed) {\n this.token(\"[\");\n this.print(key);\n this.token(\"]\");\n } else {\n this.print(key);\n }\n\n if (\n // @ts-expect-error optional is not in ObjectMethod\n node.optional\n ) {\n // TS\n this.token(\"?\");\n }\n\n this._params(\n node,\n node.computed && node.key.type !== \"StringLiteral\" ? undefined : node.key,\n undefined,\n );\n}\n\nexport function _predicate(\n this: Printer,\n node:\n | t.FunctionDeclaration\n | t.FunctionExpression\n | t.ArrowFunctionExpression,\n noLineTerminatorAfter?: boolean,\n) {\n if (node.predicate) {\n if (!node.returnType) {\n this.token(\":\");\n }\n this.space();\n this.print(node.predicate, noLineTerminatorAfter);\n }\n}\n\nexport function _functionHead(\n this: Printer,\n node: t.FunctionDeclaration | t.FunctionExpression | t.TSDeclareFunction,\n parent: ParentsOf<typeof node>,\n) {\n if (node.async) {\n this.word(\"async\");\n if (!this.format.preserveFormat) {\n // We prevent inner comments from being printed here,\n // so that they are always consistently printed in the\n // same place regardless of the function type.\n this._endsWithInnerRaw = false;\n }\n this.space();\n }\n this.word(\"function\");\n if (node.generator) {\n if (!this.format.preserveFormat) {\n // We prevent inner comments from being printed here,\n // so that they are always consistently printed in the\n // same place regardless of the function type.\n this._endsWithInnerRaw = false;\n }\n this.token(\"*\");\n }\n\n this.space();\n if (node.id) {\n this.print(node.id);\n }\n\n this._params(node, node.id, parent);\n if (node.type !== \"TSDeclareFunction\") {\n this._predicate(node);\n }\n}\n\nexport function FunctionExpression(\n this: Printer,\n node: t.FunctionExpression,\n parent: ParentsOf<typeof node>,\n) {\n this._functionHead(node, parent);\n this.space();\n this.print(node.body);\n}\n\nexport { FunctionExpression as FunctionDeclaration };\n\nexport function ArrowFunctionExpression(\n this: Printer,\n node: t.ArrowFunctionExpression,\n parent: ParentsOf<typeof node>,\n) {\n if (node.async) {\n this.word(\"async\", true);\n this.space();\n }\n\n if (this._shouldPrintArrowParamsParens(node)) {\n this._params(node, undefined, parent);\n } else {\n this.print(node.params[0], true);\n }\n\n this._predicate(node, true);\n this.space();\n // When printing (x)/*1*/=>{}, we remove the parentheses\n // and thus there aren't two contiguous inner tokens.\n // We forcefully print inner comments here.\n this.printInnerComments();\n this.token(\"=>\");\n\n this.space();\n\n this.tokenContext |= TokenContext.arrowBody;\n this.print(node.body);\n}\n\n// Try to avoid printing parens in simple cases, but only if we're pretty\n// sure that they aren't needed by type annotations or potential newlines.\nexport function _shouldPrintArrowParamsParens(\n this: Printer,\n node: t.ArrowFunctionExpression,\n): boolean {\n if (node.params.length !== 1) return true;\n\n if (node.typeParameters || node.returnType || node.predicate) {\n return true;\n }\n\n const firstParam = node.params[0];\n if (\n !isIdentifier(firstParam) ||\n firstParam.typeAnnotation ||\n firstParam.optional ||\n // Flow does not support `foo /*: string*/ => {};`\n firstParam.leadingComments?.length ||\n firstParam.trailingComments?.length\n ) {\n return true;\n }\n\n if (this.tokenMap) {\n if (node.loc == null) return true;\n if (this.tokenMap.findMatching(node, \"(\") !== null) return true;\n const arrowToken = this.tokenMap.findMatching(node, \"=>\");\n if (arrowToken?.loc == null) return true;\n return arrowToken.loc.start.line !== node.loc.start.line;\n }\n\n if (this.format.retainLines) return true;\n\n return false;\n}\n\nfunction _getFuncIdName(\n this: Printer,\n idNode: t.Expression | t.PrivateName,\n parent: ParentsOf<t.Function | t.TSDeclareMethod | t.TSDeclareFunction>,\n) {\n let id: t.Expression | t.PrivateName | t.LVal = idNode;\n\n if (!id && parent) {\n const parentType = parent.type;\n\n if (parentType === \"VariableDeclarator\") {\n id = parent.id;\n } else if (\n parentType === \"AssignmentExpression\" ||\n parentType === \"AssignmentPattern\"\n ) {\n id = parent.left;\n } else if (\n parentType === \"ObjectProperty\" ||\n parentType === \"ClassProperty\"\n ) {\n if (!parent.computed || parent.key.type === \"StringLiteral\") {\n id = parent.key;\n }\n } else if (\n parentType === \"ClassPrivateProperty\" ||\n parentType === \"ClassAccessorProperty\"\n ) {\n id = parent.key;\n }\n }\n\n if (!id) return;\n\n let nameInfo;\n\n if (id.type === \"Identifier\") {\n nameInfo = {\n pos: id.loc?.start,\n name: id.loc?.identifierName || id.name,\n };\n } else if (id.type === \"PrivateName\") {\n nameInfo = {\n pos: id.loc?.start,\n name: \"#\" + id.id.name,\n };\n } else if (id.type === \"StringLiteral\") {\n nameInfo = {\n pos: id.loc?.start,\n name: id.value,\n };\n }\n\n return nameInfo;\n}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