feat: add cached analyze stage

This commit is contained in:
Dylan Piercey 2020-12-16 14:12:38 -07:00
parent 0baaf8ce0b
commit bb6a050bbb
No known key found for this signature in database
GPG Key ID: 9736AB8CA3ED17CA
2 changed files with 8 additions and 4 deletions

View File

@ -22,9 +22,9 @@ export default (api, markoOpts) => {
markoOpts.optimize = api.env("production");
}
if (!translator || !translator.visitor) {
if (!translator || !translator.translate) {
throw new Error(
"@marko/compiler: translator must provide a visitor object"
"@marko/compiler: translator must provide a translate visitor object"
);
}
@ -49,7 +49,7 @@ export default (api, markoOpts) => {
file.markoOpts = markoOpts;
file.___taglibLookup = sourceFile.___taglibLookup;
file.___getMarkoFile = getMarkoFile;
traverse(ast, translator.visitor, file.scope, {});
traverse(ast, translator.translate, file.scope, {});
file.buildCodeFrameError = buildCodeFrameError;
file.hub.buildError = buildError;
file.markoOpts = file.___taglibLookup = file.___getMarkoFile = undefined;
@ -176,6 +176,10 @@ export function getMarkoFile(code, jsParseOptions, markoOpts) {
}
}
if (markoOpts.translator.analyze) {
traverse(file.ast, markoOpts.translator.analyze, file.scope, {});
}
compileCache.set(cacheKey, {
time: Date.now(),
file,

View File

@ -23,7 +23,7 @@ import getComponentFiles from "./util/get-component-files";
export { default as taglibs } from "./taglib";
export const visitor = {
export const translate = {
MarkoDocumentType,
MarkoDeclaration,
MarkoCDATA,