Skip to content

Commit

Permalink
improve transform-classes typings (#14624)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 20, 2022
1 parent 35fa868 commit 0343255
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 57 deletions.
8 changes: 6 additions & 2 deletions packages/babel-helper-function-name/src/index.ts
Expand Up @@ -211,7 +211,7 @@ export default function <N extends t.FunctionExpression | t.Class>(
node: N;
parent?: t.Node;
scope: Scope;
id?: any;
id?: t.LVal | t.StringLiteral | t.NumericLiteral | t.BigIntLiteral;
},
localBinding = false,
supportUnicodeId = false,
Expand All @@ -224,7 +224,11 @@ export default function <N extends t.FunctionExpression | t.Class>(
(!parent.computed || isLiteral(parent.key))
) {
// { foo() {} };
id = parent.key;
id = parent.key as
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral;
} else if (isVariableDeclarator(parent)) {
// let foo = function () {};
id = parent.id;
Expand Down
5 changes: 2 additions & 3 deletions packages/babel-helper-optimise-call-expression/src/index.ts
Expand Up @@ -11,7 +11,6 @@ import type {
CallExpression,
Expression,
OptionalCallExpression,
SpreadElement,
} from "@babel/types";

/**
Expand All @@ -21,14 +20,14 @@ import type {
* @export
* @param {Expression} callee The callee of call expression
* @param {Expression} thisNode The desired this of call expression
* @param {Readonly<Array<Expression | SpreadElement>>} args The arguments of call expression
* @param {Readonly<CallExpression["arguments"]>} args The arguments of call expression
* @param {boolean} optional Whether the call expression is optional
* @returns {CallExpression | OptionalCallExpression} The generated new call expression
*/
export default function optimiseCallExpression(
callee: Expression,
thisNode: Expression,
args: Readonly<Array<Expression | SpreadElement>>,
args: Readonly<CallExpression["arguments"]>,
optional: boolean,
): CallExpression | OptionalCallExpression {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-classes/src/index.ts
Expand Up @@ -7,7 +7,7 @@ import globals from "globals";
import transformClass from "./transformClass";
import type { Visitor, NodePath } from "@babel/traverse";

const getBuiltinClasses = (category: string) =>
const getBuiltinClasses = (category: keyof typeof globals) =>
Object.keys(globals[category]).filter(name => /^[A-Z]/.test(name));

const builtinClasses = new Set([
Expand Down
@@ -1,8 +1,8 @@
import { template, types as t } from "@babel/core";
import { template, types as t, type File } from "@babel/core";

const helperIDs = new WeakMap();

export default function addCreateSuperHelper(file) {
export default function addCreateSuperHelper(file: File) {
if (helperIDs.has(file)) {
// TODO: Only use t.cloneNode in Babel 8
// t.cloneNode isn't supported in every version
Expand Down

0 comments on commit 0343255

Please sign in to comment.