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 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(`(${cjkPattern})\n(${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(`(${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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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,${leadingSpaceCount}}`); const lineContents = text.split("\n"); const markerStyle = text[leadingSpaceCount]; // ` or ~ const marker = text.slice(leadingSpaceCount).match(new RegExp(`^[${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}${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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function embed$2(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$2(concat$f([style, node.lang, hardline$c, replaceNewlinesWithLiterallines(doc), style])); } } if (node.type === "yaml") { return markAsRoot$2(concat$f(["---", hardline$c, 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(`<$>${node.value}</$>`, { parser: "__js_expression", rootMarker: "mdx" }); } return null; function replaceNewlinesWithLiterallines(doc) { return mapDoc$3(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$f(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$4)) : currentDoc); } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
embed$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function replaceNewlinesWithLiterallines(doc) { return mapDoc$3(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$f(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$4)) : 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function startWithPragma(text) { const pragma = `@(${pragmas.join("|")})`; const regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function preprocess$1(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$1
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function splitTextIntoSentences(ast, options) { return mapAst$1(ast, (node, index, [parentNode]) => { if (node.type !== "text") { return node; } let { value } = node; if (parentNode.type === "paragraph") { if (index === 0) { value = value.trimStart(); } if (index === parentNode.children.length - 1) { value = value.trimEnd(); } } return { type: "sentence", position: node.position, children: splitText$1(value, options) }; }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
splitTextIntoSentences
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function transformIndentedCodeblockAndMarkItsParentList(ast, options) { return mapAst$1(ast, (node, index, parentStack) => { if (node.type === "code") { // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it const isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset)); node.isIndented = isIndented; if (isIndented) { for (let i = 0; i < parentStack.length; i++) { const parent = parentStack[i]; // no need to check checked items if (parent.hasIndentedCodeblock) { break; } if (parent.type === "list") { parent.hasIndentedCodeblock = true; } } } } return node; }); }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
transformIndentedCodeblockAndMarkItsParentList
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function markAlignedList(ast, options) { return mapAst$1(ast, (node, index, parentStack) => { if (node.type === "list" && node.children.length !== 0) { // if one of its parents is not aligned, it's not possible to be aligned in sub-lists for (let i = 0; i < parentStack.length; i++) { const parent = parentStack[i]; if (parent.type === "list" && !parent.isAligned) { node.isAligned = false; return node; } } node.isAligned = isAligned(node); } return node; }); function getListItemStart(listItem) { return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1; } function isAligned(list) { if (!list.ordered) { /** * - 123 * - 123 */ return true; } const [firstItem, secondItem] = list.children; const firstInfo = getOrderedListItemInfo$1(firstItem, options.originalText); if (firstInfo.leadingSpaces.length > 1) { /** * 1. 123 * * 1. 123 * 1. 123 */ return true; } const firstStart = getListItemStart(firstItem); if (firstStart === -1) { /** * 1. * * 1. * 1. */ return false; } if (list.children.length === 1) { /** * aligned: * * 11. 123 * * not aligned: * * 1. 123 */ return firstStart % options.tabWidth === 0; } const secondStart = getListItemStart(secondItem); if (firstStart !== secondStart) { /** * 11. 123 * 1. 123 * * 1. 123 * 11. 123 */ return false; } if (firstStart % options.tabWidth === 0) { /** * 11. 123 * 12. 123 */ return true; } /** * aligned: * * 11. 123 * 1. 123 * * not aligned: * * 1. 123 * 2. 123 */ const secondInfo = getOrderedListItemInfo$1(secondItem, options.originalText); return secondInfo.leadingSpaces.length > 1; } }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
markAlignedList
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getListItemStart(listItem) { return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
getListItemStart
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isAligned(list) { if (!list.ordered) { /** * - 123 * - 123 */ return true; } const [firstItem, secondItem] = list.children; const firstInfo = getOrderedListItemInfo$1(firstItem, options.originalText); if (firstInfo.leadingSpaces.length > 1) { /** * 1. 123 * * 1. 123 * 1. 123 */ return true; } const firstStart = getListItemStart(firstItem); if (firstStart === -1) { /** * 1. * * 1. * 1. */ return false; } if (list.children.length === 1) { /** * aligned: * * 11. 123 * * not aligned: * * 1. 123 */ return firstStart % options.tabWidth === 0; } const secondStart = getListItemStart(secondItem); if (firstStart !== secondStart) { /** * 11. 123 * 1. 123 * * 1. 123 * 11. 123 */ return false; } if (firstStart % options.tabWidth === 0) { /** * 11. 123 * 12. 123 */ return true; } /** * aligned: * * 11. 123 * 1. 123 * * not aligned: * * 1. 123 * 2. 123 */ const secondInfo = getOrderedListItemInfo$1(secondItem, options.originalText); return secondInfo.leadingSpaces.length > 1; }
split text into whitespaces and words @param {string} text @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
isAligned
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function insertPragma$6(text) { return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, ""); }
- add `isLeadingSpaceSensitive` field - add `isTrailingSpaceSensitive` field - add `isDanglingSpaceSensitive` field for parent nodes
insertPragma$6
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printVueFor(value, textToDoc) { const { left, operator, right } = parseVueFor(value); return concat$h([group$h(textToDoc(`function _(${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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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: `${[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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printVueSlotScope(value, textToDoc) { return textToDoc(`function _(${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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isVueEventBindingExpression$2(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$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
parse$6 = 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: ${element}`); } }); return result; })); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
parse$6
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
stringify$2 = 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(`${element.width}w`); } if (element.height) { result.push(`${element.height}h`); } if (element.density) { result.push(`${element.density}x`); } return result.join(' '); }))].join(', '); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
stringify$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$b(concat$i([",", line$a]), 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$7(alignment, " "), descriptor + unit); } return concat$i(parts); })); }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
printImgSrcset
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function concat$j(parts) { const newParts = normalizeParts$2(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$j
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function embed$4(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$j([breakParent$5, printOpeningTagPrefix(node, options), stripTrailingHardline$2(textToDoc(value, { parser })), printClosingTagSuffix(node, options)])]); } } else if (node.parent.type === "interpolation") { return concat$j([indent$c(concat$j([line$b, 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$b]); } 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$j([parser ? breakParent$5 : "", printOpeningTagPrefix(node), stripTrailingHardline$2(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$j([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$j([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$j([node.rawName, '="', group$i(mapDoc$5(embeddedAttributeValueDoc, doc => typeof doc === "string" ? doc.replace(/"/g, "&quot;") : doc)), '"']); } break; } case "yaml": return markAsRoot$4(concat$j(["---", hardline$e, node.value.trim().length === 0 ? "" : textToDoc(node.value, { parser: "yaml" }), "---"])); } }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
embed$4
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function genericPrint$5(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$i(printChildren$2(path, options, print)), hardline$e]); 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$j([group$i(concat$j([group$i(printOpeningTag(path, options, print), { id: attrGroupId }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$b : "" : concat$j([forceBreakContent$1(node) ? breakParent$5 : "", (childrenDoc => shouldHugContent ? ifBreak$8(indent$c(childrenDoc), childrenDoc, { groupId: attrGroupId }) : (isScriptLikeTag$1(node) || isVueCustomBlock$1(node, options)) && node.parent.type === "root" && options.parser === "vue" && !options.vueIndentScriptAndStyle ? childrenDoc : indent$c(childrenDoc))(concat$j([shouldHugContent ? ifBreak$8(softline$9, "", { groupId: attrGroupId }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$b : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$2(softline$9) : softline$9, printChildren$2(path, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$8(softline$9, "", { groupId: attrGroupId }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$b : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp(`\\n[\\t ]{${options.tabWidth * countParents$1(path, n => n.parent && n.parent.type !== "root")}}$`).test(node.lastChild.value) ? /** * <div> * <pre> * something * </pre> * ~ * </div> */ "" : softline$9])])), printClosingTag(node, options)]); } case "ieConditionalStartComment": case "ieConditionalEndComment": return concat$j([printOpeningTagStart(node), printClosingTagEnd(node)]); case "interpolation": return concat$j([printOpeningTagStart(node, options), concat$j(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$j([concat$j(replaceEndOfLineWith$2(value, literalline$6)), hasTrailingNewline ? hardline$e : ""]); } return fill$6(normalizeParts$2([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options)))); } case "docType": return concat$j([group$i(concat$j([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]); case "comment": { return concat$j([printOpeningTagPrefix(node, options), concat$j(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$6)), 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$j([node.rawName, concat$j(["=", quote, concat$j(replaceEndOfLineWith$2(quote === '"' ? value.replace(/"/g, "&quot;") : value.replace(/'/g, "&apos;"), literalline$6)), quote])]); } case "yaml": case "toml": return concat$j(replaceEndOfLineWith$2(node.raw, literalline$6)); default: throw new Error(`Unexpected node type ${node.type}`); } }
v-for="... in ..." v-for="... of ..." v-for="(..., ...) in ..." v-for="(..., ...) of ..."
genericPrint$5
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$j([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ? /** * <br /> * ^ */ " " : "" : concat$j([indent$c(concat$j([forceNotToBreakAttrContent ? " " : line$b, join$c(line$b, (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$j(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$6)) : 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$b : forceNotToBreakAttrContent ? "" : softline$9]), 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isNode(value, types) { return value && typeof value.type === "string" && (!types || types.includes(value.type)); }
@param {any} value @param {string[]=} types
isNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function mapNode(node, callback, parent) { return callback("children" in node ? Object.assign(Object.assign({}, node), {}, { children: node.children.map(childNode => mapNode(childNode, callback, node)) }) : node, parent); }
@param {any} value @param {string[]=} types
mapNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function defineShortcut(x, key, getter) { Object.defineProperty(x, key, { get: getter, enumerable: false }); }
@param {any} value @param {string[]=} types
defineShortcut
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isNextLineEmpty$7(node, text) { let newlineCount = 0; const textLength = text.length; for (let i = node.position.end.offset - 1; i < textLength; i++) { const char = text[i]; if (char === "\n") { newlineCount++; } if (newlineCount === 1 && /\S/.test(char)) { return false; } if (newlineCount === 2) { return true; } } return false; }
@param {any} value @param {string[]=} types
isNextLineEmpty$7
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isLastDescendantNode(path) { const node = path.getValue(); switch (node.type) { case "tag": case "anchor": case "comment": return false; } const pathStackLength = path.stack.length; for (let i = 1; i < pathStackLength; i++) { const item = path.stack[i]; const parentItem = path.stack[i - 1]; if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) { return false; } } return true; }
@param {any} value @param {string[]=} types
isLastDescendantNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getLastDescendantNode$1(node) { return "children" in node && node.children.length !== 0 ? getLastDescendantNode$1(getLast$7(node.children)) : node; }
@param {any} value @param {string[]=} types
getLastDescendantNode$1
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isPrettierIgnore$2(comment) { return comment.value.trim() === "prettier-ignore"; }
@param {any} value @param {string[]=} types
isPrettierIgnore$2
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasPrettierIgnore$7(path) { const node = path.getValue(); if (node.type === "documentBody") { const document = path.getParentNode(); return hasEndComments(document.head) && isPrettierIgnore$2(getLast$7(document.head.endComments)); } return hasLeadingComments(node) && isPrettierIgnore$2(getLast$7(node.leadingComments)); }
@param {any} value @param {string[]=} types
hasPrettierIgnore$7
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isEmptyNode(node) { return (!node.children || node.children.length === 0) && !hasComments(node); }
@param {any} value @param {string[]=} types
isEmptyNode
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasComments(node) { return hasLeadingComments(node) || hasMiddleComments(node) || hasIndicatorComment(node) || hasTrailingComment$4(node) || hasEndComments(node); }
@param {any} value @param {string[]=} types
hasComments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasLeadingComments(node) { return node && node.leadingComments && node.leadingComments.length !== 0; }
@param {any} value @param {string[]=} types
hasLeadingComments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasMiddleComments(node) { return node && node.middleComments && node.middleComments.length !== 0; }
@param {any} value @param {string[]=} types
hasMiddleComments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasIndicatorComment(node) { return node && node.indicatorComment; }
@param {any} value @param {string[]=} types
hasIndicatorComment
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasTrailingComment$4(node) { return node && node.trailingComment; }
@param {any} value @param {string[]=} types
hasTrailingComment$4
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasEndComments(node) { return node && node.endComments && node.endComments.length !== 0; }
@param {any} value @param {string[]=} types
hasEndComments
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hunkFits(hunk, toPos) { for (var j = 0; j < hunk.lines.length; j++) { var line = hunk.lines[j], operation = line.length > 0 ? line[0] : ' ', content = line.length > 0 ? line.substr(1) : line; if (operation === ' ' || operation === '-') { // Context sanity check if (!compareLine(toPos + 1, lines[toPos], operation, content)) { errorCount++; if (errorCount > fuzzFactor) { return false; } } toPos++; } } return true; } // Search best fit offsets for each hunk based on the previous ones
Checks if the hunk exactly fits on the provided location
hunkFits
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 applyPatches(uniDiff, options) { if (typeof uniDiff === 'string') { uniDiff = parsePatch(uniDiff); } var currentIndex = 0; function processIndex() { var index = uniDiff[currentIndex++]; if (!index) { return options.complete(); } options.loadFile(index, function (err, data) { if (err) { return options.complete(err); } var updatedContent = applyPatch(data, index, options); options.patched(index, updatedContent, function (err) { if (err) { return options.complete(err); } processIndex(); }); }); } processIndex(); }
Checks if the hunk exactly fits on the provided location
applyPatches
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 processIndex() { var index = uniDiff[currentIndex++]; if (!index) { return options.complete(); } options.loadFile(index, function (err, data) { if (err) { return options.complete(err); } var updatedContent = applyPatch(data, index, options); options.patched(index, updatedContent, function (err) { if (err) { return options.complete(err); } processIndex(); }); }); }
Checks if the hunk exactly fits on the provided location
processIndex
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 structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) { if (!options) { options = {}; } if (typeof options.context === 'undefined') { options.context = 4; } var diff = diffLines(oldStr, newStr, options); diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier function contextLines(lines) { return lines.map(function (entry) { return ' ' + entry; }); } var hunks = []; var oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1; var _loop = function _loop(i) { var current = diff[i], lines = current.lines || current.value.replace(/\n$/, '').split('\n'); current.lines = lines; if (current.added || current.removed) { var _curRange; // If we have previous context, start with that if (!oldRangeStart) { var prev = diff[i - 1]; oldRangeStart = oldLine; newRangeStart = newLine; if (prev) { curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : []; oldRangeStart -= curRange.length; newRangeStart -= curRange.length; } } // Output our changes (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) { return (current.added ? '+' : '-') + entry; }))); // Track the updated file position if (current.added) { newLine += lines.length; } else { oldLine += lines.length; } } else { // Identical context lines. Track line changes if (oldRangeStart) { // Close out any changes that have been output (or join overlapping) if (lines.length <= options.context * 2 && i < diff.length - 2) { var _curRange2; // Overlapping (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines))); } else { var _curRange3; // end the range and output var contextSize = Math.min(lines.length, options.context); (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize)))); var hunk = { oldStart: oldRangeStart, oldLines: oldLine - oldRangeStart + contextSize, newStart: newRangeStart, newLines: newLine - newRangeStart + contextSize, lines: curRange }; if (i >= diff.length - 2 && lines.length <= options.context) { // EOF is inside this hunk var oldEOFNewline = /\n$/.test(oldStr); var newEOFNewline = /\n$/.test(newStr); var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines; if (!oldEOFNewline && noNlBeforeAdds) { // special case: old has no eol and no trailing context; no-nl can end up before adds curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file'); } if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) { curRange.push('\\ No newline at end of file'); } } hunks.push(hunk); oldRangeStart = 0; newRangeStart = 0; curRange = []; } } oldLine += lines.length; newLine += lines.length; } }; for (var i = 0; i < diff.length; i++) { _loop(i); } return { oldFileName: oldFileName, newFileName: newFileName, oldHeader: oldHeader, newHeader: newHeader, hunks: hunks }; }
Checks if the hunk exactly fits on the provided location
structuredPatch
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 contextLines(lines) { return lines.map(function (entry) { return ' ' + entry; }); }
Checks if the hunk exactly fits on the provided location
contextLines
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
_loop = function _loop(i) { var current = diff[i], lines = current.lines || current.value.replace(/\n$/, '').split('\n'); current.lines = lines; if (current.added || current.removed) { var _curRange; // If we have previous context, start with that if (!oldRangeStart) { var prev = diff[i - 1]; oldRangeStart = oldLine; newRangeStart = newLine; if (prev) { curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : []; oldRangeStart -= curRange.length; newRangeStart -= curRange.length; } } // Output our changes (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) { return (current.added ? '+' : '-') + entry; }))); // Track the updated file position if (current.added) { newLine += lines.length; } else { oldLine += lines.length; } } else { // Identical context lines. Track line changes if (oldRangeStart) { // Close out any changes that have been output (or join overlapping) if (lines.length <= options.context * 2 && i < diff.length - 2) { var _curRange2; // Overlapping (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines))); } else { var _curRange3; // end the range and output var contextSize = Math.min(lines.length, options.context); (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize)))); var hunk = { oldStart: oldRangeStart, oldLines: oldLine - oldRangeStart + contextSize, newStart: newRangeStart, newLines: newLine - newRangeStart + contextSize, lines: curRange }; if (i >= diff.length - 2 && lines.length <= options.context) { // EOF is inside this hunk var oldEOFNewline = /\n$/.test(oldStr); var newEOFNewline = /\n$/.test(newStr); var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines; if (!oldEOFNewline && noNlBeforeAdds) { // special case: old has no eol and no trailing context; no-nl can end up before adds curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file'); } if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) { curRange.push('\\ No newline at end of file'); } } hunks.push(hunk); oldRangeStart = 0; newRangeStart = 0; curRange = []; } } oldLine += lines.length; newLine += lines.length; } }
Checks if the hunk exactly fits on the provided location
_loop
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 createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) { var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options); var ret = []; if (oldFileName == newFileName) { ret.push('Index: ' + oldFileName); } ret.push('==================================================================='); ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader)); ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader)); for (var i = 0; i < diff.hunks.length; i++) { var hunk = diff.hunks[i]; ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@'); ret.push.apply(ret, hunk.lines); } return ret.join('\n') + '\n'; }
Checks if the hunk exactly fits on the provided location
createTwoFilesPatch
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 createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) { return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options); }
Checks if the hunk exactly fits on the provided location
createPatch
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 arrayEqual(a, b) { if (a.length !== b.length) { return false; } return arrayStartsWith(a, b); }
Checks if the hunk exactly fits on the provided location
arrayEqual
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 arrayStartsWith(array, start) { if (start.length > array.length) { return false; } for (var i = 0; i < start.length; i++) { if (start[i] !== array[i]) { return false; } } return true; }
Checks if the hunk exactly fits on the provided location
arrayStartsWith
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 calcLineCount(hunk) { var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines), oldLines = _calcOldNewLineCount.oldLines, newLines = _calcOldNewLineCount.newLines; if (oldLines !== undefined) { hunk.oldLines = oldLines; } else { delete hunk.oldLines; } if (newLines !== undefined) { hunk.newLines = newLines; } else { delete hunk.newLines; } }
Checks if the hunk exactly fits on the provided location
calcLineCount
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 merge(mine, theirs, base) { mine = loadPatch(mine, base); theirs = loadPatch(theirs, base); var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning. // Leaving sanity checks on this to the API consumer that may know more about the // meaning in their own context. if (mine.index || theirs.index) { ret.index = mine.index || theirs.index; } if (mine.newFileName || theirs.newFileName) { if (!fileNameChanged(mine)) { // No header or no change in ours, use theirs (and ours if theirs does not exist) ret.oldFileName = theirs.oldFileName || mine.oldFileName; ret.newFileName = theirs.newFileName || mine.newFileName; ret.oldHeader = theirs.oldHeader || mine.oldHeader; ret.newHeader = theirs.newHeader || mine.newHeader; } else if (!fileNameChanged(theirs)) { // No header or no change in theirs, use ours ret.oldFileName = mine.oldFileName; ret.newFileName = mine.newFileName; ret.oldHeader = mine.oldHeader; ret.newHeader = mine.newHeader; } else { // Both changed... figure it out ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName); ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName); ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader); ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader); } } ret.hunks = []; var mineIndex = 0, theirsIndex = 0, mineOffset = 0, theirsOffset = 0; while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) { var mineCurrent = mine.hunks[mineIndex] || { oldStart: Infinity }, theirsCurrent = theirs.hunks[theirsIndex] || { oldStart: Infinity }; if (hunkBefore(mineCurrent, theirsCurrent)) { // This patch does not overlap with any of the others, yay. ret.hunks.push(cloneHunk(mineCurrent, mineOffset)); mineIndex++; theirsOffset += mineCurrent.newLines - mineCurrent.oldLines; } else if (hunkBefore(theirsCurrent, mineCurrent)) { // This patch does not overlap with any of the others, yay. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset)); theirsIndex++; mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines; } else { // Overlap, merge as best we can var mergedHunk = { oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart), oldLines: 0, newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset), newLines: 0, lines: [] }; mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines); theirsIndex++; mineIndex++; ret.hunks.push(mergedHunk); } } return ret; }
Checks if the hunk exactly fits on the provided location
merge
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 loadPatch(param, base) { if (typeof param === 'string') { if (/^@@/m.test(param) || /^Index:/m.test(param)) { return parsePatch(param)[0]; } if (!base) { throw new Error('Must provide a base reference or pass in a patch'); } return structuredPatch(undefined, undefined, base, param); } return param; }
Checks if the hunk exactly fits on the provided location
loadPatch
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 fileNameChanged(patch) { return patch.newFileName && patch.newFileName !== patch.oldFileName; }
Checks if the hunk exactly fits on the provided location
fileNameChanged
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 selectField(index, mine, theirs) { if (mine === theirs) { return mine; } else { index.conflict = true; return { mine: mine, theirs: theirs }; } }
Checks if the hunk exactly fits on the provided location
selectField
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 hunkBefore(test, check) { return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart; }
Checks if the hunk exactly fits on the provided location
hunkBefore
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 cloneHunk(hunk, offset) { return { oldStart: hunk.oldStart, oldLines: hunk.oldLines, newStart: hunk.newStart + offset, newLines: hunk.newLines, lines: hunk.lines }; }
Checks if the hunk exactly fits on the provided location
cloneHunk
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 mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) { // This will generally result in a conflicted hunk, but there are cases where the context // is the only overlap where we can successfully merge the content here. var mine = { offset: mineOffset, lines: mineLines, index: 0 }, their = { offset: theirOffset, lines: theirLines, index: 0 }; // Handle any leading content insertLeading(hunk, mine, their); insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each. while (mine.index < mine.lines.length && their.index < their.lines.length) { var mineCurrent = mine.lines[mine.index], theirCurrent = their.lines[their.index]; if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) { // Both modified ... mutualChange(hunk, mine, their); } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') { var _hunk$lines; // Mine inserted (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine))); } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') { var _hunk$lines2; // Theirs inserted (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their))); } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') { // Mine removed or edited removal(hunk, mine, their); } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') { // Their removed or edited removal(hunk, their, mine, true); } else if (mineCurrent === theirCurrent) { // Context identity hunk.lines.push(mineCurrent); mine.index++; their.index++; } else { // Context mismatch conflict(hunk, collectChange(mine), collectChange(their)); } } // Now push anything that may be remaining insertTrailing(hunk, mine); insertTrailing(hunk, their); calcLineCount(hunk); }
Checks if the hunk exactly fits on the provided location
mergeLines
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 mutualChange(hunk, mine, their) { var myChanges = collectChange(mine), theirChanges = collectChange(their); if (allRemoves(myChanges) && allRemoves(theirChanges)) { // Special case for remove changes that are supersets of one another if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) { var _hunk$lines3; (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges)); return; } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) { var _hunk$lines4; (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges)); return; } } else if (arrayEqual(myChanges, theirChanges)) { var _hunk$lines5; (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges)); return; } conflict(hunk, myChanges, theirChanges); }
Checks if the hunk exactly fits on the provided location
mutualChange
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 removal(hunk, mine, their, swap) { var myChanges = collectChange(mine), theirChanges = collectContext(their, myChanges); if (theirChanges.merged) { var _hunk$lines6; (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged)); } else { conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges); } }
Checks if the hunk exactly fits on the provided location
removal
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 conflict(hunk, mine, their) { hunk.conflict = true; hunk.lines.push({ conflict: true, mine: mine, theirs: their }); }
Checks if the hunk exactly fits on the provided location
conflict
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 insertLeading(hunk, insert, their) { while (insert.offset < their.offset && insert.index < insert.lines.length) { var line = insert.lines[insert.index++]; hunk.lines.push(line); insert.offset++; } }
Checks if the hunk exactly fits on the provided location
insertLeading
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 insertTrailing(hunk, insert) { while (insert.index < insert.lines.length) { var line = insert.lines[insert.index++]; hunk.lines.push(line); } }
Checks if the hunk exactly fits on the provided location
insertTrailing
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 collectChange(state) { var ret = [], operation = state.lines[state.index][0]; while (state.index < state.lines.length) { var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change. if (operation === '-' && line[0] === '+') { operation = '+'; } if (operation === line[0]) { ret.push(line); state.index++; } else { break; } } return ret; }
Checks if the hunk exactly fits on the provided location
collectChange
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 collectContext(state, matchChanges) { var changes = [], merged = [], matchIndex = 0, contextChanges = false, conflicted = false; while (matchIndex < matchChanges.length && state.index < state.lines.length) { var change = state.lines[state.index], match = matchChanges[matchIndex]; // Once we've hit our add, then we are done if (match[0] === '+') { break; } contextChanges = contextChanges || change[0] !== ' '; merged.push(match); matchIndex++; // Consume any additions in the other block as a conflict to attempt // to pull in the remaining context after this if (change[0] === '+') { conflicted = true; while (change[0] === '+') { changes.push(change); change = state.lines[++state.index]; } } if (match.substr(1) === change.substr(1)) { changes.push(change); state.index++; } else { conflicted = true; } } if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) { conflicted = true; } if (conflicted) { return changes; } while (matchIndex < matchChanges.length) { merged.push(matchChanges[matchIndex++]); } return { merged: merged, changes: changes }; }
Checks if the hunk exactly fits on the provided location
collectContext
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 allRemoves(changes) { return changes.reduce(function (prev, change) { return prev && change[0] === '-'; }, true); }
Checks if the hunk exactly fits on the provided location
allRemoves
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 skipRemoveSuperset(state, removeChanges, delta) { for (var i = 0; i < delta; i++) { var changeContent = removeChanges[removeChanges.length - delta + i].substr(1); if (state.lines[state.index + i] !== ' ' + changeContent) { return false; } } state.index += delta; return true; }
Checks if the hunk exactly fits on the provided location
skipRemoveSuperset
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 calcOldNewLineCount(lines) { var oldLines = 0; var newLines = 0; lines.forEach(function (line) { if (typeof line !== 'string') { var myCount = calcOldNewLineCount(line.mine); var theirCount = calcOldNewLineCount(line.theirs); if (oldLines !== undefined) { if (myCount.oldLines === theirCount.oldLines) { oldLines += myCount.oldLines; } else { oldLines = undefined; } } if (newLines !== undefined) { if (myCount.newLines === theirCount.newLines) { newLines += myCount.newLines; } else { newLines = undefined; } } } else { if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) { newLines++; } if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) { oldLines++; } } }); return { oldLines: oldLines, newLines: newLines }; } // See: http://code.google.com/p/google-diff-match-patch/wiki/API
Checks if the hunk exactly fits on the provided location
calcOldNewLineCount
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 convertChangesToDMP(changes) { var ret = [], change, operation; for (var i = 0; i < changes.length; i++) { change = changes[i]; if (change.added) { operation = 1; } else if (change.removed) { operation = -1; } else { operation = 0; } ret.push([operation, change.value]); } return ret; }
Checks if the hunk exactly fits on the provided location
convertChangesToDMP
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 convertChangesToXML(changes) { var ret = []; for (var i = 0; i < changes.length; i++) { var change = changes[i]; if (change.added) { ret.push('<ins>'); } else if (change.removed) { ret.push('<del>'); } ret.push(escapeHTML(change.value)); if (change.added) { ret.push('</ins>'); } else if (change.removed) { ret.push('</del>'); } } return ret.join(''); }
Checks if the hunk exactly fits on the provided location
convertChangesToXML
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 escapeHTML(s) { var n = s; n = n.replace(/&/g, '&amp;'); n = n.replace(/</g, '&lt;'); n = n.replace(/>/g, '&gt;'); n = n.replace(/"/g, '&quot;'); return n; }
Checks if the hunk exactly fits on the provided location
escapeHTML
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