Add types for @babel/standalone - #18095
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61915 |
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88fd7422a5
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import type { | ||
| buildExternalHelpers as buildExternalHelpers$1, | ||
| PluginObject, | ||
| PresetObject, | ||
| InputOptions, | ||
| transformFromAstSync, | ||
| transformFromAstAsync as transformFromAstAsync$1, | ||
| FileResult, | ||
| } from "@babel/core"; |
There was a problem hiding this comment.
Avoid unresolved type-only imports
In a TypeScript project that installs only @babel/standalone with the default skipLibCheck: false, this declaration file cannot be checked because the package does not publish any dependencies or peers for @babel/core, @babel/generator, @babel/parser, etc. The new types therefore produce Cannot find module '@babel/core' (and the other imports) before users can consume the package unless they separately install Babel internals or skip lib checking.
Useful? React with 馃憤聽/ 馃憥.
There was a problem hiding this comment.
We might have to do this.
There was a problem hiding this comment.
Yeah that ship has sailed, now that we export types we need to add type-only deps as dependencies.
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c573c66bf
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "./babel.js": "./babel.js", | ||
| "./babel.min.js": "./babel.min.js", | ||
| ".": { | ||
| "types": "./types.d.ts", |
There was a problem hiding this comment.
Expose declarations to classic TypeScript resolution
In projects that still use moduleResolution: node/node10, TypeScript does not use these conditional exports entries for declaration lookup; it follows main to babel.js and then looks for a top-level types/typings field or babel.d.ts. With only this exports.types condition, import Babel = require("@babel/standalone") reports that types.d.ts exists but cannot be resolved under the current module resolution, so the new declarations remain unusable unless users switch resolvers. Add a top-level "types": "./types.d.ts" as well.
Useful? React with 馃憤聽/ 馃憥.
| function disableScriptTags(): void; | ||
| } | ||
|
|
||
| export = Babel; |
There was a problem hiding this comment.
Declare the browser global for script-tag users
For browser/CDN consumers that use the standalone bundle as a global, referencing these types still does not make Babel available because this external-module declaration only has export = Babel. A file with /// <reference types="@babel/standalone" /> and Babel.transform(...) still fails with Cannot find name 'Babel'; add the UMD-style export as namespace Babel so the published types cover the script-tag API.
Useful? React with 馃憤聽/ 馃憥.
|
commit: |
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 439d0ad00e
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** | ||
| * Registers a named plugin for use with Babel. | ||
| */ | ||
| function registerPlugin(name: string, plugin: () => PluginObject): void; |
There was a problem hiding this comment.
Accept plugin factories with Babel parameters
When a TypeScript consumer registers a normal Babel plugin factory that declares api or options, this no-argument callback type is not assignable even though registerPlugin stores the value and transform passes it through to @babel/core, which invokes plugin factories with those parameters. This makes supported custom plugins fail type-checking; the public type should allow Babel's plugin target shape here and in registerPlugins.
Useful? React with 馃憤聽/ 馃憥.
Fixes #1, Fixes #2