Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions dist/sql-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ return /******/ (function(modules) { // webpackBootstrap

this.WHITESPACE_REGEX = /^(\s+)/;
this.NUMBER_REGEX = /^((-\s*)?[0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)\b/;
this.OPERATOR_REGEX = /^(!=|<>|==|<=|>=|!<|!>|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|.)/;
this.OPERATOR_REGEX = /^(!=|<>|<=>|&&|@>|<@|==|<=|>=|!<|!>|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|.)/;

this.BLOCK_COMMENT_REGEX = /^(\/\*[^]*?(?:\*\/|$))/;
this.LINE_COMMENT_REGEX = this.createLineCommentRegex(cfg.lineCommentTypes);
Expand All @@ -530,7 +530,7 @@ return /******/ (function(modules) { // webpackBootstrap
Tokenizer.prototype.createLineCommentRegex = function createLineCommentRegex(lineCommentTypes) {
return new RegExp("^((?:" + lineCommentTypes.map(function (c) {
return (0, _escapeRegExp2["default"])(c);
}).join("|") + ").*?(?:\n|$))");
}).join("|") + ").*?(?:\n|\r\n|$))");
};

Tokenizer.prototype.createReservedWordRegex = function createReservedWordRegex(reservedWords) {
Expand Down Expand Up @@ -564,7 +564,8 @@ return /******/ (function(modules) { // webpackBootstrap
"\"\"": "((\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*(\"|$))+)",
"''": "(('[^'\\\\]*(?:\\\\.[^'\\\\]*)*('|$))+)",
"N''": "((N'[^N'\\\\]*(?:\\\\.[^N'\\\\]*)*('|$))+)",
"{{}}": "({{(.*?)}})"
"{{}}": "({{(.*?)}})",
"${}": "(\\${(.*?)})"
};

return stringTypes.map(function (t) {
Expand Down Expand Up @@ -2064,11 +2065,11 @@ return /******/ (function(modules) { // webpackBootstrap
reservedWords: reservedWords,
reservedToplevelWords: reservedToplevelWords,
reservedNewlineWords: reservedNewlineWords,
stringTypes: ["\"\"", "N''", "''", "``", "[]", "{{}}"],
stringTypes: ["\"\"", "N''", "''", "``", "[]", "{{}}", "${}"],
openParens: ["(", "CASE"],
closeParens: [")", "END"],
indexedPlaceholderTypes: ["?"],
namedPlaceholderTypes: ["@", ":"],
namedPlaceholderTypes: ["@", ":", "$"],
lineCommentTypes: ["#", "--"]
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/sql-formatter.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Tokenizer {
constructor(cfg) {
this.WHITESPACE_REGEX = /^(\s+)/;
this.NUMBER_REGEX = /^((-\s*)?[0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)\b/;
this.OPERATOR_REGEX = /^(!=|<>|<=>|==|<=|>=|!<|!>|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|.)/;
this.OPERATOR_REGEX = /^(!=|<>|<=>|&&|@>|<@|==|<=|>=|!<|!>|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|.)/;

this.BLOCK_COMMENT_REGEX = /^(\/\*[^]*?(?:\*\/|$))/;
this.LINE_COMMENT_REGEX = this.createLineCommentRegex(cfg.lineCommentTypes);
Expand Down
6 changes: 6 additions & 0 deletions test/StandardSqlFormatterTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,10 @@ describe("StandardSqlFormatter", function() {
expect(sqlFormatter.format(queryText)).toBe(expectedFormattedQueryText);
});

it("formats array operations correctly", function() {
expect(sqlFormatter.format("ids && '{639}'")).toBe("ids && '{639}'");
expect(sqlFormatter.format("ids @> '{639}'")).toBe("ids @> '{639}'");
expect(sqlFormatter.format("ids <@ '{639}'")).toBe("ids <@ '{639}'");
});

});