Skip to content

Convert remaning runtime helpers to TypeScript #16500

@nicolo-ribaudo

Description

@nicolo-ribaudo

Our source files are mostly written in TypeScript, with the exception of most of the runtime helpers that we inject in the compiled code. Since #16495 all those helpers are stored in individual files and pre-transpiled, so we can move all those that are still written in JS to TypeScript.

There are some rules/instructions to follows:

  • Many imports currently use "bare specifiers", such as import toPropertyKey from "toPropertyKey";. They must be converted to relative imports always using the .ts extension, such as import toPropertyKey from "./toPropertyKey.ts";. The reason for using .ts even when importing .js files is that, when this issue will be completed, all those files will be using .ts anyway. If TS complain that it cannot find the types of the dependency because it's still written in JS, add // @ts-expect-error before the import.
  • The files must type-heck when running make tscheck-helpers (or yarn tsc -p ./packages/babel-helpers/src/helpers/tsconfig.json, which is equivalent)
  • Some of those helpers use absolutely unreadable variable names, such as https://github.com/babel/babel/blob/db3e9a6cbdaba16dc480a1f76a11b0d2ea84adc4/packages/babel-helpers/src/helpers/iterableToArrayLimit.js, because those files were "manually minified". No we minify helpers at build time, so we can afford to use readable variables: feel free to change them!

To coordinate this work, I split all our helpers in groups: those who want to help can leave a comment saying which group you want to work, and then start working on a PR :) If you want to work on multiple groups, start by claiming one and then after that the PR is merged you can claim a second one (and so on).

If it is the first time that you contribute to Babel, follow these steps: (you need to have make and yarn available on your machine)

  1. Fork the repo
  2. Run git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
  3. Run yarn && make bootstrap
  4. Wait ⏳
  5. Update the code!
  6. Whenever you change a helper, you'll need to run yarn gulp generate-runtime-helpers to regenerate ./packages/babel-helpers/src/helpers-generated.ts (this is probably not needed if you just add types, but it is if you for example change variable names)
  7. Once you are done, you can run make build to re-build everything, and then make test to run all the tests
  8. Run git push and open a PR!

NOTE: Some of the helpers in this list are already written in TS, but they are failing type-checking. The task for those is to remove them from packages/babel-helpers/src/helpers/tsconfig.json's exclude list and fix the type errors.

  • Legacy decorators (@amjed-98)
    • applyDecoratedDescriptors
    • initializerDefineProperty
    • initializerWarningHelper
  • New decorators (@liuxingbaoyu)
    • defineAccessor
    • identity
    • setFunctionName (see note above)
    • applyDecs2311 (see note above)
  • Arrays (@blakewilson)
    • arrayLikeToArray
    • arrayWithHoles
    • arrayWithoutHoles
    • iterableToArray
    • iterableToArrayLimit
    • iterableToArrayLoose
    • maybeArrayLike
    • unsupportedIterableToArray
    • slicedToArray
    • slicedToArrayLoose
    • toArray
    • toConsumableArray
  • Objects (@SukkaW)
    • defaults
    • extends
    • objectDestructuringEmpty
    • objectSpread2
    • objectWithoutProperties
    • objectWithoutPropertiesLoose
  • Reflection (@coelhucas)
    • defineEnumerableProperties
    • defineProperty
    • get
    • getPrototypeOf
    • set
    • setPrototypeOf
    • superPropBase
    • construct (see note above)
  • Classes (@amjed-98)
    • assertThisInitialized
    • classCallCheck
    • createClass
    • possibleConstructorReturn
  • Subclasses (@amjed-98)
    • callSuper
    • inherits
    • inheritsLoose
    • isNativeFunction
    • wrapNativeSuper
  • For-of (@SukkaW)
    • creaeForOfIteratorHelper
    • creaeForOfIteratorHelperLoose
  • Async functions/generators (@SukkaW)
    • asyncToGenerator
    • AsyncGenerator
    • asyncGeneratorDelegate
    • asyncIterator
    • awaitAsyncGenerator
    • OverloadYield
    • wrapAsyncGenerator
  • Class fields (@Zzzen)
    • checkPrivateRedeclaration
    • classPrivateFieldInitSpec
    • classPrivateMethodInitSpec
    • classStaticPrivateMethodGet
    • classPrivateFieldLooseBase
    • classPrivateFieldLooseKey
    • readOnlyError
    • writeOnlyError
  • Modules (@amjed-98)
    • interopRequireDefault
    • interopRequireWildcard
    • importDeferProxy
  • Temporal dead zone (@amjed-98)
    • tdz
    • temporalRef
    • temporalUndefined
  • Other (@SukkaW)
    • jsx
    • taggedTemplateLiteral
    • taggedTemplateLiteralLoose
    • instanceof
    • typeof
    • wrapRegExp
    • usingCtx (see note above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: helpershelp wantedoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions