-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Annotating transformed classes with #__PURE__ comment #6209
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| "column": 10 | ||
| }, | ||
| "generated": { | ||
| "line": 9, | ||
| "line": 11, | ||
| "column": 15 | ||
| } | ||
| }] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ import LooseTransformer from "./loose"; | |
| import VanillaTransformer from "./vanilla"; | ||
| import nameFunction from "babel-helper-function-name"; | ||
|
|
||
| const PURE_ANNOTATION = "#__PURE__"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use this across multiple plugins? We might want to add it in a helper.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xtuc sure thing, whats the best place to add such?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too late but I had something like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just make it when we need/get to it. It's not a breaking change to swap it out either |
||
|
|
||
| export default function({ types: t }) { | ||
| // todo: investigate traversal requeueing | ||
| const VISITED = Symbol(); | ||
|
|
@@ -51,11 +53,11 @@ export default function({ types: t }) { | |
|
|
||
| path.replaceWith(new Constructor(path, state.file).run()); | ||
|
|
||
| if ( | ||
| path.isCallExpression() && | ||
| path.get("callee").isArrowFunctionExpression() | ||
| ) { | ||
| path.get("callee").arrowFunctionToExpression(); | ||
| if (path.isCallExpression()) { | ||
| path.addComment("leading", PURE_ANNOTATION); | ||
| if (path.get("callee").isArrowFunctionExpression()) { | ||
| path.get("callee").arrowFunctionToExpression(); | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| var x = function () { | ||
| var x = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| var _proto = x.prototype; | ||
|
|
||
| _proto.f = function f() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| var Foo = function () { | ||
| var Foo = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| function Foo() {} | ||
|
|
||
| var _proto = Foo.prototype; | ||
|
|
||
| _proto["bar"] = function bar() {}; | ||
|
|
||
| return Foo; | ||
| }(); | ||
| }(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not important... but is there a reason why this is on 3 lines instead of 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its just how
babel-generatorspits out code from the AST, looks weird to me too, but 🙄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably just because we removed some logic with newlines using tokens/comments so it's like that now