Skip to content

Commit c4048e2

Browse files
committed
remove semicolon backward compatibility
1 parent d2b0026 commit c4048e2

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

src/core/Formatter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ export default class Formatter {
7171
else if (token.type === tokenTypes.PLACEHOLDER) {
7272
formattedQuery = this.formatPlaceholder(token, formattedQuery);
7373
}
74-
else if (token.type === tokenTypes.END_STATEMENT) {
75-
formattedQuery = this.formatWithoutSpaces(token, formattedQuery);
76-
}
7774
else if (token.value === ",") {
7875
formattedQuery = this.formatComma(token, formattedQuery);
7976
}
8077
else if (token.value === ":") {
8178
formattedQuery = this.formatWithSpaceAfter(token, formattedQuery);
8279
}
83-
else if (token.value === "." || token.value === ";") {
80+
else if (token.value === ".") {
8481
formattedQuery = this.formatWithoutSpaces(token, formattedQuery);
8582
}
83+
else if (token.value === ";") {
84+
formattedQuery = this.formatQuerySeparator(token, formattedQuery);
85+
}
8686
else {
8787
formattedQuery = this.formatWithSpaces(token, formattedQuery);
8888
}
@@ -188,6 +188,10 @@ export default class Formatter {
188188
return query + token.value + " ";
189189
}
190190

191+
formatQuerySeparator(token, query) {
192+
return trimEnd(query) + token.value + "\n";
193+
}
194+
191195
addNewline(query) {
192196
return trimEnd(query) + "\n" + this.indentation.getIndent();
193197
}

src/core/Tokenizer.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default class Tokenizer {
1818
*/
1919
constructor(cfg) {
2020
this.WHITESPACE_REGEX = /^(\s+)/;
21-
this.END_STATEMENT_REGEX = /^(;\n)/;
2221
this.NUMBER_REGEX = /^((-\s*)?[0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)\b/;
2322
this.OPERATOR_REGEX = /^(!=|<>|==|<=|>=|!<|!>|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|.)/;
2423

@@ -134,7 +133,6 @@ export default class Tokenizer {
134133

135134
getNextToken(input, previousToken) {
136135
return this.getWhitespaceToken(input) ||
137-
this.getEndStatementToken(input) ||
138136
this.getCommentToken(input) ||
139137
this.getStringToken(input) ||
140138
this.getOpenParenToken(input) ||
@@ -154,14 +152,6 @@ export default class Tokenizer {
154152
});
155153
}
156154

157-
getEndStatementToken(input) {
158-
return this.getTokenOnFirstMatch({
159-
input,
160-
type: tokenTypes.END_STATEMENT,
161-
regex: this.END_STATEMENT_REGEX
162-
});
163-
}
164-
165155
getCommentToken(input) {
166156
return this.getLineCommentToken(input) || this.getBlockCommentToken(input);
167157
}

src/core/tokenTypes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ export default {
1414
LINE_COMMENT: "line-comment",
1515
BLOCK_COMMENT: "block-comment",
1616
NUMBER: "number",
17-
PLACEHOLDER: "placeholder",
18-
END_STATEMENT: "end-statement"
17+
PLACEHOLDER: "placeholder"
1918
};

test/StandardSqlFormatterTest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ describe("StandardSqlFormatter", function() {
358358
"SELECT\n" +
359359
" a\n" +
360360
"FROM\n" +
361-
" b --comment\n" +
362-
";"
361+
" b --comment;"
363362
);
364363
});
365364

test/behavesLikeSqlFormatter.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,9 @@ export default function behavesLikeSqlFormatter(language) {
447447
});
448448

449449
it("keeps separation between multiple statements", function() {
450-
expect(format("foo;bar;")).toBe("foo;bar;");
451-
expect(format("foo\n;bar;")).toBe("foo;bar;");
452-
expect(format("foo;\nbar;\n\n\n")).toBe("foo;\nbar;");
453-
expect(format("foo;\n\n\nbar;\n\n\n")).toBe("foo;\nbar;");
450+
expect(format("foo;bar;")).toBe("foo;\nbar;");
451+
expect(format("foo\n;bar;")).toBe("foo;\nbar;");
452+
expect(format("foo\n\n\n;bar;\n\n")).toBe("foo;\nbar;");
454453

455454
const result = format("SELECT count(*),Column1 FROM Table1;\nSELECT count(*),Column1 FROM Table2;");
456455
expect(result).toBe(

0 commit comments

Comments
 (0)