File tree Expand file tree Collapse file tree 3 files changed +8
-8
lines changed
webcrack/src/unminify/transforms Expand file tree Collapse file tree 3 files changed +8
-8
lines changed Original file line number Diff line number Diff 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 = {
4141export type PredicateMatcher < T > = ( input : T ) => boolean ;
4242
4343export 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
Original file line number Diff line number Diff line change @@ -3,14 +3,12 @@ import { expect, test } from 'vitest';
33import * as m from '../src' ;
44
55test ( '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
1211test ( '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 ) ) ;
Original file line number Diff line number Diff line change @@ -2,14 +2,16 @@ import * as t from '@babel/types';
22import * as m from '@webcrack/matchers' ;
33import 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
79export 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 ++ ;
You can’t perform that action at this time.
0 commit comments