mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Minor updates
This commit is contained in:
parent
28a851723a
commit
149c64395e
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user