@@ -25,35 +25,25 @@ const markerExpression = new RegExp(
25
25
26
26
/**
27
27
* Parse a comment marker.
28
- * @param {unknown } node
28
+ * @param {unknown } value
29
29
* @returns {Marker|null }
30
30
*/
31
- export function commentMarker ( node ) {
32
- if (
33
- node &&
34
- typeof node === 'object' &&
35
- // @ts -ignore hush
36
- ( node . type === 'html' || node . type === 'comment' )
37
- ) {
38
- // @ts -ignore hush
39
- const match = node . value . match (
40
- // @ts -ignore hush
41
- node . type === 'comment' ? commentExpression : markerExpression
31
+ export function commentMarker ( value ) {
32
+ if ( applicable ( value ) ) {
33
+ const match = value . value . match (
34
+ value . type === 'comment' ? commentExpression : markerExpression
42
35
)
43
36
44
- // @ts -ignore hush
45
- if ( match && match [ 0 ] . length === node . value . length ) {
46
- // @ts -ignore hush
47
- const offset = node . type === 'comment' ? 1 : 2
37
+ if ( match && match [ 0 ] . length === value . value . length ) {
38
+ const offset = value . type === 'comment' ? 1 : 2
48
39
const parameters = parseParameters ( match [ offset + 1 ] || '' )
49
40
50
41
if ( parameters ) {
51
42
return {
52
43
name : match [ offset ] ,
53
44
attributes : match [ offset + 2 ] || '' ,
54
45
parameters,
55
- // @ts -ignore hush
56
- node
46
+ node : value
57
47
}
58
48
}
59
49
}
@@ -106,3 +96,17 @@ function parseParameters(value) {
106
96
return ''
107
97
}
108
98
}
99
+
100
+ /**
101
+ * @param {unknown } value
102
+ * @returns {value is HtmlNode | CommentNode }
103
+ */
104
+ function applicable ( value ) {
105
+ return Boolean (
106
+ value &&
107
+ typeof value === 'object' &&
108
+ 'type' in value &&
109
+ // @ts -expect-error hush
110
+ ( value . type === 'html' || value . type === 'comment' )
111
+ )
112
+ }
0 commit comments