Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-formatter

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-formatter - npm Package Compare versions

Comparing version 10.8.0-beta.3 to 10.8.0-beta.4

49

lib/formatter/ExpressionFormatter.js

@@ -21,3 +21,3 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

import { equalizeWhitespace } from "../utils";
import { equalizeWhitespace, isMultiline } from "../utils";
import { isTabularStyle } from "./config";

@@ -141,4 +141,4 @@ import { TokenType } from "../lexer/token";

this.withComments(node.name, function () {
_this.layout.add(_this.showKw(node.name));
this.withComments(node.nameKw, function () {
_this.layout.add(_this.showKw(node.nameKw));
});

@@ -196,5 +196,5 @@ this.formatNode(node.parenthesis);

value: function formatBetweenPredicate(node) {
this.layout.add(this.showKw(node.between), WS.SPACE);
this.layout.add(this.showKw(node.betweenKw), WS.SPACE);
this.layout = this.formatSubExpression(node.expr1);
this.layout.add(WS.NO_SPACE, WS.SPACE, this.showNonTabularKw(node.and), WS.SPACE);
this.layout.add(WS.NO_SPACE, WS.SPACE, this.showNonTabularKw(node.andKw), WS.SPACE);
this.layout = this.formatSubExpression(node.expr2);

@@ -206,3 +206,3 @@ this.layout.add(WS.SPACE);

value: function formatCaseExpression(node) {
this.formatNode(node["case"]);
this.formatNode(node.caseKw);
this.layout = this.formatSubExpression(node.expr);

@@ -213,3 +213,3 @@ this.layout.indentation.increaseBlockLevel();

this.layout.add(WS.NEWLINE, WS.INDENT);
this.formatNode(node.end);
this.formatNode(node.endKw);
}

@@ -220,5 +220,5 @@ }, {

this.layout.add(WS.NEWLINE, WS.INDENT);
this.formatNode(node.when);
this.formatNode(node.whenKw);
this.layout = this.formatSubExpression(node.condition);
this.formatNode(node.then);
this.formatNode(node.thenKw);
this.layout = this.formatSubExpression(node.result);

@@ -230,3 +230,3 @@ }

this.layout.add(WS.NEWLINE, WS.INDENT);
this.formatNode(node["else"]);
this.formatNode(node.elseKw);
this.layout = this.formatSubExpression(node.result);

@@ -238,5 +238,5 @@ }

if (isTabularStyle(this.cfg)) {
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.name), WS.SPACE);
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.nameKw), WS.SPACE);
} else {
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.name), WS.NEWLINE);
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.nameKw), WS.NEWLINE);
}

@@ -256,3 +256,3 @@

value: function formatSetOperation(node) {
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.name), WS.NEWLINE);
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.nameKw), WS.NEWLINE);
this.layout.add(WS.INDENT);

@@ -266,4 +266,4 @@ this.layout = this.formatSubExpression(node.children);

this.withComments(node.name, function () {
_this3.layout.add(WS.NEWLINE, WS.INDENT, _this3.showKw(node.name));
this.withComments(node.limitKw, function () {
_this3.layout.add(WS.NEWLINE, WS.INDENT, _this3.showKw(node.limitKw));
});

@@ -369,3 +369,3 @@ this.layout.indentation.increaseTopLevel();

value: function formatLineComment(node) {
if (/\n/.test(node.precedingWhitespace || '')) {
if (isMultiline(node.precedingWhitespace || '')) {
this.layout.add(WS.NEWLINE, WS.INDENT, node.text, WS.MANDATORY_NEWLINE, WS.INDENT);

@@ -381,6 +381,15 @@ } else {

this.splitBlockComment(node.text).forEach(function (line) {
_this5.layout.add(WS.NEWLINE, WS.INDENT, line);
});
this.layout.add(WS.NEWLINE, WS.INDENT);
if (this.isMultilineBlockComment(node)) {
this.splitBlockComment(node.text).forEach(function (line) {
_this5.layout.add(WS.NEWLINE, WS.INDENT, line);
});
this.layout.add(WS.NEWLINE, WS.INDENT);
} else {
this.layout.add(node.text, WS.SPACE);
}
}
}, {
key: "isMultilineBlockComment",
value: function isMultilineBlockComment(node) {
return isMultiline(node.text) || isMultiline(node.precedingWhitespace || '');
} // Breaks up block comment to multiple lines.

@@ -387,0 +396,0 @@ // For example this comment (dots representing leading whitespace):

@@ -66,12 +66,19 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

var addLeadingComments = function addLeadingComments(node, comments) {
return comments.length > 0 ? _objectSpread(_objectSpread({}, node), {}, {
leadingComments: comments
}) : node;
};
var addComments = function addComments(node, _ref3) {
var leading = _ref3.leading,
trailing = _ref3.trailing;
var addTrailingComments = function addTrailingComments(node, comments) {
return comments.length > 0 ? _objectSpread(_objectSpread({}, node), {}, {
trailingComments: comments
}) : node;
if (leading !== null && leading !== void 0 && leading.length) {
node = _objectSpread(_objectSpread({}, node), {}, {
leadingComments: leading
});
}
if (trailing !== null && trailing !== void 0 && trailing.length) {
node = _objectSpread(_objectSpread({}, node), {}, {
trailingComments: trailing
});
}
return node;
};

@@ -97,5 +104,5 @@

"symbols": ["main$ebnf$1"],
"postprocess": function postprocess(_ref3) {
var _ref4 = _slicedToArray(_ref3, 1),
statements = _ref4[0];
"postprocess": function postprocess(_ref4) {
var _ref5 = _slicedToArray(_ref4, 1),
statements = _ref5[0];

@@ -126,7 +133,7 @@ var last = statements[statements.length - 1];

"symbols": ["expressions_or_clauses", "statement$subexpression$1"],
"postprocess": function postprocess(_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
children = _ref6[0],
_ref6$ = _slicedToArray(_ref6[1], 1),
delimiter = _ref6$[0];
"postprocess": function postprocess(_ref6) {
var _ref7 = _slicedToArray(_ref6, 2),
children = _ref7[0],
_ref7$ = _slicedToArray(_ref7[1], 1),
delimiter = _ref7$[0];

@@ -144,3 +151,3 @@ return {

"name": "expressions_or_clauses$ebnf$1",
"symbols": ["expressions_or_clauses$ebnf$1", "expression"],
"symbols": ["expressions_or_clauses$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -161,6 +168,6 @@ return d[0].concat([d[1]]);

"symbols": ["expressions_or_clauses$ebnf$1", "expressions_or_clauses$ebnf$2"],
"postprocess": function postprocess(_ref7) {
var _ref8 = _slicedToArray(_ref7, 2),
expressions = _ref8[0],
clauses = _ref8[1];
"postprocess": function postprocess(_ref8) {
var _ref9 = _slicedToArray(_ref8, 2),
expressions = _ref9[0],
clauses = _ref9[1];

@@ -186,7 +193,7 @@ return [].concat(_toConsumableArray(expressions), _toConsumableArray(clauses));

}, {
"name": "limit_clause$ebnf$1",
"symbols": ["expression_with_comments"]
"name": "limit_clause$ebnf$1$subexpression$1$ebnf$1",
"symbols": ["free_form_sql"]
}, {
"name": "limit_clause$ebnf$1",
"symbols": ["limit_clause$ebnf$1", "expression_with_comments"],
"name": "limit_clause$ebnf$1$subexpression$1$ebnf$1",
"symbols": ["limit_clause$ebnf$1$subexpression$1$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -196,21 +203,12 @@ return d[0].concat([d[1]]);

}, {
"name": "limit_clause$ebnf$2$subexpression$1$ebnf$1",
"symbols": ["expression"]
}, {
"name": "limit_clause$ebnf$2$subexpression$1$ebnf$1",
"symbols": ["limit_clause$ebnf$2$subexpression$1$ebnf$1", "expression"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "limit_clause$ebnf$2$subexpression$1",
"name": "limit_clause$ebnf$1$subexpression$1",
"symbols": [lexer.has("COMMA") ? {
type: "COMMA"
} : COMMA, "limit_clause$ebnf$2$subexpression$1$ebnf$1"]
} : COMMA, "limit_clause$ebnf$1$subexpression$1$ebnf$1"]
}, {
"name": "limit_clause$ebnf$2",
"symbols": ["limit_clause$ebnf$2$subexpression$1"],
"name": "limit_clause$ebnf$1",
"symbols": ["limit_clause$ebnf$1$subexpression$1"],
"postprocess": id
}, {
"name": "limit_clause$ebnf$2",
"name": "limit_clause$ebnf$1",
"symbols": [],

@@ -224,9 +222,9 @@ "postprocess": function postprocess() {

type: "LIMIT"
} : LIMIT, "_", "limit_clause$ebnf$1", "limit_clause$ebnf$2"],
"postprocess": function postprocess(_ref9) {
var _ref10 = _slicedToArray(_ref9, 4),
limitToken = _ref10[0],
_ = _ref10[1],
exp1 = _ref10[2],
optional = _ref10[3];
} : LIMIT, "_", "expression_chain_", "limit_clause$ebnf$1"],
"postprocess": function postprocess(_ref10) {
var _ref11 = _slicedToArray(_ref10, 4),
limitToken = _ref11[0],
_ = _ref11[1],
exp1 = _ref11[2],
optional = _ref11[3];

@@ -240,3 +238,5 @@ if (optional) {

type: NodeType.limit_clause,
name: addTrailingComments(toKeywordNode(limitToken), _),
limitKw: addComments(toKeywordNode(limitToken), {
trailing: _
}),
offset: exp1,

@@ -248,3 +248,5 @@ count: exp2

type: NodeType.limit_clause,
name: addTrailingComments(toKeywordNode(limitToken), _),
limitKw: addComments(toKeywordNode(limitToken), {
trailing: _
}),
count: exp1

@@ -259,3 +261,3 @@ };

"name": "select_clause$subexpression$1$ebnf$1",
"symbols": ["select_clause$subexpression$1$ebnf$1", "expression"],
"symbols": ["select_clause$subexpression$1$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -272,3 +274,3 @@ return d[0].concat([d[1]]);

"name": "select_clause$subexpression$1$ebnf$2",
"symbols": ["select_clause$subexpression$1$ebnf$2", "expression"],
"symbols": ["select_clause$subexpression$1$ebnf$2", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -279,3 +281,3 @@ return d[0].concat([d[1]]);

"name": "select_clause$subexpression$1",
"symbols": ["asteriskless_expression", "select_clause$subexpression$1$ebnf$2"]
"symbols": ["asteriskless_free_form_sql", "select_clause$subexpression$1$ebnf$2"]
}, {

@@ -286,12 +288,12 @@ "name": "select_clause",

} : RESERVED_SELECT, "select_clause$subexpression$1"],
"postprocess": function postprocess(_ref11) {
var _ref12 = _slicedToArray(_ref11, 2),
nameToken = _ref12[0],
_ref12$ = _slicedToArray(_ref12[1], 2),
exp = _ref12$[0],
expressions = _ref12$[1];
"postprocess": function postprocess(_ref12) {
var _ref13 = _slicedToArray(_ref12, 2),
nameToken = _ref13[0],
_ref13$ = _slicedToArray(_ref13[1], 2),
exp = _ref13$[0],
expressions = _ref13$[1];
return {
type: NodeType.clause,
name: toKeywordNode(nameToken),
nameKw: toKeywordNode(nameToken),
children: [exp].concat(_toConsumableArray(expressions))

@@ -305,5 +307,5 @@ };

} : RESERVED_SELECT],
"postprocess": function postprocess(_ref13) {
var _ref14 = _slicedToArray(_ref13, 1),
nameToken = _ref14[0];
"postprocess": function postprocess(_ref14) {
var _ref15 = _slicedToArray(_ref14, 1),
nameToken = _ref15[0];

@@ -331,3 +333,3 @@ return {

"name": "other_clause$ebnf$1",
"symbols": ["other_clause$ebnf$1", "expression"],
"symbols": ["other_clause$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -341,10 +343,10 @@ return d[0].concat([d[1]]);

} : RESERVED_COMMAND, "other_clause$ebnf$1"],
"postprocess": function postprocess(_ref15) {
var _ref16 = _slicedToArray(_ref15, 2),
nameToken = _ref16[0],
children = _ref16[1];
"postprocess": function postprocess(_ref16) {
var _ref17 = _slicedToArray(_ref16, 2),
nameToken = _ref17[0],
children = _ref17[1];
return {
type: NodeType.clause,
name: toKeywordNode(nameToken),
nameKw: toKeywordNode(nameToken),
children: children

@@ -358,3 +360,3 @@ };

"name": "set_operation$ebnf$1",
"symbols": ["set_operation$ebnf$1", "expression"],
"symbols": ["set_operation$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -368,10 +370,10 @@ return d[0].concat([d[1]]);

} : RESERVED_SET_OPERATION, "set_operation$ebnf$1"],
"postprocess": function postprocess(_ref17) {
var _ref18 = _slicedToArray(_ref17, 2),
nameToken = _ref18[0],
children = _ref18[1];
"postprocess": function postprocess(_ref18) {
var _ref19 = _slicedToArray(_ref18, 2),
nameToken = _ref19[0],
children = _ref19[1];
return {
type: NodeType.set_operation,
name: toKeywordNode(nameToken),
nameKw: toKeywordNode(nameToken),
children: children

@@ -381,89 +383,104 @@ };

}, {
"name": "expression_with_comments",
"symbols": ["simple_expression", "_"],
"postprocess": function postprocess(_ref19) {
var _ref20 = _slicedToArray(_ref19, 2),
expr = _ref20[0],
_ = _ref20[1];
"name": "expression_chain_$ebnf$1",
"symbols": ["expression_with_comments_"]
}, {
"name": "expression_chain_$ebnf$1",
"symbols": ["expression_chain_$ebnf$1", "expression_with_comments_"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "expression_chain_",
"symbols": ["expression_chain_$ebnf$1"],
"postprocess": id
}, {
"name": "expression_with_comments_",
"symbols": ["expression", "_"],
"postprocess": function postprocess(_ref20) {
var _ref21 = _slicedToArray(_ref20, 2),
expr = _ref21[0],
_ = _ref21[1];
return addTrailingComments(expr, _);
return addComments(expr, {
trailing: _
});
}
}, {
"name": "expression$subexpression$1",
"symbols": ["asteriskless_expression"]
"name": "free_form_sql$subexpression$1",
"symbols": ["asteriskless_free_form_sql"]
}, {
"name": "expression$subexpression$1",
"name": "free_form_sql$subexpression$1",
"symbols": ["asterisk"]
}, {
"name": "expression",
"symbols": ["expression$subexpression$1"],
"name": "free_form_sql",
"symbols": ["free_form_sql$subexpression$1"],
"postprocess": unwrap
}, {
"name": "asteriskless_expression$subexpression$1",
"symbols": ["simple_expression_without_asterisk"]
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["asteriskless_expression"]
}, {
"name": "asteriskless_expression$subexpression$1",
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["between_predicate"]
}, {
"name": "asteriskless_expression$subexpression$1",
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["case_expression"]
}, {
"name": "asteriskless_expression$subexpression$1",
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["comma"]
}, {
"name": "asteriskless_expression$subexpression$1",
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["comment"]
}, {
"name": "asteriskless_expression$subexpression$1",
"name": "asteriskless_free_form_sql$subexpression$1",
"symbols": ["other_keyword"]
}, {
"name": "asteriskless_expression",
"symbols": ["asteriskless_expression$subexpression$1"],
"name": "asteriskless_free_form_sql",
"symbols": ["asteriskless_free_form_sql$subexpression$1"],
"postprocess": unwrap
}, {
"name": "simple_expression$subexpression$1",
"symbols": ["simple_expression_without_asterisk"]
"name": "expression$subexpression$1",
"symbols": ["asteriskless_expression"]
}, {
"name": "simple_expression$subexpression$1",
"name": "expression$subexpression$1",
"symbols": ["asterisk"]
}, {
"name": "simple_expression",
"symbols": ["simple_expression$subexpression$1"],
"name": "expression",
"symbols": ["expression$subexpression$1"],
"postprocess": unwrap
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["array_subscript"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["function_call"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["property_access"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["parenthesis"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["curly_braces"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["square_brackets"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["operator"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["identifier"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["parameter"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["literal"]
}, {
"name": "simple_expression_without_asterisk$subexpression$1",
"name": "asteriskless_expression$subexpression$1",
"symbols": ["keyword"]
}, {
"name": "simple_expression_without_asterisk",
"symbols": ["simple_expression_without_asterisk$subexpression$1"],
"name": "asteriskless_expression",
"symbols": ["asteriskless_expression$subexpression$1"],
"postprocess": unwrap

@@ -475,14 +492,16 @@ }, {

} : ARRAY_IDENTIFIER, "_", "square_brackets"],
"postprocess": function postprocess(_ref21) {
var _ref22 = _slicedToArray(_ref21, 3),
arrayToken = _ref22[0],
_ = _ref22[1],
brackets = _ref22[2];
"postprocess": function postprocess(_ref22) {
var _ref23 = _slicedToArray(_ref22, 3),
arrayToken = _ref23[0],
_ = _ref23[1],
brackets = _ref23[2];
return {
type: NodeType.array_subscript,
array: addTrailingComments({
array: addComments({
type: NodeType.identifier,
text: arrayToken.text
}, _),
}, {
trailing: _
}),
parenthesis: brackets

@@ -496,11 +515,13 @@ };

} : ARRAY_KEYWORD, "_", "square_brackets"],
"postprocess": function postprocess(_ref23) {
var _ref24 = _slicedToArray(_ref23, 3),
arrayToken = _ref24[0],
_ = _ref24[1],
brackets = _ref24[2];
"postprocess": function postprocess(_ref24) {
var _ref25 = _slicedToArray(_ref24, 3),
arrayToken = _ref25[0],
_ = _ref25[1],
brackets = _ref25[2];
return {
type: NodeType.array_subscript,
array: addTrailingComments(toKeywordNode(arrayToken), _),
array: addComments(toKeywordNode(arrayToken), {
trailing: _
}),
parenthesis: brackets

@@ -514,11 +535,13 @@ };

} : RESERVED_FUNCTION_NAME, "_", "parenthesis"],
"postprocess": function postprocess(_ref25) {
var _ref26 = _slicedToArray(_ref25, 3),
nameToken = _ref26[0],
_ = _ref26[1],
parens = _ref26[2];
"postprocess": function postprocess(_ref26) {
var _ref27 = _slicedToArray(_ref26, 3),
nameToken = _ref27[0],
_ = _ref27[1],
parens = _ref27[2];
return {
type: NodeType.function_call,
name: addTrailingComments(toKeywordNode(nameToken), _),
nameKw: addComments(toKeywordNode(nameToken), {
trailing: _
}),
parenthesis: parens

@@ -534,7 +557,7 @@ };

}],
"postprocess": function postprocess(_ref27) {
var _ref28 = _slicedToArray(_ref27, 3),
open = _ref28[0],
children = _ref28[1],
close = _ref28[2];
"postprocess": function postprocess(_ref28) {
var _ref29 = _slicedToArray(_ref28, 3),
open = _ref29[0],
children = _ref29[1],
close = _ref29[2];

@@ -553,3 +576,3 @@ return {

"name": "curly_braces$ebnf$1",
"symbols": ["curly_braces$ebnf$1", "expression"],
"symbols": ["curly_braces$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -565,7 +588,7 @@ return d[0].concat([d[1]]);

}],
"postprocess": function postprocess(_ref29) {
var _ref30 = _slicedToArray(_ref29, 3),
open = _ref30[0],
children = _ref30[1],
close = _ref30[2];
"postprocess": function postprocess(_ref30) {
var _ref31 = _slicedToArray(_ref30, 3),
open = _ref31[0],
children = _ref31[1],
close = _ref31[2];

@@ -584,3 +607,3 @@ return {

"name": "square_brackets$ebnf$1",
"symbols": ["square_brackets$ebnf$1", "expression"],
"symbols": ["square_brackets$ebnf$1", "free_form_sql"],
"postprocess": function postprocess(d) {

@@ -596,7 +619,7 @@ return d[0].concat([d[1]]);

}],
"postprocess": function postprocess(_ref31) {
var _ref32 = _slicedToArray(_ref31, 3),
open = _ref32[0],
children = _ref32[1],
close = _ref32[2];
"postprocess": function postprocess(_ref32) {
var _ref33 = _slicedToArray(_ref32, 3),
open = _ref33[0],
children = _ref33[1],
close = _ref33[2];

@@ -621,3 +644,3 @@ return {

"name": "property_access",
"symbols": ["simple_expression", "_", lexer.has("DOT") ? {
"symbols": ["expression", "_", lexer.has("DOT") ? {
type: "DOT"

@@ -629,15 +652,19 @@ } : DOT, "_", "property_access$subexpression$1"],

// %ARRAY_IDENTIFIER on the left side of <array_subscript>.
function postprocess(_ref33) {
var _ref34 = _slicedToArray(_ref33, 5),
object = _ref34[0],
_1 = _ref34[1],
dot = _ref34[2],
_2 = _ref34[3],
_ref34$ = _slicedToArray(_ref34[4], 1),
property = _ref34$[0];
function postprocess(_ref34) {
var _ref35 = _slicedToArray(_ref34, 5),
object = _ref35[0],
_1 = _ref35[1],
dot = _ref35[2],
_2 = _ref35[3],
_ref35$ = _slicedToArray(_ref35[4], 1),
property = _ref35$[0];
return {
type: NodeType.property_access,
object: addTrailingComments(object, _1),
property: addLeadingComments(property, _2)
object: addComments(object, {
trailing: _1
}),
property: addComments(property, {
leading: _2
})
};

@@ -649,21 +676,26 @@ }

type: "BETWEEN"
} : BETWEEN, "_", "simple_expression", "_", lexer.has("AND") ? {
} : BETWEEN, "_", "expression", "_", lexer.has("AND") ? {
type: "AND"
} : AND, "_", "simple_expression"],
"postprocess": function postprocess(_ref35) {
var _ref36 = _slicedToArray(_ref35, 7),
betweenToken = _ref36[0],
_1 = _ref36[1],
expr1 = _ref36[2],
_2 = _ref36[3],
andToken = _ref36[4],
_3 = _ref36[5],
expr2 = _ref36[6];
} : AND, "_", "expression"],
"postprocess": function postprocess(_ref36) {
var _ref37 = _slicedToArray(_ref36, 7),
betweenToken = _ref37[0],
_1 = _ref37[1],
expr1 = _ref37[2],
_2 = _ref37[3],
andToken = _ref37[4],
_3 = _ref37[5],
expr2 = _ref37[6];
return {
type: NodeType.between_predicate,
between: toKeywordNode(betweenToken),
expr1: [addTrailingComments(addLeadingComments(expr1, _1), _2)],
and: toKeywordNode(andToken),
expr2: [addLeadingComments(expr2, _3)]
betweenKw: toKeywordNode(betweenToken),
expr1: [addComments(expr1, {
leading: _1,
trailing: _2
})],
andKw: toKeywordNode(andToken),
expr2: [addComments(expr2, {
leading: _3
})]
};

@@ -673,8 +705,9 @@ }

"name": "case_expression$ebnf$1",
"symbols": []
"symbols": ["expression_chain_"],
"postprocess": id
}, {
"name": "case_expression$ebnf$1",
"symbols": ["case_expression$ebnf$1", "simple_expression"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
"symbols": [],
"postprocess": function postprocess() {
return null;
}

@@ -694,19 +727,20 @@ }, {

type: "CASE"
} : CASE, "_", "case_expression$ebnf$1", "case_expression$ebnf$2", "_", lexer.has("END") ? {
} : CASE, "_", "case_expression$ebnf$1", "case_expression$ebnf$2", lexer.has("END") ? {
type: "END"
} : END],
"postprocess": function postprocess(_ref37) {
var _ref38 = _slicedToArray(_ref37, 6),
caseToken = _ref38[0],
_1 = _ref38[1],
expr = _ref38[2],
clauses = _ref38[3],
_2 = _ref38[4],
endToken = _ref38[5];
"postprocess": function postprocess(_ref38) {
var _ref39 = _slicedToArray(_ref38, 5),
caseToken = _ref39[0],
_ = _ref39[1],
expr = _ref39[2],
clauses = _ref39[3],
endToken = _ref39[4];
return {
type: NodeType.case_expression,
"case": addTrailingComments(toKeywordNode(caseToken), _1),
end: addLeadingComments(toKeywordNode(endToken), _2),
expr: expr,
caseKw: addComments(toKeywordNode(caseToken), {
trailing: _
}),
endKw: toKeywordNode(endToken),
expr: expr || [],
clauses: clauses

@@ -716,41 +750,25 @@ };

}, {
"name": "case_clause$ebnf$1",
"symbols": ["simple_expression"]
}, {
"name": "case_clause$ebnf$1",
"symbols": ["case_clause$ebnf$1", "simple_expression"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "case_clause$ebnf$2",
"symbols": ["simple_expression"]
}, {
"name": "case_clause$ebnf$2",
"symbols": ["case_clause$ebnf$2", "simple_expression"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "case_clause",
"symbols": ["_", lexer.has("WHEN") ? {
"symbols": [lexer.has("WHEN") ? {
type: "WHEN"
} : WHEN, "_", "case_clause$ebnf$1", "_", lexer.has("THEN") ? {
} : WHEN, "_", "expression_chain_", lexer.has("THEN") ? {
type: "THEN"
} : THEN, "_", "case_clause$ebnf$2"],
"postprocess": function postprocess(_ref39) {
var _ref40 = _slicedToArray(_ref39, 8),
_1 = _ref40[0],
whenToken = _ref40[1],
_2 = _ref40[2],
cond = _ref40[3],
_3 = _ref40[4],
thenToken = _ref40[5],
_4 = _ref40[6],
expr = _ref40[7];
} : THEN, "_", "expression_chain_"],
"postprocess": function postprocess(_ref40) {
var _ref41 = _slicedToArray(_ref40, 6),
whenToken = _ref41[0],
_1 = _ref41[1],
cond = _ref41[2],
thenToken = _ref41[3],
_2 = _ref41[4],
expr = _ref41[5];
return {
type: NodeType.case_when,
when: addTrailingComments(addLeadingComments(toKeywordNode(whenToken), _1), _2),
then: addTrailingComments(addLeadingComments(toKeywordNode(thenToken), _3), _4),
whenKw: addComments(toKeywordNode(whenToken), {
trailing: _1
}),
thenKw: addComments(toKeywordNode(thenToken), {
trailing: _2
}),
condition: cond,

@@ -761,25 +779,17 @@ result: expr

}, {
"name": "case_clause$ebnf$3",
"symbols": ["simple_expression"]
}, {
"name": "case_clause$ebnf$3",
"symbols": ["case_clause$ebnf$3", "simple_expression"],
"postprocess": function postprocess(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "case_clause",
"symbols": ["_", lexer.has("ELSE") ? {
"symbols": [lexer.has("ELSE") ? {
type: "ELSE"
} : ELSE, "_", "case_clause$ebnf$3"],
"postprocess": function postprocess(_ref41) {
var _ref42 = _slicedToArray(_ref41, 4),
_1 = _ref42[0],
elseToken = _ref42[1],
_2 = _ref42[2],
expr = _ref42[3];
} : ELSE, "_", "expression_chain_"],
"postprocess": function postprocess(_ref42) {
var _ref43 = _slicedToArray(_ref42, 3),
elseToken = _ref43[0],
_ = _ref43[1],
expr = _ref43[2];
return {
type: NodeType.case_else,
"else": addTrailingComments(addLeadingComments(toKeywordNode(elseToken), _1), _2),
elseKw: addComments(toKeywordNode(elseToken), {
trailing: _
}),
result: expr

@@ -796,6 +806,6 @@ };

"symbols": ["comma$subexpression$1"],
"postprocess": function postprocess(_ref43) {
var _ref44 = _slicedToArray(_ref43, 1),
_ref44$ = _slicedToArray(_ref44[0], 1),
token = _ref44$[0];
"postprocess": function postprocess(_ref44) {
var _ref45 = _slicedToArray(_ref44, 1),
_ref45$ = _slicedToArray(_ref45[0], 1),
token = _ref45$[0];

@@ -814,6 +824,6 @@ return {

"symbols": ["asterisk$subexpression$1"],
"postprocess": function postprocess(_ref45) {
var _ref46 = _slicedToArray(_ref45, 1),
_ref46$ = _slicedToArray(_ref46[0], 1),
token = _ref46$[0];
"postprocess": function postprocess(_ref46) {
var _ref47 = _slicedToArray(_ref46, 1),
_ref47$ = _slicedToArray(_ref47[0], 1),
token = _ref47$[0];

@@ -833,6 +843,6 @@ return {

"symbols": ["operator$subexpression$1"],
"postprocess": function postprocess(_ref47) {
var _ref48 = _slicedToArray(_ref47, 1),
_ref48$ = _slicedToArray(_ref48[0], 1),
token = _ref48$[0];
"postprocess": function postprocess(_ref48) {
var _ref49 = _slicedToArray(_ref48, 1),
_ref49$ = _slicedToArray(_ref49[0], 1),
token = _ref49$[0];

@@ -862,6 +872,6 @@ return {

"symbols": ["identifier$subexpression$1"],
"postprocess": function postprocess(_ref49) {
var _ref50 = _slicedToArray(_ref49, 1),
_ref50$ = _slicedToArray(_ref50[0], 1),
token = _ref50$[0];
"postprocess": function postprocess(_ref50) {
var _ref51 = _slicedToArray(_ref50, 1),
_ref51$ = _slicedToArray(_ref51[0], 1),
token = _ref51$[0];

@@ -896,6 +906,6 @@ return {

"symbols": ["parameter$subexpression$1"],
"postprocess": function postprocess(_ref51) {
var _ref52 = _slicedToArray(_ref51, 1),
_ref52$ = _slicedToArray(_ref52[0], 1),
token = _ref52$[0];
"postprocess": function postprocess(_ref52) {
var _ref53 = _slicedToArray(_ref52, 1),
_ref53$ = _slicedToArray(_ref53[0], 1),
token = _ref53$[0];

@@ -921,6 +931,6 @@ return {

"symbols": ["literal$subexpression$1"],
"postprocess": function postprocess(_ref53) {
var _ref54 = _slicedToArray(_ref53, 1),
_ref54$ = _slicedToArray(_ref54[0], 1),
token = _ref54$[0];
"postprocess": function postprocess(_ref54) {
var _ref55 = _slicedToArray(_ref54, 1),
_ref55$ = _slicedToArray(_ref55[0], 1),
token = _ref55$[0];

@@ -965,6 +975,6 @@ return {

"symbols": ["keyword$subexpression$1"],
"postprocess": function postprocess(_ref55) {
var _ref56 = _slicedToArray(_ref55, 1),
_ref56$ = _slicedToArray(_ref56[0], 1),
token = _ref56$[0];
"postprocess": function postprocess(_ref56) {
var _ref57 = _slicedToArray(_ref56, 1),
_ref57$ = _slicedToArray(_ref57[0], 1),
token = _ref57$[0];

@@ -996,6 +1006,6 @@ return toKeywordNode(token);

"symbols": ["other_keyword$subexpression$1"],
"postprocess": function postprocess(_ref57) {
var _ref58 = _slicedToArray(_ref57, 1),
_ref58$ = _slicedToArray(_ref58[0], 1),
token = _ref58$[0];
"postprocess": function postprocess(_ref58) {
var _ref59 = _slicedToArray(_ref58, 1),
_ref59$ = _slicedToArray(_ref59[0], 1),
token = _ref59$[0];

@@ -1016,5 +1026,5 @@ return toKeywordNode(token);

"symbols": ["_$ebnf$1"],
"postprocess": function postprocess(_ref59) {
var _ref60 = _slicedToArray(_ref59, 1),
comments = _ref60[0];
"postprocess": function postprocess(_ref60) {
var _ref61 = _slicedToArray(_ref60, 1),
comments = _ref61[0];

@@ -1028,5 +1038,5 @@ return comments;

} : LINE_COMMENT],
"postprocess": function postprocess(_ref61) {
var _ref62 = _slicedToArray(_ref61, 1),
token = _ref62[0];
"postprocess": function postprocess(_ref62) {
var _ref63 = _slicedToArray(_ref62, 1),
token = _ref63[0];

@@ -1044,9 +1054,10 @@ return {

} : BLOCK_COMMENT],
"postprocess": function postprocess(_ref63) {
var _ref64 = _slicedToArray(_ref63, 1),
token = _ref64[0];
"postprocess": function postprocess(_ref64) {
var _ref65 = _slicedToArray(_ref64, 1),
token = _ref65[0];
return {
type: NodeType.block_comment,
text: token.text
text: token.text,
precedingWhitespace: token.precedingWhitespace
};

@@ -1053,0 +1064,0 @@ }

@@ -44,2 +44,3 @@ import { FormatOptions } from "../FormatOptions";

private formatBlockComment;
private isMultilineBlockComment;
private splitBlockComment;

@@ -46,0 +47,0 @@ private formatSubExpression;

@@ -36,3 +36,3 @@ import { TokenType } from "../lexer/token";

type: NodeType.clause;
name: KeywordNode;
nameKw: KeywordNode;
children: AstNode[];

@@ -42,3 +42,3 @@ }

type: NodeType.set_operation;
name: KeywordNode;
nameKw: KeywordNode;
children: AstNode[];

@@ -48,3 +48,3 @@ }

type: NodeType.function_call;
name: KeywordNode;
nameKw: KeywordNode;
parenthesis: ParenthesisNode;

@@ -65,5 +65,5 @@ }

type: NodeType.between_predicate;
between: KeywordNode;
betweenKw: KeywordNode;
expr1: AstNode[];
and: KeywordNode;
andKw: KeywordNode;
expr2: AstNode[];

@@ -73,4 +73,4 @@ }

type: NodeType.case_expression;
case: KeywordNode;
end: KeywordNode;
caseKw: KeywordNode;
endKw: KeywordNode;
expr: AstNode[];

@@ -81,4 +81,4 @@ clauses: (CaseWhenNode | CaseElseNode)[];

type: NodeType.case_when;
when: KeywordNode;
then: KeywordNode;
whenKw: KeywordNode;
thenKw: KeywordNode;
condition: AstNode[];

@@ -89,3 +89,3 @@ result: AstNode[];

type: NodeType.case_else;
else: KeywordNode;
elseKw: KeywordNode;
result: AstNode[];

@@ -95,3 +95,3 @@ }

type: NodeType.limit_clause;
name: KeywordNode;
limitKw: KeywordNode;
count: AstNode[];

@@ -142,2 +142,3 @@ offset?: AstNode[];

text: string;
precedingWhitespace: string;
}

@@ -144,0 +145,0 @@ export declare type CommentNode = LineCommentNode | BlockCommentNode;

@@ -9,2 +9,3 @@ export declare const dedupe: (arr: string[]) => string[];

export declare const flatKeywordList: (obj: Record<string, string[]>) => string[];
export declare const isMultiline: (text: string) => boolean;
export declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

@@ -63,2 +63,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

return dedupe(Object.values(obj).flat());
}; // True when string contains multiple lines
export var isMultiline = function isMultiline(text) {
return /\n/.test(text);
}; // Given a type and a field name, returns a type where this field is optional

@@ -65,0 +69,0 @@ //

{
"name": "sql-formatter",
"version": "10.8.0-beta.3",
"version": "10.8.0-beta.4",
"description": "Format whitespace in a SQL query to make it more readable",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc