Skip to content

Commit 1541d1f

Browse files
committed
Use latest source-map-version
Resolves #1427
1 parent e668696 commit 1541d1f

File tree

6 files changed

+173
-114
lines changed

6 files changed

+173
-114
lines changed

lib/precompiler.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ function loadFiles(opts, callback) {
153153
);
154154
}
155155

156-
module.exports.cli = function (opts) {
156+
module.exports.cli = async function (opts) {
157+
// TODO what implications does this have?
157158
if (opts.version) {
158159
console.log(Handlebars.VERSION);
159160
return;
@@ -222,7 +223,7 @@ module.exports.cli = function (opts) {
222223
output.add('{};\n');
223224
}
224225

225-
opts.templates.forEach(function (template) {
226+
for (const template of opts.templates) {
226227
let options = {
227228
knownHelpers: known,
228229
knownHelpersOnly: opts.o,
@@ -239,11 +240,12 @@ module.exports.cli = function (opts) {
239240

240241
// If we are generating a source map, we have to reconstruct the SourceNode object
241242
if (opts.map) {
242-
let consumer = new SourceMapConsumer(precompiled.map);
243+
let consumer = await new SourceMapConsumer(precompiled.map);
243244
precompiled = SourceNode.fromStringWithSourceMap(
244245
precompiled.code,
245246
consumer
246247
);
248+
consumer.destroy();
247249
}
248250

249251
if (opts.simple) {
@@ -265,7 +267,7 @@ module.exports.cli = function (opts) {
265267
');\n',
266268
]);
267269
}
268-
});
270+
}
269271

270272
// Output the content
271273
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": "^2.1.0",
2424
"neo-async": "^2.6.2",
25-
"source-map": "^0.6.1",
25+
"source-map": "^0.7.4",
2626
"yargs": "^16.2.0"
2727
},
2828
"peerDependencies": {

spec/precompiler.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ 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 () {
87+
// TODO do this for all other tests
88+
await Precompiler.cli({ templates: [], version: true });
8889
equals(log, Handlebars.VERSION);
8990
});
9091
it('should throw if lacking templates', function () {
9192
shouldThrow(
92-
function () {
93-
Precompiler.cli({ templates: [] });
93+
async function () {
94+
await Precompiler.cli({ templates: [] });
9495
},
9596
Handlebars.Exception,
9697
'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
}

0 commit comments

Comments
 (0)