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 assertPatternsInput(input) { const source = [].concat(input); const isValidSource = source.every(item => utils$4.string.isString(item) && !utils$4.string.isEmpty(item)); if (!isValidSource) { throw new TypeError('Patterns must be a string (non empty) or an array of strings'); } }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
assertPatternsInput
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
async function isType(fsStatType, statsMethodName, filePath) { if (typeof filePath !== 'string') { throw new TypeError(`Expected a string, got ${typeof filePath}`); } try { const stats = await promisify(fs$3[fsStatType])(filePath); return stats[statsMethodName](); } catch (error) { if (error.code === 'ENOENT') { return false; } throw error; } }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
isType
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 isTypeSync(fsStatType, statsMethodName, filePath) { if (typeof filePath !== 'string') { throw new TypeError(`Expected a string, got ${typeof filePath}`); } try { return fs$3[fsStatType](filePath)[statsMethodName](); } catch (error) { if (error.code === 'ENOENT') { return false; } throw error; } }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
isTypeSync
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
getPath = (filepath, cwd) => { const pth = filepath[0] === '!' ? filepath.slice(1) : filepath; return path$2.isAbsolute(pth) ? pth : path$2.join(cwd, pth); }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
getPath
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
getPath = (filepath, cwd) => { const pth = filepath[0] === '!' ? filepath.slice(1) : filepath; return path$2.isAbsolute(pth) ? pth : path$2.join(cwd, pth); }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
getPath
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
addExtensions = (file, extensions) => { if (path$2.extname(file)) { return `**/${file}`; } return `**/${file}.${getExtensions(extensions)}`; }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
addExtensions
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
addExtensions = (file, extensions) => { if (path$2.extname(file)) { return `**/${file}`; } return `**/${file}.${getExtensions(extensions)}`; }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
addExtensions
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
getGlob = (directory, options) => { if (options.files && !Array.isArray(options.files)) { throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof options.files}\``); } if (options.extensions && !Array.isArray(options.extensions)) { throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof options.extensions}\``); } if (options.files && options.extensions) { return options.files.map(x => path$2.posix.join(directory, addExtensions(x, options.extensions))); } if (options.files) { return options.files.map(x => path$2.posix.join(directory, `**/${x}`)); } if (options.extensions) { return [path$2.posix.join(directory, `**/*.${getExtensions(options.extensions)}`)]; } return [path$2.posix.join(directory, '**')]; }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
getGlob
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
getGlob = (directory, options) => { if (options.files && !Array.isArray(options.files)) { throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof options.files}\``); } if (options.extensions && !Array.isArray(options.extensions)) { throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof options.extensions}\``); } if (options.files && options.extensions) { return options.files.map(x => path$2.posix.join(directory, addExtensions(x, options.extensions))); } if (options.files) { return options.files.map(x => path$2.posix.join(directory, `**/${x}`)); } if (options.extensions) { return [path$2.posix.join(directory, `**/*.${getExtensions(options.extensions)}`)]; } return [path$2.posix.join(directory, '**')]; }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
getGlob
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
dirGlob = async (input, options) => { options = Object.assign({ cwd: process.cwd() }, options); if (typeof options.cwd !== 'string') { throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``); } const globs = await Promise.all([].concat(input).map(async x => { const isDirectory = await pathType.isDirectory(getPath(x, options.cwd)); return isDirectory ? getGlob(x, options) : x; })); return [].concat.apply([], globs); // eslint-disable-line prefer-spread }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
dirGlob
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
sync$7 = (input, options) => { options = Object.assign({ cwd: process.cwd() }, options); if (typeof options.cwd !== 'string') { throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``); } const globs = [].concat(input).map(x => pathType.isDirectorySync(getPath(x, options.cwd)) ? getGlob(x, options) : x); return [].concat.apply([], globs); // eslint-disable-line prefer-spread }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
sync$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 makeArray(subject) { return Array.isArray(subject) ? subject : [subject]; }
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
makeArray
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
sanitizeRange$1 = range => range.replace(REGEX_REGEXP_RANGE$1, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but // fatal for JavaScript regular expression, so eliminate it. : '')
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
sanitizeRange$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
sanitizeRange$1 = range => range.replace(REGEX_REGEXP_RANGE$1, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but // fatal for JavaScript regular expression, so eliminate it. : '')
The stream returned by the provider cannot work with an asynchronous iterator. To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams. This affects performance (+25%). I don't see best solution right now.
sanitizeRange$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
makeRegex = (pattern, negative, ignorecase) => { const r = regexCache[pattern]; if (r) { return r; } // const replacers = negative // ? NEGATIVE_REPLACERS // : POSITIVE_REPLACERS const source = REPLACERS.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern); return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
makeRegex
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
makeRegex = (pattern, negative, ignorecase) => { const r = regexCache[pattern]; if (r) { return r; } // const replacers = negative // ? NEGATIVE_REPLACERS // : POSITIVE_REPLACERS const source = REPLACERS.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern); return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
makeRegex
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
checkPattern$1 = pattern => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment. && pattern.indexOf('#') !== 0
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPattern$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
checkPattern$1 = pattern => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment. && pattern.indexOf('#') !== 0
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPattern$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
constructor(origin, pattern, negative, regex) { this.origin = origin; this.pattern = pattern; this.negative = negative; this.regex = regex; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
constructor
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
createRule$1 = (pattern, ignorecase) => { const origin = pattern; let negative = false; // > An optional prefix "!" which negates the pattern; if (pattern.indexOf('!') === 0) { negative = true; pattern = pattern.substr(1); } pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that // > begin with a literal "!", for example, `"\!important!.txt"`. .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that // > begin with a hash. .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#'); const regex = makeRegex(pattern, negative, ignorecase); return new IgnoreRule(origin, pattern, negative, regex); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createRule$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
createRule$1 = (pattern, ignorecase) => { const origin = pattern; let negative = false; // > An optional prefix "!" which negates the pattern; if (pattern.indexOf('!') === 0) { negative = true; pattern = pattern.substr(1); } pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that // > begin with a literal "!", for example, `"\!important!.txt"`. .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that // > begin with a hash. .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#'); const regex = makeRegex(pattern, negative, ignorecase); return new IgnoreRule(origin, pattern, negative, regex); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createRule$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
throwError = (message, Ctor) => { throw new Ctor(message); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
throwError
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
throwError = (message, Ctor) => { throw new Ctor(message); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
throwError
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
checkPath = (path, originalPath, doThrow) => { if (!isString(path)) { return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError); } // We don't know if we should ignore '', so throw if (!path) { return doThrow(`path must not be empty`, TypeError); } // Check if it is a relative path if (checkPath.isNotRelative(path)) { const r = '`path.relative()`d'; return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError); } return true; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPath
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
checkPath = (path, originalPath, doThrow) => { if (!isString(path)) { return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError); } // We don't know if we should ignore '', so throw if (!path) { return doThrow(`path must not be empty`, TypeError); } // Check if it is a relative path if (checkPath.isNotRelative(path)) { const r = '`path.relative()`d'; return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError); } return true; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPath
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
constructor({ ignorecase = true } = {}) { this._rules = []; this._ignorecase = ignorecase; define$1(this, KEY_IGNORE$1, true); this._initCache(); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
constructor
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
_initCache() { this._ignoreCache = Object.create(null); this._testCache = Object.create(null); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_initCache
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
_addPattern(pattern) { // #32 if (pattern && pattern[KEY_IGNORE$1]) { this._rules = this._rules.concat(pattern._rules); this._added = true; return; } if (checkPattern$1(pattern)) { const rule = createRule$1(pattern, this._ignorecase); this._added = true; this._rules.push(rule); } }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_addPattern
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
add(pattern) { this._added = false; makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore, // making the behavior changed. if (this._added) { this._initCache(); } return this; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
add
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
addPattern(pattern) { return this.add(pattern); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
addPattern
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
_testOne(path, checkUnignored) { let ignored = false; let unignored = false; this._rules.forEach(rule => { const { negative } = rule; if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) { return; } const matched = rule.regex.test(path); if (matched) { ignored = !negative; unignored = negative; } }); return { ignored, unignored }; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_testOne
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
_test(originalPath, cache, checkUnignored, slices) { const path = originalPath // Supports nullable path && checkPath.convert(originalPath); checkPath(path, originalPath, throwError); return this._t(path, cache, checkUnignored, slices); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_test
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
_t(path, cache, checkUnignored, slices) { if (path in cache) { return cache[path]; } if (!slices) { // path/to/a.js // ['path', 'to', 'a.js'] slices = path.split(SLASH$1); } slices.pop(); // If the path has no parent directory, just test it if (!slices.length) { return cache[path] = this._testOne(path, checkUnignored); } const parent = this._t(slices.join(SLASH$1) + SLASH$1, cache, checkUnignored, slices); // If the path contains a parent directory, check the parent first return cache[path] = parent.ignored // > It is not possible to re-include a file if a parent directory of // > that file is excluded. ? parent : this._testOne(path, checkUnignored); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_t
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
ignores(path) { return this._test(path, this._ignoreCache, false).ignored; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
ignores
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
createFilter() { return path => !this.ignores(path); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createFilter
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
filter(paths) { return makeArray(paths).filter(this.createFilter()); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
filter
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
test(path) { return this._test(path, this._testCache, true); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
test
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
slash$1 = path => { const isExtendedLengthPath = /^\\\\\?\\/.test(path); const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex if (isExtendedLengthPath || hasNonAscii) { return path; } return path.replace(/\\/g, '/'); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
slash$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 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isTemplateOnItsOwnLine(n, text, options) { return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$3(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function needsHardlineAfterDanglingComment(node) { if (!node.comments) { return false; } const lastDanglingComment = getLast$1(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function shouldPrintComma(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
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 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$1.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printCallArguments(path, options, print) { const node = path.getValue(); const args = node.arguments; if (args.length === 0) { return concat$6(["(", 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$6(["(", 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$6([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$2(options.originalText, arg, options.locEnd)) { if (index === 0) { hasEmptyLineFollowingFirstArg = true; } anyArgEmptyLine = true; parts.push(",", hardline$4, hardline$4); } else { parts.push(",", line$4); } shouldBreakForArrowFunction = shouldBreakForArrowFunctionInArguments(arg, argPath); return concat$6(parts); }, "arguments"); const maybeTrailingComma = // Dynamic imports cannot have trailing commas !(node.callee && node.callee.type === "Import") && shouldPrintComma$1(options, "all") ? "," : ""; function allArgsBrokenOut() { return group$2(concat$6(["(", indent$3(concat$6([line$4, concat$6(printedArguments)])), maybeTrailingComma, line$4, ")"]), { 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$6([argPath.call(p => print(p, { expandFirstArg: true })), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$4 : line$4, hasEmptyLineFollowingFirstArg ? hardline$4 : ""])].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$6(["(", concat$6(printedExpanded), ")"]); return concat$6([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([!somePrintedArgumentsWillBreak && !node.typeArguments && !node.typeParameters ? simpleConcat : ifBreak$1(allArgsBrokenOut(), simpleConcat), shouldGroupFirst ? concat$6(["(", group$2(printedExpanded[0], { shouldBreak: true }), concat$6(printedExpanded.slice(1)), ")"]) : concat$6(["(", concat$6(printedArguments.slice(0, -1)), group$2(getLast$2(printedExpanded), { shouldBreak: true }), ")"]), allArgsBrokenOut()], { shouldBreak })]); } const contents = concat$6(["(", indent$3(concat$6([softline$2, concat$6(printedArguments)])), ifBreak$1(maybeTrailingComma), softline$2, ")"]); 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$2(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$6([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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function allArgsBrokenOut() { return group$2(concat$6(["(", indent$3(concat$6([line$4, concat$6(printedArguments)])), maybeTrailingComma, line$4, ")"]), { 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function shouldGroupLastArg(args) { const lastArg = getLast$2(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$7([optional, ".", property]); } if (!n.property || isNumericLiteral$1(n.property)) { return concat$7([optional, "[", property, "]"]); } return group$3(concat$7([optional, "[", indent$4(concat$7([softline$3, property])), softline$3, "]"])); }
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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printBindExpressionCallee(path, options, print) { return concat$7(["::", 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$3(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$8([comments.printComments(path, () => concat$8([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]), options), shouldInsertEmptyLineAfter(node) ? hardline$5 : ""]) }); 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$8([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$3(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$8(["(", ...printed, ")"]); } return concat$8(printed); } function printIndentedGroup(groups) { if (groups.length === 0) { return ""; } return indent$5(group$4(concat$8([hardline$5, join$4(hardline$5, groups.map(printGroup))]))); } const printedGroups = groups.map(printGroup); const oneLine = concat$8(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$4(oneLine); } // Find out the last node in the first group and check if it has an // empty line after const lastNodeBeforeIndent = getLast$3(groups[shouldMerge ? 1 : 0]).node; const shouldHaveEmptyLineBeforeIndent = !isCallOrOptionalCallExpression$1(lastNodeBeforeIndent) && shouldInsertEmptyLineAfter(lastNodeBeforeIndent); const expanded = concat$8([printGroup(groups[0]), shouldMerge ? printGroup(groups[1]) : "", shouldHaveEmptyLineBeforeIndent ? hardline$5 : "", 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$3(getLast$3(groups)).node; const lastGroupDoc = getLast$3(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$4(expanded); } return concat$8([// 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$3 : "", 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$3(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$8([comments.printComments(path, () => concat$8([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]), options), shouldInsertEmptyLineAfter(node) ? hardline$5 : ""]) }); 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$3(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$8(["(", ...printed, ")"]); } return concat$8(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printIndentedGroup(groups) { if (groups.length === 0) { return ""; } return indent$5(group$4(concat$8([hardline$5, join$4(hardline$5, 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function lastGroupWillBreakAndOtherCallsHaveComplexArguments() { const lastGroupNode = getLast$3(getLast$3(groups)).node; const lastGroupDoc = getLast$3(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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function genericPrint(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$6 : line$5; 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$6); } } 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$6); }, "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$5(concat$9(decorators.concat(parts))); } return concat$9(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
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 printDecorators(path, options, print) { const node = path.getValue(); return group$5(concat$9([join$5(line$5, path.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators$1(node, options) ? hardline$6 : line$5])); }
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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.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$9([ifBreak$2("(", ""), indent$6(concat$9([softline$4, doc])), softline$4, ifBreak$2(")", "")]); // 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$9([line$5, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$2("", "(") : "", align$1(2, path.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$2("", ")") : "", line$5, ": ", 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$1(indent$6(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$5(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$9([].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$9(operatorOptions.beforeParts())), forceNoIndent ? concat$9(parts) : indent$6(concat$9(parts)), operatorOptions.afterParts(breakClosingParen)))); return isParentTest ? group$5(concat$9([indent$6(concat$9([softline$4, result])), softline$4])) : 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/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function replaceQuotesInInlineComments(text) { /** @typedef { 'initial' | 'single-quotes' | 'double-quotes' | 'url' | 'comment-block' | 'comment-inline' } State */ /** @type {State} */ let state = "initial"; /** @type {State} */ let stateToReturnFromQuotes = "initial"; let inlineCommentStartIndex; let inlineCommentContainsQuotes = false; const inlineCommentsToReplace = []; for (let i = 0; i < text.length; i++) { const c = text[i]; switch (state) { case "initial": if (c === "'") { state = "single-quotes"; continue; } if (c === '"') { state = "double-quotes"; continue; } if ((c === "u" || c === "U") && text.slice(i, i + 4).toLowerCase() === "url(") { state = "url"; i += 3; continue; } if (c === "*" && text[i - 1] === "/") { state = "comment-block"; continue; } if (c === "/" && text[i - 1] === "/") { state = "comment-inline"; inlineCommentStartIndex = i - 1; continue; } continue; case "single-quotes": if (c === "'" && text[i - 1] !== "\\") { state = stateToReturnFromQuotes; stateToReturnFromQuotes = "initial"; } if (c === "\n" || c === "\r") { return text; // invalid input } continue; case "double-quotes": if (c === '"' && text[i - 1] !== "\\") { state = stateToReturnFromQuotes; stateToReturnFromQuotes = "initial"; } if (c === "\n" || c === "\r") { return text; // invalid input } continue; case "url": if (c === ")") { state = "initial"; } if (c === "\n" || c === "\r") { return text; // invalid input } if (c === "'") { state = "single-quotes"; stateToReturnFromQuotes = "url"; continue; } if (c === '"') { state = "double-quotes"; stateToReturnFromQuotes = "url"; continue; } continue; case "comment-block": if (c === "/" && text[i - 1] === "*") { state = "initial"; } continue; case "comment-inline": if (c === '"' || c === "'") { inlineCommentContainsQuotes = true; } if (c === "\n" || c === "\r") { if (inlineCommentContainsQuotes) { inlineCommentsToReplace.push([inlineCommentStartIndex, i]); } state = "initial"; inlineCommentContainsQuotes = false; } continue; } } for (const [start, end] of inlineCommentsToReplace) { text = text.slice(0, start) + text.slice(start, end).replace(/'/g, "\ufffe").replace(/"/g, "\uffff") + text.slice(end); } return text; }
Workaround for a bug: quotes in inline comments corrupt loc data of subsequent nodes. This function replaces the quotes with U+FFFE and U+FFFF. Later, when the comments are printed, their content is extracted from the original text or restored by replacing the placeholder characters back with quotes. - https://github.com/prettier/prettier/issues/7780 - https://github.com/shellscape/postcss-less/issues/145 - About noncharacters (U+FFFE and U+FFFF): http://www.unicode.org/faq/private_use.html#nonchar1 @param text {string}
replaceQuotesInInlineComments
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 printStringLiteral(stringLiteral, options) { const double = { quote: '"', regex: /"/g }; const single = { quote: "'", regex: /'/g }; const preferred = options.singleQuote ? single : double; const alternate = preferred === single ? double : single; let shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for // enclosing the string, we might want to enclose with the alternate quote // instead, to minimize the number of escaped quotes. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) { const numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length; const numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length; shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes; } const enclosingQuote = shouldUseAlternateQuote ? alternate : preferred; const escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`); return concat$d([enclosingQuote.quote, escapedStringLiteral, enclosingQuote.quote]); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printStringLiteral
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 printSubExpressionPathAndParams(path, print) { const p = printPath(path, print); const params = printParams(path, print); if (!params) { return p; } return indent$9(concat$d([p, line$7, group$d(params)])); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printSubExpressionPathAndParams
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 printPathAndParams(path, print) { const p = printPath(path, print); const params = printParams(path, print); if (!params) { return p; } return indent$9(group$d(concat$d([p, line$7, params]))); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printPathAndParams
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 printPath(path, print) { return path.call(print, "path"); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printPath
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 printParams(path, print) { const node = path.getValue(); const parts = []; if (node.params.length) { const params = path.map(print, "params"); parts.push(...params); } if (node.hash && node.hash.pairs.length > 0) { const hash = path.call(print, "hash"); parts.push(hash); } if (!parts.length) { return ""; } return join$8(line$7, parts); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printParams
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 printBlockParams(node) { if (!node || !node.blockParams.length) { return ""; } return concat$d([" as |", node.blockParams.join(" "), "|"]); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printBlockParams
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 locationToOffset(source, line, column) { let seenLines = 0; let seenChars = 0; // eslint-disable-next-line no-constant-condition while (true) { if (seenChars === source.length) { return null; } let nextLine = source.indexOf("\n", seenChars); if (nextLine === -1) { nextLine = source.length; } if (seenLines === line) { if (seenChars + column > nextLine) { return null; } return seenChars + column; } else if (nextLine === -1) { return null; } seenLines += 1; seenChars = nextLine + 1; } }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
locationToOffset
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$2(text) { return /^\s*#[^\S\n]*@(format|prettier)\s*(\n|$)/.test(text); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
hasPragma$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 insertPragma$4(text) { return "# @format\n\n" + text; }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
insertPragma$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$3(path, options, print) { const n = path.getValue(); if (!n) { return ""; } if (typeof n === "string") { return n; } switch (n.kind) { case "Document": { const parts = []; path.map((pathChild, index) => { parts.push(concat$e([pathChild.call(print)])); if (index !== n.definitions.length - 1) { parts.push(hardline$b); if (isNextLineEmpty$6(options.originalText, pathChild.getValue(), options.locEnd)) { parts.push(hardline$b); } } }, "definitions"); return concat$e([concat$e(parts), hardline$b]); } case "OperationDefinition": { const hasOperation = options.originalText[options.locStart(n)] !== "{"; const hasName = !!n.name; return concat$e([hasOperation ? n.operation : "", hasOperation && hasName ? concat$e([" ", path.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.map(print, "variableDefinitions"))])), softline$7, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path.call(print, "selectionSet")]); } case "FragmentDefinition": { return concat$e(["fragment ", path.call(print, "name"), n.variableDefinitions && n.variableDefinitions.length ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.map(print, "variableDefinitions"))])), softline$7, ")"])) : "", " on ", path.call(print, "typeCondition"), printDirectives(path, print, n), " ", path.call(print, "selectionSet")]); } case "SelectionSet": { return concat$e(["{", indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(selectionsPath => printSequence(selectionsPath, options, print), "selections"))])), hardline$b, "}"]); } case "Field": { return group$f(concat$e([n.alias ? concat$e([path.call(print, "alias"), ": "]) : "", path.call(print, "name"), n.arguments.length > 0 ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$7, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? " " : "", path.call(print, "selectionSet")])); } case "Name": { return n.value; } case "StringValue": { if (n.block) { return concat$e(['"""', hardline$b, join$9(hardline$b, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$b, '"""']); } return concat$e(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']); } case "IntValue": case "FloatValue": case "EnumValue": { return n.value; } case "BooleanValue": { return n.value ? "true" : "false"; } case "NullValue": { return "null"; } case "Variable": { return concat$e(["$", path.call(print, "name")]); } case "ListValue": { return group$f(concat$e(["[", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.map(print, "values"))])), softline$7, "]"])); } case "ObjectValue": { return group$f(concat$e(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.map(print, "fields"))])), softline$7, ifBreak$5("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"])); } case "ObjectField": case "Argument": { return concat$e([path.call(print, "name"), ": ", path.call(print, "value")]); } case "Directive": { return concat$e(["@", path.call(print, "name"), n.arguments.length > 0 ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$7, ")"])) : ""]); } case "NamedType": { return path.call(print, "name"); } case "VariableDefinition": { return concat$e([path.call(print, "variable"), ": ", path.call(print, "type"), n.defaultValue ? concat$e([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]); } case "TypeExtensionDefinition": { return concat$e(["extend ", path.call(print, "definition")]); } case "ObjectTypeExtension": case "ObjectTypeDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path.call(print, "name"), n.interfaces.length > 0 ? concat$e([" implements ", concat$e(printInterfaces(path, options, print))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$e([" {", indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$b, "}"]) : ""]); } case "FieldDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", path.call(print, "name"), n.arguments.length > 0 ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$7, ")"])) : "", ": ", path.call(print, "type"), printDirectives(path, print, n)]); } case "DirectiveDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", "directive ", "@", path.call(print, "name"), n.arguments.length > 0 ? group$f(concat$e(["(", indent$a(concat$e([softline$7, join$9(concat$e([ifBreak$5("", ", "), softline$7]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$7, ")"])) : "", n.repeatable ? " repeatable" : "", concat$e([" on ", join$9(" | ", path.map(print, "locations"))])]); } case "EnumTypeExtension": case "EnumTypeDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path.call(print, "name"), printDirectives(path, print, n), n.values.length > 0 ? concat$e([" {", indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(valuesPath => printSequence(valuesPath, options, print), "values"))])), hardline$b, "}"]) : ""]); } case "EnumValueDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", path.call(print, "name"), printDirectives(path, print, n)]); } case "InputValueDefinition": { return concat$e([path.call(print, "description"), n.description ? n.description.block ? hardline$b : line$8 : "", path.call(print, "name"), ": ", path.call(print, "type"), n.defaultValue ? concat$e([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]); } case "InputObjectTypeExtension": case "InputObjectTypeDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$e([" {", indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$b, "}"]) : ""]); } case "SchemaDefinition": { return concat$e(["schema", printDirectives(path, print, n), " {", n.operationTypes.length > 0 ? indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(opsPath => printSequence(opsPath, options, print), "operationTypes"))])) : "", hardline$b, "}"]); } case "OperationTypeDefinition": { return concat$e([path.call(print, "operation"), ": ", path.call(print, "type")]); } case "InterfaceTypeExtension": case "InterfaceTypeDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path.call(print, "name"), n.interfaces.length > 0 ? concat$e([" implements ", concat$e(printInterfaces(path, options, print))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$e([" {", indent$a(concat$e([hardline$b, join$9(hardline$b, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$b, "}"]) : ""]); } case "FragmentSpread": { return concat$e(["...", path.call(print, "name"), printDirectives(path, print, n)]); } case "InlineFragment": { return concat$e(["...", n.typeCondition ? concat$e([" on ", path.call(print, "typeCondition")]) : "", printDirectives(path, print, n), " ", path.call(print, "selectionSet")]); } case "UnionTypeExtension": case "UnionTypeDefinition": { return group$f(concat$e([path.call(print, "description"), n.description ? hardline$b : "", group$f(concat$e([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path.call(print, "name"), printDirectives(path, print, n), n.types.length > 0 ? concat$e([" =", ifBreak$5("", " "), indent$a(concat$e([ifBreak$5(concat$e([line$8, " "])), join$9(concat$e([line$8, "| "]), path.map(print, "types"))]))]) : ""]))])); } case "ScalarTypeExtension": case "ScalarTypeDefinition": { return concat$e([path.call(print, "description"), n.description ? hardline$b : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path.call(print, "name"), printDirectives(path, print, n)]); } case "NonNullType": { return concat$e([path.call(print, "type"), "!"]); } case "ListType": { return concat$e(["[", path.call(print, "type"), "]"]); } default: /* istanbul ignore next */ throw new Error("unknown graphql type: " + JSON.stringify(n.kind)); } }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
genericPrint$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 printDirectives(path, print, n) { if (n.directives.length === 0) { return ""; } return group$f(concat$e([line$8, join$9(line$8, path.map(print, "directives"))])); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printDirectives
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 printSequence(sequencePath, options, print) { const count = sequencePath.getValue().length; return sequencePath.map((path, i) => { const printed = print(path); if (isNextLineEmpty$6(options.originalText, path.getValue(), options.locEnd) && i < count - 1) { return concat$e([printed, hardline$b]); } return printed; }); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printSequence
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 canAttachComment$1(node) { return node.kind && node.kind !== "Comment"; }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
canAttachComment$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 printComment$2(commentPath) { const comment = commentPath.getValue(); if (comment.kind === "Comment") { return "#" + comment.value.trimEnd(); } throw new Error("Not a comment: " + JSON.stringify(comment)); }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printComment$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 printInterfaces(path, options, print) { const node = path.getNode(); const parts = []; const { interfaces } = node; const printed = path.map(node => print(node), "interfaces"); for (let index = 0; index < interfaces.length; index++) { const interfaceNode = interfaces[index]; parts.push(printed[index]); const nextInterfaceNode = interfaces[index + 1]; if (nextInterfaceNode) { const textBetween = options.originalText.slice(interfaceNode.loc.end, nextInterfaceNode.loc.start); const hasComment = textBetween.includes("#"); const separator = textBetween.replace(/#.*/g, "").trim(); parts.push(separator === "," ? "," : " &"); parts.push(hasComment ? line$8 : " "); } } return parts; }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
printInterfaces
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 clean$4(node, newNode /*, parent*/ ) { delete newNode.loc; delete newNode.comments; }
Prints a string literal with the correct surrounding quotes based on `options.singleQuote` and the number of escaped quotes contained in the string literal. This function is the glimmer equivalent of `printString` in `common/util`, but has differences because of the way escaped characters are treated in hbs string literals. @param {string} stringLiteral - the string literal value @param {object} options - the prettier options object
clean$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