code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function isTextLikeNode(node) { return node.type === "text" || node.type === "comment"; }
there's no opening/closing tag or it's considered not breakable
isTextLikeNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isScriptLikeTag(node) { return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style" || isUnknownNamespace(node) && (node.name === "script" || node.name === "style")); }
there's no opening/closing tag or it's considered not breakable
isScriptLikeTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isFrontMatterNode(node) { return node.type === "yaml" || node.type === "toml"; }
there's no opening/closing tag or it's considered not breakable
isFrontMatterNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function canHaveInterpolation(node) { return node.children && !isScriptLikeTag(node); }
there's no opening/closing tag or it's considered not breakable
canHaveInterpolation
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isWhitespaceSensitiveNode(node) { return isScriptLikeTag(node) || node.type === "interpolation" || isIndentationSensitiveNode(node); }
there's no opening/closing tag or it's considered not breakable
isWhitespaceSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isIndentationSensitiveNode(node) { return getNodeCssStyleWhiteSpace(node).startsWith("pre"); }
there's no opening/closing tag or it's considered not breakable
isIndentationSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isLeadingSpaceSensitiveNode(node, options) { const isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode(); if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) { return node.type === "interpolation"; } return isLeadingSpaceSensitive; function _isLeadingSpaceSensitiveNode() { if (isFrontMatterNode(node)) { return false; } if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) { return true; } if (!node.parent || node.parent.cssDisplay === "none") { return false; } if (isPreLikeNode(node.parent)) { return true; } if (!node.prev && (node.parent.type === "root" || isPreLikeNode(node) && node.parent || isScriptLikeTag(node.parent) || isVueCustomBlock(node.parent, options) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) { return false; } if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) { return false; } return true; } }
there's no opening/closing tag or it's considered not breakable
isLeadingSpaceSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function _isLeadingSpaceSensitiveNode() { if (isFrontMatterNode(node)) { return false; } if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) { return true; } if (!node.parent || node.parent.cssDisplay === "none") { return false; } if (isPreLikeNode(node.parent)) { return true; } if (!node.prev && (node.parent.type === "root" || isPreLikeNode(node) && node.parent || isScriptLikeTag(node.parent) || isVueCustomBlock(node.parent, options) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) { return false; } if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) { return false; } return true; }
there's no opening/closing tag or it's considered not breakable
_isLeadingSpaceSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isTrailingSpaceSensitiveNode(node, options) { if (isFrontMatterNode(node)) { return false; } if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) { return true; } if (!node.parent || node.parent.cssDisplay === "none") { return false; } if (isPreLikeNode(node.parent)) { return true; } if (!node.next && (node.parent.type === "root" || isPreLikeNode(node) && node.parent || isScriptLikeTag(node.parent) || isVueCustomBlock(node.parent, options) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) { return false; } if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) { return false; } return true; }
there's no opening/closing tag or it's considered not breakable
isTrailingSpaceSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isDanglingSpaceSensitiveNode(node) { return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag(node); }
there's no opening/closing tag or it's considered not breakable
isDanglingSpaceSensitiveNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function forceNextEmptyLine(node) { return isFrontMatterNode(node) || node.next && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line; }
there's no opening/closing tag or it's considered not breakable
forceNextEmptyLine
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function extractWhitespaces(ast /*, options*/ ) { const TYPE_WHITESPACE = "whitespace"; return ast.map(node => { if (!node.children) { return node; } if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && htmlTrim$1(node.children[0].value).length === 0) { return node.clone({ children: [], hasDanglingSpaces: node.children.length !== 0 }); } const isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node); const isIndentationSensitive = isIndentationSensitiveNode$1(node); return node.clone({ isWhitespaceSensitive, isIndentationSensitive, children: node.children // extract whitespace nodes .reduce((newChildren, child) => { if (child.type !== "text" || isWhitespaceSensitive) { return newChildren.concat(child); } const localChildren = []; const { leadingWhitespace, text, trailingWhitespace } = getLeadingAndTrailingHtmlWhitespace$1(child.value); if (leadingWhitespace) { localChildren.push({ type: TYPE_WHITESPACE }); } const ParseSourceSpan = child.sourceSpan.constructor; if (text) { localChildren.push({ type: "text", value: text, sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingWhitespace.length), child.sourceSpan.end.moveBy(-trailingWhitespace.length)) }); } if (trailingWhitespace) { localChildren.push({ type: TYPE_WHITESPACE }); } return newChildren.concat(localChildren); }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes .reduce((newChildren, child, i, children) => { if (child.type === TYPE_WHITESPACE) { return newChildren; } const hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE; const hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE; return newChildren.concat(Object.assign(Object.assign({}, child), {}, { hasLeadingSpaces, hasTrailingSpaces })); }, []) }); }); }
- add `hasLeadingSpaces` field - add `hasTrailingSpaces` field - add `hasDanglingSpaces` field for parent nodes - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes - remove insensitive whitespaces
extractWhitespaces
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function addIsSelfClosing(ast /*, options */ ) { return ast.map(node => Object.assign(node, { isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing node.startSourceSpan === node.endSourceSpan) })); }
- add `hasLeadingSpaces` field - add `hasTrailingSpaces` field - add `hasDanglingSpaces` field for parent nodes - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes - remove insensitive whitespaces
addIsSelfClosing
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function addHasHtmComponentClosingTag(ast, options) { return ast.map(node => node.type !== "element" ? node : Object.assign(node, { hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset)) })); }
- add `hasLeadingSpaces` field - add `hasTrailingSpaces` field - add `hasDanglingSpaces` field for parent nodes - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes - remove insensitive whitespaces
addHasHtmComponentClosingTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function addCssDisplay(ast, options) { return ast.map(node => Object.assign(node, { cssDisplay: getNodeCssStyleDisplay$1(node, options) })); }
- add `hasLeadingSpaces` field - add `hasTrailingSpaces` field - add `hasDanglingSpaces` field for parent nodes - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes - remove insensitive whitespaces
addCssDisplay
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function addIsSpaceSensitive(ast, options) { return ast.map(node => { if (!node.children) { return node; } if (node.children.length === 0) { return node.clone({ isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node) }); } return node.clone({ children: node.children.map(child => { return Object.assign(Object.assign({}, child), {}, { isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child, options), isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child, options) }); }).map((child, index, children) => Object.assign(Object.assign({}, child), {}, { isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive, isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive })) }); }); }
- add `isLeadingSpaceSensitive` field - add `isTrailingSpaceSensitive` field - add `isDanglingSpaceSensitive` field for parent nodes
addIsSpaceSensitive
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function hasPragma$3(text) { return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text); }
- add `isLeadingSpaceSensitive` field - add `isTrailingSpaceSensitive` field - add `isDanglingSpaceSensitive` field for parent nodes
hasPragma$3
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function insertPragma$5(text) { return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, ""); }
- add `isLeadingSpaceSensitive` field - add `isTrailingSpaceSensitive` field - add `isDanglingSpaceSensitive` field for parent nodes
insertPragma$5
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printVueFor(value, textToDoc) { const { left, operator, right } = parseVueFor(value); return concat$8([group$8(textToDoc("function _(".concat(left, ") {}"), { parser: "babel", __isVueForBindingLeft: true })), " ", operator, " ", textToDoc(right, { parser: "__js_expression" })]); } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
printVueFor
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function parseVueFor(value) { const forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/; const forIteratorRE = /,([^,\]}]*)(?:,([^,\]}]*))?$/; const stripParensRE = /^\(|\)$/g; const inMatch = value.match(forAliasRE); if (!inMatch) { return; } const res = {}; res.for = inMatch[3].trim(); const alias = inMatch[1].trim().replace(stripParensRE, ""); const iteratorMatch = alias.match(forIteratorRE); if (iteratorMatch) { res.alias = alias.replace(forIteratorRE, ""); res.iterator1 = iteratorMatch[1].trim(); if (iteratorMatch[2]) { res.iterator2 = iteratorMatch[2].trim(); } } else { res.alias = alias; } return { left: "".concat([res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")), operator: inMatch[2], right: res.for }; }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
parseVueFor
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printVueSlotScope(value, textToDoc) { return textToDoc("function _(".concat(value, ") {}"), { parser: "babel", __isVueSlotScope: true }); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
printVueSlotScope
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isVueEventBindingExpression(eventBindingValue) { // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4 // arrow function or anonymous function const fnExpRE = /^([\w$]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b]) const simplePathRE = /^[$A-Z_a-z][\w$]*(?:\.[$A-Z_a-z][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[$A-Z_a-z][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104 const value = eventBindingValue.trim(); return fnExpRE.test(value) || simplePathRE.test(value); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
isVueEventBindingExpression
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function deepUnique(array) { return array.sort().filter((element, index) => { return JSON.stringify(element) !== JSON.stringify(array[index - 1]); }); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
deepUnique
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
parse$2 = string => { return deepUnique(string.split(',').map(part => { const result = {}; part.trim().split(/\s+/).forEach((element, index) => { if (index === 0) { result.url = element; return; } const value = element.slice(0, element.length - 1); const postfix = element[element.length - 1]; const integerValue = parseInt(value, 10); const floatValue = parseFloat(value); if (postfix === 'w' && integerRegex.test(value)) { result.width = integerValue; } else if (postfix === 'h' && integerRegex.test(value)) { result.height = integerValue; } else if (postfix === 'x' && !Number.isNaN(floatValue)) { result.density = floatValue; } else { throw new Error("Invalid srcset descriptor: ".concat(element)); } }); return result; })); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
parse$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
stringify = array => { return [...new Set(array.map(element => { if (!element.url) { throw new Error('URL is required'); } const result = [element.url]; if (element.width) { result.push("".concat(element.width, "w")); } if (element.height) { result.push("".concat(element.height, "h")); } if (element.density) { result.push("".concat(element.density, "x")); } return result.join(' '); }))].join(', '); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
stringify
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printImgSrcset(value) { const srcset = parseSrcset(value); const hasW = srcset.some(src => src.width); const hasH = srcset.some(src => src.height); const hasX = srcset.some(src => src.density); if (hasW + hasH + hasX > 1) { throw new Error("Mixed descriptor in srcset is not supported"); } const key = hasW ? "width" : hasH ? "height" : "density"; const unit = hasW ? "w" : hasH ? "h" : "x"; const getMax = values => Math.max(...values); const urls = srcset.map(src => src.url); const maxUrlLength = getMax(urls.map(url => url.length)); const descriptors = srcset.map(src => src[key]).map(descriptor => descriptor ? descriptor.toString() : ""); const descriptorLeftLengths = descriptors.map(descriptor => { const index = descriptor.indexOf("."); return index === -1 ? descriptor.length : index; }); const maxDescriptorLeftLength = getMax(descriptorLeftLengths); return join$5(concat$9([",", line$5]), urls.map((url, index) => { const parts = [url]; const descriptor = descriptors[index]; if (descriptor) { const urlPadding = maxUrlLength - url.length + 1; const descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index]; const alignment = " ".repeat(urlPadding + descriptorPadding); parts.push(ifBreak$4(alignment, " "), descriptor + unit); } return concat$9(parts); })); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
printImgSrcset
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printClassNames(value) { return value.trim().split(/\s+/).join(" "); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
printClassNames
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function concat$a(parts) { const newParts = normalizeParts$1(parts); return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
concat$a
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function embed$2(path, print, textToDoc, options) { const node = path.getValue(); switch (node.type) { case "text": { if (isScriptLikeTag$1(node.parent)) { const parser = inferScriptParser$1(node.parent); if (parser) { const value = parser === "markdown" ? dedentString$1(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value; return builders.concat([concat$a([breakParent$2, printOpeningTagPrefix(node, options), stripTrailingHardline$1(textToDoc(value, { parser })), printClosingTagSuffix(node, options)])]); } } else if (node.parent.type === "interpolation") { return concat$a([indent$5(concat$a([line$6, textToDoc(node.value, Object.assign({ __isInHtmlInterpolation: true }, options.parser === "angular" ? { parser: "__ng_interpolation", trailingComma: "none" } : options.parser === "vue" ? { parser: "__vue_expression" } : { parser: "__js_expression" }))])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$6]); } else if (isVueCustomBlock$1(node.parent, options)) { const parser = inferScriptParser$1(node.parent, options); let printed; if (parser) { try { printed = textToDoc(node.value, { parser }); } catch (error) {// Do nothing } } if (printed == null) { printed = node.value; } return concat$a([parser ? breakParent$2 : "", printOpeningTagPrefix(node), stripTrailingHardline$1(printed, true), printClosingTagSuffix(node)]); } break; } case "attribute": { if (!node.value) { break; } // lit-html: html`<my-element obj=${obj}></my-element>` if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) { return concat$a([node.rawName, "=", node.value]); } // lwc: html`<my-element data-for={value}></my-element>` if (options.parser === "lwc") { const interpolationRegex = /^{[\S\s]*}$/; if (interpolationRegex.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) { return concat$a([node.rawName, "=", node.value]); } } const embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, (code, opts) => // strictly prefer single quote to avoid unnecessary html entity escape textToDoc(code, Object.assign({ __isInHtmlAttribute: true }, opts)), options); if (embeddedAttributeValueDoc) { return concat$a([node.rawName, '="', group$9(mapDoc$2(embeddedAttributeValueDoc, doc => typeof doc === "string" ? doc.replace(/"/g, "&quot;") : doc)), '"']); } break; } case "yaml": return markAsRoot$2(concat$a(["---", hardline$7, node.value.trim().length === 0 ? "" : textToDoc(node.value, { parser: "yaml" }), "---"])); } }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
embed$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function genericPrint$2(path, options, print) { const node = path.getValue(); switch (node.type) { case "root": if (options.__onHtmlRoot) { options.__onHtmlRoot(node); } // use original concat to not break stripTrailingHardline return builders.concat([group$9(printChildren$1(path, options, print)), hardline$7]); case "element": case "ieConditionalComment": { /** * do not break: * * <div>{{ * ~ * interpolation * }}</div> * ~ * * exception: break if the opening tag breaks * * <div * long * ~ * >{{ * interpolation * }}</div * ~ * > */ const shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces; const attrGroupId = Symbol("element-attr-group-id"); return concat$a([group$9(concat$a([group$9(printOpeningTag(path, options, print), { id: attrGroupId }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$6 : "" : concat$a([forceBreakContent$1(node) ? breakParent$2 : "", (childrenDoc => shouldHugContent ? ifBreak$5(indent$5(childrenDoc), childrenDoc, { groupId: attrGroupId }) : (isScriptLikeTag$1(node) || isVueCustomBlock$1(node, options)) && node.parent.type === "root" && options.parser === "vue" && !options.vueIndentScriptAndStyle ? childrenDoc : indent$5(childrenDoc))(concat$a([shouldHugContent ? ifBreak$5(softline$4, "", { groupId: attrGroupId }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$6 : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$1(softline$4) : softline$4, printChildren$1(path, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$5(softline$4, "", { groupId: attrGroupId }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$6 : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp("\\n[\\t ]{".concat(options.tabWidth * countParents$1(path, n => n.parent && n.parent.type !== "root"), "}$")).test(node.lastChild.value) ? /** * <div> * <pre> * something * </pre> * ~ * </div> */ "" : softline$4])])), printClosingTag(node, options)]); } case "ieConditionalStartComment": case "ieConditionalEndComment": return concat$a([printOpeningTagStart(node), printClosingTagEnd(node)]); case "interpolation": return concat$a([printOpeningTagStart(node, options), concat$a(path.map(print, "children")), printClosingTagEnd(node, options)]); case "text": { if (node.parent.type === "interpolation") { // replace the trailing literalline with hardline for better readability const trailingNewlineRegex = /\n[^\S\n]*?$/; const hasTrailingNewline = trailingNewlineRegex.test(node.value); const value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value; return concat$a([concat$a(replaceEndOfLineWith$1(value, literalline$2)), hasTrailingNewline ? hardline$7 : ""]); } return fill$3(normalizeParts$1([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options)))); } case "docType": return concat$a([group$9(concat$a([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]); case "comment": { return concat$a([printOpeningTagPrefix(node, options), concat$a(replaceEndOfLineWith$1(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$2)), printClosingTagSuffix(node, options)]); } case "attribute": { if (node.value === null) { return node.rawName; } const value = unescapeQuoteEntities$1(node.value); const singleQuoteCount = countChars$1(value, "'"); const doubleQuoteCount = countChars$1(value, '"'); const quote = singleQuoteCount < doubleQuoteCount ? "'" : '"'; return concat$a([node.rawName, concat$a(["=", quote, concat$a(replaceEndOfLineWith$1(quote === '"' ? value.replace(/"/g, "&quot;") : value.replace(/'/g, "&apos;"), literalline$2)), quote])]); } case "yaml": case "toml": return concat$a(replaceEndOfLineWith$1(node.raw, literalline$2)); default: throw new Error("Unexpected node type ".concat(node.type)); } }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
genericPrint$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printOpeningTag(path, options, print) { const node = path.getValue(); const forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0; return concat$a([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ? /** * <br /> * ^ */ " " : "" : concat$a([indent$5(concat$a([forceNotToBreakAttrContent ? " " : line$6, join$6(line$6, (ignoreAttributeData => { const hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? () => ignoreAttributeData : Array.isArray(ignoreAttributeData) ? attr => ignoreAttributeData.includes(attr.rawName) : () => false; return path.map(attrPath => { const attr = attrPath.getValue(); return hasPrettierIgnoreAttribute(attr) ? concat$a(replaceEndOfLineWith$1(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$2)) : print(attrPath); }, "attrs"); })(node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData$1(node.prev.value)))])), /** * 123<a * attr * ~ * >456 */ node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) || /** * <span * >123<meta * ~ * /></span> */ node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) ? node.isSelfClosing ? " " : "" : node.isSelfClosing ? forceNotToBreakAttrContent ? " " : line$6 : forceNotToBreakAttrContent ? "" : softline$4]), node.isSelfClosing ? "" : printOpeningTagEnd(node)]); }
Want to write us a letter? Use our<a ><b><a>mailing address</a></b></a ~ >.
printOpeningTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isStyledJsx(path) { const node = path.getValue(); const parent = path.getParentNode(); const parentParent = path.getParentNode(1); return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(attribute => attribute.name.name === "jsx") || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && parent.tag.name === "css" || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "MemberExpression" && parent.tag.object.name === "css" && (parent.tag.property.name === "global" || parent.tag.property.name === "resolve"); }
Template literal in these contexts: <style jsx>{`div{color:red}`}</style> css`` css.global`` css.resolve``
isStyledJsx
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isAngularComponentStyles(path) { return path.match(node => node.type === "TemplateLiteral", (node, name) => node.type === "ArrayExpression" && name === "elements", (node, name) => (node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier" && node.key.name === "styles" && name === "value", ...angularComponentObjectExpressionPredicates); }
Angular Components can have: - Inline HTML template - Inline CSS styles ...which are both within template literals somewhere inside of the Component decorator factory. E.g. @Component({ template: `<div>...</div>`, styles: [`h1 { color: blue; }`] })
isAngularComponentStyles
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isAngularComponentTemplate(path) { return path.match(node => node.type === "TemplateLiteral", (node, name) => (node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier" && node.key.name === "template" && name === "value", ...angularComponentObjectExpressionPredicates); }
Angular Components can have: - Inline HTML template - Inline CSS styles ...which are both within template literals somewhere inside of the Component decorator factory. E.g. @Component({ template: `<div>...</div>`, styles: [`h1 { color: blue; }`] })
isAngularComponentTemplate
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function hasNgSideEffect(path) { return hasNode(path.getValue(), node => { switch (node.type) { case undefined: return false; case "CallExpression": case "OptionalCallExpression": case "AssignmentExpression": return true; } }); }
identify if an angular expression seems to have side effects
hasNgSideEffect
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isNgForOf(node, index, parentNode) { return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null; }
identify if an angular expression seems to have side effects
isNgForOf
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function templateLiteralHasNewLines(template) { return template.quasis.some(quasi => quasi.value.raw.includes("\n")); }
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
templateLiteralHasNewLines
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isTemplateOnItsOwnLine(n, text, options) { return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$4(text, options.locStart(n), { backwards: true }); }
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
isTemplateOnItsOwnLine
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function needsHardlineAfterDanglingComment(node) { if (!node.comments) { return false; } const lastDanglingComment = getLast$2(node.comments.filter(comment => !comment.leading && !comment.trailing)); return lastDanglingComment && !comments$1.isBlockComment(lastDanglingComment); } // If we have nested conditional expressions, we want to print them in JSX mode
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
needsHardlineAfterDanglingComment
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function getConditionalChainContents(node) { // Given this code: // // // Using a ConditionalExpression as the consequent is uncommon, but should // // be handled. // A ? B : C ? D : E ? F ? G : H : I // // which has this AST: // // ConditionalExpression { // test: Identifier(A), // consequent: Identifier(B), // alternate: ConditionalExpression { // test: Identifier(C), // consequent: Identifier(D), // alternate: ConditionalExpression { // test: Identifier(E), // consequent: ConditionalExpression { // test: Identifier(F), // consequent: Identifier(G), // alternate: Identifier(H), // }, // alternate: Identifier(I), // } // } // } // // we should return this Array: // // [ // Identifier(A), // Identifier(B), // Identifier(C), // Identifier(D), // Identifier(E), // Identifier(F), // Identifier(G), // Identifier(H), // Identifier(I) // ]; // // This loses the information about whether each node was the test, // consequent, or alternate, but we don't care about that here- we are only // flattening this structure to find if there's any JSXElements inside. const nonConditionalExpressions = []; function recurse(node) { if (node.type === "ConditionalExpression") { recurse(node.test); recurse(node.consequent); recurse(node.alternate); } else { nonConditionalExpressions.push(node); } } recurse(node); return nonConditionalExpressions; }
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
getConditionalChainContents
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function recurse(node) { if (node.type === "ConditionalExpression") { recurse(node.test); recurse(node.consequent); recurse(node.alternate); } else { nonConditionalExpressions.push(node); } }
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
recurse
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function conditionalExpressionChainContainsJSX(node) { return Boolean(getConditionalChainContents(node).find(isJSXNode)); } // Logic to check for args with multiple anonymous functions. For instance,
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
conditionalExpressionChainContainsJSX
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isLongCurriedCallExpression(path) { const node = path.getValue(); const parent = path.getParentNode(); return isCallOrOptionalCallExpression(node) && isCallOrOptionalCallExpression(parent) && parent.callee === node && node.arguments.length > parent.arguments.length && parent.arguments.length > 0; }
describe.each`table`(name, fn) describe.only.each`table`(name, fn) describe.skip.each`table`(name, fn) test.each`table`(name, fn) test.only.each`table`(name, fn) test.skip.each`table`(name, fn) Ref: https://github.com/facebook/jest/pull/6102
isLongCurriedCallExpression
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isSimpleCallArgument(node, depth) { if (depth >= 3) { return false; } const plusOne = node => isSimpleCallArgument(node, depth + 1); const plusTwo = node => isSimpleCallArgument(node, depth + 2); const regexpPattern = node.type === "Literal" && node.regex && node.regex.pattern || node.type === "RegExpLiteral" && node.pattern; if (regexpPattern && regexpPattern.length > 5) { return false; } if (node.type === "Literal" || node.type === "BigIntLiteral" || node.type === "BooleanLiteral" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "Identifier" || node.type === "ThisExpression" || node.type === "Super" || node.type === "PrivateName" || node.type === "ArgumentPlaceholder" || node.type === "Import") { return true; } if (node.type === "TemplateLiteral") { return node.expressions.every(plusTwo); } if (node.type === "ObjectExpression") { return node.properties.every(p => !p.computed && (p.shorthand || p.value && plusTwo(p.value))); } if (node.type === "ArrayExpression") { return node.elements.every(x => x === null || plusTwo(x)); } if (node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "NewExpression") { return plusOne(node.callee) && node.arguments.every(plusTwo); } if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") { return plusOne(node.object) && plusOne(node.property); } if (node.type === "UnaryExpression" && (node.operator === "!" || node.operator === "-")) { return plusOne(node.argument); } if (node.type === "TSNonNullExpression") { return plusOne(node.expression); } return false; }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
isSimpleCallArgument
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function rawText(node) { return node.extra ? node.extra.raw : node.raw; }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
rawText
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function identity$1(x) { return x; }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
identity$1
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isTSXFile(options) { return options.filepath && /\.tsx$/i.test(options.filepath); }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
isTSXFile
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldPrintComma$1(options, level) { level = level || "es5"; switch (options.trailingComma) { case "all": if (level === "all") { return true; } // fallthrough case "es5": if (level === "es5") { return true; } // fallthrough case "none": default: return false; } }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
shouldPrintComma$1
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function needsParens(path, options) { const parent = path.getParentNode(); if (!parent) { return false; } const name = path.getName(); const node = path.getNode(); // If the value of this path is some child of a Node and not a Node // itself, then it doesn't need parentheses. Only Node objects (in // fact, only Expression nodes) need parentheses. if (path.getValue() !== node) { return false; } // to avoid unexpected `}}` in HTML interpolations if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path)) { return true; } // Only statements don't need parentheses. if (isStatement(node)) { return false; } if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow // parser. The Flow parser turns Flow comments into type annotation nodes in its // AST, which we handle separately. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path.getValue())) { return true; } // Identifiers never need parentheses. if (node.type === "Identifier") { // ...unless those identifiers are embed placeholders. They might be substituted by complex // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS): // let tpl = html`<script> f((${expr}) / 2); </script>`; // If the inner JS formatter removes the parens, the expression might change its meaning: // f((a + b) / 2) vs f(a + b / 2) if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) { return true; } return false; } if (parent.type === "ParenthesizedExpression") { return false; } // Add parens around the extends clause of a class. It is needed for almost // all expressions. if ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node && (node.type === "ArrowFunctionExpression" || node.type === "AssignmentExpression" || node.type === "AwaitExpression" || node.type === "BinaryExpression" || node.type === "ConditionalExpression" || node.type === "LogicalExpression" || node.type === "NewExpression" || node.type === "ObjectExpression" || node.type === "ParenthesizedExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "UnaryExpression" || node.type === "UpdateExpression" || node.type === "YieldExpression")) { return true; } if (parent.type === "ExportDefaultDeclaration") { return (// `export default function` or `export default class` can't be followed by // anything after. So an expression like `export default (function(){}).toString()` // needs to be followed by a parentheses shouldWrapFunctionForExportDefault(path, options) || // `export default (foo, bar)` also needs parentheses node.type === "SequenceExpression" ); } if (parent.type === "Decorator" && parent.expression === node) { let hasCallExpression = false; let hasMemberExpression = false; let current = node; while (current) { switch (current.type) { case "MemberExpression": hasMemberExpression = true; current = current.object; break; case "CallExpression": if ( /** @(x().y) */ hasMemberExpression || /** @(x().y()) */ hasCallExpression) { return true; } hasCallExpression = true; current = current.callee; break; case "Identifier": return false; default: return true; } } return true; } if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway util$1.startsWithNoLookaheadToken(node, /* forbidFunctionClassAndDoExpr */ false) || parent.type === "ExpressionStatement" && util$1.startsWithNoLookaheadToken(node, /* forbidFunctionClassAndDoExpr */ true)) { return true; } switch (node.type) { case "SpreadElement": case "SpreadProperty": return parent.type === "MemberExpression" && name === "object" && parent.object === node; case "UpdateExpression": if (parent.type === "UnaryExpression") { return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-"); } // else fallthrough case "UnaryExpression": switch (parent.type) { case "UnaryExpression": return node.operator === parent.operator && (node.operator === "+" || node.operator === "-"); case "BindExpression": return true; case "MemberExpression": case "OptionalMemberExpression": return name === "object"; case "TaggedTemplateExpression": return true; case "NewExpression": case "CallExpression": case "OptionalCallExpression": return name === "callee"; case "BinaryExpression": return parent.operator === "**" && name === "left"; case "TSNonNullExpression": return true; default: return false; } case "BinaryExpression": { if (parent.type === "UpdateExpression" || parent.type === "PipelineTopicExpression" && node.operator === "|>") { return true; } const isLeftOfAForStatement = node => { let i = 0; while (node) { const parent = path.getParentNode(i++); if (!parent) { return false; } if (parent.type === "ForStatement" && parent.init === node) { return true; } node = parent; } return false; }; if (node.operator === "in" && isLeftOfAForStatement(node)) { return true; } if (node.operator === "|>" && node.extra && node.extra.parenthesized) { const grandParent = path.getParentNode(1); if (grandParent.type === "BinaryExpression" && grandParent.operator === "|>") { return true; } } } // fallthrough case "TSTypeAssertion": case "TSAsExpression": case "LogicalExpression": switch (parent.type) { case "ConditionalExpression": return node.type === "TSAsExpression"; case "CallExpression": case "NewExpression": case "OptionalCallExpression": return name === "callee"; case "ClassExpression": case "ClassDeclaration": return name === "superClass" && parent.superClass === node; case "TSTypeAssertion": case "TaggedTemplateExpression": case "UnaryExpression": case "JSXSpreadAttribute": case "SpreadElement": case "SpreadProperty": case "BindExpression": case "AwaitExpression": case "TSAsExpression": case "TSNonNullExpression": case "UpdateExpression": return true; case "MemberExpression": case "OptionalMemberExpression": return name === "object"; case "AssignmentExpression": return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression"); case "LogicalExpression": if (node.type === "LogicalExpression") { return parent.operator !== node.operator; } // else fallthrough case "BinaryExpression": { if (!node.operator && node.type !== "TSTypeAssertion") { return true; } const po = parent.operator; const pp = util$1.getPrecedence(po); const no = node.operator; const np = util$1.getPrecedence(no); if (pp > np) { return true; } if (pp === np && name === "right") { assert.strictEqual(parent.right, node); return true; } if (pp === np && !util$1.shouldFlatten(po, no)) { return true; } if (pp < np && no === "%") { return po === "+" || po === "-"; } // Add parenthesis when working with bitwise operators // It's not strictly needed but helps with code understanding if (util$1.isBitwiseOperator(po)) { return true; } return false; } default: return false; } case "SequenceExpression": switch (parent.type) { case "ReturnStatement": return false; case "ForStatement": // Although parentheses wouldn't hurt around sequence // expressions in the head of for loops, traditional style // dictates that e.g. i++, j++ should not be wrapped with // parentheses. return false; case "ExpressionStatement": return name !== "expression"; case "ArrowFunctionExpression": // We do need parentheses, but SequenceExpressions are handled // specially when printing bodies of arrow functions. return name !== "body"; default: // Otherwise err on the side of overparenthesization, adding // explicit exceptions above if this proves overzealous. return true; } case "YieldExpression": if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") { return true; } // else fallthrough case "AwaitExpression": switch (parent.type) { case "TaggedTemplateExpression": case "UnaryExpression": case "LogicalExpression": case "SpreadElement": case "SpreadProperty": case "TSAsExpression": case "TSNonNullExpression": case "BindExpression": return true; case "MemberExpression": case "OptionalMemberExpression": return name === "object"; case "NewExpression": case "CallExpression": case "OptionalCallExpression": return name === "callee"; case "ConditionalExpression": return parent.test === node; case "BinaryExpression": { if (!node.argument && parent.operator === "|>") { return false; } return true; } default: return false; } case "TSJSDocFunctionType": case "TSConditionalType": if (parent.type === "TSConditionalType" && node === parent.extendsType) { return true; } // fallthrough case "TSFunctionType": case "TSConstructorType": if (parent.type === "TSConditionalType" && node === parent.checkType) { return true; } // fallthrough case "TSUnionType": case "TSIntersectionType": if (parent.type === "TSUnionType" || parent.type === "TSIntersectionType") { return true; } // fallthrough case "TSTypeOperator": case "TSInferType": return parent.type === "TSArrayType" || parent.type === "TSOptionalType" || parent.type === "TSRestType" || parent.type === "TSIndexedAccessType" && node === parent.objectType || parent.type === "TSTypeOperator" || parent.type === "TSTypeAnnotation" && /^TSJSDoc/.test(path.getParentNode(1).type); case "ArrayTypeAnnotation": return parent.type === "NullableTypeAnnotation"; case "IntersectionTypeAnnotation": case "UnionTypeAnnotation": return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation"; case "NullableTypeAnnotation": return parent.type === "ArrayTypeAnnotation"; case "FunctionTypeAnnotation": { const ancestor = parent.type === "NullableTypeAnnotation" ? path.getParentNode(1) : parent; return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses // are really needed, but since ??T doesn't make sense this check // will almost never be true. ancestor.type === "NullableTypeAnnotation"; } case "StringLiteral": case "NumericLiteral": case "Literal": if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2 // See corresponding workaround in printer.js case: "Literal" options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.charAt(options.locStart(node) - 1) === "(")) { // To avoid becoming a directive const grandParent = path.getParentNode(1); return grandParent.type === "Program" || grandParent.type === "BlockStatement"; } return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node; case "AssignmentExpression": { const grandParent = path.getParentNode(1); if (parent.type === "ArrowFunctionExpression" && parent.body === node) { return true; } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) { return false; } else if (parent.type === "TSPropertySignature" && parent.name === node) { return false; } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) { return false; } else if (parent.type === "ExpressionStatement") { return node.left.type === "ObjectPattern"; } else if (parent.type === "TSPropertySignature" && parent.key === node) { return false; } else if (parent.type === "AssignmentExpression") { return false; } else if (parent.type === "SequenceExpression" && grandParent && grandParent.type === "ForStatement" && (grandParent.init === parent || grandParent.update === parent)) { return false; } else if (parent.type === "Property" && parent.value === node) { return false; } else if (parent.type === "NGChainedExpression") { return false; } return true; } case "ConditionalExpression": switch (parent.type) { case "TaggedTemplateExpression": case "UnaryExpression": case "SpreadElement": case "SpreadProperty": case "BinaryExpression": case "LogicalExpression": case "NGPipeExpression": case "ExportDefaultDeclaration": case "AwaitExpression": case "JSXSpreadAttribute": case "TSTypeAssertion": case "TypeCastExpression": case "TSAsExpression": case "TSNonNullExpression": return true; case "NewExpression": case "CallExpression": case "OptionalCallExpression": return name === "callee"; case "ConditionalExpression": return name === "test" && parent.test === node; case "MemberExpression": case "OptionalMemberExpression": return name === "object"; default: return false; } case "FunctionExpression": switch (parent.type) { case "NewExpression": case "CallExpression": case "OptionalCallExpression": // Not always necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses. // Is necessary if it is `expression` of `ExpressionStatement`. return name === "callee"; case "TaggedTemplateExpression": return true; // This is basically a kind of IIFE. default: return false; } case "ArrowFunctionExpression": switch (parent.type) { case "PipelineTopicExpression": return !!(node.extra && node.extra.parenthesized); case "BinaryExpression": return parent.operator !== "|>" || node.extra && node.extra.parenthesized; case "NewExpression": case "CallExpression": case "OptionalCallExpression": return name === "callee"; case "MemberExpression": case "OptionalMemberExpression": return name === "object"; case "TSAsExpression": case "BindExpression": case "TaggedTemplateExpression": case "UnaryExpression": case "LogicalExpression": case "AwaitExpression": case "TSTypeAssertion": return true; case "ConditionalExpression": return name === "test"; default: return false; } case "ClassExpression": switch (parent.type) { case "NewExpression": return name === "callee" && parent.callee === node; default: return false; } case "OptionalMemberExpression": case "OptionalCallExpression": if (parent.type === "MemberExpression" && name === "object" && ( // https://github.com/prettier/prettier/issues/8252 !options.parser.startsWith("__ng_") || node.extra && node.extra.parenthesized) || (parent.type === "CallExpression" || parent.type === "NewExpression") && name === "callee") { return true; } // fallthrough case "CallExpression": case "MemberExpression": case "TaggedTemplateExpression": case "TSNonNullExpression": if ((parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee") { let object = node; while (object) { switch (object.type) { case "CallExpression": case "OptionalCallExpression": return true; case "MemberExpression": case "OptionalMemberExpression": case "BindExpression": object = object.object; break; // tagged templates are basically member expressions from a grammar perspective // see https://tc39.github.io/ecma262/#prod-MemberExpression case "TaggedTemplateExpression": object = object.tag; break; case "TSNonNullExpression": object = object.expression; break; default: return false; } } } return false; case "BindExpression": return (parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && name === "object"; case "NGPipeExpression": if (parent.type === "NGRoot" || parent.type === "NGMicrosyntaxExpression" || parent.type === "ObjectProperty" && // Preserve parens for compatibility with AngularJS expressions !(node.extra && node.extra.parenthesized) || parent.type === "ArrayExpression" || (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.arguments[name] === node || parent.type === "NGPipeExpression" && name === "right" || parent.type === "MemberExpression" && name === "property" || parent.type === "AssignmentExpression") { return false; } return true; case "JSXFragment": case "JSXElement": return name === "callee" || parent.type !== "ArrayExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "AssignmentExpression" && parent.type !== "AssignmentPattern" && parent.type !== "BinaryExpression" && parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "ConditionalExpression" && parent.type !== "ExpressionStatement" && parent.type !== "JsExpressionRoot" && parent.type !== "JSXAttribute" && parent.type !== "JSXElement" && parent.type !== "JSXExpressionContainer" && parent.type !== "JSXFragment" && parent.type !== "LogicalExpression" && parent.type !== "ObjectProperty" && parent.type !== "OptionalCallExpression" && parent.type !== "Property" && parent.type !== "ReturnStatement" && parent.type !== "ThrowStatement" && parent.type !== "TypeCastExpression" && parent.type !== "VariableDeclarator" && parent.type !== "YieldExpression"; case "TypeAnnotation": return name === "returnType" && parent.type === "ArrowFunctionExpression" && includesFunctionTypeInObjectType(node); } return false; }
@param {import('estree').Node} node @param {number} depth @returns {boolean}
needsParens
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function arrayPush(array, values) { var index = -1, length = values.length, offset = array.length; while (++index < length) { array[offset + index] = values[index]; } return array; }
Appends the elements of `values` to `array`. @private @param {Array} array The array to modify. @param {Array} values The values to append. @returns {Array} Returns `array`.
arrayPush
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function getRawTag(value) { var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag]; try { value[symToStringTag] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; } else { delete value[symToStringTag]; } } return result; }
A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. @private @param {*} value The value to query. @returns {string} Returns the raw `toStringTag`.
getRawTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function objectToString(value) { return nativeObjectToString$1.call(value); }
Converts `value` to a string using `Object.prototype.toString`. @private @param {*} value The value to convert. @returns {string} Returns the converted string.
objectToString
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function baseGetTag(value) { if (value == null) { return value === undefined ? undefinedTag : nullTag; } return symToStringTag$1 && symToStringTag$1 in Object(value) ? _getRawTag(value) : _objectToString(value); }
The base implementation of `getTag` without fallbacks for buggy environments. @private @param {*} value The value to query. @returns {string} Returns the `toStringTag`.
baseGetTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isObjectLike(value) { return value != null && typeof value == 'object'; }
Checks if `value` is object-like. A value is object-like if it's not `null` and has a `typeof` result of "object". @static @memberOf _ @since 4.0.0 @category Lang @param {*} value The value to check. @returns {boolean} Returns `true` if `value` is object-like, else `false`. @example _.isObjectLike({}); // => true _.isObjectLike([1, 2, 3]); // => true _.isObjectLike(_.noop); // => false _.isObjectLike(null); // => false
isObjectLike
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function baseIsArguments(value) { return isObjectLike_1(value) && _baseGetTag(value) == argsTag; }
The base implementation of `_.isArguments`. @private @param {*} value The value to check. @returns {boolean} Returns `true` if `value` is an `arguments` object,
baseIsArguments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isFlattenable(value) { return isArray_1(value) || isArguments_1(value) || !!(spreadableSymbol && value && value[spreadableSymbol]); }
Checks if `value` is a flattenable `arguments` object or array. @private @param {*} value The value to check. @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
isFlattenable
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function baseFlatten(array, depth, predicate, isStrict, result) { var index = -1, length = array.length; predicate || (predicate = _isFlattenable); result || (result = []); while (++index < length) { var value = array[index]; if (depth > 0 && predicate(value)) { if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). baseFlatten(value, depth - 1, predicate, isStrict, result); } else { _arrayPush(result, value); } } else if (!isStrict) { result[result.length] = value; } } return result; }
The base implementation of `_.flatten` with support for restricting flattening. @private @param {Array} array The array to flatten. @param {number} depth The maximum recursion depth. @param {boolean} [predicate=isFlattenable] The function invoked per iteration. @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. @param {Array} [result=[]] The initial result value. @returns {Array} Returns the new flattened array.
baseFlatten
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function flatten(array) { var length = array == null ? 0 : array.length; return length ? _baseFlatten(array, 1) : []; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
flatten
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printCallArguments(path, options, print) { const node = path.getValue(); const args = node.arguments; if (args.length === 0) { return concat$d(["(", comments.printDanglingComments(path, options, /* sameIndent */ true), ")"]); } // useEffect(() => { ... }, [foo, bar, baz]) if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(arg => arg.comments)) { return concat$d(["(", path.call(print, "arguments", 0), ", ", path.call(print, "arguments", 1), ")"]); } // func( // ({ // a, // b // }) => {} // ); function shouldBreakForArrowFunctionInArguments(arg, argPath) { if (!arg || arg.type !== "ArrowFunctionExpression" || !arg.body || arg.body.type !== "BlockStatement" || !arg.params || arg.params.length < 1) { return false; } let shouldBreak = false; argPath.each(paramPath => { const printed = concat$d([print(paramPath)]); shouldBreak = shouldBreak || willBreak$1(printed); }, "params"); return shouldBreak; } let anyArgEmptyLine = false; let shouldBreakForArrowFunction = false; let hasEmptyLineFollowingFirstArg = false; const lastArgIndex = args.length - 1; const printedArguments = path.map((argPath, index) => { const arg = argPath.getNode(); const parts = [print(argPath)]; if (index === lastArgIndex) ; else if (isNextLineEmpty$4(options.originalText, arg, options.locEnd)) { if (index === 0) { hasEmptyLineFollowingFirstArg = true; } anyArgEmptyLine = true; parts.push(",", hardline$9, hardline$9); } else { parts.push(",", line$9); } shouldBreakForArrowFunction = shouldBreakForArrowFunctionInArguments(arg, argPath); return concat$d(parts); }, "arguments"); const maybeTrailingComma = // Dynamic imports cannot have trailing commas !(node.callee && node.callee.type === "Import") && shouldPrintComma$2(options, "all") ? "," : ""; function allArgsBrokenOut() { return group$b(concat$d(["(", indent$7(concat$d([line$9, concat$d(printedArguments)])), maybeTrailingComma, line$9, ")"]), { shouldBreak: true }); } if (path.getParentNode().type !== "Decorator" && isFunctionCompositionArgs$1(args)) { return allArgsBrokenOut(); } const shouldGroupFirst = shouldGroupFirstArg(args); const shouldGroupLast = shouldGroupLastArg(args); if (shouldGroupFirst || shouldGroupLast) { const shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine || shouldBreakForArrowFunction; // We want to print the last argument with a special flag let printedExpanded; let i = 0; path.each(argPath => { if (shouldGroupFirst && i === 0) { printedExpanded = [concat$d([argPath.call(p => print(p, { expandFirstArg: true })), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$9 : line$9, hasEmptyLineFollowingFirstArg ? hardline$9 : ""])].concat(printedArguments.slice(1)); } if (shouldGroupLast && i === args.length - 1) { printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(p => print(p, { expandLastArg: true }))); } i++; }, "arguments"); const somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1); const simpleConcat = concat$d(["(", concat$d(printedExpanded), ")"]); return concat$d([somePrintedArgumentsWillBreak ? breakParent$3 : "", conditionalGroup$1([!somePrintedArgumentsWillBreak && !node.typeArguments && !node.typeParameters ? simpleConcat : ifBreak$6(allArgsBrokenOut(), simpleConcat), shouldGroupFirst ? concat$d(["(", group$b(printedExpanded[0], { shouldBreak: true }), concat$d(printedExpanded.slice(1)), ")"]) : concat$d(["(", concat$d(printedArguments.slice(0, -1)), group$b(getLast$3(printedExpanded), { shouldBreak: true }), ")"]), allArgsBrokenOut()], { shouldBreak })]); } const contents = concat$d(["(", indent$7(concat$d([softline$6, concat$d(printedArguments)])), ifBreak$6(maybeTrailingComma), softline$6, ")"]); if (isLongCurriedCallExpression$1(path)) { // By not wrapping the arguments in a group, the printer prioritizes // breaking up these arguments rather than the args of the parent call. return contents; } return group$b(contents, { shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine }); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printCallArguments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldBreakForArrowFunctionInArguments(arg, argPath) { if (!arg || arg.type !== "ArrowFunctionExpression" || !arg.body || arg.body.type !== "BlockStatement" || !arg.params || arg.params.length < 1) { return false; } let shouldBreak = false; argPath.each(paramPath => { const printed = concat$d([print(paramPath)]); shouldBreak = shouldBreak || willBreak$1(printed); }, "params"); return shouldBreak; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
shouldBreakForArrowFunctionInArguments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function allArgsBrokenOut() { return group$b(concat$d(["(", indent$7(concat$d([line$9, concat$d(printedArguments)])), maybeTrailingComma, line$9, ")"]), { shouldBreak: true }); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
allArgsBrokenOut
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function couldGroupArg(arg) { return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" && couldGroupArg(arg.expression) || arg.type === "TSAsExpression" && couldGroupArg(arg.expression) || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && ( // we want to avoid breaking inside composite return types but not simple keywords // https://github.com/prettier/prettier/issues/4070 // export class Thing implements OtherThing { // do: (type: Type) => Provider<Prop> = memoize( // (type: ObjectType): Provider<Opts> => {} // ); // } // https://github.com/prettier/prettier/issues/6099 // app.get("/", (req, res): void => { // res.send("Hello World!"); // }); !arg.returnType || !arg.returnType.typeAnnotation || arg.returnType.typeAnnotation.type !== "TSTypeReference") && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode$1(arg.body)); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
couldGroupArg
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldGroupLastArg(args) { const lastArg = getLast$3(args); const penultimateArg = getPenultimate$1(args); return !hasLeadingComment$3(lastArg) && !hasTrailingComment$1(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type, // disable last element expansion. !penultimateArg || penultimateArg.type !== lastArg.type); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
shouldGroupLastArg
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldGroupFirstArg(args) { if (args.length !== 2) { return false; } const [firstArg, secondArg] = args; return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && secondArg.type !== "FunctionExpression" && secondArg.type !== "ArrowFunctionExpression" && secondArg.type !== "ConditionalExpression" && !couldGroupArg(secondArg); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
shouldGroupFirstArg
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printOptionalToken(path) { const node = path.getValue(); if (!node.optional || // It's an optional computed method parsed by typescript-estree. // "?" is printed in `printMethod`. node.type === "Identifier" && node === path.getParentNode().key) { return ""; } if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) { return "?."; } return "?"; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printOptionalToken
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printFunctionTypeParameters(path, options, print) { const fun = path.getValue(); if (fun.typeArguments) { return path.call(print, "typeArguments"); } if (fun.typeParameters) { return path.call(print, "typeParameters"); } return ""; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printFunctionTypeParameters
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printMemberLookup(path, options, print) { const property = path.call(print, "property"); const n = path.getValue(); const optional = printOptionalToken(path); if (!n.computed) { return concat$e([optional, ".", property]); } if (!n.property || isNumericLiteral$1(n.property)) { return concat$e([optional, "[", property, "]"]); } return group$c(concat$e([optional, "[", indent$8(concat$e([softline$7, property])), softline$7, "]"])); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printMemberLookup
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printBindExpressionCallee(path, options, print) { return concat$e(["::", path.call(print, "callee")]); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printBindExpressionCallee
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printMemberChain(path, options, print) { const parent = path.getParentNode(); const isExpressionStatement = !parent || parent.type === "ExpressionStatement"; // The first phase is to linearize the AST by traversing it down. // // a().b() // has the following AST structure: // CallExpression(MemberExpression(CallExpression(Identifier))) // and we transform it into // [Identifier, CallExpression, MemberExpression, CallExpression] const printedNodes = []; // Here we try to retain one typed empty line after each call expression or // the first group whether it is in parentheses or not function shouldInsertEmptyLineAfter(node) { const { originalText } = options; const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$3(originalText, node, options.locEnd); const nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty // line after that parenthesis if (nextChar === ")") { return isNextLineEmptyAfterIndex$2(originalText, nextCharIndex + 1, options.locEnd); } return isNextLineEmpty$5(originalText, node, options.locEnd); } function rec(path) { const node = path.getValue(); if (isCallOrOptionalCallExpression$1(node) && (isMemberish$1(node.callee) || isCallOrOptionalCallExpression$1(node.callee))) { printedNodes.unshift({ node, printed: concat$f([comments.printComments(path, () => concat$f([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]), options), shouldInsertEmptyLineAfter(node) ? hardline$a : ""]) }); path.call(callee => rec(callee), "callee"); } else if (isMemberish$1(node)) { printedNodes.unshift({ node, needsParens: needsParens_1(path, options), printed: comments.printComments(path, () => node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup$1(path, options, print) : printBindExpressionCallee$1(path, options, print), options) }); path.call(object => rec(object), "object"); } else if (node.type === "TSNonNullExpression") { printedNodes.unshift({ node, printed: comments.printComments(path, () => "!", options) }); path.call(expression => rec(expression), "expression"); } else { printedNodes.unshift({ node, printed: path.call(print) }); } } // Note: the comments of the root node have already been printed, so we // need to extract this first call without printing them as they would // if handled inside of the recursive call. const node = path.getValue(); printedNodes.unshift({ node, printed: concat$f([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]) }); path.call(callee => rec(callee), "callee"); // Once we have a linear list of printed nodes, we want to create groups out // of it. // // a().b.c().d().e // will be grouped as // [ // [Identifier, CallExpression], // [MemberExpression, MemberExpression, CallExpression], // [MemberExpression, CallExpression], // [MemberExpression], // ] // so that we can print it as // a() // .b.c() // .d() // .e // The first group is the first node followed by // - as many CallExpression as possible // < fn()()() >.something() // - as many array accessors as possible // < fn()[0][1][2] >.something() // - then, as many MemberExpression as possible but the last one // < this.items >.something() const groups = []; let currentGroup = [printedNodes[0]]; let i = 1; for (; i < printedNodes.length; ++i) { if (printedNodes[i].node.type === "TSNonNullExpression" || isCallOrOptionalCallExpression$1(printedNodes[i].node) || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral$2(printedNodes[i].node.property)) { currentGroup.push(printedNodes[i]); } else { break; } } if (!isCallOrOptionalCallExpression$1(printedNodes[0].node)) { for (; i + 1 < printedNodes.length; ++i) { if (isMemberish$1(printedNodes[i].node) && isMemberish$1(printedNodes[i + 1].node)) { currentGroup.push(printedNodes[i]); } else { break; } } } groups.push(currentGroup); currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by // a sequence of CallExpression. To compute it, we keep adding things to the // group until we has seen a CallExpression in the past and reach a // MemberExpression let hasSeenCallExpression = false; for (; i < printedNodes.length; ++i) { if (hasSeenCallExpression && isMemberish$1(printedNodes[i].node)) { // [0] should be appended at the end of the group instead of the // beginning of the next one if (printedNodes[i].node.computed && isNumericLiteral$2(printedNodes[i].node.property)) { currentGroup.push(printedNodes[i]); continue; } groups.push(currentGroup); currentGroup = []; hasSeenCallExpression = false; } if (isCallOrOptionalCallExpression$1(printedNodes[i].node)) { hasSeenCallExpression = true; } currentGroup.push(printedNodes[i]); if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(comment => comment.trailing)) { groups.push(currentGroup); currentGroup = []; hasSeenCallExpression = false; } } if (currentGroup.length > 0) { groups.push(currentGroup); } // There are cases like Object.keys(), Observable.of(), _.values() where // they are the subject of all the chained calls and therefore should // be kept on the same line: // // Object.keys(items) // .filter(x => x) // .map(x => x) // // In order to detect those cases, we use an heuristic: if the first // node is an identifier with the name starting with a capital // letter or just a sequence of _$. The rationale is that they are // likely to be factories. function isFactory(name) { return /^[A-Z]|^[$_]+$/.test(name); } // In case the Identifier is shorter than tab width, we can keep the // first call in a single line, if it's an ExpressionStatement. // // d3.scaleLinear() // .domain([0, 100]) // .range([0, width]); // function isShort(name) { return name.length <= options.tabWidth; } function shouldNotWrap(groups) { const hasComputed = groups[1].length && groups[1][0].node.computed; if (groups[0].length === 1) { const firstNode = groups[0][0].node; return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpressionStatement && isShort(firstNode.name) || hasComputed); } const lastNode = getLast$4(groups[0]).node; return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed); } const shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups); function printGroup(printedGroup) { const printed = printedGroup.map(tuple => tuple.printed); // Checks if the last node (i.e. the parent node) needs parens and print // accordingly if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) { return concat$f(["(", ...printed, ")"]); } return concat$f(printed); } function printIndentedGroup(groups) { if (groups.length === 0) { return ""; } return indent$9(group$d(concat$f([hardline$a, join$9(hardline$a, groups.map(printGroup))]))); } const printedGroups = groups.map(printGroup); const oneLine = concat$f(printedGroups); const cutoff = shouldMerge ? 3 : 2; const flatGroups = flatten_1(groups); const hasComment = flatGroups.slice(1, -1).some(node => hasLeadingComment$4(node.node)) || flatGroups.slice(0, -1).some(node => hasTrailingComment$2(node.node)) || groups[cutoff] && hasLeadingComment$4(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just // render everything concatenated together. if (groups.length <= cutoff && !hasComment) { if (isLongCurriedCallExpression$2(path)) { return oneLine; } return group$d(oneLine); } // Find out the last node in the first group and check if it has an // empty line after const lastNodeBeforeIndent = getLast$4(groups[shouldMerge ? 1 : 0]).node; const shouldHaveEmptyLineBeforeIndent = !isCallOrOptionalCallExpression$1(lastNodeBeforeIndent) && shouldInsertEmptyLineAfter(lastNodeBeforeIndent); const expanded = concat$f([printGroup(groups[0]), shouldMerge ? printGroup(groups[1]) : "", shouldHaveEmptyLineBeforeIndent ? hardline$a : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]); const callExpressions = printedNodes.map(({ node }) => node).filter(isCallOrOptionalCallExpression$1); function looksLikeFluentConfigurationPattern() { if (isExpressionStatement && callExpressions.length > 1 && // Keep simple chains like this on one line: // req.checkBody("name").notEmpty().optional(); !(callExpressions[0].arguments.length <= 1 && callExpressions.slice(1).every(expr => expr.arguments.length === 0))) { const allArgs = flatten_1(callExpressions.map(expr => expr.arguments)); return allArgs.length > 0 && allArgs.every(isLiteralLikeValue$1); } return false; } function callHasComplexArguments(expr, index) { return index !== 0 && expr.arguments.length > 2 || !expr.arguments.every(arg => isSimpleCallArgument$1(arg, 0)); } /** * If the last call's argument is a function, it's okay to inline if it fits and there is no other function arguments. * * This chain should be split: * * const mapped = scopes.filter(scope => scope.value !== '').map((scope, i) => { * // multi line content * }); * * This chain can be inlined: * * const mapped = scopes.filter(myFilter).map((scope, i) => { * // multi line content * }); * */ function lastGroupWillBreakAndOtherCallsHaveComplexArguments() { const lastGroupNode = getLast$4(getLast$4(groups)).node; const lastGroupDoc = getLast$4(printedGroups); return isCallOrOptionalCallExpression$1(lastGroupNode) && willBreak$2(lastGroupDoc) && callExpressions.some((expr, index) => index !== callExpressions.length - 1 && callHasComplexArguments(expr, index)); } // We don't want to print in one line if at least one of these conditions occurs: // * the chain has comments, // * the head of the chain is a constructor call, // * the chain is an expression statement and all the arguments are literal-like ("fluent configuration" pattern), // * the chain is longer than 2 calls and has non-trivial arguments or more than 2 arguments in any call but the first one, // * any group but the last one has a hard line, // * the last call's arguments have a hard line and other calls have non-trivial arguments. if (hasComment || printedNodes[0].node.type === "NewExpression" || looksLikeFluentConfigurationPattern() || callExpressions.length > 2 && callExpressions.some(callHasComplexArguments) || printedGroups.slice(0, -1).some(willBreak$2) || lastGroupWillBreakAndOtherCallsHaveComplexArguments()) { return group$d(expanded); } return concat$f([// We only need to check `oneLine` because if `expanded` is chosen // that means that the parent group has already been broken // naturally willBreak$2(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$4 : "", conditionalGroup$2([oneLine, expanded])]); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printMemberChain
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldInsertEmptyLineAfter(node) { const { originalText } = options; const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$3(originalText, node, options.locEnd); const nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty // line after that parenthesis if (nextChar === ")") { return isNextLineEmptyAfterIndex$2(originalText, nextCharIndex + 1, options.locEnd); } return isNextLineEmpty$5(originalText, node, options.locEnd); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
shouldInsertEmptyLineAfter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function rec(path) { const node = path.getValue(); if (isCallOrOptionalCallExpression$1(node) && (isMemberish$1(node.callee) || isCallOrOptionalCallExpression$1(node.callee))) { printedNodes.unshift({ node, printed: concat$f([comments.printComments(path, () => concat$f([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]), options), shouldInsertEmptyLineAfter(node) ? hardline$a : ""]) }); path.call(callee => rec(callee), "callee"); } else if (isMemberish$1(node)) { printedNodes.unshift({ node, needsParens: needsParens_1(path, options), printed: comments.printComments(path, () => node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup$1(path, options, print) : printBindExpressionCallee$1(path, options, print), options) }); path.call(object => rec(object), "object"); } else if (node.type === "TSNonNullExpression") { printedNodes.unshift({ node, printed: comments.printComments(path, () => "!", options) }); path.call(expression => rec(expression), "expression"); } else { printedNodes.unshift({ node, printed: path.call(print) }); } } // Note: the comments of the root node have already been printed, so we
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
rec
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isFactory(name) { return /^[A-Z]|^[$_]+$/.test(name); } // In case the Identifier is shorter than tab width, we can keep the
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
isFactory
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isShort(name) { return name.length <= options.tabWidth; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
isShort
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function shouldNotWrap(groups) { const hasComputed = groups[1].length && groups[1][0].node.computed; if (groups[0].length === 1) { const firstNode = groups[0][0].node; return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpressionStatement && isShort(firstNode.name) || hasComputed); } const lastNode = getLast$4(groups[0]).node; return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
shouldNotWrap
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printGroup(printedGroup) { const printed = printedGroup.map(tuple => tuple.printed); // Checks if the last node (i.e. the parent node) needs parens and print // accordingly if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) { return concat$f(["(", ...printed, ")"]); } return concat$f(printed); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printGroup
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printIndentedGroup(groups) { if (groups.length === 0) { return ""; } return indent$9(group$d(concat$f([hardline$a, join$9(hardline$a, groups.map(printGroup))]))); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
printIndentedGroup
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function looksLikeFluentConfigurationPattern() { if (isExpressionStatement && callExpressions.length > 1 && // Keep simple chains like this on one line: // req.checkBody("name").notEmpty().optional(); !(callExpressions[0].arguments.length <= 1 && callExpressions.slice(1).every(expr => expr.arguments.length === 0))) { const allArgs = flatten_1(callExpressions.map(expr => expr.arguments)); return allArgs.length > 0 && allArgs.every(isLiteralLikeValue$1); } return false; }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
looksLikeFluentConfigurationPattern
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function callHasComplexArguments(expr, index) { return index !== 0 && expr.arguments.length > 2 || !expr.arguments.every(arg => isSimpleCallArgument$1(arg, 0)); }
Flattens `array` a single level deep. @static @memberOf _ @since 0.1.0 @category Array @param {Array} array The array to flatten. @returns {Array} Returns the new flattened array. @example _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
callHasComplexArguments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function lastGroupWillBreakAndOtherCallsHaveComplexArguments() { const lastGroupNode = getLast$4(getLast$4(groups)).node; const lastGroupDoc = getLast$4(printedGroups); return isCallOrOptionalCallExpression$1(lastGroupNode) && willBreak$2(lastGroupDoc) && callExpressions.some((expr, index) => index !== callExpressions.length - 1 && callHasComplexArguments(expr, index)); } // We don't want to print in one line if at least one of these conditions occurs:
If the last call's argument is a function, it's okay to inline if it fits and there is no other function arguments. This chain should be split: const mapped = scopes.filter(scope => scope.value !== '').map((scope, i) => { // multi line content }); This chain can be inlined: const mapped = scopes.filter(myFilter).map((scope, i) => { // multi line content });
lastGroupWillBreakAndOtherCallsHaveComplexArguments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function genericPrint$3(path, options, printPath, args) { const node = path.getValue(); let needsParens = false; const linesWithoutParens = printPathNoParens(path, options, printPath, args); if (!node || isEmpty$1(linesWithoutParens)) { return linesWithoutParens; } const parentExportDecl = getParentExportDeclaration$1(path); const decorators = []; if (node.type === "ClassMethod" || node.type === "ClassPrivateMethod" || node.type === "ClassProperty" || node.type === "TSAbstractClassProperty" || node.type === "ClassPrivateProperty" || node.type === "MethodDefinition" || node.type === "TSAbstractMethodDefinition" || node.type === "TSDeclareMethod") ; else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator // was written before the export, the export will be responsible // for printing the decorators. !(parentExportDecl && options.locStart(parentExportDecl, { ignoreDecorators: true }) > options.locStart(node.decorators[0]))) { const shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators$1(node, options); const separator = shouldBreak ? hardline$b : line$a; path.each(decoratorPath => { let decorator = decoratorPath.getValue(); if (decorator.expression) { decorator = decorator.expression; } else { decorator = decorator.callee; } decorators.push(printPath(decoratorPath), separator); }, "decorators"); if (parentExportDecl) { decorators.unshift(hardline$b); } } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0 && // Only print decorators here if they were written before the export, // otherwise they are printed by the node.declaration options.locStart(node, { ignoreDecorators: true }) > options.locStart(node.declaration.decorators[0])) { // Export declarations are responsible for printing any decorators // that logically apply to node.declaration. path.each(decoratorPath => { const decorator = decoratorPath.getValue(); const prefix = decorator.type === "Decorator" ? "" : "@"; decorators.push(prefix, printPath(decoratorPath), hardline$b); }, "declaration", "decorators"); } else { // Nodes with decorators can't have parentheses, so we can avoid // computing pathNeedsParens() except in this case. needsParens = needsParens_1(path, options); } const parts = []; if (needsParens) { parts.unshift("("); } parts.push(linesWithoutParens); if (needsParens) { const node = path.getValue(); if (hasFlowShorthandAnnotationComment$2(node)) { parts.push(" /*"); parts.push(node.trailingComments[0].value.trimStart()); parts.push("*/"); node.trailingComments[0].printed = true; } parts.push(")"); } if (decorators.length > 0) { return group$e(concat$g(decorators.concat(parts))); } return concat$g(parts); }
If the last call's argument is a function, it's okay to inline if it fits and there is no other function arguments. This chain should be split: const mapped = scopes.filter(scope => scope.value !== '').map((scope, i) => { // multi line content }); This chain can be inlined: const mapped = scopes.filter(myFilter).map((scope, i) => { // multi line content });
genericPrint$3
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printDecorators(path, options, print) { const node = path.getValue(); return group$e(concat$g([join$a(line$a, path.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators$1(node, options) ? hardline$b : line$a])); }
If the last call's argument is a function, it's okay to inline if it fits and there is no other function arguments. This chain should be split: const mapped = scopes.filter(scope => scope.value !== '').map((scope, i) => { // multi line content }); This chain can be inlined: const mapped = scopes.filter(myFilter).map((scope, i) => { // multi line content });
printDecorators
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function printTernaryOperator(path, options, print, operatorOptions) { const node = path.getValue(); const consequentNode = node[operatorOptions.consequentNodePropertyName]; const alternateNode = node[operatorOptions.alternateNodePropertyName]; const parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode". // See tests/jsx/conditional-expression.js for more info. let jsxMode = false; const parent = path.getParentNode(); const isParentTest = parent.type === operatorOptions.conditionalNodeType && operatorOptions.testNodePropertyNames.some(prop => parent[prop] === node); let forceNoIndent = parent.type === operatorOptions.conditionalNodeType && !isParentTest; // Find the outermost non-ConditionalExpression parent, and the outermost // ConditionalExpression parent. We'll use these to determine if we should // print in JSX mode. let currentParent; let previousParent; let i = 0; do { previousParent = currentParent || node; currentParent = path.getParentNode(i); i++; } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType && operatorOptions.testNodePropertyNames.every(prop => currentParent[prop] !== previousParent)); const firstNonConditionalParent = currentParent || parent; const lastConditionalParent = previousParent; if (operatorOptions.shouldCheckJsx && (isJSXNode$2(node[operatorOptions.testNodePropertyNames[0]]) || isJSXNode$2(consequentNode) || isJSXNode$2(alternateNode) || conditionalExpressionChainContainsJSX$1(lastConditionalParent))) { jsxMode = true; forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in // parens when using ?: within JSX, because the parens are analogous to // curly braces in an if statement. const wrap = doc => concat$g([ifBreak$7("(", ""), indent$a(concat$g([softline$8, doc])), softline$8, ifBreak$7(")", "")]); // The only things we don't wrap are: // * Nested conditional expressions in alternates // * null // * undefined const isNil = node => node.type === "NullLiteral" || node.type === "Literal" && node.value === null || node.type === "Identifier" && node.name === "undefined"; parts.push(" ? ", isNil(consequentNode) ? path.call(print, operatorOptions.consequentNodePropertyName) : wrap(path.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || isNil(alternateNode) ? path.call(print, operatorOptions.alternateNodePropertyName) : wrap(path.call(print, operatorOptions.alternateNodePropertyName))); } else { // normal mode const part = concat$g([line$a, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$7("", "(") : "", align$1(2, path.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$7("", ")") : "", line$a, ": ", alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align$1(2, path.call(print, operatorOptions.alternateNodePropertyName))]); parts.push(parent.type !== operatorOptions.conditionalNodeType || parent[operatorOptions.alternateNodePropertyName] === node || isParentTest ? part : options.useTabs ? dedent$2(indent$a(part)) : align$1(Math.max(0, options.tabWidth - 2), part)); } // We want a whole chain of ConditionalExpressions to all // break if any of them break. That means we should only group around the // outer-most ConditionalExpression. const maybeGroup = doc => parent === firstNonConditionalParent ? group$e(doc) : doc; // Break the closing paren to keep the chain right after it: // (a // ? b // : c // ).call() const breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression" || parent.type === "NGPipeExpression" && parent.left === node) && !parent.computed; const result = maybeGroup(concat$g([].concat((testDoc => /** * a * ? b * : multiline * test * node * ^^ align(2) * ? d * : e */ parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc)(concat$g(operatorOptions.beforeParts())), forceNoIndent ? concat$g(parts) : indent$a(concat$g(parts)), operatorOptions.afterParts(breakClosingParen)))); return isParentTest ? group$e(concat$g([indent$a(concat$g([softline$8, result])), softline$8])) : result; }
The following is the shared logic for ternary operators, namely ConditionalExpression and TSConditionalType @typedef {Object} OperatorOptions @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`. @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression. @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode. @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType". @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent". @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate". @property {string[]} testNodePropertyNames - The properties at which the test nodes can be found on the main node, eg "test". @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node. @param {Options} options - Prettier options @param {Function} print - Print function to call recursively @param {OperatorOptions} operatorOptions @returns Doc
printTernaryOperator
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function splitText(text, options) { const KIND_NON_CJK = "non-cjk"; const KIND_CJ_LETTER = "cj-letter"; const KIND_K_LETTER = "k-letter"; const KIND_CJK_PUNCTUATION = "cjk-punctuation"; const nodes = []; (options.proseWrap === "preserve" ? text : text.replace(new RegExp("(".concat(cjkPattern, ")\n(").concat(cjkPattern, ")"), "g"), "$1$2")).split(/([\t\n ]+)/).forEach((token, index, tokens) => { // whitespace if (index % 2 === 1) { nodes.push({ type: "whitespace", value: /\n/.test(token) ? "\n" : " " }); return; } // word separated by whitespace if ((index === 0 || index === tokens.length - 1) && token === "") { return; } token.split(new RegExp("(".concat(cjkPattern, ")"))).forEach((innerToken, innerIndex, innerTokens) => { if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") { return; } // non-CJK word if (innerIndex % 2 === 0) { if (innerToken !== "") { appendNode({ type: "word", value: innerToken, kind: KIND_NON_CJK, hasLeadingPunctuation: punctuationRegex.test(innerToken[0]), hasTrailingPunctuation: punctuationRegex.test(getLast$6(innerToken)) }); } return; } // CJK character appendNode(punctuationRegex.test(innerToken) ? { type: "word", value: innerToken, kind: KIND_CJK_PUNCTUATION, hasLeadingPunctuation: true, hasTrailingPunctuation: true } : { type: "word", value: innerToken, kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER, hasLeadingPunctuation: false, hasTrailingPunctuation: false }); }); }); return nodes; function appendNode(node) { const lastNode = getLast$6(nodes); if (lastNode && lastNode.type === "word") { if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) { nodes.push({ type: "whitespace", value: " " }); } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace ![lastNode.value, node.value].some(value => /\u3000/.test(value))) { nodes.push({ type: "whitespace", value: "" }); } } nodes.push(node); function isBetween(kind1, kind2) { return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1; } } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
splitText
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function appendNode(node) { const lastNode = getLast$6(nodes); if (lastNode && lastNode.type === "word") { if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) { nodes.push({ type: "whitespace", value: " " }); } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace ![lastNode.value, node.value].some(value => /\u3000/.test(value))) { nodes.push({ type: "whitespace", value: "" }); } } nodes.push(node); function isBetween(kind1, kind2) { return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1; } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
appendNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function isBetween(kind1, kind2) { return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
isBetween
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function getOrderedListItemInfo(orderListItem, originalText) { const [, numberText, marker, leadingSpaces] = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/); return { numberText, marker, leadingSpaces }; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
getOrderedListItemInfo
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function hasGitDiffFriendlyOrderedList(node, options) { if (!node.ordered) { return false; } if (node.children.length < 2) { return false; } const firstNumber = Number(getOrderedListItemInfo(node.children[0], options.originalText).numberText); const secondNumber = Number(getOrderedListItemInfo(node.children[1], options.originalText).numberText); if (firstNumber === 0 && node.children.length > 2) { const thirdNumber = Number(getOrderedListItemInfo(node.children[2], options.originalText).numberText); return secondNumber === 1 && thirdNumber === 1; } return secondNumber === 1; } // workaround for https://github.com/remarkjs/remark/issues/351
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
hasGitDiffFriendlyOrderedList
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function getFencedCodeBlockValue(node, originalText) { const text = originalText.slice(node.position.start.offset, node.position.end.offset); const leadingSpaceCount = text.match(/^\s*/)[0].length; const replaceRegex = new RegExp("^\\s{0,".concat(leadingSpaceCount, "}")); const lineContents = text.split("\n"); const markerStyle = text[leadingSpaceCount]; // ` or ~ const marker = text.slice(leadingSpaceCount).match(new RegExp("^[".concat(markerStyle, "]+")))[0]; // https://spec.commonmark.org/0.28/#example-104: Closing fences may be indented by 0-3 spaces // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence const hasEndMarker = new RegExp("^\\s{0,3}".concat(marker)).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1))); return lineContents.slice(1, hasEndMarker ? -1 : undefined).map((x, i) => x.slice(getIndent(i + 1)).replace(replaceRegex, "")).join("\n"); function getIndent(lineIndex) { return node.position.indent[lineIndex - 1] - 1; } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
getFencedCodeBlockValue
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function getIndent(lineIndex) { return node.position.indent[lineIndex - 1] - 1; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
getIndent
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function mapAst(ast, handler) { return function preorder(node, index, parentStack) { parentStack = parentStack || []; const newNode = Object.assign({}, handler(node, index, parentStack)); if (newNode.children) { newNode.children = newNode.children.map((child, index) => { return preorder(child, index, [newNode].concat(parentStack)); }); } return newNode; }(ast, null, null); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
mapAst
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function embed$4(path, print, textToDoc, options) { const node = path.getValue(); if (node.type === "code" && node.lang !== null) { // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk) const langMatch = node.lang.match(/^[\w-]+/); const lang = langMatch ? langMatch[0] : ""; const parser = util$1.getParserName(lang, options); if (parser) { const styleUnit = options.__inJsTemplate ? "~" : "`"; const style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1)); const doc = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), { parser }); return markAsRoot$3(concat$i([style, node.lang, hardline$d, replaceNewlinesWithLiterallines(doc), style])); } } if (node.type === "yaml") { return markAsRoot$3(concat$i(["---", hardline$d, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, { parser: "yaml" })) : "", "---"])); } // MDX switch (node.type) { case "importExport": return textToDoc(node.value, { parser: "babel" }); case "jsx": return textToDoc("<$>".concat(node.value, "</$>"), { parser: "__js_expression", rootMarker: "mdx" }); } return null; function replaceNewlinesWithLiterallines(doc) { return mapDoc$4(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$i(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$5)) : currentDoc); } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
embed$4
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function replaceNewlinesWithLiterallines(doc) { return mapDoc$4(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$i(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$5)) : currentDoc); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
replaceNewlinesWithLiterallines
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function startWithPragma(text) { const pragma = "@(".concat(pragmas.join("|"), ")"); const regex = new RegExp(["<!--\\s*".concat(pragma, "\\s*-->"), "<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*".concat(pragma, "[^\\S\n]*($|\n)[\\s\\S]*\n.*-->")].join("|"), "m"); const matched = text.match(regex); return matched && matched.index === 0; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
startWithPragma
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function preprocess$2(ast, options) { ast = restoreUnescapedCharacter(ast, options); ast = mergeContinuousTexts(ast); ast = transformInlineCode(ast); ast = transformIndentedCodeblockAndMarkItsParentList(ast, options); ast = markAlignedList(ast, options); ast = splitTextIntoSentences(ast, options); ast = transformImportExport(ast); ast = mergeContinuousImportExport(ast); return ast; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
preprocess$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function transformImportExport(ast) { return mapAst$1(ast, node => { if (node.type !== "import" && node.type !== "export") { return node; } return Object.assign(Object.assign({}, node), {}, { type: "importExport" }); }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
transformImportExport
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function transformInlineCode(ast) { return mapAst$1(ast, node => { if (node.type !== "inlineCode") { return node; } return Object.assign(Object.assign({}, node), {}, { value: node.value.replace(/\s+/g, " ") }); }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
transformInlineCode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function restoreUnescapedCharacter(ast, options) { return mapAst$1(ast, node => { return node.type !== "text" ? node : Object.assign(Object.assign({}, node), {}, { value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer isSingleCharRegex.test(node.value) && node.position.end.offset - node.position.start.offset !== node.value.length ? options.originalText.slice(node.position.start.offset, node.position.end.offset) : node.value }); }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
restoreUnescapedCharacter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function mergeContinuousImportExport(ast) { return mergeChildren(ast, (prevNode, node) => prevNode.type === "importExport" && node.type === "importExport", (prevNode, node) => ({ type: "importExport", value: prevNode.value + "\n\n" + node.value, position: { start: prevNode.position.start, end: node.position.end } })); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
mergeContinuousImportExport
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function mergeChildren(ast, shouldMerge, mergeNode) { return mapAst$1(ast, node => { if (!node.children) { return node; } const children = node.children.reduce((current, child) => { const lastChild = current[current.length - 1]; if (lastChild && shouldMerge(lastChild, child)) { current.splice(-1, 1, mergeNode(lastChild, child)); } else { current.push(child); } return current; }, []); return Object.assign(Object.assign({}, node), {}, { children }); }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
mergeChildren
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0
function mergeContinuousTexts(ast) { return mergeChildren(ast, (prevNode, node) => prevNode.type === "text" && node.type === "text", (prevNode, node) => ({ type: "text", value: prevNode.value + node.value, position: { start: prevNode.position.start, end: node.position.end } })); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
mergeContinuousTexts
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/standalone.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/standalone.js
Apache-2.0