Skip to content
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

Merged
merged 9 commits into from Apr 4, 2023
Merged

Implement new @swc/helpers #7182

merged 9 commits into from Apr 4, 2023

Conversation

magic-akari
Copy link
Member

@magic-akari magic-akari commented Mar 31, 2023

Description:

  • named export
  • unified import path

BREAKING CHANGE:

Breaking changes for @swc/helpers.
new major version 0.5.0 is required.

Related issue (if exists):

@magic-akari magic-akari marked this pull request as ready for review March 31, 2023 14:19
(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")));
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

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) .

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member

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!

Copy link
Member Author

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.

Copy link
Member Author

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());

@magic-akari magic-akari requested a review from kdy1 April 1, 2023 14:24
@kdy1 kdy1 self-assigned this Apr 2, 2023
@kdy1 kdy1 added this to the Planned milestone Apr 2, 2023
@@ -1,4 +1,4 @@
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
import { _ts_generator } from "@swc/helpers/_/_ts_generator";
Copy link
Member

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

Copy link
Member Author

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()

Copy link
Member

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!

@kdy1
Copy link
Member

kdy1 commented Apr 3, 2023

I don't know why, but GitHub shows a wrong diff. I'm not sure how should I review this 🤣

@magic-akari
Copy link
Member Author

I don't know why, but GitHub shows a wrong diff. I'm not sure how should I review this 🤣

image

I wish the builtin GitHub plugin from VSCode will solve this issue.

@kdy1
Copy link
Member

kdy1 commented Apr 3, 2023

I already tried it, but it didn't work

@magic-akari
Copy link
Member Author

magic-akari commented Apr 3, 2023

I already tried it, but it didn't work

Try to checkout locally?
Or should I rebase and squash some commits?

@kdy1
Copy link
Member

kdy1 commented Apr 3, 2023

I checked it out, but git diff upstream/main...pr/magic-akari/7182 fails with fatal: upstream/main...pr/magic-akari/7182: no merge base.
Can you try rebasing?

@magic-akari magic-akari force-pushed the swc-helpers branch 2 times, most recently from c9ccd08 to fdcdafc Compare April 3, 2023 11:30
@magic-akari
Copy link
Member Author

I checked it out, but git diff upstream/main...pr/magic-akari/7182 fails with fatal: upstream/main...pr/magic-akari/7182: no merge base. Can you try rebasing?

Done.
I have split the test cases commits.

@kdy1
Copy link
Member

kdy1 commented Apr 3, 2023

It didn't work, but I think I can review it using cli tools now

kdy1
kdy1 previously approved these changes Apr 4, 2023
Copy link
Member

@kdy1 kdy1 left a 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

@kdy1 kdy1 enabled auto-merge (squash) April 4, 2023 02:20
Copy link
Collaborator

@swc-bot swc-bot left a 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

@kdy1 kdy1 merged commit a13a78e into swc-project:main Apr 4, 2023
127 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.3.45 Apr 4, 2023
@magic-akari magic-akari deleted the swc-helpers branch April 7, 2023 02:31
@swc-project swc-project locked as resolved and limited conversation to collaborators May 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Next Step for @swc/helpers
3 participants