@@ -15,7 +15,7 @@ import { transform as transformWithStylus } from './transform/stylus';
15
15
import type { IgnoreItem } from './ignore-comment' ;
16
16
import { getSvelteIgnoreItems } from './ignore-comment' ;
17
17
import { extractLeadingComments } from './extract-leading-comments' ;
18
- import { getLangValue } from '../../utils/ast-utils' ;
18
+ import { findAttribute , getLangValue } from '../../utils/ast-utils' ;
19
19
import path from 'path' ;
20
20
import fs from 'fs' ;
21
21
import semver from 'semver' ;
@@ -115,7 +115,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
115
115
transformResults . push ( ...transformScripts ( context , text ) ) ;
116
116
117
117
if ( ! transformResults . length ) {
118
- const warnings = getWarningsFromCode ( text ) ;
118
+ const warnings = getWarningsFromCode ( text , context ) ;
119
119
return {
120
120
...processIgnore (
121
121
warnings . warnings ,
@@ -296,7 +296,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
296
296
}
297
297
298
298
const code = remapContext . postprocess ( ) ;
299
- const baseWarnings = getWarningsFromCode ( code ) ;
299
+ const baseWarnings = getWarningsFromCode ( code , context ) ;
300
300
301
301
const warnings : Warning [ ] = [ ] ;
302
302
for ( const warn of baseWarnings . warnings ) {
@@ -401,17 +401,37 @@ function* transformScripts(context: RuleContext, text: string) {
401
401
}
402
402
}
403
403
404
+ function hasTagOption ( program : AST . SvelteProgram ) {
405
+ return program . body . some ( ( body ) => {
406
+ if ( body . type !== 'SvelteElement' || body . kind !== 'special' ) {
407
+ return false ;
408
+ }
409
+ if ( body . name . name !== 'svelte:options' ) {
410
+ return false ;
411
+ }
412
+
413
+ return Boolean ( findAttribute ( body , 'tag' ) ) ;
414
+ } ) ;
415
+ }
416
+
404
417
/**
405
418
* Get compile warnings
406
419
*/
407
- function getWarningsFromCode ( code : string ) : {
420
+ function getWarningsFromCode (
421
+ code : string ,
422
+ context : RuleContext
423
+ ) : {
408
424
warnings : Warning [ ] ;
409
425
kind : 'warn' | 'error' ;
410
426
} {
411
427
try {
412
428
const result = compiler . compile ( code , {
413
429
generate : false ,
414
- ...( semver . satisfies ( compiler . VERSION , '>=4.0.0-0' ) ? { customElement : true } : { } )
430
+ ...( semver . satisfies ( compiler . VERSION , '>=4.0.0-0' )
431
+ ? { customElement : true }
432
+ : hasTagOption ( context . getSourceCode ( ) . ast )
433
+ ? { customElement : true }
434
+ : { } )
415
435
} ) ;
416
436
417
437
return { warnings : result . warnings as Warning [ ] , kind : 'warn' } ;
0 commit comments