Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/precompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ function loadFiles(opts, callback) {
);
}

module.exports.cli = function (opts) {
module.exports.cli = async function (opts) {
// TODO what implications does this have?
if (opts.version) {
console.log(Handlebars.VERSION);
return;
Expand Down Expand Up @@ -222,7 +223,7 @@ module.exports.cli = function (opts) {
output.add('{};\n');
}

opts.templates.forEach(function (template) {
for (const template of opts.templates) {
let options = {
knownHelpers: known,
knownHelpersOnly: opts.o,
Expand All @@ -239,11 +240,12 @@ module.exports.cli = function (opts) {

// If we are generating a source map, we have to reconstruct the SourceNode object
if (opts.map) {
let consumer = new SourceMapConsumer(precompiled.map);
let consumer = await new SourceMapConsumer(precompiled.map);
precompiled = SourceNode.fromStringWithSourceMap(
precompiled.code,
consumer
);
consumer.destroy();
}

if (opts.simple) {
Expand All @@ -265,7 +267,7 @@ module.exports.cli = function (opts) {
');\n',
]);
}
});
}

// Output the content
if (!opts.simple) {
Expand Down
65 changes: 57 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@handlebars/parser": "^2.1.0",
"neo-async": "^2.6.2",
"source-map": "^0.6.1",
"source-map": "^0.7.4",
"yargs": "^16.2.0"
},
"peerDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions spec/precompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ describe('precompiler', function () {
console.error = errorLogFunction;
});

it('should output version', function () {
Precompiler.cli({ templates: [], version: true });
it('should output version', async function () {
// TODO do this for all other tests
await Precompiler.cli({ templates: [], version: true });
equals(log, Handlebars.VERSION);
});
it('should throw if lacking templates', function () {
shouldThrow(
function () {
Precompiler.cli({ templates: [] });
async function () {
await Precompiler.cli({ templates: [] });
},
Handlebars.Exception,
'Must define at least one template or directory.'
Expand Down
6 changes: 4 additions & 2 deletions spec/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('source-map', function () {
equal(!!template.code, true);
equal(!!template.map, !CompilerContext.browser);
});
it('should map source properly', function () {
it('should map source properly', async function () {
var templateSource =
' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}',
template = Handlebars.precompile(templateSource, {
Expand All @@ -30,13 +30,15 @@ describe('source-map', function () {
});

if (template.map) {
var consumer = new SourceMapConsumer(template.map),
var consumer = await new SourceMapConsumer(template.map),
lines = template.code.split('\n'),
srcLines = templateSource.split('\n'),
generated = grepLine('" b"', lines),
source = grepLine(' b', srcLines);

var mapped = consumer.originalPositionFor(generated);
consumer.destroy();

equal(mapped.line, source.line);
equal(mapped.column, source.column);
}
Expand Down
Loading