Skip to content

Commit

Permalink
Import types from @babel/core in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 15, 2024
1 parent a6d0cdd commit 1519a1b
Show file tree
Hide file tree
Showing 46 changed files with 65 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { types as t, template } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, template, type NodePath } from "@babel/core";

const buildForAwait = template(`
async function wrapper() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { declare } from "@babel/helper-plugin-utils";
import remapAsyncToGenerator from "@babel/helper-remap-async-to-generator";
import type { NodePath, Visitor } from "@babel/traverse";
import { traverse, types as t, type PluginPass } from "@babel/core";
import type { NodePath, Visitor, PluginPass } from "@babel/core";
import { traverse, types as t } from "@babel/core";
import rewriteForAwait from "./for-await.ts";
import environmentVisitor from "@babel/helper-environment-visitor";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, type NodePath } from "@babel/core";

export default declare(api => {
api.assertVersion(REQUIRED_VERSION(7));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { types as t } from "@babel/core";
import type { NodePath, Visitor, Scope } from "@babel/traverse";
import type { NodePath, Visitor, Scope } from "@babel/core";

// Whenever a function declaration in a nested block scope
// doesn't conflict with a block-scoped binding from an outer
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-block-scoping/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import type { NodePath, Scope, Visitor } from "@babel/traverse";
import { type PluginPass, types as t, traverse } from "@babel/core";
import type { NodePath, Scope, Visitor, PluginPass } from "@babel/core";
import { types as t, traverse } from "@babel/core";

import {
getLoopBodyBindings,
Expand Down
9 changes: 6 additions & 3 deletions packages/babel-plugin-transform-block-scoping/src/loop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { template, types as t } from "@babel/core";
import type { NodePath, Visitor, Binding } from "@babel/traverse";
import type { NodePath, Visitor, Scope } from "@babel/core";

interface LoopBodyBindingsState {
blockScoped: Binding[];
blockScoped: Scope.Binding[];
}

const collectLoopBodyBindingsVisitor: Visitor<LoopBodyBindingsState> = {
Expand Down Expand Up @@ -32,7 +32,10 @@ export function getLoopBodyBindings(loopPath: NodePath<t.Loop>) {
return state.blockScoped;
}

export function getUsageInBody(binding: Binding, loopPath: NodePath<t.Loop>) {
export function getUsageInBody(
binding: Scope.Binding,
loopPath: NodePath<t.Loop>,
) {
// UpdateExpressions are counted both as a reference and a mutation,
// so we need to de-duplicate them.
const seen = new WeakSet<t.Node>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { types as t, type PluginPass } from "@babel/core";
import type { Binding, NodePath } from "@babel/traverse";
import { types as t } from "@babel/core";
import type { Scope, NodePath, PluginPass } from "@babel/core";

export function validateUsage(
path: NodePath<t.VariableDeclaration>,
Expand All @@ -25,7 +25,7 @@ export function validateUsage(

function disallowConstantViolations(
name: string,
binding: Binding,
binding: Scope.Binding,
state: PluginPass,
) {
for (const violation of binding.constantViolations) {
Expand Down Expand Up @@ -151,7 +151,7 @@ function getTDZReplacement(
return { status, node: buildTDZAssert(status, id, state) };
}

function injectTDZChecks(binding: Binding, state: PluginPass) {
function injectTDZChecks(binding: Scope.Binding, state: PluginPass) {
const allUsages = new Set(binding.referencePaths);
binding.constantViolations.forEach(allUsages.add, allUsages);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import type { Scope } from "@babel/traverse";
import type { Scope } from "@babel/core";

import {
enableFeature,
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-classes/src/transformClass.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { NodePath, Scope, Visitor } from "@babel/traverse";
import type { NodePath, Scope, Visitor, File } from "@babel/core";
import nameFunction from "@babel/helper-function-name";
import ReplaceSupers from "@babel/helper-replace-supers";
import environmentVisitor from "@babel/helper-environment-visitor";
import { traverse, template, types as t, type File } from "@babel/core";
import { traverse, template, types as t } from "@babel/core";
import annotateAsPure from "@babel/helper-annotate-as-pure";

import addCallSuperHelper from "./inline-callSuper-helpers.ts";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { types as t } from "@babel/core";
import type { PluginPass } from "@babel/core";
import type { PluginPass, Scope } from "@babel/core";
import { declare } from "@babel/helper-plugin-utils";
import template from "@babel/template";
import type { Scope } from "@babel/traverse";

export interface Options {
loose?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-destructuring/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import { types as t, type NodePath } from "@babel/core";
import {
DestructuringTransformer,
convertVariableDeclaration,
Expand All @@ -8,7 +8,6 @@ import {
type DestructuringTransformerNode,
} from "./util.ts";
export { buildObjectExcludingKeys, unshiftForXStatementBody } from "./util.ts";
import type { NodePath } from "@babel/traverse";

/**
* Test if a VariableDeclaration's declarations contains any Patterns.
Expand Down
6 changes: 2 additions & 4 deletions packages/babel-plugin-transform-destructuring/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { types as t } from "@babel/core";
import type { File } from "@babel/core";
import type { Scope, NodePath } from "@babel/traverse";
import type { TraversalAncestors } from "@babel/types";
import type { File, Scope, NodePath } from "@babel/core";

function isPureVoid(node: t.Node) {
return (
Expand Down Expand Up @@ -61,7 +59,7 @@ interface ArrayUnpackVisitorState {
// NOTE: This visitor is meant to be used via t.traverse
const arrayUnpackVisitor = (
node: t.Node,
ancestors: TraversalAncestors,
ancestors: t.TraversalAncestors,
state: ArrayUnpackVisitorState,
) => {
if (!ancestors.length) {
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-flow-comments/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxFlow from "@babel/plugin-syntax-flow";
import { types as t } from "@babel/core";
import { types as t, type NodePath } from "@babel/core";
import generateCode from "@babel/generator";
import type { NodePath } from "@babel/traverse";

export default declare(api => {
api.assertVersion(REQUIRED_VERSION(7));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxFlow from "@babel/plugin-syntax-flow";
import { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, type NodePath } from "@babel/core";

export interface Options {
requireDirective?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-for-of/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { template, types as t, type NodePath } from "@babel/core";

import transformWithoutHelper from "./no-helper-implementation.ts";
import { skipTransparentExprWrapperNodes } from "@babel/helper-skip-transparent-expression-wrappers";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type PluginPass, template, types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { template, types as t } from "@babel/core";
import type { PluginPass, NodePath } from "@babel/core";

// This is the legacy implementation, which inlines all the code.
// It must be kept for compatibility reasons.
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-json-strings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import type * as t from "@babel/types";
import type { NodePath } from "@babel/traverse";
import type { NodePath, types as t } from "@babel/core";

export default declare(api => {
api.assertVersion(REQUIRED_VERSION(7));
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-modules-amd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
wrapInterop,
getModuleName,
} from "@babel/helper-module-transforms";
import { template, types as t, type PluginPass } from "@babel/core";
import { template, types as t } from "@babel/core";
import type { PluginOptions } from "@babel/helper-module-transforms";
import type { NodePath } from "@babel/traverse";
import type { NodePath, PluginPass } from "@babel/core";

const buildWrapper = template.statement(`
define(MODULE_NAME, AMD_ARGUMENTS, function(IMPORT_NAMES) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Heavily inspired by
// https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/master/src/utils.js

import type { NodePath } from "@babel/traverse";
import { types as t, template, type File } from "@babel/core";
import type { File, NodePath } from "@babel/core";
import { types as t, template } from "@babel/core";
import { buildDynamicImport } from "@babel/helper-module-transforms";

const requireNoInterop = (source: t.Expression) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-modules-commonjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
getModuleName,
} from "@babel/helper-module-transforms";
import simplifyAccess from "@babel/helper-simple-access";
import { template, types as t, type PluginPass } from "@babel/core";
import { template, types as t } from "@babel/core";
import type { PluginPass, Visitor, Scope, NodePath } from "@babel/core";
import type { PluginOptions } from "@babel/helper-module-transforms";
import type { Visitor, Scope, NodePath } from "@babel/traverse";

import { transformDynamicImport } from "./dynamic-import.ts";
import { lazyImportsHook } from "./lazy.ts";
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-modules-systemjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { declare } from "@babel/helper-plugin-utils";
import hoistVariables from "@babel/helper-hoist-variables";
import { template, types as t, type PluginPass } from "@babel/core";
import { template, types as t } from "@babel/core";
import type { PluginPass, NodePath, Scope, Visitor } from "@babel/core";
import {
buildDynamicImport,
getModuleName,
rewriteThis,
} from "@babel/helper-module-transforms";
import type { PluginOptions } from "@babel/helper-module-transforms";
import { isIdentifierName } from "@babel/helper-validator-identifier";
import type { NodePath, Scope, Visitor } from "@babel/traverse";

const buildTemplate = template.statement(`
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-modules-umd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
getModuleName,
} from "@babel/helper-module-transforms";
import type { PluginOptions } from "@babel/helper-module-transforms";
import { types as t, template } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, template, type NodePath } from "@babel/core";

const buildPrerequisiteAssignment = template(`
GLOBAL_REFERENCE = GLOBAL_REFERENCE || {}
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-new-target/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, type NodePath } from "@babel/core";

export default declare(api => {
api.assertVersion(REQUIRED_VERSION(7));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
import type { NodePath, types as t } from "@babel/core";

/**
* Given a bigIntLiteral or NumericLiteral, remove numeric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import type { PluginPass } from "@babel/core";
import type { NodePath, Scope } from "@babel/traverse";
import type { PluginPass, NodePath, Scope } from "@babel/core";
import { convertFunctionParams } from "@babel/plugin-transform-parameters";
import { isRequired } from "@babel/helper-compilation-targets";
import shouldStoreRHSInTemporaryVariable from "./shouldStoreRHSInTemporaryVariable.ts";
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-transform-object-super/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { declare } from "@babel/helper-plugin-utils";
import ReplaceSupers from "@babel/helper-replace-supers";
import { types as t, type File } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t } from "@babel/core";
import type { File, NodePath } from "@babel/core";

function replacePropertySuper(
path: NodePath<t.ObjectMethod>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import { transform, transformOptionalChain } from "./transform.ts";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
import type { NodePath, types as t } from "@babel/core";

export interface Options {
loose?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { types as t, template } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, template, type NodePath } from "@babel/core";
import {
skipTransparentExprWrapperNodes,
skipTransparentExprWrappers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NodePath } from "@babel/traverse";
import type { NodePath } from "@babel/core";
import { isTransparentExprWrapper } from "@babel/helper-skip-transparent-expression-wrappers";
/**
* Test if a NodePath will be cast to boolean when evaluated.
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-parameters/src/rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { template, types as t } from "@babel/core";
import type { NodePath, Visitor } from "@babel/traverse";
import type { NodePath, Visitor } from "@babel/core";

import {
iifeVisitor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { types as t } from "@babel/core";
import type { NodePath, Scope, Visitor } from "@babel/traverse";
import type { NodePath, Scope, Visitor } from "@babel/core";

type State = {
needsOuterBinding: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
buildCheckInRHS,
} from "@babel/helper-create-class-features-plugin";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import type * as t from "@babel/types";
import type { NodePath, Scope } from "@babel/traverse";
import type { NodePath, Scope, types as t } from "@babel/core";

export interface Options {
loose?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t, template } from "@babel/core";
import type { Visitor, Scope, NodePath } from "@babel/traverse";
import type { Visitor, Scope, NodePath } from "@babel/core";

export interface Options {
allowMutablePropsOnTags?: null | string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import type { Visitor, NodePath } from "@babel/traverse";
import type { Visitor, NodePath } from "@babel/core";

const TRACE_ID = "__self";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import jsx from "@babel/plugin-syntax-jsx";
import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import type { PluginPass } from "@babel/core";
import type { NodePath, Scope, Visitor } from "@babel/traverse";
import type { PluginPass, NodePath, Scope, Visitor } from "@babel/core";
import { addNamed, addNamespace, isModule } from "@babel/helper-module-imports";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, type NodePath } from "@babel/core";

// Mapping of React top-level methods that are pure.
// This plugin adds a /*#__PURE__#/ annotation to calls to these methods,
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-reserved-words/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { types as t, type NodePath } from "@babel/core";

export default declare(api => {
api.assertVersion(REQUIRED_VERSION(7));
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-transform-spread/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { declare } from "@babel/helper-plugin-utils";
import { skipTransparentExprWrappers } from "@babel/helper-skip-transparent-expression-wrappers";
import type { File } from "@babel/core";
import { types as t } from "@babel/core";
import type { NodePath, Scope } from "@babel/traverse";
import type { File, NodePath, Scope } from "@babel/core";

type ListElement = t.SpreadElement | t.Expression;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";
import { template, types as t, type NodePath } from "@babel/core";

export interface Options {
loose?: boolean;
Expand Down
Loading

0 comments on commit 1519a1b

Please sign in to comment.