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/standalone.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
}(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
var name = "prettier";
|
|
8
|
-
var version = "2.0.
|
|
8
|
+
var version = "2.0.2";
|
|
9
9
|
var description = "Prettier is an opinionated code formatter";
|
|
10
10
|
var bin = "./bin/prettier.js";
|
|
11
11
|
var repository = "prettier/prettier";
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
var dependencies = {
|
|
20
20
|
"@angular/compiler": "9.0.5",
|
|
21
21
|
"@babel/code-frame": "7.8.0",
|
|
22
|
-
"@babel/parser": "7.9.
|
|
22
|
+
"@babel/parser": "7.9.3",
|
|
23
23
|
"@glimmer/syntax": "0.48.0",
|
|
24
24
|
"@iarna/toml": "2.2.3",
|
|
25
25
|
"@typescript-eslint/typescript-estree": "2.24.0",
|
|
@@ -52,12 +52,13 @@
|
|
|
52
52
|
"json-stable-stringify": "1.0.1",
|
|
53
53
|
leven: "3.1.0",
|
|
54
54
|
"lines-and-columns": "1.1.6",
|
|
55
|
-
"linguist-languages": "7.
|
|
55
|
+
"linguist-languages": "7.9.0",
|
|
56
56
|
lodash: "4.17.15",
|
|
57
57
|
mem: "6.0.1",
|
|
58
58
|
minimatch: "3.0.4",
|
|
59
59
|
minimist: "1.2.5",
|
|
60
60
|
"n-readlines": "1.0.0",
|
|
61
|
+
"please-upgrade-node": "3.2.0",
|
|
61
62
|
"postcss-less": "3.1.4",
|
|
62
63
|
"postcss-media-query-parser": "0.2.3",
|
|
63
64
|
"postcss-scss": "2.0.0",
|
|
@@ -76,21 +77,21 @@
|
|
|
76
77
|
"yaml-unist-parser": "1.1.1"
|
|
77
78
|
};
|
|
78
79
|
var devDependencies = {
|
|
79
|
-
"@babel/core": "7.
|
|
80
|
-
"@babel/preset-env": "7.
|
|
80
|
+
"@babel/core": "7.9.0",
|
|
81
|
+
"@babel/preset-env": "7.9.0",
|
|
81
82
|
"@rollup/plugin-alias": "3.0.1",
|
|
82
83
|
"@rollup/plugin-commonjs": "11.0.2",
|
|
83
84
|
"@rollup/plugin-json": "4.0.2",
|
|
84
85
|
"@rollup/plugin-node-resolve": "7.1.1",
|
|
85
86
|
"@rollup/plugin-replace": "2.3.1",
|
|
86
|
-
"babel-loader": "8.0
|
|
87
|
+
"babel-loader": "8.1.0",
|
|
87
88
|
benchmark: "2.1.4",
|
|
88
89
|
"builtin-modules": "3.1.0",
|
|
89
90
|
codecov: "3.6.5",
|
|
90
91
|
"cross-env": "7.0.2",
|
|
91
92
|
cspell: "4.0.55",
|
|
92
93
|
eslint: "6.8.0",
|
|
93
|
-
"eslint-config-prettier": "6.10.
|
|
94
|
+
"eslint-config-prettier": "6.10.1",
|
|
94
95
|
"eslint-formatter-friendly": "7.0.0",
|
|
95
96
|
"eslint-plugin-import": "2.20.1",
|
|
96
97
|
"eslint-plugin-prettier": "3.1.2",
|
|
@@ -98,11 +99,10 @@
|
|
|
98
99
|
"eslint-plugin-unicorn": "17.2.0",
|
|
99
100
|
execa: "4.0.0",
|
|
100
101
|
jest: "25.1.0",
|
|
101
|
-
"jest-junit": "10.0.0",
|
|
102
102
|
"jest-snapshot-serializer-ansi": "1.0.0",
|
|
103
103
|
"jest-snapshot-serializer-raw": "1.1.0",
|
|
104
104
|
"jest-watch-typeahead": "0.4.2",
|
|
105
|
-
prettier: "2.0.
|
|
105
|
+
prettier: "2.0.1",
|
|
106
106
|
rimraf: "3.0.2",
|
|
107
107
|
rollup: "2.1.0",
|
|
108
108
|
"rollup-plugin-babel": "4.4.0",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"lint:changelog": "node ./scripts/lint-changelog.js",
|
|
131
131
|
"lint:prettier": "prettier \"**/*.{md,json,yml,html,css}\" --check",
|
|
132
132
|
"lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2016 \"dist/!(bin-prettier|index|third-party).js\"",
|
|
133
|
-
"lint:spellcheck": "cspell {bin,scripts,src}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md",
|
|
133
|
+
"lint:spellcheck": "cspell {bin,scripts,src,website}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md",
|
|
134
134
|
"lint:deps": "node ./scripts/check-deps.js",
|
|
135
135
|
build: "node --max-old-space-size=3072 ./scripts/build/build.js",
|
|
136
136
|
"build-docs": "node ./scripts/build-docs.js"
|
|
@@ -13842,6 +13842,7 @@
|
|
|
13842
13842
|
try {
|
|
13843
13843
|
fd = fs.openSync(filepath, "r");
|
|
13844
13844
|
} catch (err) {
|
|
13845
|
+
// istanbul ignore next
|
|
13845
13846
|
return "";
|
|
13846
13847
|
}
|
|
13847
13848
|
|
|
@@ -13878,13 +13879,20 @@
|
|
|
13878
13879
|
}
|
|
13879
13880
|
|
|
13880
13881
|
function inferParser(filepath, plugins) {
|
|
13881
|
-
const filename = path.basename(filepath).toLowerCase();
|
|
13882
|
+
const filename = path.basename(filepath).toLowerCase();
|
|
13883
|
+
const languages = getSupportInfo$1({
|
|
13884
|
+
plugins
|
|
13885
|
+
}).languages.filter(language => language.since !== null); // If the file has no extension, we can try to infer the language from the
|
|
13882
13886
|
// interpreter in the shebang line, if any; but since this requires FS access,
|
|
13883
13887
|
// do it last.
|
|
13884
13888
|
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13889
|
+
let language = languages.find(language => language.extensions && language.extensions.some(extension => filename.endsWith(extension)) || language.filenames && language.filenames.find(name => name.toLowerCase() === filename));
|
|
13890
|
+
|
|
13891
|
+
if (!language && !filename.includes(".")) {
|
|
13892
|
+
const interpreter = getInterpreter(filepath);
|
|
13893
|
+
language = languages.find(language => language.interpreters && language.interpreters.includes(interpreter));
|
|
13894
|
+
}
|
|
13895
|
+
|
|
13888
13896
|
return language && language.parsers[0];
|
|
13889
13897
|
}
|
|
13890
13898
|
|
|
@@ -14984,7 +14992,11 @@
|
|
|
14984
14992
|
}
|
|
14985
14993
|
|
|
14986
14994
|
function hasNodeIgnoreComment(node) {
|
|
14987
|
-
return node && node.comments && node.comments.length > 0 && node.comments.some(comment => comment.
|
|
14995
|
+
return node && (node.comments && node.comments.length > 0 && node.comments.some(comment => isNodeIgnoreComment(comment) && !comment.unignore) || node.prettierIgnore);
|
|
14996
|
+
}
|
|
14997
|
+
|
|
14998
|
+
function isNodeIgnoreComment(comment) {
|
|
14999
|
+
return comment.value.trim() === "prettier-ignore";
|
|
14988
15000
|
}
|
|
14989
15001
|
|
|
14990
15002
|
function addCommentHelper(node, comment) {
|
|
@@ -15084,6 +15096,7 @@
|
|
|
15084
15096
|
printNumber,
|
|
15085
15097
|
hasIgnoreComment,
|
|
15086
15098
|
hasNodeIgnoreComment,
|
|
15099
|
+
isNodeIgnoreComment,
|
|
15087
15100
|
makeString,
|
|
15088
15101
|
addLeadingComment,
|
|
15089
15102
|
addDanglingComment,
|
|
@@ -17091,7 +17104,7 @@
|
|
|
17091
17104
|
}
|
|
17092
17105
|
|
|
17093
17106
|
for (let i = 0; i < astComments.length; ++i) {
|
|
17094
|
-
if (astComments[i]
|
|
17107
|
+
if (util$1.isNodeIgnoreComment(astComments[i])) {
|
|
17095
17108
|
// If there's a prettier-ignore, we're not printing that sub-tree so we
|
|
17096
17109
|
// don't know if the comments was printed or not.
|
|
17097
17110
|
return;
|
|
@@ -23638,8 +23651,22 @@
|
|
|
23638
23651
|
|
|
23639
23652
|
function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
|
|
23640
23653
|
if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
|
|
23641
|
-
|
|
23642
|
-
|
|
23654
|
+
if (util$1.isNodeIgnoreComment(comment)) {
|
|
23655
|
+
followingNode.prettierIgnore = true;
|
|
23656
|
+
comment.unignore = true;
|
|
23657
|
+
}
|
|
23658
|
+
|
|
23659
|
+
if (precedingNode) {
|
|
23660
|
+
addTrailingComment$3(precedingNode, comment);
|
|
23661
|
+
return true;
|
|
23662
|
+
}
|
|
23663
|
+
|
|
23664
|
+
return false;
|
|
23665
|
+
}
|
|
23666
|
+
|
|
23667
|
+
if (followingNode && (followingNode.type === "UnionTypeAnnotation" || followingNode.type === "TSUnionType") && util$1.isNodeIgnoreComment(comment)) {
|
|
23668
|
+
followingNode.types[0].prettierIgnore = true;
|
|
23669
|
+
comment.unignore = true;
|
|
23643
23670
|
}
|
|
23644
23671
|
|
|
23645
23672
|
return false;
|
|
@@ -23845,7 +23872,31 @@
|
|
|
23845
23872
|
const rawQuasis = node.quasis.map(q => q.value.raw);
|
|
23846
23873
|
let placeholderID = 0;
|
|
23847
23874
|
const text = rawQuasis.reduce((prevVal, currVal, idx) => {
|
|
23848
|
-
|
|
23875
|
+
if (idx === 0) {
|
|
23876
|
+
return currVal;
|
|
23877
|
+
}
|
|
23878
|
+
|
|
23879
|
+
let specialSuffix = ""; // colons and whitespaces
|
|
23880
|
+
|
|
23881
|
+
const trailingColons = currVal.match(/^(\s*)(:+)(\s*)/);
|
|
23882
|
+
|
|
23883
|
+
if (trailingColons) {
|
|
23884
|
+
const whitespaceBeforeColons = !!trailingColons[1];
|
|
23885
|
+
const numberOfColons = trailingColons[2].length;
|
|
23886
|
+
const whitespaceAfterColons = !!trailingColons[3];
|
|
23887
|
+
|
|
23888
|
+
if (whitespaceAfterColons) ; else {
|
|
23889
|
+
if (whitespaceBeforeColons) {
|
|
23890
|
+
specialSuffix += "-whitespace";
|
|
23891
|
+
}
|
|
23892
|
+
|
|
23893
|
+
specialSuffix += "-colon".repeat(numberOfColons);
|
|
23894
|
+
currVal = "\uffff" + currVal.slice(trailingColons[0].length);
|
|
23895
|
+
}
|
|
23896
|
+
}
|
|
23897
|
+
|
|
23898
|
+
const placeholder = "@prettier-placeholder".concat(specialSuffix, "-").concat(placeholderID++, "-id");
|
|
23899
|
+
return prevVal + placeholder + currVal;
|
|
23849
23900
|
}, "");
|
|
23850
23901
|
const doc = textToDoc(text, {
|
|
23851
23902
|
parser: "css"
|
|
@@ -24047,12 +24098,19 @@
|
|
|
24047
24098
|
if (atPlaceholderIndex > -1) {
|
|
24048
24099
|
const placeholder = parts[atPlaceholderIndex];
|
|
24049
24100
|
const rest = parts.slice(atPlaceholderIndex + 1);
|
|
24050
|
-
const placeholderMatch = placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
|
|
24051
|
-
const
|
|
24101
|
+
const placeholderMatch = placeholder.match(/@prettier-placeholder((?:-whitespace|-colon)*)-(.+)-id([\s\S]*)/);
|
|
24102
|
+
const specialSuffix = placeholderMatch[1]; // colons and whitespaces
|
|
24103
|
+
|
|
24104
|
+
const placeholderID = placeholderMatch[2]; // When the expression has a suffix appended, like:
|
|
24052
24105
|
// animation: linear ${time}s ease-out;
|
|
24053
24106
|
|
|
24054
|
-
|
|
24107
|
+
let suffix = placeholderMatch[3];
|
|
24055
24108
|
const expression = expressions[placeholderID];
|
|
24109
|
+
|
|
24110
|
+
if (specialSuffix) {
|
|
24111
|
+
suffix = specialSuffix.replace(/-whitespace/g, " ").replace(/-colon/g, ":") + suffix.replace(/^\uffff/g, "");
|
|
24112
|
+
}
|
|
24113
|
+
|
|
24056
24114
|
replaceCounter++;
|
|
24057
24115
|
parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(rest);
|
|
24058
24116
|
}
|
|
@@ -28255,8 +28313,13 @@
|
|
|
28255
28313
|
|
|
28256
28314
|
case "TSIndexSignature":
|
|
28257
28315
|
{
|
|
28258
|
-
const parent = path.getParentNode();
|
|
28259
|
-
|
|
28316
|
+
const parent = path.getParentNode(); // The typescript parser accepts multiple parameters here. If you're
|
|
28317
|
+
// using them, it makes sense to have a trailing comma. But if you
|
|
28318
|
+
// aren't, this is more like a computed property name than an array.
|
|
28319
|
+
// So we leave off the trailing comma when there's just one parameter.
|
|
28320
|
+
|
|
28321
|
+
const trailingComma = n.parameters.length > 1 ? ifBreak$6(shouldPrintComma$1(options) ? "," : "") : "";
|
|
28322
|
+
const parametersGroup = group$b(concat$d([indent$7(concat$d([softline$6, join$9(concat$d([", ", softline$6]), path.map(print, "parameters"))])), trailingComma, softline$6]));
|
|
28260
28323
|
return concat$d([n.export ? "export " : "", n.accessibility ? concat$d([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? parametersGroup : "", n.typeAnnotation ? "]: " : "]", n.typeAnnotation ? path.call(print, "typeAnnotation") : "", parent.type === "ClassBody" ? semi : ""]);
|
|
28261
28324
|
}
|
|
28262
28325
|
|
|
@@ -30052,7 +30115,7 @@
|
|
|
30052
30115
|
) {
|
|
30053
30116
|
const node = path.getValue();
|
|
30054
30117
|
const parent = path.getParentNode();
|
|
30055
|
-
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$4(path);
|
|
30118
|
+
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$4(path) || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType");
|
|
30056
30119
|
}
|
|
30057
30120
|
|
|
30058
30121
|
function canAttachComment$1(node) {
|
|
@@ -30575,6 +30638,7 @@
|
|
|
30575
30638
|
"jsonc"
|
|
30576
30639
|
];
|
|
30577
30640
|
var extensions$d = [
|
|
30641
|
+
".jsonc",
|
|
30578
30642
|
".sublime-build",
|
|
30579
30643
|
".sublime-commands",
|
|
30580
30644
|
".sublime-completions",
|
|
@@ -31612,19 +31676,6 @@
|
|
|
31612
31676
|
}
|
|
31613
31677
|
|
|
31614
31678
|
function printLine(path, value, options) {
|
|
31615
|
-
const greatGrandParentNode = path.getParentNode(2);
|
|
31616
|
-
|
|
31617
|
-
if (greatGrandParentNode && greatGrandParentNode.type === "listItem") {
|
|
31618
|
-
const parentNode = path.getParentNode();
|
|
31619
|
-
const grandParentNode = path.getParentNode(1);
|
|
31620
|
-
const index = grandParentNode.children.indexOf(parentNode);
|
|
31621
|
-
const prevGrandParentNode = grandParentNode.children[index - 1];
|
|
31622
|
-
|
|
31623
|
-
if (prevGrandParentNode && prevGrandParentNode.type === "break") {
|
|
31624
|
-
return "";
|
|
31625
|
-
}
|
|
31626
|
-
}
|
|
31627
|
-
|
|
31628
31679
|
if (options.proseWrap === "preserve" && value === "\n") {
|
|
31629
31680
|
return hardline$c;
|
|
31630
31681
|
}
|
|
@@ -32795,7 +32846,8 @@
|
|
|
32795
32846
|
".clang-format",
|
|
32796
32847
|
".clang-tidy",
|
|
32797
32848
|
".gemrc",
|
|
32798
|
-
"glide.lock"
|
|
32849
|
+
"glide.lock",
|
|
32850
|
+
"yarn.lock"
|
|
32799
32851
|
];
|
|
32800
32852
|
var aceMode$g = "yaml";
|
|
32801
32853
|
var codemirrorMode$c = "yaml";
|
|
@@ -32831,10 +32883,12 @@
|
|
|
32831
32883
|
|
|
32832
32884
|
var require$$0$8 = getCjsExportFromNamespace(YAML$1);
|
|
32833
32885
|
|
|
32834
|
-
const languages$6 = [createLanguage(require$$0$8,
|
|
32886
|
+
const languages$6 = [createLanguage(require$$0$8, data => ({
|
|
32835
32887
|
since: "1.14.0",
|
|
32836
32888
|
parsers: ["yaml"],
|
|
32837
|
-
vscodeLanguageIds: ["yaml"]
|
|
32889
|
+
vscodeLanguageIds: ["yaml"],
|
|
32890
|
+
// yarn.lock is not YAML: https://github.com/yarnpkg/yarn/issues/5629
|
|
32891
|
+
filenames: data.filenames.filter(filename => filename !== "yarn.lock")
|
|
32838
32892
|
}))];
|
|
32839
32893
|
var languageYaml = {
|
|
32840
32894
|
languages: languages$6,
|