Created
December 24, 2018 10:45
-
-
Save evanxg852000/bdd199c18f88e9a6c7f848057b89cdd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Templater { | |
... | |
render(file, context){ | |
let sourceFile = path.join(this._dir, file) | |
let compiledFile = this._compiledFile(file) | |
if(!fs.existsSync(sourceFile)){ | |
throw Error('Template not found!') | |
} | |
let render = null | |
//checks if compiled file exist | |
if(this._cached && fs.existsSync(compiledFile)){ | |
render = require(compiledFile) | |
return render(context) | |
} | |
let ast = this.compile(file) | |
this._saveGenCode(file, this.generate(ast)) | |
render = require(compiledFile) | |
return render(context) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment