Skip to content

Commit f74a2b4

Browse files
committed
attempt to optimize transpile of regular fields
+ perf tracking them
1 parent 35ff9c7 commit f74a2b4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/cubejs-schema-compiler/src/compiler/YamlCompiler.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,26 @@ export class YamlCompiler {
206206
} else if (typeof obj === 'string') {
207207
let code = obj;
208208

209+
if (obj === '') {
210+
return t.nullLiteral();
211+
}
212+
213+
if (code.match(PY_TEMPLATE_SYNTAX)) {
214+
if (!nonStringFields.has(propertyPath[propertyPath.length - 1])) {
215+
code = `f"${this.escapeDoubleQuotes(obj)}"`;
216+
}
217+
218+
const parsePythonAndTranspileToJsTimer225 = perfTracker.start('parsePythonAndTranspileToJs call 225');
219+
const ast = this.parsePythonAndTranspileToJs(code, errorsReport);
220+
parsePythonAndTranspileToJsTimer225.end();
221+
return this.extractProgramBodyIfNeeded(ast);
222+
}
223+
209224
if (!nonStringFields.has(propertyPath[propertyPath.length - 1])) {
210-
code = `f"${this.escapeDoubleQuotes(obj)}"`;
225+
return t.templateLiteral([t.templateElement({ raw: code, cooked: code })], []);
211226
}
212227

213-
const parsePythonAndTranspileToJsTimer225 = perfTracker.start('parsePythonAndTranspileToJs call 225');
214-
const ast = this.parsePythonAndTranspileToJs(code, errorsReport);
215-
parsePythonAndTranspileToJsTimer225.end();
216-
return this.extractProgramBodyIfNeeded(ast);
228+
return t.identifier(code);
217229
} else if (typeof obj === 'boolean') {
218230
return t.booleanLiteral(obj);
219231
} else if (typeof obj === 'number') {

0 commit comments

Comments
 (0)