1+ /* global require -- node */
12import assert from "assert"
23import fs from "fs"
4+ import semver from "semver"
35
46import { traverseNodes } from "../../../src/traverse"
57import { parseForESLint } from "../../../src"
@@ -24,6 +26,7 @@ describe("Check for AST.", () => {
2426 inputFileName,
2527 outputFileName,
2628 scopeFileName,
29+ requirements,
2730 } of listupFixtures ( ) ) {
2831 describe ( inputFileName , ( ) => {
2932 let result : any
@@ -34,11 +37,26 @@ describe("Check for AST.", () => {
3437 const output = fs . readFileSync ( outputFileName , "utf8" )
3538 assert . strictEqual ( astJson , output )
3639 } )
37- it ( "most to generate the expected scope." , ( ) => {
38- const json = scopeToJSON ( result . scopeManager )
39- const output = fs . readFileSync ( scopeFileName , "utf8" )
40- assert . strictEqual ( json , output )
41- } )
40+ if ( canTest ( requirements , "scope" ) )
41+ it ( "most to generate the expected scope." , ( ) => {
42+ let json : any = scopeToJSON ( result . scopeManager )
43+ let output : any = fs . readFileSync ( scopeFileName , "utf8" )
44+
45+ if (
46+ result . services ?. program // use ts parser
47+ ) {
48+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore
49+ const pkg = require ( "@typescript-eslint/parser/package.json" )
50+ if ( ! semver . satisfies ( pkg . version , "^5.6.0" ) ) {
51+ // adjust global scope
52+ json = JSON . parse ( json )
53+ output = JSON . parse ( output )
54+ json . variables = output . variables
55+ }
56+ }
57+
58+ assert . deepStrictEqual ( json , output )
59+ } )
4260
4361 it ( "location must be correct." , ( ) => {
4462 // check tokens
@@ -58,6 +76,25 @@ describe("Check for AST.", () => {
5876 }
5977} )
6078
79+ function canTest (
80+ requirements : { scope ?: Record < string , string > } ,
81+ key : "scope" ,
82+ ) {
83+ const obj = requirements [ key ]
84+ if ( obj ) {
85+ if (
86+ Object . entries ( obj ) . some ( ( [ pkgName , pkgVersion ] ) => {
87+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore
88+ const pkg = require ( `${ pkgName } /package.json` )
89+ return ! semver . satisfies ( pkg . version , pkgVersion )
90+ } )
91+ ) {
92+ return false
93+ }
94+ }
95+ return true
96+ }
97+
6198function checkTokens ( ast : SvelteProgram , input : string ) {
6299 const allTokens = [ ...ast . tokens , ...ast . comments ] . sort (
63100 ( a , b ) => a . range [ 0 ] - b . range [ 0 ] ,
0 commit comments