mirror of
https://github.com/hanzoai/babel.git
synced 2026-10-30 14:46:06 +00:00
* Convert `@babel/helpers` tests to ESM * Run some tests on older versions * Fix * Update jest.config.js
25 lines
687 B
JavaScript
25 lines
687 B
JavaScript
import path from "path";
|
|
import _template from "@babel/template";
|
|
import _helpers from "../../lib/helpers.js";
|
|
const template = _template.default || _template;
|
|
const helpers = _helpers.default || _helpers;
|
|
|
|
function getHelperId(baseURL, name) {
|
|
const testName = path.basename(new URL(".", baseURL).pathname);
|
|
return `_$_${testName}_${name}`;
|
|
}
|
|
|
|
export default function defineHelper(baseURL, name, code) {
|
|
const id = getHelperId(baseURL, name);
|
|
if (id in helpers) {
|
|
throw new Error(`The ${id} helper is already defined.`);
|
|
}
|
|
Object.defineProperty(helpers, id, {
|
|
value: {
|
|
minVersion: "7.0.0-beta.0",
|
|
ast: template.program(code),
|
|
},
|
|
});
|
|
return id;
|
|
}
|