@@ -15,7 +15,7 @@ import { transform as transformWithStylus } from './transform/stylus';
1515import type { IgnoreItem } from './ignore-comment' ;
1616import { getSvelteIgnoreItems } from './ignore-comment' ;
1717import { extractLeadingComments } from './extract-leading-comments' ;
18- import { getLangValue } from '../../utils/ast-utils' ;
18+ import { findAttribute , getLangValue } from '../../utils/ast-utils' ;
1919import path from 'path' ;
2020import fs from 'fs' ;
2121import semver from 'semver' ;
@@ -115,7 +115,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
115115 transformResults . push ( ...transformScripts ( context , text ) ) ;
116116
117117 if ( ! transformResults . length ) {
118- const warnings = getWarningsFromCode ( text ) ;
118+ const warnings = getWarningsFromCode ( text , context ) ;
119119 return {
120120 ...processIgnore (
121121 warnings . warnings ,
@@ -296,7 +296,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
296296 }
297297
298298 const code = remapContext . postprocess ( ) ;
299- const baseWarnings = getWarningsFromCode ( code ) ;
299+ const baseWarnings = getWarningsFromCode ( code , context ) ;
300300
301301 const warnings : Warning [ ] = [ ] ;
302302 for ( const warn of baseWarnings . warnings ) {
@@ -401,17 +401,37 @@ function* transformScripts(context: RuleContext, text: string) {
401401 }
402402}
403403
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+
404417/**
405418 * Get compile warnings
406419 */
407- function getWarningsFromCode ( code : string ) : {
420+ function getWarningsFromCode (
421+ code : string ,
422+ context : RuleContext
423+ ) : {
408424 warnings : Warning [ ] ;
409425 kind : 'warn' | 'error' ;
410426} {
411427 try {
412428 const result = compiler . compile ( code , {
413429 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+ : { } )
415435 } ) ;
416436
417437 return { warnings : result . warnings as Warning [ ] , kind : 'warn' } ;
0 commit comments