Remove deprecated parser & update sharedUtil (#6993)
* Remove some old stuff * Add changelog * Fix test * util changes * restore parser * Fix `util` usage
This commit is contained in:
1 parent
2877dda67e
commit
0c93198942
10 files changed
+114
-69
No files matched your search
@@ -0,0 +1,21 @@
|
||||
#### Remove deprecated api ([#6993](https://github.com/prettier/prettier/pull/6993) by [@fisker](https://github.com/fisker))
|
||||
|
||||
- Parser `typescript-eslint` is removed.
|
||||
|
||||
Use `typescript` instead.
|
||||
|
||||
- `prettier.util.mapDoc` is removed
|
||||
|
||||
Use `prettier.doc.utils.mapDoc` instead.
|
||||
|
||||
- `prettier.util.isNextLineEmpty` is updated
|
||||
|
||||
Use `isNextLineEmpty(text, node, locEnd)` instead of `isNextLineEmpty(text, node, options)`.
|
||||
|
||||
- `prettier.util.isPreviousLineEmpty` is updated
|
||||
|
||||
Use `isPreviousLineEmpty(text, node, locStart)` instead of `isNextLineEmpty(text, node, options)`.
|
||||
|
||||
- `prettier.util.getNextNonSpaceNonCommentCharacterIndex` is updated
|
||||
|
||||
Use `getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)` instead of `getNextNonSpaceNonCommentCharacterIndex(text, node, options)`.
|
||||
@@ -249,7 +249,6 @@ function getNextNonSpaceNonCommentCharacterIndex<N>(text: string, node: N, locEn
|
||||
function isNextLineEmptyAfterIndex(text: string, index: number): boolean;
|
||||
function isNextLineEmpty<N>(text: string, node: N, locEnd: (node: N) => number): boolean;
|
||||
function isPreviousLineEmpty<N>(text: string, node: N, locStart: (node: N) => number): boolean;
|
||||
function mapDoc(doc: object, callback: function): void;
|
||||
```
|
||||
|
||||
### Tutorials
|
||||
|
||||
@@ -59,13 +59,6 @@ module.exports = [
|
||||
return eval("require")("../language-js/parser-typescript").parsers
|
||||
.typescript;
|
||||
},
|
||||
/**
|
||||
* TODO: Remove this old alias in a major version
|
||||
*/
|
||||
get "typescript-eslint"() {
|
||||
return eval("require")("../language-js/parser-typescript").parsers
|
||||
.typescript;
|
||||
},
|
||||
// JS - Angular Action
|
||||
get __ng_action() {
|
||||
return eval("require")("../language-js/parser-angular").parsers
|
||||
@@ -136,7 +129,6 @@ module.exports = [
|
||||
return eval("require")("../language-markdown/parser-markdown").parsers
|
||||
.remark;
|
||||
},
|
||||
// TODO: Delete this in 2.0
|
||||
get markdown() {
|
||||
return eval("require")("../language-markdown/parser-markdown").parsers
|
||||
.remark;
|
||||
|
||||
+47
-41
@@ -1,47 +1,53 @@
|
||||
"use strict";
|
||||
|
||||
const util = require("./util");
|
||||
const { mapDoc } = require("../document").utils;
|
||||
|
||||
function isNextLineEmpty(text, node, options) {
|
||||
return util.isNextLineEmpty(text, node, options.locEnd);
|
||||
}
|
||||
|
||||
function isPreviousLineEmpty(text, node, options) {
|
||||
return util.isPreviousLineEmpty(text, node, options.locStart);
|
||||
}
|
||||
|
||||
function getNextNonSpaceNonCommentCharacterIndex(text, node, options) {
|
||||
return util.getNextNonSpaceNonCommentCharacterIndex(
|
||||
text,
|
||||
node,
|
||||
options.locEnd
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getMaxContinuousCount: util.getMaxContinuousCount,
|
||||
getStringWidth: util.getStringWidth,
|
||||
getAlignmentSize: util.getAlignmentSize,
|
||||
getIndentSize: util.getIndentSize,
|
||||
skip: util.skip,
|
||||
skipWhitespace: util.skipWhitespace,
|
||||
skipSpaces: util.skipSpaces,
|
||||
skipNewline: util.skipNewline,
|
||||
skipToLineEnd: util.skipToLineEnd,
|
||||
skipEverythingButNewLine: util.skipEverythingButNewLine,
|
||||
skipInlineComment: util.skipInlineComment,
|
||||
skipTrailingComment: util.skipTrailingComment,
|
||||
hasNewline: util.hasNewline,
|
||||
hasNewlineInRange: util.hasNewlineInRange,
|
||||
hasSpaces: util.hasSpaces,
|
||||
const {
|
||||
getMaxContinuousCount,
|
||||
getStringWidth,
|
||||
getAlignmentSize,
|
||||
getIndentSize,
|
||||
skip,
|
||||
skipWhitespace,
|
||||
skipSpaces,
|
||||
skipNewline,
|
||||
skipToLineEnd,
|
||||
skipEverythingButNewLine,
|
||||
skipInlineComment,
|
||||
skipTrailingComment,
|
||||
hasNewline,
|
||||
hasNewlineInRange,
|
||||
hasSpaces,
|
||||
isNextLineEmpty,
|
||||
isNextLineEmptyAfterIndex: util.isNextLineEmptyAfterIndex,
|
||||
isNextLineEmptyAfterIndex,
|
||||
isPreviousLineEmpty,
|
||||
getNextNonSpaceNonCommentCharacterIndex,
|
||||
mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils
|
||||
makeString: util.makeString,
|
||||
addLeadingComment: util.addLeadingComment,
|
||||
addDanglingComment: util.addDanglingComment,
|
||||
addTrailingComment: util.addTrailingComment
|
||||
makeString,
|
||||
addLeadingComment,
|
||||
addDanglingComment,
|
||||
addTrailingComment
|
||||
} = require("./util");
|
||||
|
||||
module.exports = {
|
||||
getMaxContinuousCount,
|
||||
getStringWidth,
|
||||
getAlignmentSize,
|
||||
getIndentSize,
|
||||
skip,
|
||||
skipWhitespace,
|
||||
skipSpaces,
|
||||
skipNewline,
|
||||
skipToLineEnd,
|
||||
skipEverythingButNewLine,
|
||||
skipInlineComment,
|
||||
skipTrailingComment,
|
||||
hasNewline,
|
||||
hasNewlineInRange,
|
||||
hasSpaces,
|
||||
isNextLineEmpty,
|
||||
isNextLineEmptyAfterIndex,
|
||||
isPreviousLineEmpty,
|
||||
getNextNonSpaceNonCommentCharacterIndex,
|
||||
makeString,
|
||||
addLeadingComment,
|
||||
addDanglingComment,
|
||||
addTrailingComment
|
||||
};
|
||||
@@ -893,7 +893,7 @@ function printNodeSequence(path, options, print) {
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
pathChild.getValue(),
|
||||
options
|
||||
options.locEnd
|
||||
) &&
|
||||
node.nodes[i].type !== "yaml" &&
|
||||
node.nodes[i].type !== "toml"
|
||||
|
||||
@@ -32,7 +32,11 @@ function genericPrint(path, options, print) {
|
||||
if (index !== n.definitions.length - 1) {
|
||||
parts.push(hardline);
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, pathChild.getValue(), options)
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
pathChild.getValue(),
|
||||
options.locEnd
|
||||
)
|
||||
) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
@@ -629,7 +633,7 @@ function printSequence(sequencePath, options, print) {
|
||||
const printed = print(path);
|
||||
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, path.getValue(), options) &&
|
||||
isNextLineEmpty(options.originalText, path.getValue(), options.locEnd) &&
|
||||
i < count - 1
|
||||
) {
|
||||
return concat([printed, hardline]);
|
||||
|
||||
@@ -535,7 +535,11 @@ function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const index = getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
|
||||
const index = getNextNonSpaceNonCommentCharacterIndex(
|
||||
text,
|
||||
comment,
|
||||
options.locEnd
|
||||
);
|
||||
if (text.slice(index, index + 2) === "=>") {
|
||||
addDanglingComment(enclosingNode, comment);
|
||||
return true;
|
||||
|
||||
@@ -480,7 +480,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
path.each(childPath => {
|
||||
parts.push(print(childPath), semi, hardline);
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, childPath.getValue(), options)
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
childPath.getValue(),
|
||||
options.locEnd
|
||||
)
|
||||
) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
@@ -834,7 +838,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
const nextCharacter = getNextNonSpaceNonCommentCharacterIndex(
|
||||
options.originalText,
|
||||
comment,
|
||||
options
|
||||
options.locEnd
|
||||
);
|
||||
return (
|
||||
options.originalText.slice(nextCharacter, nextCharacter + 2) ===
|
||||
@@ -1117,7 +1121,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
path.each(childPath => {
|
||||
parts.push(indent(concat([hardline, print(childPath), semi])));
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, childPath.getValue(), options)
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
childPath.getValue(),
|
||||
options.locEnd
|
||||
)
|
||||
) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
@@ -1352,7 +1360,9 @@ function printPathNoParens(path, options, print, args) {
|
||||
) {
|
||||
separatorParts.shift();
|
||||
}
|
||||
if (isNextLineEmpty(options.originalText, prop.node, options)) {
|
||||
if (
|
||||
isNextLineEmpty(options.originalText, prop.node, options.locEnd)
|
||||
) {
|
||||
separatorParts.push(hardline);
|
||||
}
|
||||
return result;
|
||||
@@ -2037,7 +2047,11 @@ function printPathNoParens(path, options, print, args) {
|
||||
return concat([
|
||||
casePath.call(print),
|
||||
n.cases.indexOf(caseNode) !== n.cases.length - 1 &&
|
||||
isNextLineEmpty(options.originalText, caseNode, options)
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
caseNode,
|
||||
options.locEnd
|
||||
)
|
||||
? hardline
|
||||
: ""
|
||||
]);
|
||||
@@ -3556,7 +3570,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
case "InterpreterDirective":
|
||||
parts.push("#!", n.value, hardline);
|
||||
|
||||
if (isNextLineEmpty(options.originalText, n, options)) {
|
||||
if (isNextLineEmpty(options.originalText, n, options.locEnd)) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
|
||||
@@ -3723,7 +3737,10 @@ function printStatementSequence(path, options, print) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isNextLineEmpty(text, stmt, options) && !isLastStatement(stmtPath)) {
|
||||
if (
|
||||
isNextLineEmpty(text, stmt, options.locEnd) &&
|
||||
!isLastStatement(stmtPath)
|
||||
) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
|
||||
@@ -4057,7 +4074,7 @@ function printArgumentsList(path, options, print) {
|
||||
|
||||
if (index === lastArgIndex) {
|
||||
// do nothing
|
||||
} else if (isNextLineEmpty(options.originalText, arg, options)) {
|
||||
} else if (isNextLineEmpty(options.originalText, arg, options.locEnd)) {
|
||||
if (index === 0) {
|
||||
hasEmptyLineFollowingFirstArg = true;
|
||||
}
|
||||
@@ -4260,7 +4277,7 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) {
|
||||
shouldExpandParameters
|
||||
) {
|
||||
parts.push(", ");
|
||||
} else if (isNextLineEmpty(options.originalText, param, options)) {
|
||||
} else if (isNextLineEmpty(options.originalText, param, options.locEnd)) {
|
||||
parts.push(",", hardline, hardline);
|
||||
} else {
|
||||
parts.push(",", line);
|
||||
@@ -4832,7 +4849,7 @@ function printMemberChain(path, options, print) {
|
||||
const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex(
|
||||
originalText,
|
||||
node,
|
||||
options
|
||||
options.locEnd
|
||||
);
|
||||
const nextChar = originalText.charAt(nextCharIndex);
|
||||
|
||||
@@ -4842,11 +4859,11 @@ function printMemberChain(path, options, print) {
|
||||
return isNextLineEmptyAfterIndex(
|
||||
originalText,
|
||||
nextCharIndex + 1,
|
||||
options
|
||||
options.locEnd
|
||||
);
|
||||
}
|
||||
|
||||
return isNextLineEmpty(originalText, node, options);
|
||||
return isNextLineEmpty(originalText, node, options.locEnd);
|
||||
}
|
||||
|
||||
function rec(path) {
|
||||
@@ -5950,7 +5967,11 @@ function printArrayItems(path, options, printPath, print) {
|
||||
separatorParts = [",", line];
|
||||
if (
|
||||
childPath.getValue() &&
|
||||
isNextLineEmpty(options.originalText, childPath.getValue(), options)
|
||||
isNextLineEmpty(
|
||||
options.originalText,
|
||||
childPath.getValue(),
|
||||
options.locEnd
|
||||
)
|
||||
) {
|
||||
separatorParts.push(softline);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,6 @@ const mdxParser = { ...baseParser, parse: createParse({ isMDX: true }) };
|
||||
module.exports = {
|
||||
parsers: {
|
||||
remark: markdownParser,
|
||||
// TODO: Delete this in 2.0
|
||||
markdown: markdownParser,
|
||||
mdx: mdxParser
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ test("shared util has correct structure", () => {
|
||||
expect(typeof sharedUtil.getNextNonSpaceNonCommentCharacterIndex).toEqual(
|
||||
"function"
|
||||
);
|
||||
expect(typeof sharedUtil.mapDoc).toEqual("function");
|
||||
expect(typeof sharedUtil.makeString).toEqual("function");
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user