@@ -201,8 +201,8 @@ export class DataSchemaCompiler {
201201 }
202202
203203 async transpileFile ( file , errorsReport , options ) {
204- if ( R . endsWith ( '.jinja' , file . fileName ) ||
205- ( R . endsWith ( '.yml' , file . fileName ) || R . endsWith ( '.yaml' , file . fileName ) )
204+ if ( file . fileName . endsWith ( '.jinja' ) ||
205+ ( file . fileName . endsWith ( '.yml' ) || file . fileName . endsWith ( '.yaml' ) )
206206 // TODO do Jinja syntax check with jinja compiler
207207 && file . content . match ( JINJA_SYNTAX )
208208 ) {
@@ -216,9 +216,9 @@ export class DataSchemaCompiler {
216216 this . yamlCompiler . getJinjaEngine ( ) . loadTemplate ( file . fileName , file . content ) ;
217217
218218 return file ;
219- } else if ( R . endsWith ( '.yml' , file . fileName ) || R . endsWith ( '.yaml' , file . fileName ) ) {
219+ } else if ( file . fileName . endsWith ( '.yml' ) || file . fileName . endsWith ( '.yaml' ) ) {
220220 return file ;
221- } else if ( R . endsWith ( '.js' , file . fileName ) ) {
221+ } else if ( file . fileName . endsWith ( '.js' ) ) {
222222 return this . transpileJsFile ( file , errorsReport , options ) ;
223223 } else {
224224 return file ;
@@ -247,7 +247,7 @@ export class DataSchemaCompiler {
247247 errorsReport . addWarnings ( res . warnings ) ;
248248 errorsReport . exitFile ( ) ;
249249
250- return Object . assign ( { } , file , { content : res . code } ) ;
250+ return { ... file , content : res . code } ;
251251 } else if ( getEnv ( 'transpilationWorkerThreads' ) ) {
252252 const data = {
253253 fileName : file . fileName ,
@@ -261,7 +261,7 @@ export class DataSchemaCompiler {
261261 errorsReport . addErrors ( res . errors ) ;
262262 errorsReport . addWarnings ( res . warnings ) ;
263263
264- return Object . assign ( { } , file , { content : res . content } ) ;
264+ return { ... file , content : res . content } ;
265265 } else {
266266 const ast = parse (
267267 file . content ,
@@ -279,7 +279,7 @@ export class DataSchemaCompiler {
279279 errorsReport . exitFile ( ) ;
280280
281281 const content = babelGenerator ( ast , { } , file . content ) . code ;
282- return Object . assign ( { } , file , { content } ) ;
282+ return { ... file , content } ;
283283 }
284284 } catch ( e ) {
285285 if ( e . toString ( ) . indexOf ( 'SyntaxError' ) !== - 1 ) {
@@ -337,19 +337,19 @@ export class DataSchemaCompiler {
337337 }
338338
339339 compileFile (
340- file , errorsReport , cubes , exports , contexts , toCompile , compiledFiles , asyncModules
340+ file , errorsReport , cubes , exports , contexts , toCompile , compiledFiles , asyncModules , { doSyntaxCheck } = { doSyntaxCheck : false }
341341 ) {
342342 if ( compiledFiles [ file . fileName ] ) {
343343 return ;
344344 }
345345
346346 compiledFiles [ file . fileName ] = true ;
347347
348- if ( R . endsWith ( '.js' , file . fileName ) ) {
349- this . compileJsFile ( file , errorsReport , cubes , contexts , exports , asyncModules , toCompile , compiledFiles ) ;
350- } else if ( R . endsWith ( '.yml.jinja' , file . fileName ) || R . endsWith ( '.yaml.jinja' , file . fileName ) ||
348+ if ( file . fileName . endsWith ( '.js' ) ) {
349+ this . compileJsFile ( file , errorsReport , cubes , contexts , exports , asyncModules , toCompile , compiledFiles , { doSyntaxCheck } ) ;
350+ } else if ( file . fileName . endsWith ( '.yml.jinja' ) || file . fileName . endsWith ( '.yaml.jinja' ) ||
351351 (
352- R . endsWith ( '.yml' , file . fileName ) || R . endsWith ( '.yaml' , file . fileName )
352+ file . fileName . endsWith ( '.yml' ) || file . fileName . endsWith ( '.yaml' )
353353 // TODO do Jinja syntax check with jinja compiler
354354 ) && file . content . match ( JINJA_SYNTAX )
355355 ) {
@@ -365,31 +365,36 @@ export class DataSchemaCompiler {
365365 this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
366366 this . pythonContext
367367 ) ) ;
368- } else if ( R . endsWith ( '.yml' , file . fileName ) || R . endsWith ( '.yaml' , file . fileName ) ) {
368+ } else if ( file . fileName . endsWith ( '.yml' ) || file . fileName . endsWith ( '.yaml' ) ) {
369369 this . yamlCompiler . compileYamlFile ( file , errorsReport , cubes , contexts , exports , asyncModules , toCompile , compiledFiles ) ;
370370 }
371371 }
372372
373- compileJsFile ( file , errorsReport , cubes , contexts , exports , asyncModules , toCompile , compiledFiles ) {
374- const err = syntaxCheck ( file . content , file . fileName ) ;
375- if ( err ) {
376- errorsReport . error ( err . toString ( ) ) ;
373+ compileJsFile ( file , errorsReport , cubes , contexts , exports , asyncModules , toCompile , compiledFiles , { doSyntaxCheck } = { doSyntaxCheck : false } ) {
374+ if ( doSyntaxCheck ) {
375+ // There is no need to run syntax check for data model files
376+ // because they were checked during transpilation/transformation phase
377+ // Only external files (included modules) might need syntax check
378+ const err = syntaxCheck ( file . content , file . fileName ) ;
379+ if ( err ) {
380+ errorsReport . error ( err . toString ( ) ) ;
381+ }
377382 }
378383
379384 try {
380385 vm . runInNewContext ( file . content , {
381386 view : ( name , cube ) => (
382387 ! cube ?
383388 this . cubeFactory ( { ...name , fileName : file . fileName , isView : true } ) :
384- cubes . push ( Object . assign ( { } , cube , { name, fileName : file . fileName , isView : true } ) )
389+ cubes . push ( { ... cube , name, fileName : file . fileName , isView : true } )
385390 ) ,
386391 cube :
387392 ( name , cube ) => (
388393 ! cube ?
389394 this . cubeFactory ( { ...name , fileName : file . fileName } ) :
390- cubes . push ( Object . assign ( { } , cube , { name, fileName : file . fileName } ) )
395+ cubes . push ( { ... cube , name, fileName : file . fileName } )
391396 ) ,
392- context : ( name , context ) => contexts . push ( Object . assign ( { } , context , { name, fileName : file . fileName } ) ) ,
397+ context : ( name , context ) => contexts . push ( { ... context , name, fileName : file . fileName } ) ,
393398 addExport : ( obj ) => {
394399 exports [ file . fileName ] = exports [ file . fileName ] || { } ;
395400 exports [ file . fileName ] = Object . assign ( exports [ file . fileName ] , obj ) ;
@@ -424,6 +429,8 @@ export class DataSchemaCompiler {
424429 contexts ,
425430 toCompile ,
426431 compiledFiles ,
432+ [ ] ,
433+ { doSyntaxCheck : true }
427434 ) ;
428435 exports [ foundFile . fileName ] = exports [ foundFile . fileName ] || { } ;
429436 return exports [ foundFile . fileName ] ;
@@ -469,7 +476,7 @@ export class DataSchemaCompiler {
469476 path . resolve ( 'node_modules' , path . dirname ( currentFile . fileName ) , modulePath ) :
470477 path . resolve ( 'node_modules' , modulePath ) ;
471478
472- if ( absPath . indexOf ( nodeModulesPath ) !== 0 ) {
479+ if ( ! absPath . startsWith ( nodeModulesPath ) ) {
473480 if ( this . allowNodeRequire ) {
474481 return null ;
475482 }
0 commit comments