Skip to content

Commit 0310879

Browse files
committed
Use latest source-map-version
Resolves #1427
1 parent 29ed243 commit 0310879

File tree

6 files changed

+75
-20
lines changed

6 files changed

+75
-20
lines changed

lib/precompiler.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ function loadFiles(opts, callback) {
150150
);
151151
}
152152

153-
module.exports.cli = function(opts) {
153+
module.exports.cli = async function(opts) {
154+
// TODO what implications does this have?
154155
if (opts.version) {
155156
console.log(Handlebars.VERSION);
156157
return;
@@ -219,7 +220,7 @@ module.exports.cli = function(opts) {
219220
output.add('{};\n');
220221
}
221222

222-
opts.templates.forEach(function(template) {
223+
for (const template of opts.templates) {
223224
let options = {
224225
knownHelpers: known,
225226
knownHelpersOnly: opts.o
@@ -236,11 +237,12 @@ module.exports.cli = function(opts) {
236237

237238
// If we are generating a source map, we have to reconstruct the SourceNode object
238239
if (opts.map) {
239-
let consumer = new SourceMapConsumer(precompiled.map);
240+
let consumer = await new SourceMapConsumer(precompiled.map);
240241
precompiled = SourceNode.fromStringWithSourceMap(
241242
precompiled.code,
242243
consumer
243244
);
245+
consumer.destroy();
244246
}
245247

246248
if (opts.simple) {
@@ -262,7 +264,7 @@ module.exports.cli = function(opts) {
262264
');\n'
263265
]);
264266
}
265-
});
267+
}
266268

267269
// Output the content
268270
if (!opts.simple) {

package-lock.json

Lines changed: 57 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@handlebars/parser": "^1.1.0",
2424
"neo-async": "^2.6.2",
25-
"source-map": "^0.6.1",
25+
"source-map": "^0.7.3",
2626
"yargs": "^16.2.0"
2727
},
2828
"peerDependencies": {

spec/precompiler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ describe('precompiler', function() {
8383
console.error = errorLogFunction;
8484
});
8585

86-
it('should output version', function() {
87-
Precompiler.cli({ templates: [], version: true });
86+
it('should output version', async function() { // TODO do this for all other tests
87+
await Precompiler.cli({ templates: [], version: true });
8888
equals(log, Handlebars.VERSION);
8989
});
90-
it('should throw if lacking templates', function() {
90+
it('should throw if lacking templates', async function() {
9191
shouldThrow(
9292
function() {
93-
Precompiler.cli({ templates: [] });
93+
await Precompiler.cli({ templates: [] });
9494
},
9595
Handlebars.Exception,
9696
'Must define at least one template or directory.'

spec/source-map.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('source-map', function() {
2121
equal(!!template.code, true);
2222
equal(!!template.map, !CompilerContext.browser);
2323
});
24-
it('should map source properly', function() {
24+
it('should map source properly', async function() {
2525
var templateSource =
2626
' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}',
2727
template = Handlebars.precompile(templateSource, {
@@ -30,13 +30,15 @@ describe('source-map', function() {
3030
});
3131

3232
if (template.map) {
33-
var consumer = new SourceMapConsumer(template.map),
33+
var consumer = await new SourceMapConsumer(template.map),
3434
lines = template.code.split('\n'),
3535
srcLines = templateSource.split('\n'),
3636
generated = grepLine('" b"', lines),
3737
source = grepLine(' b', srcLines);
3838

3939
var mapped = consumer.originalPositionFor(generated);
40+
consumer.destroy();
41+
4042
equal(mapped.line, source.line);
4143
equal(mapped.column, source.column);
4244
}

tests/print-script.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var template = Handlebars.precompile(script, {
2222
if (!verbose) {
2323
console.log(template);
2424
} else {
25-
var consumer = new SourceMapConsumer(template.map),
25+
var consumer = await new SourceMapConsumer(template.map),
2626
lines = template.code.split('\n'),
2727
srcLines = script.split('\n');
2828

@@ -111,4 +111,6 @@ if (!verbose) {
111111
);
112112
}
113113
});
114+
115+
consumer.destroy();
114116
}

0 commit comments

Comments
 (0)