Permalink
Browse files

Merge branch 'master' of github.com:paularmstrong/swig

  • Loading branch information...
2 parents b97809c + 7781239 commit 5c5495b1577bf1390f8f0367c0415fc7bf2a8215 @paularmstrong committed Feb 28, 2012
Showing with 13 additions and 8 deletions.
  1. +7 −4 lib/parser.js
  2. +1 −1 lib/tags/set.js
  3. +2 −0 lib/tags/set.test.js
  4. +2 −2 package.json
  5. +1 −1 scripts/runlint.js
View
@@ -301,7 +301,8 @@ exports.compile = function compile(indent, parentBlock) {
parent,
filepath,
blockname,
- varOutput;
+ varOutput,
+ wrappedInMethod;
indent = indent || '';
@@ -377,14 +378,16 @@ exports.compile = function compile(indent, parentBlock) {
args = (token.args && token.args.length) ? token.args : '';
code += 'if (typeof _context !== "undefined" && typeof _context' + key + ' === "function") {\n';
- code += ' _output += ' + helpers.wrapMethod('', { name: name, args: args }, '_context') + ';\n';
+ wrappedInMethod = helpers.wrapMethod('', { name: name, args: args }, '_context');
+ code += ' _output = (typeof _output === "undefined") ? ' + wrappedInMethod + ': _output + ' + wrappedInMethod + ';\n';
if (helpers.isValidName(name)) {
code += '} else if (typeof ' + name + ' === "function") {\n';
- code += ' _output += ' + helpers.wrapMethod('', { name: name, args: args }) + ';\n';
+ wrappedInMethod = helpers.wrapMethod('', { name: name, args: args });
+ code += ' _output = (typeof _output === "undefined") ? ' + wrappedInMethod + ': _output + ' + wrappedInMethod + ';\n';
}
code += '} else {\n';
code += helpers.setVar('__' + name, token);
- code += ' _output += __' + name + ';\n';
+ code += ' _output = (typeof _output === "undefined") ? __' + name + ': _output + __' + name + ';\n';
code += '}\n';
}
View
@@ -22,7 +22,7 @@ module.exports = function (indent, parentBlock, parser) {
value = parser.parseVariable(value);
return ' ' + varname + ' = ' +
'(function () {\n' +
- ' var _output = "";\n' +
+ ' var _output;\n' +
parser.compile.apply({ tokens: [value] }, [indent, parentBlock]) + '\n' +
' return _output;\n' +
'})();\n';
View
@@ -39,6 +39,8 @@ exports.set = testCase({
'set number is really a number [gh-53]': function (test) {
test.strictEqual(swig.compile('{% set foo = 1 %}{{ foo|add(1) }}')(), '2', 'literal number is a number');
test.strictEqual(swig.compile('{% set foo = "1" %}{{ foo|add(1) }}')(), '11', 'string number is not a number');
+ test.strictEqual(swig.compile('{% set bar = 1 %} {% set foo = bar %}{{ foo|add(1) }}')(), ' 2', 'number remains a number after set from variable');
+ test.strictEqual(swig.compile('{% set foo = 1 %} {% set foo = foo|add(1) %}{% set foo = foo|add(1) %}{{ foo|add(1) }}')(), ' 4', 'number remains a number after set from filter');
test.done();
}
});
View
@@ -16,8 +16,8 @@
},
"devDependencies": {
"express": ">=2.5.0",
- "nodelint": ">=0.5.2",
- "nodeunit": ">=0.6.4",
+ "nodelint": "~0.6",
+ "nodeunit": "~0.7",
"uglify-js": ">=1.1.0"
},
"main": "index",
View
@@ -22,7 +22,7 @@ function runLint(error, stdout, stderr) {
var files = stdout.trim().replace(/\n/g, ' ');
child_process.exec('node ' + __dirname + '/../node_modules/nodelint/nodelint ' + files + ' --config ' + configFile + '.js', { cwd: config.root }, function (error, stdout, stderr) {
- util.puts(stderr);
+ util.puts(stdout);
});
}

0 comments on commit 5c5495b

Please sign in to comment.