File tree Expand file tree Collapse file tree 5 files changed +14
-12
lines changed Expand file tree Collapse file tree 5 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -196,11 +196,12 @@ function parseStyle(value, tagName) {
196
196
try {
197
197
styleToObject ( value , iterator )
198
198
} catch ( error ) {
199
- // To do: use `cause`.
200
- const exception = /** @type {Error } */ ( error )
201
- exception . message =
202
- tagName + '[style]' + exception . message . slice ( 'undefined' . length )
203
- throw error
199
+ const cause = /** @type {Error } */ ( error )
200
+ const exception = new Error (
201
+ 'Could not parse `style` attribute on `' + tagName + '`' ,
202
+ { cause}
203
+ )
204
+ throw exception
204
205
}
205
206
206
207
return result
Original file line number Diff line number Diff line change 99
99
* Casing to use for property names in `style` objects.
100
100
*/
101
101
102
+ import { ok as assert } from 'devlop'
102
103
import { html , svg } from 'property-information'
103
104
import { position } from 'unist-util-position'
104
105
import { zwitch } from 'zwitch'
@@ -185,8 +186,8 @@ function invalid(value) {
185
186
* Nothing (crashes).
186
187
*/
187
188
function unknown ( node ) {
188
- // To do: use `devlop`.
189
- // @ts -expect-error: JS guarantees there’s a `type`.
189
+ assert ( node && typeof node === 'object' )
190
+ assert ( 'type' in node )
190
191
throw new Error ( 'Cannot handle unknown node `' + node . type + '`' )
191
192
}
192
193
@@ -331,9 +332,8 @@ function createJsxNameFromString(name) {
331
332
if ( name . includes ( '.' ) ) {
332
333
const names = name . split ( '.' )
333
334
let part = names . shift ( )
334
- // To do: use `devlop`.
335
- /** @type {JsxMemberExpression } */
336
- // @ts -expect-error: hush, the first is always defined.
335
+ assert ( part , 'Expected `part` to be defined' )
336
+ /** @type {JsxIdentifier | JsxMemberExpression } */
337
337
let node = { type : 'JSXIdentifier' , name : part }
338
338
339
339
while ( ( part = names . shift ( ) ) ) {
Original file line number Diff line number Diff line change 44
44
"@types/estree-jsx" : " ^1.0.0" ,
45
45
"@types/hast" : " ^3.0.0" ,
46
46
"comma-separated-tokens" : " ^2.0.0" ,
47
+ "devlop" : " ^1.0.0" ,
47
48
"estree-util-attach-comments" : " ^3.0.0" ,
48
49
"estree-util-is-identifier-name" : " ^3.0.0" ,
49
50
"hast-util-whitespace" : " ^3.0.0" ,
Original file line number Diff line number Diff line change @@ -362,7 +362,7 @@ test('toEstree', async function (t) {
362
362
await t . test ( 'should crash on an incorrect style string' , async function ( ) {
363
363
assert . throws ( function ( ) {
364
364
toEstree ( h ( 'a' , { style : 'x' } ) )
365
- } , / a \[ s t y l e ] : 1 : 2 : p r o p e r t y m i s s i n g ' : ' / )
365
+ } , / C o u l d n o t p a r s e ` s t y l e ` a t t r i b u t e o n ` a ` / )
366
366
} )
367
367
368
368
await t . test (
Original file line number Diff line number Diff line change 5
5
"declaration" : true ,
6
6
"emitDeclarationOnly" : true ,
7
7
"exactOptionalPropertyTypes" : true ,
8
- "lib" : [" es2020 " ],
8
+ "lib" : [" es2022 " ],
9
9
"module" : " node16" ,
10
10
"strict" : true ,
11
11
"target" : " es2020"
You can’t perform that action at this time.
0 commit comments