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

Return compiled Handlebars string, no source maps #24

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
23 changes: 13 additions & 10 deletions strcalc/src/main/frontend/rollup-plugin-handlebars-precompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class PluginImpl {
this.#isPartial = createFilter(options.partials || DEFAULT_PARTIALS)
this.#partialName = options.partialName || DEFAULT_PARTIAL_NAME
this.#partialPath = options.partialPath || DEFAULT_PARTIAL_PATH

if (this.#options.compiler) {
delete this.#options.compiler.srcName
delete this.#options.compiler.destName
}
}

hasHelpers() { return this.#helpers.length }
Expand All @@ -112,16 +117,14 @@ class PluginImpl {
const collector = new PartialCollector()
collector.accept(ast)

return {
code: [
IMPORT_HANDLEBARS,
...(this.hasHelpers() ? [ IMPORT_HELPERS ] : []),
...collector.partials.map(p => `import '${this.#partialPath(p, id)}'`),
`const Template = Handlebars.template(${tmpl})`,
'export default Template',
...(this.#isPartial(id) ? [ this.partialRegistration(id) ] : [])
].join('\n')
}
return [
IMPORT_HANDLEBARS,
...(this.hasHelpers() ? [ IMPORT_HELPERS ] : []),
...collector.partials.map(p => `import '${this.#partialPath(p, id)}'`),
`const Template = Handlebars.template(${tmpl})`,
'export default Template',
...(this.#isPartial(id) ? [ this.partialRegistration(id) ] : [])
].join('\n')
}

partialRegistration(id) {
Expand Down