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

[helpers TS conversion] classes #16511

Merged
merged 10 commits into from
May 20, 2024

Conversation

amjed-98
Copy link
Contributor

Q                       A
Fixed Issues? Fixes Part of #16500
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

Migrate all classes helper functions (createClass, possibleConstructorReturn, classCallCheck, assertThisInitialized) to TypeScript

@amjed-98 amjed-98 changed the title Migrate classes helpers [helpers TS conversion] classes May 18, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented May 18, 2024

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

@liuxingbaoyu
Copy link
Member

Thanks! For compatibility, we need to keep var. :)

var _typeof = require("./typeof.js")["default"];
var assertThisInitialized = require("./assertThisInitialized.js");

function _possibleConstructorReturn<T, U>(t: T, e: U): U | T {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to migrate to export default? Let's give it a shot and see if the make test passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!
on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I also convert require() to use esm import?
@SukkaW

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files in this directory should be automatically generated and we should not edit it manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah you're right

there is another file called possibleConstructorReturn.js in packages/babel-helpers/src/helpers/possibleConstructorReturn.js

which has the same name as this one

should I also convert it to typescript?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should convert packages/babel-helpers/src/helpers/possibleConstructorReturn.js and remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed and pushed

amjed-98 and others added 2 commits May 19, 2024 09:09
make the function accept undefined as a param type

Co-authored-by: Sukka <isukkaw@gmail.com>
@amjed-98
Copy link
Contributor Author

For compatibility, we need to keep var. :)

I must have changed it out of habit unconsciously

reverted! @liuxingbaoyu

@liuxingbaoyu
Copy link
Member

Did you forget to push your changes? :)

@amjed-98
Copy link
Contributor Author

pushed

import toPropertyKey from "toPropertyKey";
function _defineProperties(target, props) {
// @ts-expect-error Migrate in another PR
import toPropertyKey from "toPropertyKey.ts";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import toPropertyKey from "toPropertyKey.ts";
import toPropertyKey from "./toPropertyKey.ts";

(and it's already written in TS :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 5 to 7
export default function _possibleConstructorReturn<
T extends object | undefined,
>(self: T, call: T | ((...args: any[]) => T) | undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are here, let's rename call to value. Calling it call makes absolutely no sense 😅

It's the value passed to return in a derived class constructor:

class A extends B {
  constructor() {
    return 1;
  }
}

"call" is 1 in this case.

(and probably it's type should just be any or unknown)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!!
that makes much sense now!

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 3b1a3c0 into babel:main May 20, 2024
51 checks passed
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.

None yet

5 participants