Commit f3d0c31 1 parent b196730 commit f3d0c31 Copy full SHA for f3d0c31
File tree 3 files changed +52
-13
lines changed
3 files changed +52
-13
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,9 @@ export const parse: Parser<Root | Document> = (
134
134
} ) as Root ;
135
135
} catch ( err ) {
136
136
if ( err instanceof CssSyntaxError ) {
137
- const line = node . loc ? ` (${ opts ?. from ?? 'unknown' } :${ node . loc . start . line } )` : opts ?. from ;
137
+ const line = node . loc
138
+ ? ` (${ opts ?. from ?? 'unknown' } :${ node . loc . start . line } )`
139
+ : opts ?. from ;
138
140
139
141
console . warn (
140
142
'[postcss-lit]' ,
Original file line number Diff line number Diff line change @@ -363,6 +363,47 @@ describe('parse', () => {
363
363
assert . equal ( ast . nodes . length , 0 ) ;
364
364
} ) ;
365
365
366
+ it ( 'should ignore a child node' , ( ) => {
367
+ const { ast} = createTestAst ( `
368
+ class MyClass {
369
+ // postcss-lit-disable-next-line
370
+ static style = css\`
371
+ .foo { color: hotpink; }
372
+ \`;
373
+ }
374
+ ` ) ;
375
+
376
+ assert . equal ( ast . nodes . length , 0 ) ;
377
+ } ) ;
378
+
379
+ it ( 'should ignore a child node from an array' , ( ) => {
380
+ const { ast} = createTestAst ( `
381
+ class MyClass {
382
+ static style = [
383
+ // postcss-lit-disable-next-line
384
+ css\`
385
+ .foo { color: hotpink; }
386
+ \`,
387
+ ];
388
+ }
389
+ ` ) ;
390
+
391
+ assert . equal ( ast . nodes . length , 0 ) ;
392
+ } ) ;
393
+
394
+ it ( 'should ignore everything inside a disabled parent node' , ( ) => {
395
+ const { ast} = createTestAst ( `
396
+ // postcss-lit-disable-next-line
397
+ class MyClass {
398
+ static style = css\`
399
+ .foo { color: hotpink; }
400
+ \`;
401
+ }
402
+ ` ) ;
403
+
404
+ assert . equal ( ast . nodes . length , 0 ) ;
405
+ } ) ;
406
+
366
407
it ( 'should ignore deeply disabled lines' , ( ) => {
367
408
const { ast} = createTestAst ( `
368
409
// postcss-lit-disable-next-line
Original file line number Diff line number Diff line change @@ -20,18 +20,14 @@ export function isDisableComment(node: Comment): boolean {
20
20
export function hasDisableComment (
21
21
path : NodePath < TaggedTemplateExpression >
22
22
) : boolean {
23
- const statement = path . getStatementParent ( ) ;
24
-
25
- if ( statement && statement . node . leadingComments ) {
26
- const comment =
27
- statement . node . leadingComments [ statement . node . leadingComments . length - 1 ] ;
28
-
29
- if ( comment !== undefined && isDisableComment ( comment ) ) {
30
- return true ;
31
- }
32
- }
33
-
34
- return false ;
23
+ // The comment could be directly above the node or above any of its parents
24
+ return (
25
+ path . find (
26
+ ( p ) =>
27
+ // There could be multiple preceding the comments
28
+ p . node . leadingComments ?. some ( isDisableComment ) === true
29
+ ) !== null
30
+ ) ;
35
31
}
36
32
37
33
export type Position =
You can’t perform that action at this time.
0 commit comments