-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Convert remaning runtime helpers to TypeScript #16500
Comments
I'm down to help out with |
Thank you! If you need any help feel free to ask :) |
I am going to work on Update Finished in #16505. |
Thanks! |
I can get |
|
They are yours :) @coelhucas After that #16505 is merged, you might need to rebase your changes to remove some |
I would like to work on the |
It's yours :) |
I am concerned about using TypeScript with Babel helpers. Does type really make sense? In my experience, Babel helper is already js in downstream users' node_modules, and usually our tsc also turns on Do we have enough TypeScript code using Babel helpers so that the helper is imported and checked by |
@magic-akari Yes, helpers being written in TS is mostly for internal type checking in the monorepo (among the helpers themselves). All the helpers we added in the past few years are already written in TS because:
When published, helpers are never meant to be manually imported in code that people write, but they are just injected by Babel and thus at that point don't need type checking. |
can I have Update: |
Yes! |
can I get Update: |
Yes! |
|
quick question does it accept a generic argument or is there a constraint? /* @minVersion 7.17.0 */
export default function _identity<T>(x: T): T {
return x;
} |
No constraint. I think currently we only pass functions to it, but let's keep it as generic as possible since we might use for other things. |
|
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.ts
extension, such asimport 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.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
make
andyarn
available on your machine)git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
yarn && make bootstrap
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)make build
to re-build everything, and thenmake test
to run all the testsgit 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
'sexclude
list and fix the type errors.applyDecoratedDescriptors
initializerDefineProperty
initializerWarningHelper
defineAccessor
identity
setFunctionName
(see note above)applyDecs2311
(see note above)arrayLikeToArray
arrayWithHoles
arrayWithoutHoles
iterableToArray
iterableToArrayLimit
iterableToArrayLoose
maybeArrayLike
unsupportedIterableToArray
slicedToArray
slicedToArrayLoose
toArray
toConsumableArray
defaults
extends
objectDestructuringEmpty
objectSpread2
objectWithoutProperties
objectWithoutPropertiesLoose
defineEnumerableProperties
defineProperty
get
getPrototypeOf
set
setPrototypeOf
superPropBase
construct
(see note above)assertThisInitialized
classCallCheck
createClass
possibleConstructorReturn
createSuper
inherits
inheritsLoose
isNativeFunction
wrapNativeSuper
creaeForOfIteratorHelper
creaeForOfIteratorHelperLoose
asyncToGenerator
AsyncGenerator
asyncGeneratorDelegate
asyncIterator
awaitAsyncGenerator
OverloadYield
wrapAsyncGenerator
checkPrivateRedeclaration
classPrivateFieldInitSpec
classPrivateMethodInitSpec
classStaticPrivateMethodGet
classPrivateFieldLooseBase
classPrivateFieldLooseKey
readOnlyError
writeOnlyError
interopRequireDefault
interopRequireWildcard
importDeferProxy
tdz
temporalRef
temporalUndefined
jsx
taggedTemplateLiteral
taggedTemplateLiteralLoose
instanceof
typeof
wrapRegExp
usingCtx
(see note above)The text was updated successfully, but these errors were encountered: