Use .program template for helpers.

This commit is contained in:
Logan Smyth 2017-10-15 15:51:40 -04:00
parent cc802c1e00
commit 107c37715e
3 changed files with 3 additions and 4 deletions

View File

@ -7,7 +7,7 @@ export default helpers;
// Helpers never include placeholders, so we disable placeholder pattern // Helpers never include placeholders, so we disable placeholder pattern
// matching to allow us to use pattern-like variable names. // matching to allow us to use pattern-like variable names.
const defineHelper = template({ placeholderPattern: false }); const defineHelper = template.program({ placeholderPattern: false });
helpers.typeof = defineHelper(` helpers.typeof = defineHelper(`
export default function _typeof(obj) { export default function _typeof(obj) {

View File

@ -232,8 +232,7 @@ function loadHelper(name) {
if (!helpers[name]) throw new ReferenceError(`Unknown helper ${name}`); if (!helpers[name]) throw new ReferenceError(`Unknown helper ${name}`);
const fn = () => { const fn = () => {
const ast = helpers[name](); return t.file(helpers[name]());
return t.file(t.program(Array.isArray(ast) ? ast : [ast]));
}; };
const metadata = getHelperMetadata(fn()); const metadata = getHelperMetadata(fn());

View File

@ -17,7 +17,7 @@ export default function defineHelper(
throw new Error(`The ${id} helper is already defined.`); throw new Error(`The ${id} helper is already defined.`);
} }
Object.defineProperty(helpers, id, { Object.defineProperty(helpers, id, {
value: template(code), value: template.program(code),
}); });
return id; return id;
} }