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
Implement new @swc/helpers
#7182
Conversation
c09e926
to
88036a5
Compare
(async function() { | ||
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../packages/a/src/index"))); | ||
const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ (0, _interop_require_wildcard._interop_require_wildcard)(require("../packages/a/src/index"))); |
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.
I think this will regress the bundle size by margin.
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.
Do you mean the indirect call?
We known that there is no this
issue in our helpers.
Is it safe to call function directlly?
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.
I meant that _interop_xxx
cannot be optimized by the minifier.
I think it's better to invoke it directly
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.
I meant that
_interop_xxx
cannot be optimized by the minifier.I think it's better to invoke it directly
Done. fixed by keep using the pattern fn.apply(this, arguments)
.
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.
I still need to handle it in CJS/AMD/UMD
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.
I meant that
_interop_xxx
cannot be optimized by the minifier.I think it's better to invoke it directly
The first solution is to disable rewriting exported functions in esm so that we can safely use var foo = require("foo").foo
.
But if other bundler handle our helpers, it does not know that our export is constant and may not apply such optimization.
The second solution is to add another constant named export with shorter name such as _
, and then use it in transpiled file as follows:
var foo = require("foo");
foo._(bar);.
Which is better?
Compare:
magic-akari/swc@swc-helpers...magic-akari:swc:swc-helpers-short-named
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.
Wow, the second one sounds cool. What a clever trick!
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.
is there a simple way to get helpers SyntaxContext?
I am trying to skip the indrect call (0, foo)._
for helpers.
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.
I got it by using
HELPERS.with(|helper| helper.mark());
@@ -1,4 +1,4 @@ | |||
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; | |||
import { _ts_generator } from "@swc/helpers/_/_ts_generator"; |
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.
I think this will regress the bundle size, too.
import { _ts_generator as e } from "@swc/helpers/_/_ts_generator";
e()
This is how it's optimized, but this looks problematic
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.
The test cases will be updated.
It will be changed to the following:
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
and with optimized phase:
import { _ as e } from "@swc/helpers/_/_ts_generator";
e()
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.
I see, thank you so much!
I don't know why, but GitHub shows a wrong diff. I'm not sure how should I review this 🤣 |
I already tried it, but it didn't work |
Try to checkout locally? |
I checked it out, but |
c9ccd08
to
fdcdafc
Compare
Done. |
It didn't work, but I think I can review it using cli tools now |
- named export - unified import path
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.
Thank you! I'll update swc/fixture and swc/tsc soon
swc-bump:
- swc_ecma_utils
- swc_ecma_transforms_base --breaking
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.
Automated review comment generated by auto-rebase script
Description:
BREAKING CHANGE:
Breaking changes for
@swc/helpers
.new major version
0.5.0
is required.Related issue (if exists):