Skip to content
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

Provide plugin/preset typings from plugin-utils #14499

Merged
merged 22 commits into from Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cf26c37
type: refine assumptions interface
JLHwung Apr 26, 2022
dd73f4c
fix: use UidIdentifier when partial callee is not identifier
JLHwung Apr 27, 2022
7a21c70
perf: scan object properties in one pass
JLHwung Apr 27, 2022
11c80b9
fix: support private name in member proeprty
JLHwung Apr 27, 2022
1a016a2
fix: add pipeline operator to BinaryOperators
JLHwung Apr 27, 2022
dc43dd0
typings: fix GeneratorOptions
JLHwung Apr 27, 2022
046daab
update babel parser typings
JLHwung Apr 27, 2022
8ef9dd2
fix: add predicate to @babel/types
JLHwung Apr 27, 2022
381fd18
typings: export Plugin/Preset related types
JLHwung Apr 27, 2022
99d3abd
feat: add declarePreset method and refine declare types
JLHwung Apr 27, 2022
beda280
use helper-plugin-utils in named-capturing-groups
JLHwung Apr 27, 2022
c20d40b
fix typing issues
JLHwung Apr 27, 2022
e82aa35
Update packages/babel-core/src/config/validation/plugins.ts
JLHwung Apr 27, 2022
d39e051
Update packages/babel-plugin-proposal-nullish-coalescing-operator/src…
JLHwung Apr 27, 2022
cc42fdf
Update packages/babel-helper-plugin-utils/src/index.ts
JLHwung Apr 27, 2022
cd4cdf2
simplify declare/declarePreset
JLHwung Apr 27, 2022
032ebf4
improve decorator 2021-12 transformer typings
JLHwung Apr 27, 2022
84153ee
Do not expose plugin state
JLHwung Apr 28, 2022
dd42d4f
bump typescript to 4.6.3
JLHwung Apr 28, 2022
e2106bf
fix AssumptionFunction return type
JLHwung Apr 28, 2022
b0fd195
misc
JLHwung Apr 28, 2022
6c2d2d9
noNewArrows defaults to true
JLHwung Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/helpers/config-api.ts
Expand Up @@ -24,7 +24,7 @@ type CallerFactory = (
extractor: (callerMetadata: CallerMetadata | void) => unknown,
) => SimpleType;
type TargetsFunction = () => Targets;
type AssumptionFunction = (name: AssumptionName) => boolean;
type AssumptionFunction = (name: AssumptionName) => boolean | void;

