Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/ExplicitImports.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading