Skip to content

Commit 27dec86

Browse files
committed
fix: OrMatcher types
1 parent a89ab45 commit 27dec86

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/matchers/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type NodeSchema<T extends t.Node> = {
1717
[K in Exclude<keyof T, ExcludedNodeKeys>]?: Schema<T[K]> | undefined;
1818
};
1919

20-
export type OrMatcher<T extends unknown[]> = {
20+
export type OrMatcher<T> = {
2121
type: 'or';
2222
schema: T;
2323
};
@@ -41,7 +41,7 @@ export type FromCaptureMatcher = {
4141
export type PredicateMatcher<T> = (input: T) => boolean;
4242

4343
export type Matcher<T> =
44-
| OrMatcher<T[]>
44+
| OrMatcher<T>
4545
| ArraySchema<T>
4646
| NullableSchema<T>
4747
| CaptureMatcher<T>
@@ -62,9 +62,9 @@ export type Infer<T> =
6262
T extends NullableSchema<infer U>
6363
? U | null
6464
: T extends ArraySchema<infer U>
65-
? U
65+
? U[]
6666
: T extends OrMatcher<infer U>
67-
? U[number]
67+
? U
6868
: T extends CaptureMatcher<infer U>
6969
? U
7070
: T extends FromCaptureMatcher

packages/matchers/test/captures.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { expect, test } from 'vitest';
33
import * as m from '../src';
44

55
test('capture number', () => {
6-
// @ts-expect-error idk
76
const matcher = m.compile(m.numericLiteral(m.capture('value')));
87
const captures = matcher(t.numericLiteral(1));
98
expect(captures).toEqual({ value: 1 });
109
});
1110

1211
test('capture node', () => {
13-
// @ts-expect-error idk
1412
const matcher = m.compile(m.variableDeclarator(m.capture('id')));
1513
const id = t.identifier('foo');
1614
const captures = matcher(t.variableDeclarator(id));

packages/webcrack/src/unminify/transforms/void-to-undefined.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import * as t from '@babel/types';
22
import * as m from '@webcrack/matchers';
33
import type { Transform } from '../../ast-utils';
44

5-
const visitor = m.compileVisitor(m.unaryExpression('void', m.numericLiteral()));
5+
const onVoidNumber = m.compileVisitor(
6+
m.unaryExpression('void', m.numericLiteral()),
7+
);
68

79
export default {
810
name: 'void-to-undefined',
911
tags: ['safe'],
1012
scope: true,
1113
visitor: () =>
12-
visitor((path, state) => {
14+
onVoidNumber((path, state) => {
1315
if (!path.scope.hasBinding('undefined', { noGlobals: true })) {
1416
path.replaceWith(t.identifier('undefined'));
1517
state.changes++;

0 commit comments

Comments
 (0)