Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline
regeneratorRuntime
as a normal helper (#14538)
Co-authored-by: Babel Bot <babel-bot@users.noreply.github.com>
- Loading branch information
1 parent
e57d081
commit e0a2a71
Showing
88 changed files
with
1,243 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/babel-helpers/scripts/generate-regenerator-runtime.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
import fs from "fs"; | ||
import { createRequire } from "module"; | ||
|
||
const [parse, generate] = await Promise.all([ | ||
import("@babel/parser").then(ns => ns.parse), | ||
import("@babel/generator").then(ns => ns.default.default), | ||
]).catch(error => | ||
Promise.reject( | ||
new Error( | ||
"Before running generate-helpers.js you must compile @babel/parser and @babel/generator.", | ||
{ cause: error } | ||
) | ||
) | ||
); | ||
|
||
const REGENERATOR_RUNTIME_IN_FILE = fs.readFileSync( | ||
createRequire(import.meta.url).resolve("regenerator-runtime"), | ||
"utf8" | ||
); | ||
|
||
const MIN_VERSION = "7.17.9"; | ||
|
||
const HEADER = `/* @minVersion ${MIN_VERSION} */ | ||
/* | ||
* This file is auto-generated! Do not modify it directly. | ||
* To re-generate, update the regenerator-runtime dependency of | ||
* @babel/helpers and run 'yarn gulp generate-runtime-helpers'. | ||
*/ | ||
/* eslint-disable */ | ||
`; | ||
|
||
const COPYRIGHT = `/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */`; | ||
|
||
export default function generateRegeneratorRuntimeHelper() { | ||
const ast = parse(REGENERATOR_RUNTIME_IN_FILE, { sourceType: "script" }); | ||
|
||
const factoryFunction = ast.program.body[0].declarations[0].init.callee; | ||
factoryFunction.type = "FunctionDeclaration"; | ||
factoryFunction.id = { type: "Identifier", name: "_regeneratorRuntime" }; | ||
factoryFunction.params = []; | ||
factoryFunction.body.body.unshift( | ||
...stmts(` | ||
${COPYRIGHT} | ||
_regeneratorRuntime = function () { return exports; }; | ||
var exports = {}; | ||
`) | ||
); | ||
|
||
const { code } = generate({ | ||
type: "ExportDefaultDeclaration", | ||
declaration: factoryFunction, | ||
}); | ||
|
||
return HEADER + code; | ||
} | ||
|
||
function stmts(code) { | ||
return parse(`function _() { ${code} }`, { | ||
sourceType: "script", | ||
}).program.body[0].body.body; | ||
} |
Oops, something went wrong.