2
2
3
3
type Queryable = Document | DocumentFragment | Element
4
4
5
- class InvariantError extends Error {
5
+ class QueryError extends Error {
6
6
framesToPop : number
7
7
8
8
constructor ( message ) {
9
9
super ( message )
10
- this . name = 'Invariant Violation'
11
10
this . framesToPop = 1
12
11
}
13
12
}
@@ -18,7 +17,7 @@ export function closest<T: Element>(element: Element, selectors: string, type: C
18
17
if ( el instanceof klass ) {
19
18
return el
20
19
}
21
- throw new InvariantError ( `Element not found: <${ klass . name } > ${ selectors } ` )
20
+ throw new QueryError ( `Element not found: <${ klass . name } > ${ selectors } ` )
22
21
}
23
22
24
23
export function query < T : Element > ( context : Queryable , selectors : string , type : Class < T > ) : T {
@@ -27,7 +26,7 @@ export function query<T: Element>(context: Queryable, selectors: string, type: C
27
26
if ( el instanceof klass ) {
28
27
return el
29
28
}
30
- throw new InvariantError ( `Element not found: <${ klass . name } > ${ selectors } ` )
29
+ throw new QueryError ( `Element not found: <${ klass . name } > ${ selectors } ` )
31
30
}
32
31
33
32
export function querySelectorAll < T : Element > ( context : Queryable , selectors : string , type : Class < T > ) : Array < T > {
@@ -47,13 +46,13 @@ export function namedItem<T: HTMLElement>(form: HTMLFormElement, itemName: strin
47
46
if ( el instanceof klass ) {
48
47
return el
49
48
}
50
- throw new InvariantError ( `Element not found by name: <${ klass . name } > ${ itemName } ` )
49
+ throw new QueryError ( `Element not found by name: <${ klass . name } > ${ itemName } ` )
51
50
}
52
51
53
52
export function getAttribute ( element : Element , attributeName : string ) : string {
54
53
const attribute = element . getAttribute ( attributeName )
55
54
if ( attribute != null ) {
56
55
return attribute
57
56
}
58
- throw new InvariantError ( `Attribute not found on element: ${ attributeName } ` )
57
+ throw new QueryError ( `Attribute not found on element: ${ attributeName } ` )
59
58
}
0 commit comments