Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

compiler: accept ometajs options

  • Loading branch information...
commit 902c11bfc92755071a7ed487c2482a5b92b981f1 1 parent dfc9d43
@indutny indutny authored
Showing with 23 additions and 12 deletions.
  1. +22 −11 lib/xjst/compiler.js
  2. +1 −1  package.json
View
33 lib/xjst/compiler.js
@@ -19,12 +19,13 @@ var xjst = require('../xjst'),
// #### @identifier {Identifier} internal
// Returns AST for input string
//
-exports.parse = function parse(code, filename, id, identifier) {
+exports.parse = function parse(code, filename, options, id, identifier) {
+ if (!options) options = {};
var tree = XJSTParser.matchAll(code, 'topLevel', undefined,
- utils.errorHandler(code));
+ utils.errorHandler(code), options.ometa);
if (identifier === undefined) id = 0;
- tree = xjst.translate(tree, id, identifier);
+ tree = xjst.translate(tree, options, id, identifier);
// Load parent templates
if (filename) {
@@ -43,7 +44,11 @@ exports.parse = function parse(code, filename, id, identifier) {
);
}).forEach(function(filename) {
var content = fs.readFileSync(filename).toString(),
- dependency = exports.parse(content, filename, ++id, identifier);
+ dependency = exports.parse(content,
+ filename,
+ options,
+ ++id,
+ identifier);
// And add it's templates to current ones
[0, 1, 3].forEach(function (i) {
@@ -73,17 +78,21 @@ exports.parse = function parse(code, filename, id, identifier) {
};
//
-// ### function translate (tree)
+// ### function translate (tree, options)
// #### @tree {Array} AST Tree
+// #### @options {Object} *optional* options
// Translates XJST AST into usable form
//
-exports.translate = function translate(tree, id, identifier) {
+exports.translate = function translate(tree, options, id, identifier) {
+ if (!options) options = {};
if (identifier === undefined) {
return XJSTTranslator.matchAll(tree, 'topLevel', [id],
- utils.errorHandler(tree));
+ utils.errorHandler(tree),
+ options.ometa);
} else {
return XJSTTranslator.matchAll(tree, 'topLevelEx', [id, identifier],
- utils.errorHandler(tree));
+ utils.errorHandler(tree),
+ options.ometa);
}
}
@@ -151,7 +160,7 @@ exports.generate = function generate(ast, options) {
if (options['no-opt']) {
// Just compile `template` to `if`, and `local`
body = [
- XJSTCompiler.match(ast, 'topLevel')
+ XJSTCompiler.match(ast, 'topLevel', options.ometa)
];
} else {
// Optimize recursion and minimize comparisons tree
@@ -175,7 +184,7 @@ exports.generate = function generate(ast, options) {
// Finally render tree
body = [
- XJSTCompiler.match(ast[0], 'other'),
+ XJSTCompiler.match(ast[0], 'other', options.ometa),
serializer.render(tree)
];
}
@@ -231,8 +240,10 @@ exports.compile = function compile(code, filename, options) {
filename = null;
}
+ if (!options) options = {};
+
// Compile and evaluate source
- var parsed = exports.parse(code, filename),
+ var parsed = exports.parse(code, filename, options.ometa),
compiled = exports.generate(parsed, options),
evaluated = vm.runInThisContext(compiled, filename);
View
2  package.json
@@ -20,7 +20,7 @@
},
"dependencies": {
"coa": "~ 0.3.8",
- "ometajs": "~ 3.1.17",
+ "ometajs": "~ 3.1.19",
"q": "~ 0.8.10",
"uglify-js": "1.3.x",
"spoon": "~ 0.1.3"
Please sign in to comment.
Something went wrong with that request. Please try again.