Content-Length: 294475 | pFad | http://redirect.github.com/babel/babel/pull/16743

65 Work with symbol polyfill by breeze2 · Pull Request #16743 · babel/babel · GitHub
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

Work with symbol polyfill #16743

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Work with symbol polyfill #16743

wants to merge 1 commit into from

Conversation

breeze2
Copy link

@breeze2 breeze2 commented Aug 14, 2024

Q                       A
Fixed Issues?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Make the toPrimitive work with Symbol polyfill.
For example, there is a symbol x, normally typeof x === "symbol" is true. But typeof x === "object" is true when the Symbol is polyfilled.

Related links:

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 14, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57690

@nicolo-ribaudo
Copy link
Member

I'm confused by why this is needed.

  1. If you are using babel/runtime, then that typeof expression is replaced by a call to the typeof helper, which handles polygilled symbols
  2. If you are not, you should be using babel/plugin-transform-typeof-symbol anyway (so that typeof works in general), and it will make this typeof work.

@breeze2
Copy link
Author

breeze2 commented Aug 17, 2024

I'm confused by why this is needed.

  1. If you are using babel/runtime, then that typeof expression is replaced by a call to the typeof helper, which handles polygilled symbols
  2. If you are not, you should be using babel/plugin-transform-typeof-symbol anyway (so that typeof works in general), and it will make this typeof work.

Thanks for your reply.
I think the point is that the current typeof res !== "object" is not transformed to _typeof(res) !== "object".
So, should I do it this way,

// packages/babel-helpers/src/helpers/toPrimitive.ts

import typeOf from "./typeof.ts";
...
if (typeOf(res) !== "object") return res;
...

or do you have any other suggestions?

@breeze2
Copy link
Author

breeze2 commented Aug 17, 2024

Interestingly, I saw another scene in @babel/helpers (https://unpkg.com/browse/@babel/helpers@7.25.0/lib/helpers/toPrimitive.js), and the mobx (https://unpkg.com/browse/mobx@6.13.1/dist/mobx.esm.js#:~:text=function-,_toPrimitive,-(t%2C%20r) really doesn't use the _typeof function.

So, is it an issue with the mobx build configuration?

@breeze2
Copy link
Author

breeze2 commented Aug 22, 2024

Please confirm whether need to use typeOf in toPrimitive.
If not, please close this pr.

@nicolo-ribaudo
Copy link
Member

I investigated this a bit. The reason seems (seems because I cannot find Mobx's Babel config) that Mobx is not transpiled to support IE11, and thus the injected _typeof helper does not support the symbol polyfill for IE11.

There are two solutions:

  • Mobx starts transpiling their code targeting IE11
  • You (user of Mobx) have to transpile Mobx's code with Babel from your node_modules, targeting IE11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://redirect.github.com/babel/babel/pull/16743

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy