-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split source elements relative to their language. #3069
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,59 +204,73 @@ function isSourceElement(opts, node) { | |
if (node == null) { | ||
return false; | ||
} | ||
switch (node.type || node.kind) { | ||
case "ObjectExpression": // JSON | ||
case "ArrayExpression": // JSON | ||
case "StringLiteral": // JSON | ||
case "NumericLiteral": // JSON | ||
case "BooleanLiteral": // JSON | ||
case "NullLiteral": // JSON | ||
case "FunctionDeclaration": | ||
case "BlockStatement": | ||
case "BreakStatement": | ||
case "ContinueStatement": | ||
case "DebuggerStatement": | ||
case "DoWhileStatement": | ||
case "EmptyStatement": | ||
case "ExpressionStatement": | ||
case "ForInStatement": | ||
case "ForStatement": | ||
case "IfStatement": | ||
case "LabeledStatement": | ||
case "ReturnStatement": | ||
case "SwitchStatement": | ||
case "ThrowStatement": | ||
case "TryStatement": | ||
case "VariableDeclaration": | ||
case "WhileStatement": | ||
case "WithStatement": | ||
case "ClassDeclaration": // ES 2015 | ||
case "ImportDeclaration": // Module | ||
case "ExportDefaultDeclaration": // Module | ||
case "ExportNamedDeclaration": // Module | ||
case "ExportAllDeclaration": // Module | ||
case "TypeAlias": // Flow | ||
case "InterfaceDeclaration": // Flow, Typescript | ||
case "TypeAliasDeclaration": // Typescript | ||
case "ExportAssignment": // Typescript | ||
case "ExportDeclaration": // Typescript | ||
case "OperationDefinition": // GraphQL | ||
case "FragmentDefinition": // GraphQL | ||
case "VariableDefinition": // GraphQL | ||
case "TypeExtensionDefinition": // GraphQL | ||
case "ObjectTypeDefinition": // GraphQL | ||
case "FieldDefinition": // GraphQL | ||
case "DirectiveDefinition": // GraphQL | ||
case "EnumTypeDefinition": // GraphQL | ||
case "EnumValueDefinition": // GraphQL | ||
case "InputValueDefinition": // GraphQL | ||
case "InputObjectTypeDefinition": // GraphQL | ||
case "SchemaDefinition": // GraphQL | ||
case "OperationTypeDefinition": // GraphQL | ||
case "InterfaceTypeDefinition": // GraphQL | ||
case "UnionTypeDefinition": // GraphQL | ||
case "ScalarTypeDefinition": // GraphQL | ||
return true; | ||
// JS and JS like to avoid repetitions | ||
const jsSourceElements = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the rule with global variables? those |
||
"FunctionDeclaration", | ||
"BlockStatement", | ||
"BreakStatement", | ||
"ContinueStatement", | ||
"DebuggerStatement", | ||
"DoWhileStatement", | ||
"EmptyStatement", | ||
"ExpressionStatement", | ||
"ForInStatement", | ||
"ForStatement", | ||
"IfStatement", | ||
"LabeledStatement", | ||
"ReturnStatement", | ||
"SwitchStatement", | ||
"ThrowStatement", | ||
"TryStatement", | ||
"VariableDeclaration", | ||
"WhileStatement", | ||
"WithStatement", | ||
"ClassDeclaration", // ES 2015 | ||
"ImportDeclaration", // Module | ||
"ExportDefaultDeclaration", // Module | ||
"ExportNamedDeclaration", // Module | ||
"ExportAllDeclaration", // Module | ||
"TypeAlias", // Flow | ||
"InterfaceDeclaration", // Flow, Typescript | ||
"TypeAliasDeclaration", // Typescript | ||
"ExportAssignment", // Typescript | ||
"ExportDeclaration" // Typescript | ||
]; | ||
const jsonSourceElements = [ | ||
"ObjectExpression", | ||
"ArrayExpression", | ||
"StringLiteral", | ||
"NumericLiteral", | ||
"BooleanLiteral", | ||
"NullLiteral" | ||
]; | ||
const graphqlSourceElements = [ | ||
"OperationDefinition", | ||
"FragmentDefinition", | ||
"VariableDefinition", | ||
"TypeExtensionDefinition", | ||
"ObjectTypeDefinition", | ||
"FieldDefinition", | ||
"DirectiveDefinition", | ||
"EnumTypeDefinition", | ||
"EnumValueDefinition", | ||
"InputValueDefinition", | ||
"InputObjectTypeDefinition", | ||
"SchemaDefinition", | ||
"OperationTypeDefinition", | ||
"InterfaceTypeDefinition", | ||
"UnionTypeDefinition", | ||
"ScalarTypeDefinition" | ||
]; | ||
switch (opts.parser) { | ||
case "flow": | ||
case "babylon": | ||
case "typescript": | ||
return jsSourceElements.indexOf(node.type) > -1; | ||
case "json": | ||
return jsonSourceElements.indexOf(node.type) > -1; | ||
case "graphql": | ||
return graphqlSourceElements.indexOf(node.kind) > -1; | ||
} | ||
return false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const y = {<<<PRETTIER_RANGE_START>>>a:1<<<PRETTIER_RANGE_END>>>, b:2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
const y = [ | ||
{ | ||
a: 1, | ||
},<<<PRETTIER_RANGE_START>>> | ||
{ | ||
a: 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add an additional property to this object? Otherwise it could be treated as a block + label. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it's certainly clearer than trying to find a semicolon |
||
b:2 | ||
},<<<PRETTIER_RANGE_END>>> | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be "JS and TS like to avoid repetitions"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I interpreted as
JS-like
= flow, TypeScript.