From 149c64395e97368b226bd41cad23d875003a673b Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Fri, 11 Dec 2015 15:54:03 -0700 Subject: [PATCH] Minor updates --- compiler/Compiler.js | 6 ++++++ docs/compiler-advanced.md | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/Compiler.js b/compiler/Compiler.js index cf0ce817b..1af6d799c 100644 --- a/compiler/Compiler.js +++ b/compiler/Compiler.js @@ -75,15 +75,20 @@ class Compiler { ok(filename); var context = new CompileContext(src, filename, this.builder); + + // STAGE 1: Parse the template to produce the initial AST var ast = this.parser.parse(src, context); // console.log('ROOT', JSON.stringify(ast, null, 2)); + // STAGE 2: Transform the initial AST to produce the final AST var transformedAST = transformTree(ast, context); // console.log('transformedAST', JSON.stringify(ast, null, 2)); + // STAGE 3: Generate the code using the final AST var codeGenerator = new CodeGenerator(context); codeGenerator.generateCode(transformedAST); + // If there were any errors then compilation failed. if (context.hasErrors()) { var errors = context.getErrors(); @@ -97,6 +102,7 @@ class Compiler { throw error; } + // Return the generated code as the compiled output: var compiledSrc = codeGenerator.getCode(); return compiledSrc; } diff --git a/docs/compiler-advanced.md b/docs/compiler-advanced.md index 0f188032d..73d4ada13 100644 --- a/docs/compiler-advanced.md +++ b/docs/compiler-advanced.md @@ -5,7 +5,7 @@ The Marko compiler is responsible for taking an input Marko template and produci # Compiler stages -The three primary stages of the Marko compiler are parse, transform, generate: +The three primary stages of the Marko compiler are parse, transform and generate: - __parse__ - Parse the template source to produce an [Abstract Syntax Tree (AST)](https//en.wikipedia.org/wiki/Abstract_syntax_tree). - __transform__ - Transform the AST (add/remove/modify/rearrange nodes) @@ -95,7 +95,7 @@ if (ifAttr && ifAttr.argument) { // Create a new "If" node using the provided "builder" // (described later) - var ifNode = builder.ifStatement(ifArgument); + var ifNode = builder.ifStatement(ifAttr.argument); //Surround the existing node with an "If" node node.wrap(ifNode);