source: imaps-frontend/node_modules/@babel/helpers/scripts/generate-regenerator-runtime.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import fs from "fs";
2import { createRequire } from "module";
3
4const [parse, generate] = await Promise.all([
5 import("@babel/parser").then(ns => ns.parse),
6 import("@babel/generator").then(ns => ns.default.default || ns.default),
7]).catch(error => {
8 console.error(error);
9 throw new Error(
10 "Before running generate-helpers.js you must compile @babel/parser and @babel/generator.",
11 { cause: error }
12 );
13});
14
15const REGENERATOR_RUNTIME_IN_FILE = fs.readFileSync(
16 createRequire(import.meta.url).resolve("regenerator-runtime"),
17 "utf8"
18);
19
20const MIN_VERSION = "7.18.0";
21
22const HEADER = `/* @minVersion ${MIN_VERSION} */
23/*
24 * This file is auto-generated! Do not modify it directly.
25 * To re-generate, update the regenerator-runtime dependency of
26 * @babel/helpers and run 'yarn gulp generate-runtime-helpers'.
27 */
28
29/* eslint-disable */
30`;
31
32const COPYRIGHT = `/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */`;
33
34export default function generateRegeneratorRuntimeHelper() {
35 const ast = parse(REGENERATOR_RUNTIME_IN_FILE, { sourceType: "script" });
36
37 const factoryFunction = ast.program.body[0].declarations[0].init.callee;
38 factoryFunction.type = "FunctionDeclaration";
39 factoryFunction.id = { type: "Identifier", name: "_regeneratorRuntime" };
40 factoryFunction.params = [];
41 factoryFunction.body.body.unshift(
42 ...stmts(`
43 ${COPYRIGHT}
44 _regeneratorRuntime = function () { return exports; };
45 var exports = {};
46 `)
47 );
48
49 const { code } = generate({
50 type: "ExportDefaultDeclaration",
51 declaration: factoryFunction,
52 });
53
54 return HEADER + code;
55}
56
57function stmts(code) {
58 return parse(`function _() { ${code} }`, {
59 sourceType: "script",
60 }).program.body[0].body.body;
61}
Note: See TracBrowser for help on using the repository browser.