Skip to content

Commit 9638a1a

Browse files
committed
fix: Syntax error during parsing: Unexpected token, expected: escaping back ticks
1 parent 65fdc9f commit 9638a1a

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

packages/cubejs-schema-compiler/scaffolding/ScaffoldingTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ScaffoldingTemplate {
9797
const items = descriptor.map(desc => this.render(desc, level + 1)).join(', ');
9898
return `[${items}]`;
9999
} else if (typeof descriptor === 'string') {
100-
return "`" + descriptor + "`";
100+
return `\`${descriptor.replace(/`/g, '\\`')}\``;
101101
} else if (descriptor instanceof MemberReference) {
102102
return descriptor.member;
103103
} else if (typeof descriptor === 'object') {

packages/cubejs-schema-compiler/test/ScaffoldingSchemaTest.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const driver = {
66
quoteIdentifier: (name) => `"${name}"`
77
};
88

9+
const mySqlDriver = {
10+
quoteIdentifier: (name) => `\`${name}\``
11+
};
12+
913
describe('ScaffoldingSchema', () => {
1014
it('schema', () => {
1115
const schema = new ScaffoldingSchema({
@@ -399,6 +403,64 @@ describe('ScaffoldingSchema', () => {
399403
}
400404
}
401405
});
406+
`
407+
}
408+
]);
409+
});
410+
411+
it('escaping back tick', () => {
412+
const template = new ScaffoldingTemplate({
413+
public: {
414+
someOrders: [{
415+
"name": "id",
416+
"type": "integer",
417+
"attributes": []
418+
}, {
419+
"name": "amount",
420+
"type": "integer",
421+
"attributes": []
422+
}, {
423+
"name": "someDimension",
424+
"type": "string",
425+
"attributes": []
426+
}]
427+
}
428+
}, mySqlDriver);
429+
template.generateFilesByTableNames(['public.someOrders']).should.be.deepEqual([
430+
{
431+
fileName: 'SomeOrders.js',
432+
content: `cube(\`SomeOrders\`, {
433+
sql: \`SELECT * FROM public.\\\`someOrders\\\`\`,
434+
435+
joins: {
436+
437+
},
438+
439+
measures: {
440+
count: {
441+
type: \`count\`,
442+
drillMembers: [id]
443+
},
444+
445+
amount: {
446+
sql: \`amount\`,
447+
type: \`sum\`
448+
}
449+
},
450+
451+
dimensions: {
452+
id: {
453+
sql: \`id\`,
454+
type: \`number\`,
455+
primaryKey: true
456+
},
457+
458+
somedimension: {
459+
sql: \`\${CUBE}.\\\`someDimension\\\`\`,
460+
type: \`string\`
461+
}
462+
}
463+
});
402464
`
403465
}
404466
]);

0 commit comments

Comments
 (0)