2017-01-10 20:18:22 +03:00
|
|
|
"use strict";
|
2017-01-28 18:50:22 +03:00
|
|
|
|
2017-10-15 07:57:31 +03:00
|
|
|
const stringWidth = require("string-width");
|
|
|
|
const emojiRegex = require("emoji-regex")();
|
2017-10-12 01:46:44 +03:00
|
|
|
const escapeStringRegexp = require("escape-string-regexp");
|
2017-11-11 19:08:24 +03:00
|
|
|
|
2018-07-02 05:47:55 +03:00
|
|
|
// eslint-disable-next-line no-control-regex
|
|
|
|
const notAsciiRegex = /[^\x20-\x7F]/;
|
|
|
|
|
2017-01-20 00:45:36 +03:00
|
|
|
function isExportDeclaration(node) {
|
2017-05-25 01:57:05 +03:00
|
|
|
if (node) {
|
2017-01-28 18:50:22 +03:00
|
|
|
switch (node.type) {
|
2017-01-13 23:03:53 +03:00
|
|
|
case "ExportDefaultDeclaration":
|
|
|
|
case "ExportDefaultSpecifier":
|
|
|
|
case "DeclareExportDeclaration":
|
|
|
|
case "ExportNamedDeclaration":
|
|
|
|
case "ExportAllDeclaration":
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-25 01:57:05 +03:00
|
|
|
}
|
2016-12-23 21:38:10 +03:00
|
|
|
|
|
|
|
return false;
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2016-12-23 21:38:10 +03:00
|
|
|
|
2017-01-20 00:45:36 +03:00
|
|
|
function getParentExportDeclaration(path) {
|
2017-05-19 23:00:38 +03:00
|
|
|
const parentNode = path.getParentNode();
|
2017-01-20 21:12:37 +03:00
|
|
|
if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
|
2016-12-23 21:38:10 +03:00
|
|
|
return parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2016-12-23 21:38:10 +03:00
|
|
|
|
2017-02-25 20:56:13 +03:00
|
|
|
function getPenultimate(arr) {
|
|
|
|
if (arr.length > 1) {
|
|
|
|
return arr[arr.length - 2];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:45:36 +03:00
|
|
|
function getLast(arr) {
|
2017-01-13 23:03:53 +03:00
|
|
|
if (arr.length > 0) {
|
2017-01-04 23:24:10 +03:00
|
|
|
return arr[arr.length - 1];
|
|
|
|
}
|
|
|
|
return null;
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2017-01-09 21:47:02 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
function skip(chars) {
|
|
|
|
return (text, index, opts) => {
|
|
|
|
const backwards = opts && opts.backwards;
|
|
|
|
|
|
|
|
// Allow `skip` functions to be threaded together without having
|
|
|
|
// to check for failures (did someone say monads?).
|
2017-01-28 18:50:22 +03:00
|
|
|
if (index === false) {
|
2017-01-26 22:57:43 +03:00
|
|
|
return false;
|
2017-01-18 06:33:55 +03:00
|
|
|
}
|
2017-01-26 22:57:43 +03:00
|
|
|
|
|
|
|
const length = text.length;
|
|
|
|
let cursor = index;
|
|
|
|
while (cursor >= 0 && cursor < length) {
|
|
|
|
const c = text.charAt(cursor);
|
2017-01-28 18:50:22 +03:00
|
|
|
if (chars instanceof RegExp) {
|
|
|
|
if (!chars.test(c)) {
|
2017-01-26 22:57:43 +03:00
|
|
|
return cursor;
|
|
|
|
}
|
2017-01-28 18:50:22 +03:00
|
|
|
} else if (chars.indexOf(c) === -1) {
|
2017-01-26 22:57:43 +03:00
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
backwards ? cursor-- : cursor++;
|
2017-01-18 06:33:55 +03:00
|
|
|
}
|
2017-01-26 22:57:43 +03:00
|
|
|
|
2017-01-28 18:50:22 +03:00
|
|
|
if (cursor === -1 || cursor === length) {
|
2017-01-26 22:57:43 +03:00
|
|
|
// If we reached the beginning or end of the file, return the
|
|
|
|
// out-of-bounds cursor. It's up to the caller to handle this
|
|
|
|
// correctly. We don't want to indicate `false` though if it
|
|
|
|
// actually skipped valid characters.
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
return false;
|
2017-01-28 18:50:22 +03:00
|
|
|
};
|
2017-01-14 07:07:09 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
const skipWhitespace = skip(/\s/);
|
|
|
|
const skipSpaces = skip(" \t");
|
2017-02-09 19:08:58 +03:00
|
|
|
const skipToLineEnd = skip(",; \t");
|
2017-01-31 19:27:44 +03:00
|
|
|
const skipEverythingButNewLine = skip(/[^\r\n]/);
|
|
|
|
|
|
|
|
function skipInlineComment(text, index) {
|
|
|
|
if (index === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
|
2017-05-19 23:00:38 +03:00
|
|
|
for (let i = index + 2; i < text.length; ++i) {
|
2017-01-31 19:27:44 +03:00
|
|
|
if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
|
|
|
|
return i + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function skipTrailingComment(text, index) {
|
|
|
|
if (index === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
|
|
|
|
return skipEverythingButNewLine(text, index);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
2017-01-26 22:57:43 +03:00
|
|
|
|
|
|
|
// This one doesn't use the above helper function because it wants to
|
|
|
|
// test \r\n in order and `skip` doesn't support ordering and we only
|
|
|
|
// want to skip one newline. It's simple to implement.
|
|
|
|
function skipNewline(text, index, opts) {
|
|
|
|
const backwards = opts && opts.backwards;
|
2017-01-28 18:50:22 +03:00
|
|
|
if (index === false) {
|
2017-01-26 22:57:43 +03:00
|
|
|
return false;
|
2017-04-05 20:54:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const atIndex = text.charAt(index);
|
|
|
|
if (backwards) {
|
2017-04-15 02:02:19 +03:00
|
|
|
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
|
|
|
|
return index - 2;
|
|
|
|
}
|
2017-04-12 20:16:11 +03:00
|
|
|
if (
|
|
|
|
atIndex === "\n" ||
|
|
|
|
atIndex === "\r" ||
|
|
|
|
atIndex === "\u2028" ||
|
|
|
|
atIndex === "\u2029"
|
|
|
|
) {
|
2017-01-26 22:57:43 +03:00
|
|
|
return index - 1;
|
|
|
|
}
|
2017-01-28 18:50:22 +03:00
|
|
|
} else {
|
2017-04-05 20:54:39 +03:00
|
|
|
if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
|
2017-01-26 22:57:43 +03:00
|
|
|
return index + 2;
|
2017-01-09 21:47:02 +03:00
|
|
|
}
|
2017-04-12 20:16:11 +03:00
|
|
|
if (
|
|
|
|
atIndex === "\n" ||
|
|
|
|
atIndex === "\r" ||
|
|
|
|
atIndex === "\u2028" ||
|
|
|
|
atIndex === "\u2029"
|
|
|
|
) {
|
2017-04-05 20:54:39 +03:00
|
|
|
return index + 1;
|
|
|
|
}
|
2017-01-09 21:47:02 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
return index;
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2017-01-09 21:47:02 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
function hasNewline(text, index, opts) {
|
|
|
|
opts = opts || {};
|
|
|
|
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
|
|
const idx2 = skipNewline(text, idx, opts);
|
|
|
|
return idx !== idx2;
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2017-01-10 01:37:45 +03:00
|
|
|
|
2017-01-30 20:08:55 +03:00
|
|
|
function hasNewlineInRange(text, start, end) {
|
2017-05-19 23:00:38 +03:00
|
|
|
for (let i = start; i < end; ++i) {
|
2017-01-30 20:08:55 +03:00
|
|
|
if (text.charAt(i) === "\n") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-07 20:41:49 +03:00
|
|
|
// Note: this function doesn't ignore leading comments unlike isNextLineEmpty
|
2018-02-09 15:17:48 +03:00
|
|
|
function isPreviousLineEmpty(text, node, locStart) {
|
2017-02-07 20:41:49 +03:00
|
|
|
let idx = locStart(node) - 1;
|
2017-02-16 06:56:11 +03:00
|
|
|
idx = skipSpaces(text, idx, { backwards: true });
|
|
|
|
idx = skipNewline(text, idx, { backwards: true });
|
2017-02-16 17:56:12 +03:00
|
|
|
idx = skipSpaces(text, idx, { backwards: true });
|
|
|
|
const idx2 = skipNewline(text, idx, { backwards: true });
|
|
|
|
return idx !== idx2;
|
2017-02-07 20:41:49 +03:00
|
|
|
}
|
|
|
|
|
2017-10-19 01:25:51 +03:00
|
|
|
function isNextLineEmptyAfterIndex(text, index) {
|
2017-01-31 19:27:44 +03:00
|
|
|
let oldIdx = null;
|
2017-10-19 01:25:51 +03:00
|
|
|
let idx = index;
|
2017-01-31 19:27:44 +03:00
|
|
|
while (idx !== oldIdx) {
|
|
|
|
// We need to skip all the potential trailing inline comments
|
|
|
|
oldIdx = idx;
|
2017-04-10 21:03:35 +03:00
|
|
|
idx = skipToLineEnd(text, idx);
|
2017-01-31 19:27:44 +03:00
|
|
|
idx = skipInlineComment(text, idx);
|
|
|
|
idx = skipSpaces(text, idx);
|
|
|
|
}
|
|
|
|
idx = skipTrailingComment(text, idx);
|
2017-01-30 20:10:54 +03:00
|
|
|
idx = skipNewline(text, idx);
|
|
|
|
return hasNewline(text, idx);
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:17:48 +03:00
|
|
|
function isNextLineEmpty(text, node, locEnd) {
|
2017-10-19 01:25:51 +03:00
|
|
|
return isNextLineEmptyAfterIndex(text, locEnd(node));
|
|
|
|
}
|
|
|
|
|
2018-11-10 19:10:19 +03:00
|
|
|
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
2017-04-10 21:05:10 +03:00
|
|
|
let oldIdx = null;
|
|
|
|
while (idx !== oldIdx) {
|
|
|
|
oldIdx = idx;
|
|
|
|
idx = skipSpaces(text, idx);
|
|
|
|
idx = skipInlineComment(text, idx);
|
|
|
|
idx = skipTrailingComment(text, idx);
|
|
|
|
idx = skipNewline(text, idx);
|
|
|
|
}
|
2017-10-19 01:25:51 +03:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2018-11-10 19:10:19 +03:00
|
|
|
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
|
|
return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
|
|
|
|
text,
|
|
|
|
locEnd(node)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:17:48 +03:00
|
|
|
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
|
|
|
|
return text.charAt(
|
|
|
|
getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
|
|
|
|
);
|
2017-04-10 21:05:10 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
function hasSpaces(text, index, opts) {
|
|
|
|
opts = opts || {};
|
|
|
|
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
|
|
return idx !== index;
|
2017-01-10 01:37:45 +03:00
|
|
|
}
|
2017-01-10 05:24:42 +03:00
|
|
|
|
|
|
|
function setLocStart(node, index) {
|
2017-01-13 23:03:53 +03:00
|
|
|
if (node.range) {
|
2017-01-19 02:31:46 +03:00
|
|
|
node.range[0] = index;
|
2017-01-13 23:03:53 +03:00
|
|
|
} else {
|
2017-01-10 05:24:42 +03:00
|
|
|
node.start = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLocEnd(node, index) {
|
2017-01-13 23:03:53 +03:00
|
|
|
if (node.range) {
|
2017-01-19 02:31:46 +03:00
|
|
|
node.range[1] = index;
|
2017-01-13 23:03:53 +03:00
|
|
|
} else {
|
2017-01-10 05:24:42 +03:00
|
|
|
node.end = index;
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 22:37:53 +03:00
|
|
|
|
2017-05-19 23:00:38 +03:00
|
|
|
const PRECEDENCE = {};
|
2017-01-19 01:01:17 +03:00
|
|
|
[
|
2017-10-16 01:13:25 +03:00
|
|
|
["|>"],
|
|
|
|
["||", "??"],
|
2017-01-28 18:50:22 +03:00
|
|
|
["&&"],
|
|
|
|
["|"],
|
|
|
|
["^"],
|
|
|
|
["&"],
|
|
|
|
["==", "===", "!=", "!=="],
|
|
|
|
["<", ">", "<=", ">=", "in", "instanceof"],
|
|
|
|
[">>", "<<", ">>>"],
|
|
|
|
["+", "-"],
|
2017-03-09 00:11:53 +03:00
|
|
|
["*", "/", "%"],
|
|
|
|
["**"]
|
2017-05-21 22:11:09 +03:00
|
|
|
].forEach((tier, i) => {
|
|
|
|
tier.forEach(op => {
|
2017-01-19 01:01:17 +03:00
|
|
|
PRECEDENCE[op] = i;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-20 00:45:36 +03:00
|
|
|
function getPrecedence(op) {
|
2017-01-19 01:01:17 +03:00
|
|
|
return PRECEDENCE[op];
|
2017-01-20 21:12:37 +03:00
|
|
|
}
|
2017-01-20 00:45:36 +03:00
|
|
|
|
2017-07-08 10:31:28 +03:00
|
|
|
const equalityOperators = {
|
|
|
|
"==": true,
|
|
|
|
"!=": true,
|
|
|
|
"===": true,
|
|
|
|
"!==": true
|
|
|
|
};
|
|
|
|
const multiplicativeOperators = {
|
|
|
|
"*": true,
|
|
|
|
"/": true,
|
|
|
|
"%": true
|
|
|
|
};
|
2017-07-15 13:54:33 +03:00
|
|
|
const bitshiftOperators = {
|
2017-07-08 10:31:28 +03:00
|
|
|
">>": true,
|
|
|
|
">>>": true,
|
2017-07-15 13:54:33 +03:00
|
|
|
"<<": true
|
2017-07-08 10:31:28 +03:00
|
|
|
};
|
2017-07-07 16:57:17 +03:00
|
|
|
|
|
|
|
function shouldFlatten(parentOp, nodeOp) {
|
|
|
|
if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ** is right-associative
|
|
|
|
// x ** y ** z --> x ** (y ** z)
|
|
|
|
if (parentOp === "**") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// x == y == z --> (x == y) == z
|
|
|
|
if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// x * y % z --> (x * y) % z
|
|
|
|
if (
|
|
|
|
(nodeOp === "%" && multiplicativeOperators[parentOp]) ||
|
|
|
|
(parentOp === "%" && multiplicativeOperators[nodeOp])
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-03 00:48:40 +03:00
|
|
|
// x * y / z --> (x * y) / z
|
|
|
|
// x / y * z --> (x / y) * z
|
|
|
|
if (
|
|
|
|
nodeOp !== parentOp &&
|
|
|
|
multiplicativeOperators[nodeOp] &&
|
|
|
|
multiplicativeOperators[parentOp]
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-08 10:31:28 +03:00
|
|
|
// x << y << z --> (x << y) << z
|
2017-07-15 13:54:33 +03:00
|
|
|
if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
|
2017-07-08 10:31:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-07 16:57:17 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-08 10:31:28 +03:00
|
|
|
function isBitwiseOperator(operator) {
|
2017-07-15 13:54:33 +03:00
|
|
|
return (
|
|
|
|
!!bitshiftOperators[operator] ||
|
|
|
|
operator === "|" ||
|
|
|
|
operator === "^" ||
|
|
|
|
operator === "&"
|
|
|
|
);
|
2017-07-08 10:31:28 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:41:17 +03:00
|
|
|
// Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
|
|
|
|
// holds) `function`, `class`, or `do {}`. Will be overzealous if there's
|
|
|
|
// already necessary grouping parentheses.
|
|
|
|
function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
|
2017-05-02 00:32:52 +03:00
|
|
|
node = getLeftMost(node);
|
|
|
|
switch (node.type) {
|
|
|
|
case "FunctionExpression":
|
|
|
|
case "ClassExpression":
|
2018-05-15 19:41:17 +03:00
|
|
|
case "DoExpression":
|
|
|
|
return forbidFunctionClassAndDoExpr;
|
2017-05-02 00:32:52 +03:00
|
|
|
case "ObjectExpression":
|
|
|
|
return true;
|
|
|
|
case "MemberExpression":
|
2018-05-15 19:41:17 +03:00
|
|
|
return startsWithNoLookaheadToken(
|
|
|
|
node.object,
|
|
|
|
forbidFunctionClassAndDoExpr
|
|
|
|
);
|
2017-05-02 00:32:52 +03:00
|
|
|
case "TaggedTemplateExpression":
|
|
|
|
if (node.tag.type === "FunctionExpression") {
|
|
|
|
// IIFEs are always already parenthesized
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-15 19:41:17 +03:00
|
|
|
return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
|
2017-05-02 00:32:52 +03:00
|
|
|
case "CallExpression":
|
|
|
|
if (node.callee.type === "FunctionExpression") {
|
|
|
|
// IIFEs are always already parenthesized
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-15 19:41:17 +03:00
|
|
|
return startsWithNoLookaheadToken(
|
|
|
|
node.callee,
|
|
|
|
forbidFunctionClassAndDoExpr
|
|
|
|
);
|
2017-05-02 00:32:52 +03:00
|
|
|
case "ConditionalExpression":
|
2018-05-15 19:41:17 +03:00
|
|
|
return startsWithNoLookaheadToken(
|
|
|
|
node.test,
|
|
|
|
forbidFunctionClassAndDoExpr
|
|
|
|
);
|
2017-05-02 00:32:52 +03:00
|
|
|
case "UpdateExpression":
|
|
|
|
return (
|
|
|
|
!node.prefix &&
|
2018-05-15 19:41:17 +03:00
|
|
|
startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr)
|
2017-05-02 00:32:52 +03:00
|
|
|
);
|
|
|
|
case "BindExpression":
|
|
|
|
return (
|
|
|
|
node.object &&
|
2018-05-15 19:41:17 +03:00
|
|
|
startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr)
|
2017-05-02 00:32:52 +03:00
|
|
|
);
|
|
|
|
case "SequenceExpression":
|
|
|
|
return startsWithNoLookaheadToken(
|
|
|
|
node.expressions[0],
|
2018-05-15 19:41:17 +03:00
|
|
|
forbidFunctionClassAndDoExpr
|
2017-05-02 00:32:52 +03:00
|
|
|
);
|
2017-06-03 02:08:45 +03:00
|
|
|
case "TSAsExpression":
|
|
|
|
return startsWithNoLookaheadToken(
|
|
|
|
node.expression,
|
2018-05-15 19:41:17 +03:00
|
|
|
forbidFunctionClassAndDoExpr
|
2017-06-03 02:08:45 +03:00
|
|
|
);
|
2017-05-02 00:32:52 +03:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLeftMost(node) {
|
|
|
|
if (node.left) {
|
|
|
|
return getLeftMost(node.left);
|
|
|
|
}
|
2017-06-06 01:12:59 +03:00
|
|
|
return node;
|
2017-05-02 00:32:52 +03:00
|
|
|
}
|
|
|
|
|
Add `--range-start` and `--range-end` options to format only parts of the input (#1609)
* Add `--range-start` and `--range-end` options to format only parts of the input
These options default to `0` and `Infinity`, respectively, so that the
entire input is formatted by default. However, if either option is
specified such that a node lies completely outside the resulting range,
the node will be treated as if it has a `// prettier-ignore` comment.
Related to https://github.com/prettier/prettier/pull/1577#issuecomment-300551179
Related to https://github.com/prettier/prettier/issues/1324
Related to https://github.com/prettier/prettier/issues/593
* printer: Extract hasPrettierIgnoreComment() helper
* Move isOutsideRange() to util
* Don't throw errors about comments outside range "not printing"
* Remove unnecessary check from isOutsideRange()
* Make --range-end exclusive
This lets it use the conventional way of specifying ranges in strings.
Note that if the rangeEnd in the tests is changed to 158, it will fail,
but it wouldn't have failed before this change.
* Change range formatting approach
NOTE: This doesn't pass its test yet. Note that since we're reading the
indentation from the first line, it is expected not to change. However,
a semicolon is added, and the lines outside the range are not changed.
The new approach is roughly:
* Require that the range exactly covers an integer number of lines of the input
* Detect the indentation of the line the range starts on
* Format the range's substring using `printAstToDoc`
* Add enough `indent`s to the doc to restore the detected indentation
* Format the doc to a string with `printDocToString`
* Prepend/append the original input before/after the range
See https://github.com/prettier/prettier/pull/1609#issuecomment-301582273
---
Given `tests/range/range.js`, run the following:
prettier tests/range/range.js --range-start 165 --range-end 246
See the range's text with:
dd if=tests/range/range.js ibs=1 skip=165 count=81 2>/dev/null
* Don't use default function parameters
Node v4 doesn't support them. See
http://node.green/#ES2015-syntax-default-function-parameters
* Hackily fix indentation of range formatting
See
https://github.com/prettier/prettier/pull/1609#issuecomment-301625368
Also update the snapshot to reflect that the indentation actually should
decrease by one space, since there were 13 spaces in the input and we
round down after dividing by tabWidth.
* Revert "printer: Extract hasPrettierIgnoreComment() helper"
See https://github.com/prettier/prettier/pull/1609#discussion_r116804853
This reverts commit 62bf068ca98f69d4a7fd0ae188b3554d409eee8d.
* Test automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Fix automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Propagate breaks after adding an indentation-triggering hardline
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116805581
* Extract getAlignmentSize(), use instead of countIndents()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Extract addAlignmentToDoc(), use instead of addIndentsToDoc()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Document that --range-start and --range-end include the entire line
* Fix rangeStart calculation
Before, it was incorrectly resulting in 1 when the originally provided
value was 0
* Extract formatRange() helper function
* Move getAlignmentSize() from printer to util
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636241
* Move addAlignmentToDoc() from printer to doc-builders
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636251
2017-05-21 20:14:13 +03:00
|
|
|
function getAlignmentSize(value, tabWidth, startIndex) {
|
|
|
|
startIndex = startIndex || 0;
|
|
|
|
|
|
|
|
let size = 0;
|
|
|
|
for (let i = startIndex; i < value.length; ++i) {
|
2017-05-21 21:00:16 +03:00
|
|
|
if (value[i] === "\t") {
|
Add `--range-start` and `--range-end` options to format only parts of the input (#1609)
* Add `--range-start` and `--range-end` options to format only parts of the input
These options default to `0` and `Infinity`, respectively, so that the
entire input is formatted by default. However, if either option is
specified such that a node lies completely outside the resulting range,
the node will be treated as if it has a `// prettier-ignore` comment.
Related to https://github.com/prettier/prettier/pull/1577#issuecomment-300551179
Related to https://github.com/prettier/prettier/issues/1324
Related to https://github.com/prettier/prettier/issues/593
* printer: Extract hasPrettierIgnoreComment() helper
* Move isOutsideRange() to util
* Don't throw errors about comments outside range "not printing"
* Remove unnecessary check from isOutsideRange()
* Make --range-end exclusive
This lets it use the conventional way of specifying ranges in strings.
Note that if the rangeEnd in the tests is changed to 158, it will fail,
but it wouldn't have failed before this change.
* Change range formatting approach
NOTE: This doesn't pass its test yet. Note that since we're reading the
indentation from the first line, it is expected not to change. However,
a semicolon is added, and the lines outside the range are not changed.
The new approach is roughly:
* Require that the range exactly covers an integer number of lines of the input
* Detect the indentation of the line the range starts on
* Format the range's substring using `printAstToDoc`
* Add enough `indent`s to the doc to restore the detected indentation
* Format the doc to a string with `printDocToString`
* Prepend/append the original input before/after the range
See https://github.com/prettier/prettier/pull/1609#issuecomment-301582273
---
Given `tests/range/range.js`, run the following:
prettier tests/range/range.js --range-start 165 --range-end 246
See the range's text with:
dd if=tests/range/range.js ibs=1 skip=165 count=81 2>/dev/null
* Don't use default function parameters
Node v4 doesn't support them. See
http://node.green/#ES2015-syntax-default-function-parameters
* Hackily fix indentation of range formatting
See
https://github.com/prettier/prettier/pull/1609#issuecomment-301625368
Also update the snapshot to reflect that the indentation actually should
decrease by one space, since there were 13 spaces in the input and we
round down after dividing by tabWidth.
* Revert "printer: Extract hasPrettierIgnoreComment() helper"
See https://github.com/prettier/prettier/pull/1609#discussion_r116804853
This reverts commit 62bf068ca98f69d4a7fd0ae188b3554d409eee8d.
* Test automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Fix automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Propagate breaks after adding an indentation-triggering hardline
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116805581
* Extract getAlignmentSize(), use instead of countIndents()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Extract addAlignmentToDoc(), use instead of addIndentsToDoc()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Document that --range-start and --range-end include the entire line
* Fix rangeStart calculation
Before, it was incorrectly resulting in 1 when the originally provided
value was 0
* Extract formatRange() helper function
* Move getAlignmentSize() from printer to util
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636241
* Move addAlignmentToDoc() from printer to doc-builders
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636251
2017-05-21 20:14:13 +03:00
|
|
|
// Tabs behave in a way that they are aligned to the nearest
|
|
|
|
// multiple of tabWidth:
|
|
|
|
// 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
|
|
|
|
// 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
|
2018-05-27 21:22:34 +03:00
|
|
|
size = size + tabWidth - (size % tabWidth);
|
Add `--range-start` and `--range-end` options to format only parts of the input (#1609)
* Add `--range-start` and `--range-end` options to format only parts of the input
These options default to `0` and `Infinity`, respectively, so that the
entire input is formatted by default. However, if either option is
specified such that a node lies completely outside the resulting range,
the node will be treated as if it has a `// prettier-ignore` comment.
Related to https://github.com/prettier/prettier/pull/1577#issuecomment-300551179
Related to https://github.com/prettier/prettier/issues/1324
Related to https://github.com/prettier/prettier/issues/593
* printer: Extract hasPrettierIgnoreComment() helper
* Move isOutsideRange() to util
* Don't throw errors about comments outside range "not printing"
* Remove unnecessary check from isOutsideRange()
* Make --range-end exclusive
This lets it use the conventional way of specifying ranges in strings.
Note that if the rangeEnd in the tests is changed to 158, it will fail,
but it wouldn't have failed before this change.
* Change range formatting approach
NOTE: This doesn't pass its test yet. Note that since we're reading the
indentation from the first line, it is expected not to change. However,
a semicolon is added, and the lines outside the range are not changed.
The new approach is roughly:
* Require that the range exactly covers an integer number of lines of the input
* Detect the indentation of the line the range starts on
* Format the range's substring using `printAstToDoc`
* Add enough `indent`s to the doc to restore the detected indentation
* Format the doc to a string with `printDocToString`
* Prepend/append the original input before/after the range
See https://github.com/prettier/prettier/pull/1609#issuecomment-301582273
---
Given `tests/range/range.js`, run the following:
prettier tests/range/range.js --range-start 165 --range-end 246
See the range's text with:
dd if=tests/range/range.js ibs=1 skip=165 count=81 2>/dev/null
* Don't use default function parameters
Node v4 doesn't support them. See
http://node.green/#ES2015-syntax-default-function-parameters
* Hackily fix indentation of range formatting
See
https://github.com/prettier/prettier/pull/1609#issuecomment-301625368
Also update the snapshot to reflect that the indentation actually should
decrease by one space, since there were 13 spaces in the input and we
round down after dividing by tabWidth.
* Revert "printer: Extract hasPrettierIgnoreComment() helper"
See https://github.com/prettier/prettier/pull/1609#discussion_r116804853
This reverts commit 62bf068ca98f69d4a7fd0ae188b3554d409eee8d.
* Test automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Fix automatically using the beginning of the rangeStart line and same for the end
See https://github.com/prettier/prettier/pull/1609#issuecomment-301862076
* Propagate breaks after adding an indentation-triggering hardline
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116805581
* Extract getAlignmentSize(), use instead of countIndents()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Extract addAlignmentToDoc(), use instead of addIndentsToDoc()
See https://github.com/prettier/prettier/pull/1609/files/c1a61ebde8be73414c0a54bde3f323ac24295715#r116804694
* Document that --range-start and --range-end include the entire line
* Fix rangeStart calculation
Before, it was incorrectly resulting in 1 when the originally provided
value was 0
* Extract formatRange() helper function
* Move getAlignmentSize() from printer to util
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636241
* Move addAlignmentToDoc() from printer to doc-builders
This addresses https://github.com/prettier/prettier/pull/1609#discussion_r117636251
2017-05-21 20:14:13 +03:00
|
|
|
} else {
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-10-08 12:34:24 +03:00
|
|
|
function getIndentSize(value, tabWidth) {
|
|
|
|
const lastNewlineIndex = value.lastIndexOf("\n");
|
|
|
|
if (lastNewlineIndex === -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getAlignmentSize(
|
|
|
|
// All the leading whitespaces
|
|
|
|
value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0],
|
|
|
|
tabWidth
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-05 00:36:00 +03:00
|
|
|
function getPreferredQuote(raw, preferredQuote) {
|
2017-08-14 09:57:16 +03:00
|
|
|
// `rawContent` is the string exactly like it appeared in the input source
|
|
|
|
// code, without its enclosing quotes.
|
|
|
|
const rawContent = raw.slice(1, -1);
|
|
|
|
|
|
|
|
const double = { quote: '"', regex: /"/g };
|
|
|
|
const single = { quote: "'", regex: /'/g };
|
|
|
|
|
2018-11-05 00:36:00 +03:00
|
|
|
const preferred = preferredQuote === "'" ? single : double;
|
2017-08-14 09:57:16 +03:00
|
|
|
const alternate = preferred === single ? double : single;
|
|
|
|
|
2018-11-05 00:36:00 +03:00
|
|
|
let result = preferred.quote;
|
2017-08-14 09:57:16 +03:00
|
|
|
|
|
|
|
// If `rawContent` 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 (
|
|
|
|
rawContent.includes(preferred.quote) ||
|
|
|
|
rawContent.includes(alternate.quote)
|
|
|
|
) {
|
|
|
|
const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
|
|
|
|
const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
|
|
|
|
|
2018-11-05 00:36:00 +03:00
|
|
|
result =
|
|
|
|
numPreferredQuotes > numAlternateQuotes
|
|
|
|
? alternate.quote
|
|
|
|
: preferred.quote;
|
2017-08-14 09:57:16 +03:00
|
|
|
}
|
|
|
|
|
2018-11-05 00:36:00 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function printString(raw, options, isDirectiveLiteral) {
|
|
|
|
// `rawContent` is the string exactly like it appeared in the input source
|
|
|
|
// code, without its enclosing quotes.
|
|
|
|
const rawContent = raw.slice(1, -1);
|
|
|
|
|
|
|
|
// Check for the alternate quote, to determine if we're allowed to swap
|
|
|
|
// the quotes on a DirectiveLiteral.
|
|
|
|
const canChangeDirectiveQuotes =
|
|
|
|
!rawContent.includes('"') && !rawContent.includes("'");
|
|
|
|
|
2017-08-14 09:57:16 +03:00
|
|
|
const enclosingQuote =
|
|
|
|
options.parser === "json"
|
2018-11-05 00:36:00 +03:00
|
|
|
? '"'
|
2018-11-04 18:03:07 +03:00
|
|
|
: options.__isInHtmlAttribute
|
2018-11-07 04:12:25 +03:00
|
|
|
? "'"
|
|
|
|
: getPreferredQuote(raw, options.singleQuote ? "'" : '"');
|
2017-08-14 09:57:16 +03:00
|
|
|
|
|
|
|
// Directives are exact code unit sequences, which means that you can't
|
|
|
|
// change the escape sequences they use.
|
|
|
|
// See https://github.com/prettier/prettier/issues/1555
|
|
|
|
// and https://tc39.github.io/ecma262/#directive-prologue
|
|
|
|
if (isDirectiveLiteral) {
|
|
|
|
if (canChangeDirectiveQuotes) {
|
|
|
|
return enclosingQuote + rawContent + enclosingQuote;
|
|
|
|
}
|
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It might sound unnecessary to use `makeString` even if the string already
|
|
|
|
// is enclosed with `enclosingQuote`, but it isn't. The string could contain
|
|
|
|
// unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
|
|
|
|
// sure that we consistently output the minimum amount of escaped quotes.
|
2017-09-26 08:08:11 +03:00
|
|
|
return makeString(
|
|
|
|
rawContent,
|
|
|
|
enclosingQuote,
|
|
|
|
!(
|
|
|
|
options.parser === "css" ||
|
|
|
|
options.parser === "less" ||
|
2018-11-04 18:03:07 +03:00
|
|
|
options.parser === "scss" ||
|
|
|
|
options.parentParser === "html" ||
|
|
|
|
options.parentParser === "vue" ||
|
|
|
|
options.parentParser === "angular"
|
2017-09-26 08:08:11 +03:00
|
|
|
)
|
|
|
|
);
|
2017-08-14 09:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
|
|
|
|
const otherQuote = enclosingQuote === '"' ? "'" : '"';
|
|
|
|
|
|
|
|
// Matches _any_ escape and unescaped quotes (both single and double).
|
|
|
|
const regex = /\\([\s\S])|(['"])/g;
|
|
|
|
|
|
|
|
// Escape and unescape single and double quotes as needed to be able to
|
|
|
|
// enclose `rawContent` with `enclosingQuote`.
|
|
|
|
const newContent = rawContent.replace(regex, (match, escaped, quote) => {
|
|
|
|
// If we matched an escape, and the escaped character is a quote of the
|
|
|
|
// other type than we intend to enclose the string with, there's no need for
|
|
|
|
// it to be escaped, so return it _without_ the backslash.
|
|
|
|
if (escaped === otherQuote) {
|
|
|
|
return escaped;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we matched an unescaped quote and it is of the _same_ type as we
|
|
|
|
// intend to enclose the string with, it must be escaped, so return it with
|
|
|
|
// a backslash.
|
|
|
|
if (quote === enclosingQuote) {
|
|
|
|
return "\\" + quote;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quote) {
|
|
|
|
return quote;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unescape any unnecessarily escaped character.
|
|
|
|
// Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
|
|
|
|
return unescapeUnnecessaryEscapes &&
|
2017-09-15 22:49:55 +03:00
|
|
|
/^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped)
|
2017-08-14 09:57:16 +03:00
|
|
|
? escaped
|
|
|
|
: "\\" + escaped;
|
|
|
|
});
|
|
|
|
|
|
|
|
return enclosingQuote + newContent + enclosingQuote;
|
|
|
|
}
|
|
|
|
|
2017-08-15 18:25:57 +03:00
|
|
|
function printNumber(rawNumber) {
|
|
|
|
return (
|
|
|
|
rawNumber
|
|
|
|
.toLowerCase()
|
|
|
|
// Remove unnecessary plus and zeroes from scientific notation.
|
2017-08-30 21:26:11 +03:00
|
|
|
.replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
|
2017-08-15 18:25:57 +03:00
|
|
|
// Remove unnecessary scientific notation (1e0).
|
2017-08-30 21:26:11 +03:00
|
|
|
.replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
|
2017-08-15 18:25:57 +03:00
|
|
|
// Make sure numbers always start with a digit.
|
2017-08-30 21:26:11 +03:00
|
|
|
.replace(/^([+-])?\./, "$10.")
|
2017-08-15 18:25:57 +03:00
|
|
|
// Remove extraneous trailing decimal zeroes.
|
|
|
|
.replace(/(\.\d+?)0+(?=e|$)/, "$1")
|
|
|
|
// Remove trailing dot.
|
|
|
|
.replace(/\.(?=e|$)/, "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-12 01:46:44 +03:00
|
|
|
function getMaxContinuousCount(str, target) {
|
|
|
|
const results = str.match(
|
|
|
|
new RegExp(`(${escapeStringRegexp(target)})+`, "g")
|
|
|
|
);
|
|
|
|
|
|
|
|
if (results === null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return results.reduce(
|
|
|
|
(maxCount, result) => Math.max(maxCount, result.length / target.length),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-15 07:57:31 +03:00
|
|
|
function getStringWidth(text) {
|
2017-10-24 07:19:27 +03:00
|
|
|
if (!text) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-02 05:47:55 +03:00
|
|
|
// shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
|
|
|
|
if (!notAsciiRegex.test(text)) {
|
|
|
|
return text.length;
|
|
|
|
}
|
|
|
|
|
2017-10-15 07:57:31 +03:00
|
|
|
// emojis are considered 2-char width for consistency
|
|
|
|
// see https://github.com/sindresorhus/string-width/issues/11
|
|
|
|
// for the reason why not implemented in `string-width`
|
|
|
|
return stringWidth(text.replace(emojiRegex, " "));
|
|
|
|
}
|
|
|
|
|
2017-12-26 04:23:50 +03:00
|
|
|
function hasIgnoreComment(path) {
|
|
|
|
const node = path.getValue();
|
|
|
|
return hasNodeIgnoreComment(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasNodeIgnoreComment(node) {
|
|
|
|
return (
|
|
|
|
node &&
|
|
|
|
node.comments &&
|
|
|
|
node.comments.length > 0 &&
|
|
|
|
node.comments.some(comment => comment.value.trim() === "prettier-ignore")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-08 21:15:50 +03:00
|
|
|
function matchAncestorTypes(path, types, index) {
|
|
|
|
index = index || 0;
|
|
|
|
types = types.slice();
|
|
|
|
while (types.length) {
|
|
|
|
const parent = path.getParentNode(index);
|
|
|
|
const type = types.shift();
|
|
|
|
if (!parent || parent.type !== type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-21 04:39:28 +03:00
|
|
|
function addCommentHelper(node, comment) {
|
|
|
|
const comments = node.comments || (node.comments = []);
|
|
|
|
comments.push(comment);
|
|
|
|
comment.printed = false;
|
|
|
|
|
|
|
|
// For some reason, TypeScript parses `// x` inside of JSXText as a comment
|
|
|
|
// We already "print" it via the raw text, we don't need to re-print it as a
|
|
|
|
// comment
|
|
|
|
if (node.type === "JSXText") {
|
|
|
|
comment.printed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addLeadingComment(node, comment) {
|
|
|
|
comment.leading = true;
|
|
|
|
comment.trailing = false;
|
|
|
|
addCommentHelper(node, comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDanglingComment(node, comment) {
|
|
|
|
comment.leading = false;
|
|
|
|
comment.trailing = false;
|
|
|
|
addCommentHelper(node, comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addTrailingComment(node, comment) {
|
|
|
|
comment.leading = false;
|
|
|
|
comment.trailing = true;
|
|
|
|
addCommentHelper(node, comment);
|
|
|
|
}
|
|
|
|
|
2018-07-20 22:48:37 +03:00
|
|
|
function isWithinParentArrayProperty(path, propertyName) {
|
|
|
|
const node = path.getValue();
|
|
|
|
const parent = path.getParentNode();
|
|
|
|
|
|
|
|
if (parent == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.isArray(parent[propertyName])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const key = path.getName();
|
|
|
|
return parent[propertyName][key] === node;
|
|
|
|
}
|
|
|
|
|
2018-12-08 13:28:29 +03:00
|
|
|
function replaceEndOfLineWith(text, replacement) {
|
|
|
|
const parts = [];
|
|
|
|
for (const part of text.split("\n")) {
|
|
|
|
if (parts.length !== 0) {
|
|
|
|
parts.push(replacement);
|
|
|
|
}
|
|
|
|
parts.push(part);
|
|
|
|
}
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:45:36 +03:00
|
|
|
module.exports = {
|
2018-12-08 13:28:29 +03:00
|
|
|
replaceEndOfLineWith,
|
2017-10-15 07:57:31 +03:00
|
|
|
getStringWidth,
|
2017-10-12 01:46:44 +03:00
|
|
|
getMaxContinuousCount,
|
2017-01-20 00:45:36 +03:00
|
|
|
getPrecedence,
|
2017-07-07 16:57:17 +03:00
|
|
|
shouldFlatten,
|
2017-07-08 10:31:28 +03:00
|
|
|
isBitwiseOperator,
|
2017-01-20 00:45:36 +03:00
|
|
|
isExportDeclaration,
|
|
|
|
getParentExportDeclaration,
|
2017-02-25 20:56:13 +03:00
|
|
|
getPenultimate,
|
2017-01-20 00:45:36 +03:00
|
|
|
getLast,
|
2018-11-10 19:10:19 +03:00
|
|
|
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
|
2017-10-19 01:25:51 +03:00
|
|
|
getNextNonSpaceNonCommentCharacterIndex,
|
2017-04-10 21:05:10 +03:00
|
|
|
getNextNonSpaceNonCommentCharacter,
|
2018-10-17 17:53:38 +03:00
|
|
|
skip,
|
2017-01-26 22:57:43 +03:00
|
|
|
skipWhitespace,
|
2017-01-20 00:45:36 +03:00
|
|
|
skipSpaces,
|
2018-10-17 17:53:38 +03:00
|
|
|
skipToLineEnd,
|
|
|
|
skipEverythingButNewLine,
|
|
|
|
skipInlineComment,
|
|
|
|
skipTrailingComment,
|
2017-01-26 22:57:43 +03:00
|
|
|
skipNewline,
|
2017-10-19 01:25:51 +03:00
|
|
|
isNextLineEmptyAfterIndex,
|
2017-01-30 20:10:54 +03:00
|
|
|
isNextLineEmpty,
|
2017-02-07 20:41:49 +03:00
|
|
|
isPreviousLineEmpty,
|
2017-01-26 22:57:43 +03:00
|
|
|
hasNewline,
|
2017-01-30 20:08:55 +03:00
|
|
|
hasNewlineInRange,
|
2017-01-26 22:57:43 +03:00
|
|
|
hasSpaces,
|
2017-01-20 00:45:36 +03:00
|
|
|
setLocStart,
|
|
|
|
setLocEnd,
|
2017-05-15 01:58:06 +03:00
|
|
|
startsWithNoLookaheadToken,
|
2017-08-14 09:57:16 +03:00
|
|
|
getAlignmentSize,
|
2017-10-08 12:34:24 +03:00
|
|
|
getIndentSize,
|
2018-11-05 00:36:00 +03:00
|
|
|
getPreferredQuote,
|
2017-08-15 18:25:57 +03:00
|
|
|
printString,
|
2017-12-26 04:23:50 +03:00
|
|
|
printNumber,
|
|
|
|
hasIgnoreComment,
|
2018-02-09 15:17:48 +03:00
|
|
|
hasNodeIgnoreComment,
|
2018-03-21 04:39:28 +03:00
|
|
|
makeString,
|
2018-06-08 21:15:50 +03:00
|
|
|
matchAncestorTypes,
|
2018-03-21 04:39:28 +03:00
|
|
|
addLeadingComment,
|
|
|
|
addDanglingComment,
|
2018-07-20 22:48:37 +03:00
|
|
|
addTrailingComment,
|
|
|
|
isWithinParentArrayProperty
|
2017-01-20 00:45:36 +03:00
|
|
|
};
|