export type ConfigAPI = {
version: string;
Expand Down
Expand Up @@ -185,7 +185,7 @@ export function createClassFeaturePlugin({
const privateNamesMap = buildPrivateNamesMap(props);
const privateNamesNodes = buildPrivateNamesNodes(
privateNamesMap,
privateFieldsAsProperties ?? loose,
(privateFieldsAsProperties ?? loose) as boolean,
state,
);

Expand Down Expand Up @@ -224,9 +224,9 @@ export function createClassFeaturePlugin({
props,
privateNamesMap,
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
constantSuper ?? loose,
(setPublicClassFields ?? loose) as boolean,
(privateFieldsAsProperties ?? loose) as boolean,
(constantSuper ?? loose) as boolean,
innerBinding,
));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-module-transforms/src/index.ts
Expand Up @@ -185,7 +185,7 @@ export function wrapInterop(
export function buildNamespaceInitStatements(
metadata: ModuleMetadata,
sourceMetadata: SourceModuleMetadata,
constantReexports: boolean = false,
constantReexports: boolean | void = false,
) {
const statements = [];

Expand Down
Expand Up @@ -7,8 +7,8 @@ import type * as t from "@babel/types";
export default declare(api => {
api.assertVersion(7);

const noDocumentAll = api.assumption("noDocumentAll");
const pureGetters = api.assumption("pureGetters");
const noDocumentAll = (api.assumption("noDocumentAll") ?? false) as boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is microsoft/TypeScript#40359. TS currently can not narrow down (boolean | void) ?? boolean to boolean

const pureGetters = (api.assumption("pureGetters") ?? false) as boolean;

return {
name: "bugfix-v8-spread-parameters-in-optional-chaining",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-proposal-optional-chaining/src/index.ts
Expand Up @@ -11,8 +11,8 @@ export default declare((api, options: Options) => {
api.assertVersion(7);

const { loose = false } = options;
const noDocumentAll = api.assumption("noDocumentAll") ?? loose;
const pureGetters = api.assumption("pureGetters") ?? loose;
const noDocumentAll = (api.assumption("noDocumentAll") ?? loose) as boolean;
const pureGetters = (api.assumption("pureGetters") ?? loose) as boolean;

return {
name: "proposal-optional-chaining",
Expand Down
Expand Up @@ -16,8 +16,9 @@ export default declare<State>((api, options: Options) => {
api.assertVersion(7);

const { method, module } = options;
const noNewArrows = api.assumption("noNewArrows");
const ignoreFunctionLength = api.assumption("ignoreFunctionLength");
const noNewArrows = (api.assumption("noNewArrows") ?? false) as boolean;
const ignoreFunctionLength = (api.assumption("ignoreFunctionLength") ??
false) as boolean;

if (method && module) {
return {
Expand Down
16 changes: 9 additions & 7 deletions packages/babel-plugin-transform-classes/src/index.ts
Expand Up @@ -22,13 +22,15 @@ export interface Options {
export default declare((api, options: Options) => {
api.assertVersion(7);

const { loose } = options;

const setClassMethods = api.assumption("setClassMethods") ?? options.loose;
const constantSuper = api.assumption("constantSuper") ?? options.loose;
const superIsCallableConstructor =
api.assumption("superIsCallableConstructor") ?? options.loose;
const noClassCalls = api.assumption("noClassCalls") ?? options.loose;
const { loose = false } = options;

const setClassMethods = (api.assumption("setClassMethods") ??
loose) as boolean;
const constantSuper = (api.assumption("constantSuper") ?? loose) as boolean;
const superIsCallableConstructor = (api.assumption(
"superIsCallableConstructor",
) ?? loose) as boolean;
const noClassCalls = (api.assumption("noClassCalls") ?? loose) as boolean;

// todo: investigate traversal requeueing
const VISITED = Symbol();
Expand Down
14 changes: 9 additions & 5 deletions packages/babel-plugin-transform-destructuring/src/index.ts
Expand Up @@ -30,11 +30,15 @@ export default declare((api, options: Options) => {

const { useBuiltIns = false } = options;

const iterableIsArray = api.assumption("iterableIsArray") ?? options.loose;
const arrayLikeIsIterable =
options.allowArrayLike ?? api.assumption("arrayLikeIsIterable");
const objectRestNoSymbols =
api.assumption("objectRestNoSymbols") ?? options.loose;
const iterableIsArray = (api.assumption("iterableIsArray") ??
options.loose ??
false) as boolean;
const arrayLikeIsIterable = (options.allowArrayLike ??
api.assumption("arrayLikeIsIterable") ??
false) as boolean;
const objectRestNoSymbols = (api.assumption("objectRestNoSymbols") ??
options.loose ??
false) as boolean;

return {
name: "transform-destructuring",
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-plugin-transform-modules-commonjs/src/index.ts
Expand Up @@ -49,14 +49,14 @@ export default declare((api, options: Options) => {
lazy = false,
// Defaulting to 'true' for now. May change before 7.x major.
allowCommonJSExports = true,
loose = false,
} = options;

const constantReexports =
api.assumption("constantReexports") ?? options.loose;
const enumerableModuleMeta =
api.assumption("enumerableModuleMeta") ?? options.loose;
const noIncompleteNsImportDetection =
api.assumption("noIncompleteNsImportDetection") ?? false;
const constantReexports = api.assumption("constantReexports") ?? loose;
const enumerableModuleMeta = api.assumption("enumerableModuleMeta") ?? loose;
const noIncompleteNsImportDetection = (api.assumption(
"noIncompleteNsImportDetection",
) ?? false) as boolean;

if (
typeof lazy !== "boolean" &&
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-traverse/src/path/conversion.ts
Expand Up @@ -143,6 +143,10 @@ export function arrowFunctionToExpression(
specCompliant = false,
// TODO(Babel 8): Consider defaulting to `false` for spec compliancy
noNewArrows = !specCompliant,
}: {
allowInsertArrow?: boolean | void;
specCompliant?: boolean | void;
noNewArrows?: boolean | void;
} = {},
) {
if (!this.isArrowFunctionExpression()) {
Expand Down Expand Up @@ -217,8 +221,8 @@ const getSuperCallsVisitor = mergeVisitors<{
function hoistFunctionEnvironment(
fnPath: NodePath<t.Function>,
// TODO(Babel 8): Consider defaulting to `false` for spec compliancy
noNewArrows = true,
allowInsertArrow = true,
noNewArrows: boolean | void = true,
allowInsertArrow: boolean | void = true,
): { thisBinding: string; fnPath: NodePath<t.Function> } {
let arrowParent;
let thisEnvFn = fnPath.findParent(p => {
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-traverse/src/scope/index.ts
Expand Up @@ -640,7 +640,11 @@ export default class Scope {
}

// TODO: (Babel 8) Split i in two parameters, and use an object of flags
toArray(node: t.Node, i?: number | boolean, arrayLikeIsIterable?: boolean) {
toArray(
node: t.Node,
i?: number | boolean,
arrayLikeIsIterable?: boolean | void,
) {
if (isIdentifier(node)) {
const binding = this.getBinding(node.name);
if (binding?.constant && binding.path.isGenericType("Array")) {
Expand Down