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)
- 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-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)
- Once you are done, you can run
make build to re-build everything, and then make test to run all the tests
- 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.
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:
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.make tscheck-helpers(oryarn tsc -p ./packages/babel-helpers/src/helpers/tsconfig.json, which is equivalent)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
makeandyarnavailable on your machine)git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babelyarn && make bootstrapyarn 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)make buildto re-build everything, and thenmake testto run all the testsgit 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'sexcludelist and fix the type errors.applyDecoratedDescriptorsinitializerDefinePropertyinitializerWarningHelperdefineAccessoridentitysetFunctionName(see note above)applyDecs2311(see note above)arrayLikeToArrayarrayWithHolesarrayWithoutHolesiterableToArrayiterableToArrayLimititerableToArrayLoosemaybeArrayLikeunsupportedIterableToArrayslicedToArrayslicedToArrayLoosetoArraytoConsumableArraydefaultsextendsobjectDestructuringEmptyobjectSpread2objectWithoutPropertiesobjectWithoutPropertiesLoosedefineEnumerablePropertiesdefinePropertygetgetPrototypeOfsetsetPrototypeOfsuperPropBaseconstruct(see note above)assertThisInitializedclassCallCheckcreateClasspossibleConstructorReturncallSuperinheritsinheritsLooseisNativeFunctionwrapNativeSupercreaeForOfIteratorHelpercreaeForOfIteratorHelperLooseasyncToGeneratorAsyncGeneratorasyncGeneratorDelegateasyncIteratorawaitAsyncGeneratorOverloadYieldwrapAsyncGeneratorcheckPrivateRedeclarationclassPrivateFieldInitSpecclassPrivateMethodInitSpecclassStaticPrivateMethodGetclassPrivateFieldLooseBaseclassPrivateFieldLooseKeyreadOnlyErrorwriteOnlyErrorinteropRequireDefaultinteropRequireWildcardimportDeferProxytdztemporalReftemporalUndefinedjsxtaggedTemplateLiteraltaggedTemplateLiteralLooseinstanceoftypeofwrapRegExpusingCtx(see note above)