diff --git a/src/ExplicitImports.jl b/src/ExplicitImports.jl index f533fad..f99899b 100644 --- a/src/ExplicitImports.jl +++ b/src/ExplicitImports.jl @@ -1,20 +1,31 @@ module ExplicitImports +const BASE_JULIASYNTAX_VERSION = v"1.12.0-DEV.0" +const USE_BASE_JULIASYNTAX = VERSION >= BASE_JULIASYNTAX_VERSION + #! explicit-imports: off # We vendor some dependencies to avoid compatibility problems. We tell ExplicitImports to ignore # these as we don't want it to recurse into vendored dependencies. # We also add `Vendored` to `ignore_submodules` elsewhere. module Vendored -include(joinpath("vendored", "JuliaSyntax", "src", "JuliaSyntax.jl")) +using ..ExplicitImports: USE_BASE_JULIASYNTAX +if !USE_BASE_JULIASYNTAX + include(joinpath("vendored", "JuliaSyntax", "src", "JuliaSyntax.jl")) +end include(joinpath("vendored", "AbstractTrees", "src", "AbstractTrees.jl")) end #! explicit-imports: on -using .Vendored.JuliaSyntax +if USE_BASE_JULIASYNTAX + import Base: JuliaSyntax +else + import .Vendored: JuliaSyntax +end +using .JuliaSyntax # suppress warning about Base.parse collision, even though parse is never used # this avoids a warning when loading the package while creating an unused explicit import # the former occurs for all users, the latter only for developers of this package -using .Vendored.JuliaSyntax: parse +using .JuliaSyntax: parse using .Vendored.AbstractTrees using .Vendored.AbstractTrees: parent diff --git a/test/runtests.jl b/test/runtests.jl index 5b26716..0c67a8e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1286,6 +1286,16 @@ include("issue_140.jl") end end + @testset "JuliaSyntax backend selection" begin + if VERSION >= ExplicitImports.BASE_JULIASYNTAX_VERSION + @test ExplicitImports.JuliaSyntax === Base.JuliaSyntax + @test !isdefined(ExplicitImports.Vendored, :JuliaSyntax) + else + @test isdefined(ExplicitImports.Vendored, :JuliaSyntax) + @test ExplicitImports.JuliaSyntax === ExplicitImports.Vendored.JuliaSyntax + end + end + @testset "backtick modules and locations" begin @testset "print_explicit_imports" begin # Test that module names and file:line locations are surrounded by backticks