| 1 | import path from "path"; |
| 2 | import _template from "@babel/template"; |
| 3 | import _helpers from "../../lib/helpers.js"; |
| 4 | const template = _template.default || _template; |
| 5 | const helpers = _helpers.default || _helpers; |
| 6 | |
| 7 | function getHelperId(baseURL, name) { |
| 8 | const testName = path.basename(new URL(".", baseURL).pathname); |
| 9 | return `_$_${testName}_${name}`; |
| 10 | } |
| 11 | |
| 12 | export default function defineHelper(baseURL, name, code) { |
| 13 | const id = getHelperId(baseURL, name); |
| 14 | if (id in helpers) { |
| 15 | throw new Error(`The ${id} helper is already defined.`); |
| 16 | } |
| 17 | Object.defineProperty(helpers, id, { |
| 18 | value: { |
| 19 | minVersion: "7.0.0-beta.0", |
| 20 | ast: template.program(code), |
| 21 | }, |
| 22 | }); |
| 23 | return id; |
| 24 | } |