@@ -15,9 +15,10 @@ 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
+ import semver from 'semver' ;
21
22
22
23
type WarningTargetNode =
23
24
| ( AST . SvelteProgram & ASTNodeWithParent )
@@ -114,7 +115,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
114
115
transformResults . push ( ...transformScripts ( context , text ) ) ;
115
116
116
117
if ( ! transformResults . length ) {
117
- const warnings = getWarningsFromCode ( text ) ;
118
+ const warnings = getWarningsFromCode ( text , context ) ;
118
119
return {
119
120
...processIgnore (
120
121
warnings . warnings ,
@@ -295,7 +296,7 @@ function getSvelteCompileWarningsWithoutCache(context: RuleContext): SvelteCompi
295
296
}
296
297
297
298
const code = remapContext . postprocess ( ) ;
298
- const baseWarnings = getWarningsFromCode ( code ) ;
299
+ const baseWarnings = getWarningsFromCode ( code , context ) ;
299
300
300
301
const warnings : Warning [ ] = [ ] ;
301
302
for ( const warn of baseWarnings . warnings ) {
@@ -400,17 +401,37 @@ function* transformScripts(context: RuleContext, text: string) {
400
401
}
401
402
}
402
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
+
403
417
/**
404
418
* Get compile warnings
405
419
*/
406
- function getWarningsFromCode ( code : string ) : {
420
+ function getWarningsFromCode (
421
+ code : string ,
422
+ context : RuleContext
423
+ ) : {
407
424
warnings : Warning [ ] ;
408
425
kind : 'warn' | 'error' ;
409
426
} {
410
427
try {
411
428
const result = compiler . compile ( code , {
412
429
generate : false ,
413
- customElement : true
430
+ ...( semver . satisfies ( compiler . VERSION , '>=4.0.0-0' )
431
+ ? { customElement : true }
432
+ : hasTagOption ( context . getSourceCode ( ) . ast )
433
+ ? { customElement : true }
434
+ : { } )
414
435
} ) ;
415
436
416
437
return { warnings : result . warnings as Warning [ ] , kind : 'warn' } ;
0 commit comments