Skip to content

Commit 324d615

Browse files
committed
Enforce 100% code coverage
1 parent c3cbaa2 commit 324d615

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

lib/handlebars/compiler/code-gen.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ CodeGen.prototype = {
9090
}
9191
},
9292

93-
empty: function(loc = this.currentLocation || {start: {}}) {
93+
empty: function() {
94+
let loc = this.currentLocation || {start: {}};
9495
return new SourceNode(loc.start.line, loc.start.column, this.srcFile);
9596
},
9697
wrap: function(chunk, loc = this.currentLocation || {start: {}}) {
@@ -137,22 +138,22 @@ CodeGen.prototype = {
137138
},
138139

139140

140-
generateList: function(entries, loc) {
141-
let ret = this.empty(loc);
141+
generateList: function(entries) {
142+
let ret = this.empty();
142143

143144
for (let i = 0, len = entries.length; i < len; i++) {
144145
if (i) {
145146
ret.add(',');
146147
}
147148

148-
ret.add(castChunk(entries[i], this, loc));
149+
ret.add(castChunk(entries[i], this));
149150
}
150151

151152
return ret;
152153
},
153154

154-
generateArray: function(entries, loc) {
155-
let ret = this.generateList(entries, loc);
155+
generateArray: function(entries) {
156+
let ret = this.generateList(entries);
156157
ret.prepend('[');
157158
ret.add(']');
158159

lib/handlebars/compiler/helpers.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,20 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
124124

125125
export function prepareProgram(statements, loc) {
126126
if (!loc && statements.length) {
127-
const first = statements[0].loc,
128-
last = statements[statements.length - 1].loc;
127+
const firstLoc = statements[0].loc,
128+
lastLoc = statements[statements.length - 1].loc;
129129

130-
if (first && last) {
130+
/* istanbul ignore else */
131+
if (firstLoc && lastLoc) {
131132
loc = {
132-
source: first.source,
133+
source: firstLoc.source,
133134
start: {
134-
line: first.start.line,
135-
column: first.start.column
135+
line: firstLoc.start.line,
136+
column: firstLoc.start.column
136137
},
137138
end: {
138-
line: last.end.line,
139-
column: last.end.column
139+
line: lastLoc.end.line,
140+
column: lastLoc.end.column
140141
}
141142
};
142143
}

spec/ast.js

+11
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ describe('ast', function() {
100100
});
101101

102102
describe('PartialStatement', function() {
103+
it('provides default params', function() {
104+
var pn = new handlebarsEnv.AST.PartialStatement('so_partial', undefined, {}, {}, LOCATION_INFO);
105+
equals(pn.params.length, 0);
106+
});
103107
it('stores location info', function() {
104108
var pn = new handlebarsEnv.AST.PartialStatement('so_partial', [], {}, {}, LOCATION_INFO);
105109
testLocationInfoStorage(pn);
@@ -113,6 +117,13 @@ describe('ast', function() {
113117
});
114118
});
115119

120+
describe('SubExpression', function() {
121+
it('provides default params', function() {
122+
var pn = new handlebarsEnv.AST.SubExpression('path', undefined, {}, LOCATION_INFO);
123+
equals(pn.params.length, 0);
124+
});
125+
});
126+
116127
describe('Line Numbers', function() {
117128
var ast, body;
118129

spec/blocks.js

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe('blocks', function() {
6565
shouldCompileTo(string, hash, 'Goodbye cruel sad OMG!');
6666
});
6767

68+
it('works with cached blocks', function() {
69+
var template = CompilerContext.compile('{{#each person}}{{#with .}}{{first}} {{last}}{{/with}}{{/each}}', {data: false});
70+
71+
var result = template({person: [{first: 'Alan', last: 'Johnson'}, {first: 'Alan', last: 'Johnson'}]});
72+
equals(result, 'Alan JohnsonAlan Johnson');
73+
});
74+
6875
describe('inverted sections', function() {
6976
it('inverted sections with unset value', function() {
7077
var string = '{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}';

tasks/test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,17 @@ module.exports = function(grunt) {
4040
done();
4141
});
4242
});
43-
grunt.registerTask('test', ['test:bin', 'test:cov']);
43+
44+
grunt.registerTask('test:check-cov', function() {
45+
var done = this.async();
46+
47+
var runner = childProcess.fork('node_modules/.bin/istanbul', ['check-coverage', '--statements', '100', '--functions', '100', '--branches', '100', '--lines 100'], {stdio: 'inherit'});
48+
runner.on('close', function(code) {
49+
if (code != 0) {
50+
grunt.fatal('Coverage check failed: ' + code);
51+
}
52+
done();
53+
});
54+
});
55+
grunt.registerTask('test', ['test:bin', 'test:cov', 'test:check-cov']);
4456
};

0 commit comments

Comments
 (0)