prettier 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -8
- package/bin-prettier.js +508 -416
- package/doc.js +6 -1
- package/index.js +95 -41
- package/package.json +1 -1
- package/parser-babel.js +1 -1
- package/parser-flow.js +1 -1
- package/parser-markdown.js +1 -1
- package/parser-postcss.js +1 -1
- package/parser-typescript.js +3 -3
- package/standalone.js +95 -41
package/doc.js
CHANGED
|
@@ -1056,7 +1056,11 @@
|
|
|
1056
1056
|
}
|
|
1057
1057
|
|
|
1058
1058
|
function hasNodeIgnoreComment(node) {
|
|
1059
|
-
return node && node.comments && node.comments.length > 0 && node.comments.some(comment => comment.
|
|
1059
|
+
return node && (node.comments && node.comments.length > 0 && node.comments.some(comment => isNodeIgnoreComment(comment) && !comment.unignore) || node.prettierIgnore);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function isNodeIgnoreComment(comment) {
|
|
1063
|
+
return comment.value.trim() === "prettier-ignore";
|
|
1060
1064
|
}
|
|
1061
1065
|
|
|
1062
1066
|
function addCommentHelper(node, comment) {
|
|
@@ -1156,6 +1160,7 @@
|
|
|
1156
1160
|
printNumber,
|
|
1157
1161
|
hasIgnoreComment,
|
|
1158
1162
|
hasNodeIgnoreComment,
|
|
1163
|
+
isNodeIgnoreComment,
|
|
1159
1164
|
makeString,
|
|
1160
1165
|
addLeadingComment,
|
|
1161
1166
|
addDanglingComment,
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var stream$5 = _interopDefault(require('stream'));
|
|
|
12
12
|
var events = _interopDefault(require('events'));
|
|
13
13
|
|
|
14
14
|
var name = "prettier";
|
|
15
|
-
var version = "2.0.
|
|
15
|
+
var version = "2.0.2";
|
|
16
16
|
var description = "Prettier is an opinionated code formatter";
|
|
17
17
|
var bin = "./bin/prettier.js";
|
|
18
18
|
var repository = "prettier/prettier";
|
|
@@ -26,7 +26,7 @@ var engines = {
|
|
|
26
26
|
var dependencies = {
|
|
27
27
|
"@angular/compiler": "9.0.5",
|
|
28
28
|
"@babel/code-frame": "7.8.0",
|
|
29
|
-
"@babel/parser": "7.9.
|
|
29
|
+
"@babel/parser": "7.9.3",
|
|
30
30
|
"@glimmer/syntax": "0.48.0",
|
|
31
31
|
"@iarna/toml": "2.2.3",
|
|
32
32
|
"@typescript-eslint/typescript-estree": "2.24.0",
|
|
@@ -59,12 +59,13 @@ var dependencies = {
|
|
|
59
59
|
"json-stable-stringify": "1.0.1",
|
|
60
60
|
leven: "3.1.0",
|
|
61
61
|
"lines-and-columns": "1.1.6",
|
|
62
|
-
"linguist-languages": "7.
|
|
62
|
+
"linguist-languages": "7.9.0",
|
|
63
63
|
lodash: "4.17.15",
|
|
64
64
|
mem: "6.0.1",
|
|
65
65
|
minimatch: "3.0.4",
|
|
66
66
|
minimist: "1.2.5",
|
|
67
67
|
"n-readlines": "1.0.0",
|
|
68
|
+
"please-upgrade-node": "3.2.0",
|
|
68
69
|
"postcss-less": "3.1.4",
|
|
69
70
|
"postcss-media-query-parser": "0.2.3",
|
|
70
71
|
"postcss-scss": "2.0.0",
|
|
@@ -83,21 +84,21 @@ var dependencies = {
|
|
|
83
84
|
"yaml-unist-parser": "1.1.1"
|
|
84
85
|
};
|
|
85
86
|
var devDependencies = {
|
|
86
|
-
"@babel/core": "7.
|
|
87
|
-
"@babel/preset-env": "7.
|
|
87
|
+
"@babel/core": "7.9.0",
|
|
88
|
+
"@babel/preset-env": "7.9.0",
|
|
88
89
|
"@rollup/plugin-alias": "3.0.1",
|
|
89
90
|
"@rollup/plugin-commonjs": "11.0.2",
|
|
90
91
|
"@rollup/plugin-json": "4.0.2",
|
|
91
92
|
"@rollup/plugin-node-resolve": "7.1.1",
|
|
92
93
|
"@rollup/plugin-replace": "2.3.1",
|
|
93
|
-
"babel-loader": "8.0
|
|
94
|
+
"babel-loader": "8.1.0",
|
|
94
95
|
benchmark: "2.1.4",
|
|
95
96
|
"builtin-modules": "3.1.0",
|
|
96
97
|
codecov: "3.6.5",
|
|
97
98
|
"cross-env": "7.0.2",
|
|
98
99
|
cspell: "4.0.55",
|
|
99
100
|
eslint: "6.8.0",
|
|
100
|
-
"eslint-config-prettier": "6.10.
|
|
101
|
+
"eslint-config-prettier": "6.10.1",
|
|
101
102
|
"eslint-formatter-friendly": "7.0.0",
|
|
102
103
|
"eslint-plugin-import": "2.20.1",
|
|
103
104
|
"eslint-plugin-prettier": "3.1.2",
|
|
@@ -105,11 +106,10 @@ var devDependencies = {
|
|
|
105
106
|
"eslint-plugin-unicorn": "17.2.0",
|
|
106
107
|
execa: "4.0.0",
|
|
107
108
|
jest: "25.1.0",
|
|
108
|
-
"jest-junit": "10.0.0",
|
|
109
109
|
"jest-snapshot-serializer-ansi": "1.0.0",
|
|
110
110
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
111
111
|
"jest-watch-typeahead": "0.4.2",
|
|
112
|
-
prettier: "2.0.
|
|
112
|
+
prettier: "2.0.1",
|
|
113
113
|
rimraf: "3.0.2",
|
|
114
114
|
rollup: "2.1.0",
|
|
115
115
|
"rollup-plugin-babel": "4.4.0",
|
|
@@ -137,7 +137,7 @@ var scripts = {
|
|
|
137
137
|
"lint:changelog": "node ./scripts/lint-changelog.js",
|
|
138
138
|
"lint:prettier": "prettier \"**/*.{md,json,yml,html,css}\" --check",
|
|
139
139
|
"lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2016 \"dist/!(bin-prettier|index|third-party).js\"",
|
|
140
|
-
"lint:spellcheck": "cspell {bin,scripts,src}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md",
|
|
140
|
+
"lint:spellcheck": "cspell {bin,scripts,src,website}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md",
|
|
141
141
|
"lint:deps": "node ./scripts/check-deps.js",
|
|
142
142
|
build: "node --max-old-space-size=3072 ./scripts/build/build.js",
|
|
143
143
|
"build-docs": "node ./scripts/build-docs.js"
|
|
@@ -11500,6 +11500,7 @@ function getInterpreter(filepath) {
|
|
|
11500
11500
|
try {
|
|
11501
11501
|
fd = fs$2.openSync(filepath, "r");
|
|
11502
11502
|
} catch (err) {
|
|
11503
|
+
// istanbul ignore next
|
|
11503
11504
|
return "";
|
|
11504
11505
|
}
|
|
11505
11506
|
|
|
@@ -11536,13 +11537,20 @@ function getInterpreter(filepath) {
|
|
|
11536
11537
|
}
|
|
11537
11538
|
|
|
11538
11539
|
function inferParser(filepath, plugins) {
|
|
11539
|
-
const filename = path$1.basename(filepath).toLowerCase();
|
|
11540
|
+
const filename = path$1.basename(filepath).toLowerCase();
|
|
11541
|
+
const languages = getSupportInfo$1({
|
|
11542
|
+
plugins
|
|
11543
|
+
}).languages.filter(language => language.since !== null); // If the file has no extension, we can try to infer the language from the
|
|
11540
11544
|
// interpreter in the shebang line, if any; but since this requires FS access,
|
|
11541
11545
|
// do it last.
|
|
11542
11546
|
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11547
|
+
let language = languages.find(language => language.extensions && language.extensions.some(extension => filename.endsWith(extension)) || language.filenames && language.filenames.find(name => name.toLowerCase() === filename));
|
|
11548
|
+
|
|
11549
|
+
if (!language && !filename.includes(".")) {
|
|
11550
|
+
const interpreter = getInterpreter(filepath);
|
|
11551
|
+
language = languages.find(language => language.interpreters && language.interpreters.includes(interpreter));
|
|
11552
|
+
}
|
|
11553
|
+
|
|
11546
11554
|
return language && language.parsers[0];
|
|
11547
11555
|
}
|
|
11548
11556
|
|
|
@@ -12636,7 +12644,11 @@ function hasIgnoreComment(path) {
|
|
|
12636
12644
|
}
|
|
12637
12645
|
|
|
12638
12646
|
function hasNodeIgnoreComment(node) {
|
|
12639
|
-
return node && node.comments && node.comments.length > 0 && node.comments.some(comment => comment.
|
|
12647
|
+
return node && (node.comments && node.comments.length > 0 && node.comments.some(comment => isNodeIgnoreComment(comment) && !comment.unignore) || node.prettierIgnore);
|
|
12648
|
+
}
|
|
12649
|
+
|
|
12650
|
+
function isNodeIgnoreComment(comment) {
|
|
12651
|
+
return comment.value.trim() === "prettier-ignore";
|
|
12640
12652
|
}
|
|
12641
12653
|
|
|
12642
12654
|
function addCommentHelper(node, comment) {
|
|
@@ -12736,6 +12748,7 @@ var util$1 = {
|
|
|
12736
12748
|
printNumber,
|
|
12737
12749
|
hasIgnoreComment,
|
|
12738
12750
|
hasNodeIgnoreComment,
|
|
12751
|
+
isNodeIgnoreComment,
|
|
12739
12752
|
makeString,
|
|
12740
12753
|
addLeadingComment,
|
|
12741
12754
|
addDanglingComment,
|
|
@@ -14741,7 +14754,7 @@ function ensureAllCommentsPrinted(astComments) {
|
|
|
14741
14754
|
}
|
|
14742
14755
|
|
|
14743
14756
|
for (let i = 0; i < astComments.length; ++i) {
|
|
14744
|
-
if (astComments[i]
|
|
14757
|
+
if (util$1.isNodeIgnoreComment(astComments[i])) {
|
|
14745
14758
|
// If there's a prettier-ignore, we're not printing that sub-tree so we
|
|
14746
14759
|
// don't know if the comments was printed or not.
|
|
14747
14760
|
return;
|
|
@@ -35336,8 +35349,22 @@ function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
|
|
|
35336
35349
|
|
|
35337
35350
|
function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
|
|
35338
35351
|
if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
|
|
35339
|
-
|
|
35340
|
-
|
|
35352
|
+
if (util$1.isNodeIgnoreComment(comment)) {
|
|
35353
|
+
followingNode.prettierIgnore = true;
|
|
35354
|
+
comment.unignore = true;
|
|
35355
|
+
}
|
|
35356
|
+
|
|
35357
|
+
if (precedingNode) {
|
|
35358
|
+
addTrailingComment$3(precedingNode, comment);
|
|
35359
|
+
return true;
|
|
35360
|
+
}
|
|
35361
|
+
|
|
35362
|
+
return false;
|
|
35363
|
+
}
|
|
35364
|
+
|
|
35365
|
+
if (followingNode && (followingNode.type === "UnionTypeAnnotation" || followingNode.type === "TSUnionType") && util$1.isNodeIgnoreComment(comment)) {
|
|
35366
|
+
followingNode.types[0].prettierIgnore = true;
|
|
35367
|
+
comment.unignore = true;
|
|
35341
35368
|
}
|
|
35342
35369
|
|
|
35343
35370
|
return false;
|
|
@@ -35543,7 +35570,31 @@ function embed(path, print, textToDoc, options) {
|
|
|
35543
35570
|
const rawQuasis = node.quasis.map(q => q.value.raw);
|
|
35544
35571
|
let placeholderID = 0;
|
|
35545
35572
|
const text = rawQuasis.reduce((prevVal, currVal, idx) => {
|
|
35546
|
-
|
|
35573
|
+
if (idx === 0) {
|
|
35574
|
+
return currVal;
|
|
35575
|
+
}
|
|
35576
|
+
|
|
35577
|
+
let specialSuffix = ""; // colons and whitespaces
|
|
35578
|
+
|
|
35579
|
+
const trailingColons = currVal.match(/^(\s*)(:+)(\s*)/);
|
|
35580
|
+
|
|
35581
|
+
if (trailingColons) {
|
|
35582
|
+
const whitespaceBeforeColons = !!trailingColons[1];
|
|
35583
|
+
const numberOfColons = trailingColons[2].length;
|
|
35584
|
+
const whitespaceAfterColons = !!trailingColons[3];
|
|
35585
|
+
|
|
35586
|
+
if (whitespaceAfterColons) ; else {
|
|
35587
|
+
if (whitespaceBeforeColons) {
|
|
35588
|
+
specialSuffix += "-whitespace";
|
|
35589
|
+
}
|
|
35590
|
+
|
|
35591
|
+
specialSuffix += "-colon".repeat(numberOfColons);
|
|
35592
|
+
currVal = "\uffff" + currVal.slice(trailingColons[0].length);
|
|
35593
|
+
}
|
|
35594
|
+
}
|
|
35595
|
+
|
|
35596
|
+
const placeholder = `@prettier-placeholder${specialSuffix}-${placeholderID++}-id`;
|
|
35597
|
+
return prevVal + placeholder + currVal;
|
|
35547
35598
|
}, "");
|
|
35548
35599
|
const doc = textToDoc(text, {
|
|
35549
35600
|
parser: "css"
|
|
@@ -35745,12 +35796,19 @@ function replacePlaceholders(quasisDoc, expressionDocs) {
|
|
|
35745
35796
|
if (atPlaceholderIndex > -1) {
|
|
35746
35797
|
const placeholder = parts[atPlaceholderIndex];
|
|
35747
35798
|
const rest = parts.slice(atPlaceholderIndex + 1);
|
|
35748
|
-
const placeholderMatch = placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
|
|
35749
|
-
const
|
|
35799
|
+
const placeholderMatch = placeholder.match(/@prettier-placeholder((?:-whitespace|-colon)*)-(.+)-id([\s\S]*)/);
|
|
35800
|
+
const specialSuffix = placeholderMatch[1]; // colons and whitespaces
|
|
35801
|
+
|
|
35802
|
+
const placeholderID = placeholderMatch[2]; // When the expression has a suffix appended, like:
|
|
35750
35803
|
// animation: linear ${time}s ease-out;
|
|
35751
35804
|
|
|
35752
|
-
|
|
35805
|
+
let suffix = placeholderMatch[3];
|
|
35753
35806
|
const expression = expressions[placeholderID];
|
|
35807
|
+
|
|
35808
|
+
if (specialSuffix) {
|
|
35809
|
+
suffix = specialSuffix.replace(/-whitespace/g, " ").replace(/-colon/g, ":") + suffix.replace(/^\uffff/g, "");
|
|
35810
|
+
}
|
|
35811
|
+
|
|
35754
35812
|
replaceCounter++;
|
|
35755
35813
|
parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(rest);
|
|
35756
35814
|
}
|
|
@@ -40139,8 +40197,13 @@ function printPathNoParens(path, options, print, args) {
|
|
|
40139
40197
|
|
|
40140
40198
|
case "TSIndexSignature":
|
|
40141
40199
|
{
|
|
40142
|
-
const parent = path.getParentNode();
|
|
40143
|
-
|
|
40200
|
+
const parent = path.getParentNode(); // The typescript parser accepts multiple parameters here. If you're
|
|
40201
|
+
// using them, it makes sense to have a trailing comma. But if you
|
|
40202
|
+
// aren't, this is more like a computed property name than an array.
|
|
40203
|
+
// So we leave off the trailing comma when there's just one parameter.
|
|
40204
|
+
|
|
40205
|
+
const trailingComma = n.parameters.length > 1 ? ifBreak$1(shouldPrintComma(options) ? "," : "") : "";
|
|
40206
|
+
const parametersGroup = group$2(concat$6([indent$3(concat$6([softline$2, join$4(concat$6([", ", softline$2]), path.map(print, "parameters"))])), trailingComma, softline$2]));
|
|
40144
40207
|
return concat$6([n.export ? "export " : "", n.accessibility ? concat$6([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? parametersGroup : "", n.typeAnnotation ? "]: " : "]", n.typeAnnotation ? path.call(print, "typeAnnotation") : "", parent.type === "ClassBody" ? semi : ""]);
|
|
40145
40208
|
}
|
|
40146
40209
|
|
|
@@ -41936,7 +41999,7 @@ function willPrintOwnComments(path
|
|
|
41936
41999
|
) {
|
|
41937
42000
|
const node = path.getValue();
|
|
41938
42001
|
const parent = path.getParentNode();
|
|
41939
|
-
return (node && (isJSXNode$1(node) || hasFlowShorthandAnnotationComment$2(node) || parent && (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && (hasFlowAnnotationComment$1(node.leadingComments) || hasFlowAnnotationComment$1(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$2(path);
|
|
42002
|
+
return (node && (isJSXNode$1(node) || hasFlowShorthandAnnotationComment$2(node) || parent && (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && (hasFlowAnnotationComment$1(node.leadingComments) || hasFlowAnnotationComment$1(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && (!hasIgnoreComment$2(path) || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType");
|
|
41940
42003
|
}
|
|
41941
42004
|
|
|
41942
42005
|
function canAttachComment(node) {
|
|
@@ -42516,6 +42579,7 @@ var aliases$2 = [
|
|
|
42516
42579
|
"jsonc"
|
|
42517
42580
|
];
|
|
42518
42581
|
var extensions$5 = [
|
|
42582
|
+
".jsonc",
|
|
42519
42583
|
".sublime-build",
|
|
42520
42584
|
".sublime-commands",
|
|
42521
42585
|
".sublime-completions",
|
|
@@ -46079,19 +46143,6 @@ function getAncestorNode$2(path, typeOrTypes) {
|
|
|
46079
46143
|
}
|
|
46080
46144
|
|
|
46081
46145
|
function printLine(path, value, options) {
|
|
46082
|
-
const greatGrandParentNode = path.getParentNode(2);
|
|
46083
|
-
|
|
46084
|
-
if (greatGrandParentNode && greatGrandParentNode.type === "listItem") {
|
|
46085
|
-
const parentNode = path.getParentNode();
|
|
46086
|
-
const grandParentNode = path.getParentNode(1);
|
|
46087
|
-
const index = grandParentNode.children.indexOf(parentNode);
|
|
46088
|
-
const prevGrandParentNode = grandParentNode.children[index - 1];
|
|
46089
|
-
|
|
46090
|
-
if (prevGrandParentNode && prevGrandParentNode.type === "break") {
|
|
46091
|
-
return "";
|
|
46092
|
-
}
|
|
46093
|
-
}
|
|
46094
|
-
|
|
46095
46146
|
if (options.proseWrap === "preserve" && value === "\n") {
|
|
46096
46147
|
return hardline$b;
|
|
46097
46148
|
}
|
|
@@ -50326,7 +50377,8 @@ var filenames$4 = [
|
|
|
50326
50377
|
".clang-format",
|
|
50327
50378
|
".clang-tidy",
|
|
50328
50379
|
".gemrc",
|
|
50329
|
-
"glide.lock"
|
|
50380
|
+
"glide.lock",
|
|
50381
|
+
"yarn.lock"
|
|
50330
50382
|
];
|
|
50331
50383
|
var aceMode$g = "yaml";
|
|
50332
50384
|
var codemirrorMode$c = "yaml";
|
|
@@ -50362,10 +50414,12 @@ var YAML$1 = /*#__PURE__*/Object.freeze({
|
|
|
50362
50414
|
|
|
50363
50415
|
var require$$0$7 = getCjsExportFromNamespace(YAML$1);
|
|
50364
50416
|
|
|
50365
|
-
const languages$6 = [createLanguage(require$$0$7,
|
|
50417
|
+
const languages$6 = [createLanguage(require$$0$7, data => ({
|
|
50366
50418
|
since: "1.14.0",
|
|
50367
50419
|
parsers: ["yaml"],
|
|
50368
|
-
vscodeLanguageIds: ["yaml"]
|
|
50420
|
+
vscodeLanguageIds: ["yaml"],
|
|
50421
|
+
// yarn.lock is not YAML: https://github.com/yarnpkg/yarn/issues/5629
|
|
50422
|
+
filenames: data.filenames.filter(filename => filename !== "yarn.lock")
|
|
50369
50423
|
}))];
|
|
50370
50424
|
var languageYaml = {
|
|
50371
50425
|
languages: languages$6,
|