@@ -34,9 +34,8 @@ function processMacros(text) {
3434// Simple #if/else/endif preprocessing for a file. Checks if the
3535// ident checked is true in our global.
3636// Also handles #include x.js (similar to C #include <file>)
37- // Param filenameHint can be passed as a description to identify the file that is being processed, used
38- // to locate errors for reporting and for html files to stop expansion between <style> and </style>.
39- function preprocess ( text , filenameHint ) {
37+ function preprocess ( filename ) {
38+ let text = read ( filename ) ;
4039 if ( EXPORT_ES6 && USE_ES6_IMPORT_META ) {
4140 // `eval`, Terser and Closure don't support module syntax; to allow it,
4241 // we need to temporarily replace `import.meta` and `await import` usages
@@ -56,8 +55,8 @@ function preprocess(text, filenameHint) {
5655 const showStack = [ ] ;
5756 const showCurrentLine = ( ) => showStack . every ( ( x ) => x == SHOW ) ;
5857
59- currentlyParsedFilename = filenameHint ;
60- const fileExt = ( filenameHint ) ? filenameHint . split ( '.' ) . pop ( ) . toLowerCase ( ) : '' ;
58+ currentlyParsedFilename = filename ;
59+ const fileExt = filename . split ( '.' ) . pop ( ) . toLowerCase ( ) ;
6160 const isHtml = ( fileExt === 'html' || fileExt === 'htm' ) ? true : false ;
6261 let inStyle = false ;
6362 const lines = text . split ( '\n' ) ;
@@ -94,16 +93,15 @@ function preprocess(text, filenameHint) {
9493 }
9594 }
9695 const after = trimmed . substring ( trimmed . indexOf ( ' ' ) ) ;
97- const truthy = ! ! vm . runInThisContext ( after , { filename : filenameHint , lineOffset : i , columnOffset : line . indexOf ( after ) } ) ;
96+ const truthy = ! ! vm . runInThisContext ( after , { filename, lineOffset : i , columnOffset : line . indexOf ( after ) } ) ;
9897 showStack . push ( truthy ? SHOW : IGNORE ) ;
9998 } else if ( first === '#include' ) {
10099 if ( showCurrentLine ( ) ) {
101100 let filename = line . substr ( line . indexOf ( ' ' ) + 1 ) ;
102101 if ( filename . startsWith ( '"' ) ) {
103102 filename = filename . substr ( 1 , filename . length - 2 ) ;
104103 }
105- const included = read ( filename ) ;
106- const result = preprocess ( included , filename ) ;
104+ const result = preprocess ( filename ) ;
107105 if ( result ) {
108106 ret += `// include: ${ filename } \n` ;
109107 ret += result ;
@@ -123,14 +121,14 @@ function preprocess(text, filenameHint) {
123121 showStack . pop ( ) ;
124122 } else if ( first === '#warning' ) {
125123 if ( showCurrentLine ( ) ) {
126- printErr ( `${ filenameHint } :${ i + 1 } : #warning ${ trimmed . substring ( trimmed . indexOf ( ' ' ) ) . trim ( ) } ` ) ;
124+ printErr ( `${ filename } :${ i + 1 } : #warning ${ trimmed . substring ( trimmed . indexOf ( ' ' ) ) . trim ( ) } ` ) ;
127125 }
128126 } else if ( first === '#error' ) {
129127 if ( showCurrentLine ( ) ) {
130- error ( `${ filenameHint } :${ i + 1 } : #error ${ trimmed . substring ( trimmed . indexOf ( ' ' ) ) . trim ( ) } ` ) ;
128+ error ( `${ filename } :${ i + 1 } : #error ${ trimmed . substring ( trimmed . indexOf ( ' ' ) ) . trim ( ) } ` ) ;
131129 }
132130 } else {
133- throw new Error ( `${ filenameHint } :${ i + 1 } : Unknown preprocessor directive ${ first } ` ) ;
131+ throw new Error ( `${ filename } :${ i + 1 } : Unknown preprocessor directive ${ first } ` ) ;
134132 }
135133 } else {
136134 if ( showCurrentLine ( ) ) {
@@ -152,7 +150,7 @@ function preprocess(text, filenameHint) {
152150 }
153151 }
154152 }
155- assert ( showStack . length == 0 , `preprocessing error in file ${ filenameHint } , \
153+ assert ( showStack . length == 0 , `preprocessing error in file ${ filename } , \
156154no matching #endif found (${ showStack . length$ } ' unmatched preprocessing directives on stack)` ) ;
157155 return ret ;
158156 } finally {
0 commit comments