File tree 2 files changed +7
-12
lines changed
packages/tools/lib/hbs2lit/src
2 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const removeWhiteSpaces = (source) => {
11
11
const compileString = async ( sInput , config ) => {
12
12
let sPreprocessed = sInput ;
13
13
14
- sPreprocessed = await includesReplacer . replace ( sPreprocessed , config ) ;
14
+ sPreprocessed = includesReplacer . replace ( sPreprocessed , config ) ;
15
15
sPreprocessed = removeWhiteSpaces ( sPreprocessed ) ;
16
16
17
17
const ast = Handlebars . parse ( sPreprocessed ) ;
Original file line number Diff line number Diff line change 1
1
const path = require ( "path" ) ;
2
- const { promisify} = require ( "util" ) ;
3
2
const nativeFs = require ( "fs" ) ;
4
3
5
4
function replaceIncludes ( hbs , config ) {
6
5
const fs = config . fs || nativeFs ;
7
- const readFile = promisify ( fs . readFile ) ;
8
6
const inclRegex = / { { > \s * i n c l u d e \s * [ " ' ] ( [ a - z A - Z . \/ ] + ) [ " ' ] } } / g;
7
+ let match ;
9
8
10
- async function replacer ( match , p1 ) {
11
- const includeContent = await readFile ( path . join ( config . templatesPath , p1 ) , "utf-8" ) ;
12
- hbs = hbs . replace ( match , includeContent ) ;
9
+ while ( ( match = inclRegex . exec ( hbs ) ) !== null ) {
10
+ inclRegex . lastIndex = 0 ;
11
+ const includeContent = fs . readFileSync ( path . join ( config . templatesPath , match [ 1 ] ) , "utf-8" ) ;
12
+ hbs = hbs . replace ( match [ 0 ] , includeContent ) ;
13
13
}
14
14
15
- let match ;
16
- const replacers = [ ] ;
17
- while ( ( match = inclRegex . exec ( hbs ) ) !== null ) {
18
- replacers . push ( replacer ( match [ 0 ] , match [ 1 ] ) ) ;
19
- }
20
- return Promise . all ( replacers ) . then ( ( ) => hbs ) ;
15
+ return hbs ;
21
16
}
22
17
23
18
module . exports = {
You can’t perform that action at this time.
0 commit comments