Skip to content

Commit

Permalink
fix: Syntax error during parsing: Unexpected token, expected: escapin…
Browse files Browse the repository at this point in the history
…g back ticks
  • Loading branch information
paveltiunov committed Jun 30, 2019
1 parent 65fdc9f commit 9638a1a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ScaffoldingTemplate {
const items = descriptor.map(desc => this.render(desc, level + 1)).join(', ');
return `[${items}]`;
} else if (typeof descriptor === 'string') {
return "`" + descriptor + "`";
return `\`${descriptor.replace(/`/g, '\\`')}\``;
} else if (descriptor instanceof MemberReference) {
return descriptor.member;
} else if (typeof descriptor === 'object') {
Expand Down
62 changes: 62 additions & 0 deletions packages/cubejs-schema-compiler/test/ScaffoldingSchemaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const driver = {
quoteIdentifier: (name) => `"${name}"`
};

const mySqlDriver = {
quoteIdentifier: (name) => `\`${name}\``
};

describe('ScaffoldingSchema', () => {
it('schema', () => {
const schema = new ScaffoldingSchema({
Expand Down Expand Up @@ -399,6 +403,64 @@ describe('ScaffoldingSchema', () => {
}
}
});
`
}
]);
});

it('escaping back tick', () => {
const template = new ScaffoldingTemplate({
public: {
someOrders: [{
"name": "id",
"type": "integer",
"attributes": []
}, {
"name": "amount",
"type": "integer",
"attributes": []
}, {
"name": "someDimension",
"type": "string",
"attributes": []
}]
}
}, mySqlDriver);
template.generateFilesByTableNames(['public.someOrders']).should.be.deepEqual([
{
fileName: 'SomeOrders.js',
content: `cube(\`SomeOrders\`, {
sql: \`SELECT * FROM public.\\\`someOrders\\\`\`,
joins: {
},
measures: {
count: {
type: \`count\`,
drillMembers: [id]
},
amount: {
sql: \`amount\`,
type: \`sum\`
}
},
dimensions: {
id: {
sql: \`id\`,
type: \`number\`,
primaryKey: true
},
somedimension: {
sql: \`\${CUBE}.\\\`someDimension\\\`\`,
type: \`string\`
}
}
});
`
}
]);
Expand Down

0 comments on commit 9638a1a

Please sign in to comment.