Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a Runtime Crash #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ function asyncHelpers(hbs) {

return function(context, execOptions) {
context = context || {}
const result = compiled.call(handlebars, context, execOptions)

if (isPromise(result)) {
// this are dummy methods to work with handlebar code, it is only designed for usage with that, otherwise it may break!
result.split = () => { return [] }
result.join = () => { return result }

return compiled.call(handlebars, context, execOptions)
return result

}
return result
}
}
handlebars.ASYNC_VERSION = app.version
Expand Down
31 changes: 31 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,37 @@ describe('Test async helpers', () => {
const compiled = hbs.compile(template),
result = await compiled()
should.equal(result, expected)
})

it('Test indentation with async partial', async () => {
const hbs = asyncHelpers(Handlebars),
template = `<div>Parent
{{> child}}
<div class="test">
{{> child}}
</div>
</div>`,
child = '<div>Child:\n\t\t\t{{> grandChild}}\n</div>',
grandChild = '<p>\nGrand Child: {{#delayed 50}}\n{{/delayed}}\n</p>'

hbs.registerHelper('delayed', (time) => {
return new Promise((resolve) => {
setTimeout(() => resolve('Hello!'), time)
})
})


hbs.registerPartial('child', child)
hbs.registerPartial('grandChild', grandChild)

const compiled = hbs.compile(template)

const result = compiled()
await result.should.be.fulfilled();




})

it('Test synchronous helper', async () => {
Expand Down