@@ -149,9 +149,19 @@ export class YamlCompiler {
149
149
const fullPath = propertyPath . join ( '.' ) ;
150
150
if ( fullPath . match ( p ) ) {
151
151
if ( typeof obj === 'string' && [ 'sql' , 'sqlTable' ] . includes ( propertyPath [ propertyPath . length - 1 ] ) ) {
152
- return this . parsePythonIntoArrowFunction ( `f"${ this . escapeDoubleQuotes ( obj ) } "` , cubeName , obj , errorsReport ) ;
152
+ if ( obj . match ( PY_TEMPLATE_SYNTAX ) ) {
153
+ return this . parsePythonIntoArrowFunction ( `f"${ this . escapeDoubleQuotes ( obj ) } "` , cubeName , obj , errorsReport ) ;
154
+ } else {
155
+ // Optimization: directly create arrow function returning string instead of parsing Python
156
+ return t . arrowFunctionExpression ( [ ] , t . stringLiteral ( obj ) ) ;
157
+ }
153
158
} else if ( typeof obj === 'string' ) {
154
- return this . parsePythonIntoArrowFunction ( obj , cubeName , obj , errorsReport ) ;
159
+ if ( obj . match ( PY_TEMPLATE_SYNTAX ) ) {
160
+ return this . parsePythonIntoArrowFunction ( obj , cubeName , obj , errorsReport ) ;
161
+ } else {
162
+ // Optimization: directly create arrow function returning identifier instead of parsing Python
163
+ return this . astIntoArrowFunction ( t . program ( [ t . expressionStatement ( t . identifier ( obj ) ) ] ) , obj , cubeName ) ;
164
+ }
155
165
} else if ( Array . isArray ( obj ) ) {
156
166
const resultAst = t . program ( [ t . expressionStatement ( t . arrayExpression ( obj . map ( code => {
157
167
let ast : t . Program | t . NullLiteral | t . BooleanLiteral | t . NumericLiteral | t . StringLiteral | null = null ;
@@ -172,7 +182,7 @@ export class YamlCompiler {
172
182
} else if ( code instanceof Date ) {
173
183
// Special case when dates are defined in YAML as strings without quotes
174
184
// YAML parser treats them as Date objects, but for conversion we need them as strings
175
- ast = this . parsePythonAndTranspileToJs ( `f" ${ this . escapeDoubleQuotes ( code . toISOString ( ) ) } "` , errorsReport ) ;
185
+ ast = t . stringLiteral ( code . toISOString ( ) ) ;
176
186
}
177
187
}
178
188
if ( ast === null ) {
@@ -196,14 +206,26 @@ export class YamlCompiler {
196
206
} else if ( typeof obj === 'string' ) {
197
207
let code = obj ;
198
208
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
+
199
224
if ( ! nonStringFields . has ( propertyPath [ propertyPath . length - 1 ] ) ) {
200
- code = `f" ${ this . escapeDoubleQuotes ( obj ) } "` ;
225
+ return t . templateLiteral ( [ t . templateElement ( { raw : code , cooked : code } ) ] , [ ] ) ;
201
226
}
202
227
203
- const parsePythonAndTranspileToJsTimer225 = perfTracker . start ( 'parsePythonAndTranspileToJs call 225' ) ;
204
- const ast = this . parsePythonAndTranspileToJs ( code , errorsReport ) ;
205
- parsePythonAndTranspileToJsTimer225 . end ( ) ;
206
- return this . extractProgramBodyIfNeeded ( ast ) ;
228
+ return t . identifier ( code ) ;
207
229
} else if ( typeof obj === 'boolean' ) {
208
230
return t . booleanLiteral ( obj ) ;
209
231
} else if ( typeof obj === 'number' ) {
0 commit comments