-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Convert remaning runtime helpers to TypeScript #16500
Description
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.tsextension, such asimport toPropertyKey from "./toPropertyKey.ts";. The reason for using.tseven when importing.jsfiles is that, when this issue will be completed, all those files will be using.tsanyway. If TS complain that it cannot find the types of the dependency because it's still written in JS, add// @ts-expect-errorbefore the import. - The files must type-heck when running
make tscheck-helpers(oryarn 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)
- Fork the repo
- Run
git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel - Run
yarn && make bootstrap - Wait ⏳
- Update the code!
- Whenever you change a helper, you'll need to run
yarn gulp generate-runtime-helpersto 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) - Once you are done, you can run
make buildto re-build everything, and thenmake testto run all the tests - Run
git pushand 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)
applyDecoratedDescriptorsinitializerDefinePropertyinitializerWarningHelper
- New decorators (@liuxingbaoyu)
defineAccessoridentitysetFunctionName(see note above)applyDecs2311(see note above)
- Arrays (@blakewilson)
arrayLikeToArrayarrayWithHolesarrayWithoutHolesiterableToArrayiterableToArrayLimititerableToArrayLoosemaybeArrayLikeunsupportedIterableToArrayslicedToArrayslicedToArrayLoosetoArraytoConsumableArray
- Objects (@SukkaW)
defaultsextendsobjectDestructuringEmptyobjectSpread2objectWithoutPropertiesobjectWithoutPropertiesLoose
- Reflection (@coelhucas)
defineEnumerablePropertiesdefinePropertygetgetPrototypeOfsetsetPrototypeOfsuperPropBaseconstruct(see note above)
- Classes (@amjed-98)
assertThisInitializedclassCallCheckcreateClasspossibleConstructorReturn
- Subclasses (@amjed-98)
callSuperinheritsinheritsLooseisNativeFunctionwrapNativeSuper
- For-of (@SukkaW)
creaeForOfIteratorHelpercreaeForOfIteratorHelperLoose
- Async functions/generators (@SukkaW)
asyncToGeneratorAsyncGeneratorasyncGeneratorDelegateasyncIteratorawaitAsyncGeneratorOverloadYieldwrapAsyncGenerator
- Class fields (@Zzzen)
checkPrivateRedeclarationclassPrivateFieldInitSpecclassPrivateMethodInitSpecclassStaticPrivateMethodGetclassPrivateFieldLooseBaseclassPrivateFieldLooseKeyreadOnlyErrorwriteOnlyError
- Modules (@amjed-98)
interopRequireDefaultinteropRequireWildcardimportDeferProxy
- Temporal dead zone (@amjed-98)
tdztemporalReftemporalUndefined
- Other (@SukkaW)
jsxtaggedTemplateLiteraltaggedTemplateLiteralLooseinstanceoftypeofwrapRegExpusingCtx(see note above)