Skip to content

Commit b0cf3c4

Browse files
committed
simplify jinja check
1 parent 164b783 commit b0cf3c4

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const NATIVE_IS_SUPPORTED = isNativeSupported();
1515

1616
const moduleFileCache = {};
1717

18-
const JINJA_SYNTAX = /{%|%}|{{|}}/ig;
18+
const JINJA_SYNTAX = /{%|%}|{{|}}/;
1919

2020
export class DataSchemaCompiler {
2121
constructor(repository, options = {}) {
@@ -114,10 +114,10 @@ export class DataSchemaCompiler {
114114
}
115115

116116
transpileFile(file, errorsReport) {
117-
if (R.endsWith('.jinja', file.fileName) ||
118-
(R.endsWith('.yml', file.fileName) || R.endsWith('.yaml', file.fileName))
117+
if (file.fileName.endsWith('.jinja') ||
118+
(file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml'))
119119
// TODO do Jinja syntax check with jinja compiler
120-
&& file.content.match(JINJA_SYNTAX)
120+
&& JINJA_SYNTAX.test(file.content)
121121
) {
122122
if (NATIVE_IS_SUPPORTED !== true) {
123123
throw new Error(
@@ -129,9 +129,9 @@ export class DataSchemaCompiler {
129129
this.yamlCompiler.getJinjaEngine().loadTemplate(file.fileName, file.content);
130130

131131
return file;
132-
} else if (R.endsWith('.yml', file.fileName) || R.endsWith('.yaml', file.fileName)) {
132+
} else if (file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) {
133133
return file;
134-
} else if (R.endsWith('.js', file.fileName)) {
134+
} else if (file.fileName.endsWith('.js')) {
135135
return this.transpileJsFile(file, errorsReport);
136136
} else {
137137
return file;
@@ -221,13 +221,12 @@ export class DataSchemaCompiler {
221221

222222
compiledFiles[file.fileName] = true;
223223

224-
if (R.endsWith('.js', file.fileName)) {
224+
if (file.fileName.endsWith('.js')) {
225225
this.compileJsFile(file, errorsReport, cubes, contexts, exports, asyncModules, toCompile, compiledFiles);
226-
} else if (R.endsWith('.yml.jinja', file.fileName) || R.endsWith('.yaml.jinja', file.fileName) ||
227-
(
228-
R.endsWith('.yml', file.fileName) || R.endsWith('.yaml', file.fileName)
229-
// TODO do Jinja syntax check with jinja compiler
230-
) && file.content.match(JINJA_SYNTAX)
226+
} else if (file.fileName.endsWith('.yml.jinja') || file.fileName.endsWith('.yaml.jinja') ||
227+
(file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml'))
228+
// TODO do Jinja syntax check with jinja compiler
229+
&& JINJA_SYNTAX.test(file.content)
231230
) {
232231
asyncModules.push(() => this.yamlCompiler.compileYamlWithJinjaFile(
233232
file,
@@ -241,7 +240,7 @@ export class DataSchemaCompiler {
241240
this.standalone ? {} : this.cloneCompileContextWithGetterAlias(this.compileContext),
242241
this.pythonContext
243242
));
244-
} else if (R.endsWith('.yml', file.fileName) || R.endsWith('.yaml', file.fileName)) {
243+
} else if (file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) {
245244
this.yamlCompiler.compileYamlFile(file, errorsReport, cubes, contexts, exports, asyncModules, toCompile, compiledFiles);
246245
}
247246
}

0 commit comments

Comments
 (0)