Comparing version 1.3.8 to 1.4.0
@@ -58,2 +58,8 @@ var esprima = require('esprima'), | ||
} | ||
this.globalInit = {}; | ||
if (this.options.globalInit) { | ||
Object.keys(this.options.globalInit).forEach(function(name) { | ||
return this.globalInit['$$' + name] = this.options.globalInit[name]; | ||
}, this); | ||
} | ||
@@ -903,3 +909,3 @@ this.program = null; | ||
callee: { type: 'Identifier', name: 'applyc' }, | ||
arguments: [applyContext, this.ref] | ||
arguments: [{ type: 'Identifier', name: 'ctx' }, this.ref] | ||
} | ||
@@ -925,3 +931,3 @@ }] | ||
}, | ||
right: applyContext | ||
right: { type: 'Identifier', name: 'ctx' } | ||
} | ||
@@ -1042,2 +1048,3 @@ }, { | ||
var globals = this.globals; | ||
var globalInit = this.globalInit; | ||
var globalKeys = Object.keys(globals); | ||
@@ -1049,2 +1056,21 @@ if (globalKeys.length !== 0) { | ||
declarations: globalKeys.map(function(name) { | ||
// Initialize globals from the context if asked | ||
if (globalInit[name]) { | ||
apply.body.body.unshift({ | ||
type: 'ExpressionStatement', | ||
expression: { | ||
type: 'AssignmentExpression', | ||
operator: '=', | ||
left: { type: 'Identifier', name: name }, | ||
right: { | ||
type: 'MemberExpression', | ||
computed: true, | ||
object: { type: 'Identifier', name: 'ctx' }, | ||
property: { type: 'Literal', value: globalInit[name] } | ||
} | ||
} | ||
}); | ||
} | ||
// Declare globals | ||
return { | ||
@@ -1055,6 +1081,17 @@ type: 'VariableDeclarator', | ||
}; | ||
}) | ||
}, this) | ||
}); | ||
} | ||
// ctx = ctx || this | ||
apply.body.body.unshift({ | ||
type: 'ExpressionStatement', | ||
expression: { | ||
type: 'AssignmentExpression', | ||
operator: '=', | ||
left: { type: 'Identifier', name: 'ctx' }, | ||
right: applyContext | ||
} | ||
}); | ||
/// Apply to the bottom | ||
@@ -1061,0 +1098,0 @@ if (out.apply) applyBody = applyBody.concat(out.apply); |
{ | ||
"name": "xjst", | ||
"description": "XSLT inspired JavaScript templates (with spices)", | ||
"version": "1.3.8", | ||
"version": "1.4.0", | ||
"homepage": "http://github.com/veged/xjst", | ||
@@ -6,0 +6,0 @@ "author": "Sergey Berezhnoy <veged@mail.ru> (http://github.com/veged)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111786
2595