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
Migrate eslint-parser
to cts
#16222
Migrate eslint-parser
to cts
#16222
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56184/ |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56147/ |
Unfortunately I can't make tsc happy. |
@@ -14,5 +16,5 @@ exports.normalizeESLintConfig = function (options) { | |||
sourceType, | |||
requireConfigFile, | |||
...otherOptions, | |||
}; | |||
} as Options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add it in the return type of the function rather than casting?
import convertAST = require("./convertAST.cts"); | ||
import type { AST, ParseResult } from "../types.cts"; | ||
|
||
export function convertFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to think of TypeScript as "just adding types on top of otherwise untransformed JS code". Given that this file is meant to be CommonJS, would it be possible to do exports.convertFile = function (...) { ... }
? Or does TS complain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS will complain about this. When we import, the type of function does not exist.
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
210fc52
to
bf4d83a
Compare
microsoft/TypeScript#56785 |
bf4d83a
to
2773358
Compare
tsconfig.base.json
Outdated
"esModuleInterop": true, | ||
"isolatedModules": true, | ||
"allowImportingTsExtensions": true, | ||
"skipLibCheck": false, | ||
"skipLibCheck": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node_modules/@types/node/events.d.ts:878:14 - error TS1291: 'events' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'events' is imported.
878 export = events;
~~~~~~
node_modules/@types/node/module.d.ts:314:14 - error TS1291: 'module' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'module' is imported.
314 export = module;
~~~~~~
node_modules/@types/node/stream.d.ts:1700:14 - error TS1291: 'stream' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'import type' where 'stream' is imported.
1700 export = stream;
~~~~~~
Found 3 errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@types/node
is so popular that it not working is worrisome 😅 I know it's probably because we are using a pre-release, but I opened DefinitelyTyped/DefinitelyTyped#68285
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems sufficient to mark the import assignment in @types/node
as type only:
- import events = require("events");
+ import type events = require("events");
Can we patch this library so we don't have to turn off the lib check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to mark the import assignment in
@types/node
as type only
But it is not type only. It looks like a bug in TS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in TS: microsoft/TypeScript#57148
import astInfo = require("./ast-info.cts"); | ||
import extractParserOptionsPlugin = require("./extract-parser-options-plugin.cjs"); | ||
|
||
import type { ConfigItem } from "../../../../packages/babel-core/src/config/item"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be imported from @babel/core
.
@@ -24,7 +24,7 @@ import { | |||
} from "@babel/types"; | |||
import type * as t from "@babel/types"; | |||
import File from "../transformation/file/file.ts"; | |||
import type { PublicReplacements } from "@babel/template/src/options"; | |||
import type { PublicReplacements } from "../../../babel-template/src/options.ts"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not exported and we accidentally referenced the internal file earlier.
I'm not sure if I want to export it.
It looks like we should export them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@babel/traverse](https://babel.dev/docs/en/next/babel-traverse) ([source](https://github.com/babel/babel)) | resolutions | patch | [`7.23.7` -> `7.23.9`](https://renovatebot.com/diffs/npm/@babel%2ftraverse/7.23.7/7.23.9) | --- ### Release Notes <details> <summary>babel/babel (@​babel/traverse)</summary> ### [`v7.23.9`](https://github.com/babel/babel/blob/HEAD/CHANGELOG.md#v7239-2024-01-25) [Compare Source](babel/babel@v7.23.7...v7.23.9) ##### 🐛 Bug Fix - `babel-helper-transform-fixture-test-runner`, `babel-plugin-transform-function-name`, `babel-plugin-transform-modules-systemjs`, `babel-preset-env` - [#​16225](babel/babel#16225) fix: `systemjs` re-traverses helpers ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) - `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-decorators` - [#​16226](babel/babel#16226) Improve decorated private method check ([@​JLHwung](https://github.com/JLHwung)) - `babel-plugin-proposal-decorators`, `babel-plugin-transform-async-generator-functions`, `babel-plugin-transform-runtime`, `babel-preset-env` - [#​16224](babel/babel#16224) Properly sort `core-js@3` imports ([@​nicolo-ribaudo](https://github.com/nicolo-ribaudo)) - `babel-traverse` - [#​15383](babel/babel#15383) fix: Don't throw in `getTypeAnnotation` when using TS+inference ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) - Other - [#​16210](babel/babel#16210) \[eslint] Fix `no-use-before-define` for class ref in fields ([@​nicolo-ribaudo](https://github.com/nicolo-ribaudo)) ##### 🏠 Internal - `babel-core`, `babel-parser`, `babel-template` - [#​16222](babel/babel#16222) Migrate `eslint-parser` to cts ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) - `babel-types` - [#​16213](babel/babel#16213) Remove `@babel/types` props that are not produced by the parser ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) ##### 🏃♀️ Performance - `babel-parser` - [#​16072](babel/babel#16072) perf: Improve parser performance for typescript ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) ##### 🔬 Output optimization - `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-decorators`, `babel-plugin-proposal-destructuring-private`, `babel-plugin-proposal-pipeline-operator`, `babel-plugin-transform-class-properties`, `babel-plugin-transform-class-static-block`, `babel-plugin-transform-new-target`, `babel-plugin-transform-parameters`, `babel-plugin-transform-private-methods`, `babel-preset-env` - [#​16218](babel/babel#16218) Improve temporary variables for decorators ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) - `babel-helpers`, `babel-plugin-proposal-explicit-resource-management`, `babel-runtime-corejs2`, `babel-runtime-corejs3`, `babel-runtime` - [#​15959](babel/babel#15959) Improve output of `using` ([@​liuxingbaoyu](https://github.com/liuxingbaoyu)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=--> Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/142 Reviewed-by: Vylpes <ethan@vylpes.com> Co-authored-by: Renovate Bot <renovate@vylpes.com> Co-committed-by: Renovate Bot <renovate@vylpes.com>
Fixes #1, Fixes #2
I'm using a lot of
any
ineslint/babel-eslint-parser/src/analyze-scope.cts
because I was surprised that we even support scopes for both ts and flow and https://github.com/babel //pull/16210#issue-2076517615.