Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/@babel/generator/lib/generators/methods.js
rd565449 r0c6b92a 12 12 exports._params = _params; 13 13 exports._predicate = _predicate; 14 exports._shouldPrintArrowParamsParens = _shouldPrintArrowParamsParens; 14 15 var _t = require("@babel/types"); 15 16 var _index = require("../node/index.js"); … … 18 19 } = _t; 19 20 function _params(node, idNode, parentNode) { 20 this.print(node.typeParameters , node);21 this.print(node.typeParameters); 21 22 const nameInfo = _getFuncIdName.call(this, idNode, parentNode); 22 23 if (nameInfo) { … … 24 25 } 25 26 this.tokenChar(40); 26 this._parameters(node.params, node); 27 this.tokenChar(41); 27 this._parameters(node.params, ")"); 28 28 const noLineTerminator = node.type === "ArrowFunctionExpression"; 29 this.print(node.returnType, no de, noLineTerminator);29 this.print(node.returnType, noLineTerminator); 30 30 this._noLineTerminator = noLineTerminator; 31 31 } 32 function _parameters(parameters, parent) { 33 const exit = this.enterForStatementInit(false); 32 function _parameters(parameters, endToken) { 33 const exit = this.enterDelimited(); 34 const trailingComma = this.shouldPrintTrailingComma(endToken); 34 35 const paramLength = parameters.length; 35 36 for (let i = 0; i < paramLength; i++) { 36 this._param(parameters[i] , parent);37 if ( i < parameters.length - 1) {38 this.token Char(44);37 this._param(parameters[i]); 38 if (trailingComma || i < paramLength - 1) { 39 this.token(",", null, i); 39 40 this.space(); 40 41 } 41 42 } 43 this.token(endToken); 42 44 exit(); 43 45 } 44 function _param(parameter , parent) {45 this.printJoin(parameter.decorators , parameter);46 this.print(parameter , parent);46 function _param(parameter) { 47 this.printJoin(parameter.decorators); 48 this.print(parameter); 47 49 if (parameter.optional) { 48 50 this.tokenChar(63); 49 51 } 50 this.print(parameter.typeAnnotation , parameter);52 this.print(parameter.typeAnnotation); 51 53 } 52 54 function _methodHead(node) { … … 68 70 if (node.computed) { 69 71 this.tokenChar(91); 70 this.print(key , node);72 this.print(key); 71 73 this.tokenChar(93); 72 74 } else { 73 this.print(key , node);75 this.print(key); 74 76 } 75 77 if (node.optional) { … … 84 86 } 85 87 this.space(); 86 this.print(node.predicate, no de, noLineTerminatorAfter);88 this.print(node.predicate, noLineTerminatorAfter); 87 89 } 88 90 } … … 90 92 if (node.async) { 91 93 this.word("async"); 92 this._endsWithInnerRaw = false; 94 if (!this.format.preserveFormat) { 95 this._endsWithInnerRaw = false; 96 } 93 97 this.space(); 94 98 } 95 99 this.word("function"); 96 100 if (node.generator) { 97 this._endsWithInnerRaw = false; 101 if (!this.format.preserveFormat) { 102 this._endsWithInnerRaw = false; 103 } 98 104 this.tokenChar(42); 99 105 } 100 106 this.space(); 101 107 if (node.id) { 102 this.print(node.id , node);108 this.print(node.id); 103 109 } 104 110 this._params(node, node.id, parent); … … 110 116 this._functionHead(node, parent); 111 117 this.space(); 112 this.print(node.body , node);118 this.print(node.body); 113 119 } 114 120 function ArrowFunctionExpression(node, parent) { … … 117 123 this.space(); 118 124 } 119 let firstParam; 120 if (!this.format.retainLines && node.params.length === 1 && isIdentifier(firstParam = node.params[0]) && !hasTypesOrComments(node, firstParam)) { 121 this.print(firstParam, node, true); 125 if (this._shouldPrintArrowParamsParens(node)) { 126 this._params(node, undefined, parent); 122 127 } else { 123 this. _params(node, undefined, parent);128 this.print(node.params[0], true); 124 129 } 125 130 this._predicate(node, true); … … 129 134 this.space(); 130 135 this.tokenContext |= _index.TokenContext.arrowBody; 131 this.print(node.body , node);136 this.print(node.body); 132 137 } 133 function hasTypesOrComments(node, param) { 134 var _param$leadingComment, _param$trailingCommen; 135 return !!(node.typeParameters || node.returnType || node.predicate || param.typeAnnotation || param.optional || (_param$leadingComment = param.leadingComments) != null && _param$leadingComment.length || (_param$trailingCommen = param.trailingComments) != null && _param$trailingCommen.length); 138 function _shouldPrintArrowParamsParens(node) { 139 var _firstParam$leadingCo, _firstParam$trailingC; 140 if (node.params.length !== 1) return true; 141 if (node.typeParameters || node.returnType || node.predicate) { 142 return true; 143 } 144 const firstParam = node.params[0]; 145 if (!isIdentifier(firstParam) || firstParam.typeAnnotation || firstParam.optional || (_firstParam$leadingCo = firstParam.leadingComments) != null && _firstParam$leadingCo.length || (_firstParam$trailingC = firstParam.trailingComments) != null && _firstParam$trailingC.length) { 146 return true; 147 } 148 if (this.tokenMap) { 149 if (node.loc == null) return true; 150 if (this.tokenMap.findMatching(node, "(") !== null) return true; 151 const arrowToken = this.tokenMap.findMatching(node, "=>"); 152 if ((arrowToken == null ? void 0 : arrowToken.loc) == null) return true; 153 return arrowToken.loc.start.line !== node.loc.start.line; 154 } 155 if (this.format.retainLines) return true; 156 return false; 136 157 } 137 158 function _getFuncIdName(idNode, parent) {
Note:
See TracChangeset
for help on using the changeset viewer.