master
Stephen Scott 2017-09-27 17:20:13 -06:00
parent 038d02b3e2
commit 75781a6d16
4 changed files with 11 additions and 5 deletions

View File

@ -8,7 +8,7 @@ Tip! Don't write this stuff manually.
-->
**Prettier 1.7.1**
**Prettier 1.7.2**
[Playground link](https://prettier.io/playground/#.....)
```sh
# Options (if any):

View File

@ -1,3 +1,9 @@
# 1.7.2
[link](https://github.com/jlongster/prettier/compare/1.7.1...1.7.2)
* Revert "Fix line break in test declarations with a single argument function declaration" (#2912)
# 1.7.1
[link](https://github.com/jlongster/prettier/compare/1.7.0...1.7.1)

View File

@ -1,6 +1,6 @@
{
"name": "prettier",
"version": "1.7.1",
"version": "1.7.2",
"description": "Prettier is an opinionated code formatter",
"bin": {
"prettier": "./bin/prettier.js"

View File

@ -176,7 +176,7 @@ if(isBlock){return concat([contents,util$2.hasNewline(options.originalText,locEn
// if this a comment on its own line; normal trailing comments are
// always at the end of another expression.
var isLineBeforeEmpty=util$2.isPreviousLineEmpty(options.originalText,comment);return lineSuffix(concat([hardline,isLineBeforeEmpty?hardline:"",contents]));}else if(isBlock){// Trailing block comments never need a newline
return concat([" ",contents]);}return concat([lineSuffix(" "+contents),!isBlock?breakParent:""]);}function printDanglingComments(path,options,sameIndent){var parts=[];var node=path.getValue();if(!node||!node.comments){return"";}path.each(function(commentPath){var comment=commentPath.getValue();if(comment&&!comment.leading&&!comment.trailing){parts.push(printComment(commentPath,options));}},"comments");if(parts.length===0){return"";}if(sameIndent){return join(hardline,parts);}return indent(concat([hardline,join(hardline,parts)]));}function prependCursorPlaceholder(path,options,printed){if(path.getNode()===options.cursorNode&&path.getValue()){return concat([cursor,printed]);}return printed;}function printComments(path,print,options,needsSemi){var value=path.getValue();var printed=print(path);var comments=value&&value.comments;if(!comments||comments.length===0){return prependCursorPlaceholder(path,options,printed);}var leadingParts=[];var trailingParts=[needsSemi?";":"",printed];path.each(function(commentPath){var comment=commentPath.getValue();var leading=comment.leading;var trailing=comment.trailing;if(leading){var contents=printLeadingComment(commentPath,print,options);if(!contents){return;}leadingParts.push(contents);var text=options.originalText;if(util$2.hasNewline(text,util$2.skipNewline(text,util$2.locEnd(comment)))){leadingParts.push(hardline);}}else if(trailing){trailingParts.push(printTrailingComment(commentPath,print,options));}},"comments");return prependCursorPlaceholder(path,options,concat(leadingParts.concat(trailingParts)));}var comments$1={attach:attach,printComments:printComments,printDanglingComments:printDanglingComments,getSortedChildNodes:getSortedChildNodes};var name="prettier";var version$1="1.7.1";var description="Prettier is an opinionated code formatter";var bin={"prettier":"./bin/prettier.js"};var repository="prettier/prettier";var homepage="https://prettier.io";var author="James Long";var license="MIT";var main="./index.js";var engines={"node":">=4"};var dependencies={"babel-code-frame":"7.0.0-alpha.12","babylon":"7.0.0-beta.23","camelcase":"4.1.0","chalk":"2.1.0","cosmiconfig":"3.0.1","dashify":"0.2.2","diff":"3.2.0","esutils":"2.0.2","flow-parser":"0.51.0","get-stream":"3.0.0","globby":"^6.1.0","graphql":"0.10.1","ignore":"^3.3.3","jest-docblock":"21.1.0","jest-validate":"21.1.0","leven":"2.1.0","mem":"1.1.0","minimatch":"3.0.4","minimist":"1.2.0","parse5":"3.0.2","postcss-less":"^1.0.0","postcss-media-query-parser":"0.2.3","postcss-scss":"1.0.0","postcss-selector-parser":"2.2.3","postcss-values-parser":"git://github.com/lydell/postcss-values-parser.git#af2c80b2bb558a6e7d61540d97f068f9fa162b38","strip-bom":"3.0.0","typescript":"2.5.3","typescript-eslint-parser":"git://github.com/eslint/typescript-eslint-parser.git#9c71a627da36e97da52ed2731d58509c952b67ae"};var devDependencies={"babel-cli":"6.24.1","babel-preset-es2015":"6.24.1","codecov":"2.2.0","cross-env":"5.0.1","eslint":"4.1.1","eslint-friendly-formatter":"3.0.0","eslint-plugin-import":"2.6.1","eslint-plugin-prettier":"2.1.2","eslint-plugin-react":"7.1.0","jest":"21.1.0","markdown-toc":"1.1.0","mkdirp":"^0.5.1","prettier":"1.7.0","rimraf":"2.6.1","rollup":"0.41.1","rollup-plugin-commonjs":"7.0.0","rollup-plugin-json":"2.1.0","rollup-plugin-node-builtins":"2.0.0","rollup-plugin-node-globals":"1.1.0","rollup-plugin-node-resolve":"2.0.0","rollup-plugin-replace":"1.1.1","shelljs":"0.7.8","sw-toolbox":"3.6.0","uglify-es":"3.0.15","webpack":"2.6.1"};var scripts={"test":"jest","test-integration":"jest tests_integration","lint":"cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter","build":"node ./scripts/build/build.js","toc":"node ./scripts/table-of-contents.js"};var _package={name:name,version:version$1,description:description,bin:bin,repository:repository,homepage:homepage,author:author,license:license,main:main,engines:engines,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts};var _package$1=Object.freeze({name:name,version:version$1,description:description,bin:bin,repository:repository,homepage:homepage,author:author,license:license,main:main,engines:engines,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts,default:_package});var assert$2=require$$0;var util$6=util$3;var startsWithNoLookaheadToken$1=util$6.startsWithNoLookaheadToken;function FastPath$1(value){assert$2.ok(this instanceof FastPath$1);this.stack=[value];}// The name of the current property is always the penultimate element of
return concat([" ",contents]);}return concat([lineSuffix(" "+contents),!isBlock?breakParent:""]);}function printDanglingComments(path,options,sameIndent){var parts=[];var node=path.getValue();if(!node||!node.comments){return"";}path.each(function(commentPath){var comment=commentPath.getValue();if(comment&&!comment.leading&&!comment.trailing){parts.push(printComment(commentPath,options));}},"comments");if(parts.length===0){return"";}if(sameIndent){return join(hardline,parts);}return indent(concat([hardline,join(hardline,parts)]));}function prependCursorPlaceholder(path,options,printed){if(path.getNode()===options.cursorNode&&path.getValue()){return concat([cursor,printed]);}return printed;}function printComments(path,print,options,needsSemi){var value=path.getValue();var printed=print(path);var comments=value&&value.comments;if(!comments||comments.length===0){return prependCursorPlaceholder(path,options,printed);}var leadingParts=[];var trailingParts=[needsSemi?";":"",printed];path.each(function(commentPath){var comment=commentPath.getValue();var leading=comment.leading;var trailing=comment.trailing;if(leading){var contents=printLeadingComment(commentPath,print,options);if(!contents){return;}leadingParts.push(contents);var text=options.originalText;if(util$2.hasNewline(text,util$2.skipNewline(text,util$2.locEnd(comment)))){leadingParts.push(hardline);}}else if(trailing){trailingParts.push(printTrailingComment(commentPath,print,options));}},"comments");return prependCursorPlaceholder(path,options,concat(leadingParts.concat(trailingParts)));}var comments$1={attach:attach,printComments:printComments,printDanglingComments:printDanglingComments,getSortedChildNodes:getSortedChildNodes};var name="prettier";var version$1="1.7.2";var description="Prettier is an opinionated code formatter";var bin={"prettier":"./bin/prettier.js"};var repository="prettier/prettier";var homepage="https://prettier.io";var author="James Long";var license="MIT";var main="./index.js";var engines={"node":">=4"};var dependencies={"babel-code-frame":"7.0.0-alpha.12","babylon":"7.0.0-beta.23","camelcase":"4.1.0","chalk":"2.1.0","cosmiconfig":"3.0.1","dashify":"0.2.2","diff":"3.2.0","esutils":"2.0.2","flow-parser":"0.51.0","get-stream":"3.0.0","globby":"^6.1.0","graphql":"0.10.1","ignore":"^3.3.3","jest-docblock":"21.1.0","jest-validate":"21.1.0","leven":"2.1.0","mem":"1.1.0","minimatch":"3.0.4","minimist":"1.2.0","parse5":"3.0.2","postcss-less":"^1.0.0","postcss-media-query-parser":"0.2.3","postcss-scss":"1.0.0","postcss-selector-parser":"2.2.3","postcss-values-parser":"git://github.com/lydell/postcss-values-parser.git#af2c80b2bb558a6e7d61540d97f068f9fa162b38","strip-bom":"3.0.0","typescript":"2.5.3","typescript-eslint-parser":"git://github.com/eslint/typescript-eslint-parser.git#9c71a627da36e97da52ed2731d58509c952b67ae"};var devDependencies={"babel-cli":"6.24.1","babel-preset-es2015":"6.24.1","codecov":"2.2.0","cross-env":"5.0.1","eslint":"4.1.1","eslint-friendly-formatter":"3.0.0","eslint-plugin-import":"2.6.1","eslint-plugin-prettier":"2.1.2","eslint-plugin-react":"7.1.0","jest":"21.1.0","markdown-toc":"1.1.0","mkdirp":"^0.5.1","prettier":"1.7.0","rimraf":"2.6.1","rollup":"0.41.1","rollup-plugin-commonjs":"7.0.0","rollup-plugin-json":"2.1.0","rollup-plugin-node-builtins":"2.0.0","rollup-plugin-node-globals":"1.1.0","rollup-plugin-node-resolve":"2.0.0","rollup-plugin-replace":"1.1.1","shelljs":"0.7.8","sw-toolbox":"3.6.0","uglify-es":"3.0.15","webpack":"2.6.1"};var scripts={"test":"jest","test-integration":"jest tests_integration","lint":"cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter","build":"node ./scripts/build/build.js","toc":"node ./scripts/table-of-contents.js"};var _package={name:name,version:version$1,description:description,bin:bin,repository:repository,homepage:homepage,author:author,license:license,main:main,engines:engines,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts};var _package$1=Object.freeze({name:name,version:version$1,description:description,bin:bin,repository:repository,homepage:homepage,author:author,license:license,main:main,engines:engines,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts,default:_package});var assert$2=require$$0;var util$6=util$3;var startsWithNoLookaheadToken$1=util$6.startsWithNoLookaheadToken;function FastPath$1(value){assert$2.ok(this instanceof FastPath$1);this.stack=[value];}// The name of the current property is always the penultimate element of
// this.stack, and always a String.
FastPath$1.prototype.getName=function getName(){var s=this.stack;var len=s.length;if(len>1){return s[len-2];}// Since the name is always a string, null is a safe sentinel value to
// return if we do not know the name of the (root) value.
@ -470,11 +470,11 @@ var shouldAddSoftLine=args&&args.expandLastArg;// In order to avoid confusion be
// a <= a ? a : a
var shouldAddParens=n.body.type==="ConditionalExpression"&&!util$5.startsWithNoLookaheadToken(n.body,/* forbidFunctionAndClass */false);return group$1(concat$2([concat$2(parts),group$1(concat$2([indent$2(concat$2([line$1,shouldAddParens?ifBreak$1("","("):"",body,shouldAddParens?ifBreak$1("",")"):""])),shouldAddSoftLine?concat$2([ifBreak$1(shouldPrintComma(options,"all")?",":""),softline$1]):""]))]));}case"MethodDefinition":case"TSAbstractMethodDefinition":if(n.accessibility){parts.push(n.accessibility+" ");}if(n.static){parts.push("static ");}if(n.type==="TSAbstractMethodDefinition"){parts.push("abstract ");}parts.push(printMethod(path,options,print));return concat$2(parts);case"YieldExpression":parts.push("yield");if(n.delegate){parts.push("*");}if(n.argument){parts.push(" ",path.call(print,"argument"));}return concat$2(parts);case"AwaitExpression":return concat$2(["await ",path.call(print,"argument")]);case"ImportSpecifier":if(n.importKind){parts.push(path.call(print,"importKind")," ");}parts.push(path.call(print,"imported"));if(n.local&&n.local.name!==n.imported.name){parts.push(" as ",path.call(print,"local"));}return concat$2(parts);case"ExportSpecifier":parts.push(path.call(print,"local"));if(n.exported&&n.exported.name!==n.local.name){parts.push(" as ",path.call(print,"exported"));}return concat$2(parts);case"ImportNamespaceSpecifier":parts.push("* as ");if(n.local){parts.push(path.call(print,"local"));}else if(n.id){parts.push(path.call(print,"id"));}return concat$2(parts);case"ImportDefaultSpecifier":if(n.local){return path.call(print,"local");}return path.call(print,"id");case"TSExportAssignment":return concat$2(["export = ",path.call(print,"expression"),semi]);case"ExportDefaultDeclaration":case"ExportNamedDeclaration":return printExportDeclaration(path,options,print);case"ExportAllDeclaration":parts.push("export ");if(n.exportKind==="type"){parts.push("type ");}parts.push("* from ",path.call(print,"source"),semi);return concat$2(parts);case"ExportNamespaceSpecifier":case"ExportDefaultSpecifier":return path.call(print,"exported");case"ImportDeclaration":{parts.push("import ");if(n.importKind&&n.importKind!=="value"){parts.push(n.importKind+" ");}var standalones=[];var grouped=[];if(n.specifiers&&n.specifiers.length>0){path.each(function(specifierPath){var value=specifierPath.getValue();if(value.type==="ImportDefaultSpecifier"||value.type==="ImportNamespaceSpecifier"){standalones.push(print(specifierPath));}else{grouped.push(print(specifierPath));}},"specifiers");if(standalones.length>0){parts.push(join$2(", ",standalones));}if(standalones.length>0&&grouped.length>0){parts.push(", ");}if(grouped.length===1&&standalones.length===0&&n.specifiers&&!n.specifiers.some(function(node){return node.comments;})){parts.push(concat$2(["{",options.bracketSpacing?" ":"",concat$2(grouped),options.bracketSpacing?" ":"","}"]));}else if(grouped.length>=1){parts.push(group$1(concat$2(["{",indent$2(concat$2([options.bracketSpacing?line$1:softline$1,join$2(concat$2([",",line$1]),grouped)])),ifBreak$1(shouldPrintComma(options)?",":""),options.bracketSpacing?line$1:softline$1,"}"])));}parts.push(" from ");}else if(n.importKind&&n.importKind==="type"||// import {} from 'x'
/{\s*}/.test(options.originalText.slice(util$5.locStart(n),util$5.locStart(n.source)))){parts.push("{} from ");}parts.push(path.call(print,"source"),semi);return concat$2(parts);}case"Import":return"import";case"BlockStatement":{var naked=path.call(function(bodyPath){return printStatementSequence(bodyPath,options,print);},"body");var hasContent=n.body.find(function(node){return node.type!=="EmptyStatement";});var hasDirectives=n.directives&&n.directives.length>0;var _parent6=path.getParentNode();var _parentParent=path.getParentNode(1);if(!hasContent&&!hasDirectives&&!n.comments&&(_parent6.type==="ArrowFunctionExpression"||_parent6.type==="FunctionExpression"||_parent6.type==="FunctionDeclaration"||_parent6.type==="ObjectMethod"||_parent6.type==="ClassMethod"||_parent6.type==="ForStatement"||_parent6.type==="WhileStatement"||_parent6.type==="DoWhileStatement"||_parent6.type==="CatchClause"&&!_parentParent.finalizer)){return"{}";}parts.push("{");// Babel 6
if(hasDirectives){path.each(function(childPath){parts.push(indent$2(concat$2([hardline$2,print(childPath),semi])));if(util$5.isNextLineEmpty(options.originalText,childPath.getValue())){parts.push(hardline$2);}},"directives");}if(hasContent){parts.push(indent$2(concat$2([hardline$2,naked])));}parts.push(comments$3.printDanglingComments(path,options));parts.push(hardline$2,"}");return concat$2(parts);}case"ReturnStatement":parts.push("return");if(n.argument){if(returnArgumentHasLeadingComment(options,n.argument)){parts.push(concat$2([" (",indent$2(concat$2([softline$1,path.call(print,"argument")])),line$1,")"]));}else if(n.argument.type==="LogicalExpression"||n.argument.type==="BinaryExpression"||n.argument.type==="SequenceExpression"){parts.push(group$1(concat$2([ifBreak$1(" ("," "),indent$2(concat$2([softline$1,path.call(print,"argument")])),softline$1,ifBreak$1(")")])));}else{parts.push(" ",path.call(print,"argument"));}}if(hasDanglingComments(n)){parts.push(" ",comments$3.printDanglingComments(path,options,/* sameIndent */true));}parts.push(semi);return concat$2(parts);case"NewExpression":case"CallExpression":{var isNew=n.type==="NewExpression";var unitTestRe=/^(f|x)?(it|describe|test)$/;var isTestDeclaration=!isNew&&(n.callee.type==="Identifier"&&unitTestRe.test(n.callee.name)||n.callee.type==="MemberExpression"&&n.callee.object.type==="Identifier"&&n.callee.property.type==="Identifier"&&unitTestRe.test(n.callee.object.name)&&(n.callee.property.name==="only"||n.callee.property.name==="skip"))&&n.arguments.length===2&&(n.arguments[0].type==="StringLiteral"||n.arguments[0].type==="TemplateLiteral"||n.arguments[0].type==="Literal"&&typeof n.arguments[0].value==="string")&&(n.arguments[1].type==="FunctionExpression"||n.arguments[1].type==="ArrowFunctionExpression")&&n.arguments[1].params.length<=1;var optional=printOptionalToken(path);if(// We want to keep require calls as a unit
if(hasDirectives){path.each(function(childPath){parts.push(indent$2(concat$2([hardline$2,print(childPath),semi])));if(util$5.isNextLineEmpty(options.originalText,childPath.getValue())){parts.push(hardline$2);}},"directives");}if(hasContent){parts.push(indent$2(concat$2([hardline$2,naked])));}parts.push(comments$3.printDanglingComments(path,options));parts.push(hardline$2,"}");return concat$2(parts);}case"ReturnStatement":parts.push("return");if(n.argument){if(returnArgumentHasLeadingComment(options,n.argument)){parts.push(concat$2([" (",indent$2(concat$2([softline$1,path.call(print,"argument")])),line$1,")"]));}else if(n.argument.type==="LogicalExpression"||n.argument.type==="BinaryExpression"||n.argument.type==="SequenceExpression"){parts.push(group$1(concat$2([ifBreak$1(" ("," "),indent$2(concat$2([softline$1,path.call(print,"argument")])),softline$1,ifBreak$1(")")])));}else{parts.push(" ",path.call(print,"argument"));}}if(hasDanglingComments(n)){parts.push(" ",comments$3.printDanglingComments(path,options,/* sameIndent */true));}parts.push(semi);return concat$2(parts);case"NewExpression":case"CallExpression":{var isNew=n.type==="NewExpression";var unitTestRe=/^(f|x)?(it|describe|test)$/;var optional=printOptionalToken(path);if(// We want to keep require calls as a unit
!isNew&&n.callee.type==="Identifier"&&n.callee.name==="require"||n.callee.type==="Import"||// Template literals as single arguments
n.arguments.length===1&&isTemplateOnItsOwnLine(n.arguments[0],options.originalText)||// Keep test declarations on a single line
// e.g. `it('long name', () => {`
isTestDeclaration){var printedArgs=path.map(print,"arguments");if(isTestDeclaration){printedArgs=printedArgs.map(docUtils.removeLines);}return concat$2([isNew?"new ":"",path.call(print,"callee"),optional,path.call(print,"typeParameters"),concat$2(["(",join$2(", ",printedArgs),")"])]);}// We detect calls on member lookups and possibly print them in a
!isNew&&(n.callee.type==="Identifier"&&unitTestRe.test(n.callee.name)||n.callee.type==="MemberExpression"&&n.callee.object.type==="Identifier"&&n.callee.property.type==="Identifier"&&unitTestRe.test(n.callee.object.name)&&(n.callee.property.name==="only"||n.callee.property.name==="skip"))&&n.arguments.length===2&&(n.arguments[0].type==="StringLiteral"||n.arguments[0].type==="TemplateLiteral"||n.arguments[0].type==="Literal"&&typeof n.arguments[0].value==="string")&&(n.arguments[1].type==="FunctionExpression"||n.arguments[1].type==="ArrowFunctionExpression")&&n.arguments[1].params.length<=1){return concat$2([isNew?"new ":"",path.call(print,"callee"),optional,path.call(print,"typeParameters"),concat$2(["(",join$2(", ",path.map(print,"arguments")),")"])]);}// We detect calls on member lookups and possibly print them in a
// special chain format. See `printMemberChain` for more info.
if(!isNew&&isMemberish(n.callee)){return printMemberChain(path,options,print);}return concat$2([isNew?"new ":"",path.call(print,"callee"),optional,printFunctionTypeParameters(path,options,print),printArgumentsList(path,options,print)]);}case"TSInterfaceDeclaration":if(isNodeStartingWithDeclare(n,options)){parts.push("declare ");}parts.push(n.abstract?"abstract ":"",printTypeScriptModifiers(path,options,print),"interface ",path.call(print,"id"),n.typeParameters?path.call(print,"typeParameters"):""," ");if(n.heritage.length){parts.push(group$1(indent$2(concat$2([softline$1,"extends ",indent$2(join$2(concat$2([",",line$1]),path.map(print,"heritage")))," "]))));}parts.push(path.call(print,"body"));return concat$2(parts);case"ObjectExpression":case"ObjectPattern":case"ObjectTypeAnnotation":case"TSInterfaceBody":case"TSTypeLiteral":{var isTypeAnnotation=n.type==="ObjectTypeAnnotation";var shouldBreak=n.type==="TSInterfaceBody"||n.type!=="ObjectPattern"&&util$5.hasNewlineInRange(options.originalText,util$5.locStart(n),util$5.locEnd(n));var _parent7=path.getParentNode(0);var isFlowInterfaceLikeBody=isTypeAnnotation&&_parent7&&(_parent7.type==="InterfaceDeclaration"||_parent7.type==="DeclareInterface"||_parent7.type==="DeclareClass")&&path.getName()==="body";var separator=isFlowInterfaceLikeBody?";":n.type==="TSInterfaceBody"||n.type==="TSTypeLiteral"?ifBreak$1(semi,";"):",";var fields=[];var leftBrace=n.exact?"{|":"{";var rightBrace=n.exact?"|}":"}";var propertiesField=void 0;if(n.type==="TSTypeLiteral"){propertiesField="members";}else if(n.type==="TSInterfaceBody"){propertiesField="body";}else{propertiesField="properties";}if(isTypeAnnotation){fields.push("indexers","callProperties");}fields.push(propertiesField);// Unfortunately, things are grouped together in the ast can be
// interleaved in the source code. So we need to reorder them before