New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel-plugin-async-to-generator should add #__PURE__ comment #6572
Comments
Hey @winstonewert! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Hello, It seems no one has offered to provide a solution. Would you mind if I had a go at it? It is my first time contributing to open software, but I think I can manage something. :) |
@Eric-Zayas Go for it! |
@Eric-Zayas Perhaps you could try something like this? --- a/packages/babel-helper-remap-async-to-generator/src/index.js
+++ b/packages/babel-helper-remap-async-to-generator/src/index.js
@@ -4,6 +4,7 @@ import type { NodePath } from "@babel/traverse";
import wrapFunction from "@babel/helper-wrap-function";
import * as t from "@babel/types";
import rewriteForAwait from "./for-await";
+import annotateAsPure from "@babel/helper-annotate-as-pure";
const awaitVisitor = {
Function(path) {
@@ -71,4 +72,5 @@ export default function(path: NodePath, file: Object, helpers: Object) {
path.node.generator = true;
wrapFunction(path, helpers.wrapAsync);
+ annotateAsPure(path.isDeclaration() ? path.get("declarations.0.init") : path);
} I didn't run the test suite due to unrelated errors in my environment. |
@Eric-Zayas Have you found some time to work on the issue? Should we keep it as claimed for you? No rush, just let us know :) |
I'd like to work on this if you don't have time @Eric-Zayas |
@Eric-Zayas FYI a PR has been merged for this. Sorry if you was working on it but you didn't answer. |
Request: add pure comments to async function helpers to aid in dead code elimination.
Input Code
https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=IYZwngdgxgBAZgV2gFwJYHsLwKbKgCwAVgBzbAEWGWAAoAHU7AShgG8AoGGAJ1wW6ysAvuyFA&debug=false&circleciRepo=&evaluate=false&lineWrap=true&presets=es2015%2Creact%2Cstage-2&targets=&version=6.26.0
Expected Behavior
Generated code should be able to be removed as dead by uglifyjs/similiar if the async function is not called.
Current Behavior
Note that while regeneratorRuntime.mark is marked as #PURE, the call to _asyncToGenerator and the IIFE aren't.
Possible Solution
Generated code should start with:
var fetchPageData = /#__PURE/ function () {
Context
I have a react app which runs on both client and server. However, I have various async functions that only run on the server. I want to have them removed during the minification process.
The text was updated successfully, but these errors were encountered: