Skip to content

Commit

Permalink
Don't interpret backticks in comments in SQLX. (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBirt authored and probot-auto-merge[bot] committed Jul 15, 2019
1 parent a835cbf commit d65d964
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions core/sqlx_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ function buildSqlxLexer() {
match: /[^\S\r\n]*---[^\S\r\n]*$/,
value: () => ""
};
sqlLexer[SQL_LEXER_TOKEN_NAMES.SINGLE_LINE_COMMENT] = /--.*?$/;
sqlLexer[SQL_LEXER_TOKEN_NAMES.MULTI_LINE_COMMENT] = /\/\*[\s\S]*?\*\//;
sqlLexer[SQL_LEXER_TOKEN_NAMES.SINGLE_LINE_COMMENT] = {
match: /--.*?$/,
value: (value: string) => value.replace(/`/g, "\\`")
};
sqlLexer[SQL_LEXER_TOKEN_NAMES.MULTI_LINE_COMMENT] = {
match: /\/\*[\s\S]*?\*\//,
value: (value: string) => value.replace(/`/g, "\\`")
};
sqlLexer[SQL_LEXER_TOKEN_NAMES.SINGLE_QUOTE_STRING] = /'(?:\\['\\]|[^\n'\\])*'/;
sqlLexer[SQL_LEXER_TOKEN_NAMES.DOUBLE_QUOTE_STRING] = /"(?:\\["\\]|[^\n"\\])*"/;
sqlLexer[SQL_LEXER_TOKEN_NAMES.START_JS_PLACEHOLDER] = {
Expand Down
4 changes: 4 additions & 0 deletions examples/bigquery_language_v2/definitions/example_table.sqlx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
config { type: "table" }
select * from ${ref("sample_data")}

-- here is a `comment

/* another ` backtick ` containing ```comment */

post_operations {
GRANT SELECT ON ${self()} TO GROUP "[email protected]"
---
Expand Down
6 changes: 4 additions & 2 deletions tests/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ describe("@dataform/api", () => {
expect(exampleTable).to.not.be.undefined;
expect(exampleTable.type).equals("table");
expect(exampleTable.query.trim()).equals(
`select * from \`tada-analytics.${schemaWithSuffix("df_integration_test")}.sample_data\``
`select * from \`tada-analytics.${schemaWithSuffix(
"df_integration_test"
)}.sample_data\`\n\n-- here is a \`comment\n\n/* another \` backtick \` containing \`\`\`comment */`
);
expect(exampleTable.dependencies).deep.equals(["sample_data"]);
expect(exampleTable.preOps).to.eql([]);
Expand Down Expand Up @@ -745,7 +747,7 @@ describe("@dataform/api", () => {
// Check testcase.
const testCase = graph.tests.find(t => t.name === "example_test_case");
expect(testCase.testQuery.trim()).equals(
"select * from (\n select 'hi' as faked union all\n select 'ben' as faked union all\n select 'sup?' as faked\n)"
"select * from (\n select 'hi' as faked union all\n select 'ben' as faked union all\n select 'sup?' as faked\n)\n\n-- here is a `comment\n\n/* another ` backtick ` containing ```comment */"
);
expect(testCase.expectedOutputQuery.trim()).equals(
"select 'hi' as faked union all\nselect 'ben' as faked union all\nselect 'sup?' as faked"
Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NOTE: If you change the format of this line, you must change the bash command
# in /scripts/publish to extract the version string correctly.
DF_VERSION = "1.0.1"
DF_VERSION = "1.0.2"

0 comments on commit d65d964

Please sign in to comment.