|
1 | 1 | # Defines node "expanders" that transform nodes from the parsed markdown files.
|
2 | 2 |
|
| 3 | +function clear_global!(M::Module, name::Symbol) |
| 4 | + isconst(M, name) && return |
| 5 | + if VERSION >= v"1.9" |
| 6 | + Nothing <: Core.get_binding_type(M, name) || return |
| 7 | + setglobal!(M, name, nothing) |
| 8 | + else |
| 9 | + Core.eval(M, :($name = $nothing)) |
| 10 | + end |
| 11 | + return nothing |
| 12 | +end |
| 13 | + |
3 | 14 | # helper for "cleaning up" content of modules to enable garbage collection.
|
4 | 15 | # See also <https://github.com/JuliaDocs/Documenter.jl/issues/2640>.
|
5 | 16 | function clear_module!(M::Module)
|
6 | 17 | # we need `invokelatest` here for Julia >= 1.12 (or 1.13?)
|
7 |
| - for name in Base.invokelatest(names, M, all = true) |
8 |
| - if !isconst(M, name) |
9 |
| - # see, e.g https://github.com/JuliaDocs/Documenter.jl/issues/2673 |
10 |
| - # it is not possible to set `nothing` to variables, which are strongly typed |
11 |
| - # still attempt to set it, but ignore any errors |
12 |
| - try |
13 |
| - @eval M $name = $nothing |
14 |
| - catch err |
15 |
| - @debug "Could not clear variable `$name` by assigning `nothing`" err |
16 |
| - end |
| 18 | + for name in Base.invokelatest(names, M, all = true)::Vector{Symbol} |
| 19 | + # see, e.g https://github.com/JuliaDocs/Documenter.jl/issues/2673 |
| 20 | + # it is not possible to set `nothing` to variables, which are strongly typed |
| 21 | + # still attempt to set it, but ignore any errors |
| 22 | + try |
| 23 | + Base.invokelatest(clear_global!, M, name::Symbol) |
| 24 | + catch err |
| 25 | + @debug "Could not clear variable `$name` by assigning `nothing`" err |
17 | 26 | end
|
| 27 | + VERSION >= v"1.12" && Base.delete_binding(M, name) |
18 | 28 | end
|
19 | 29 | return
|
20 | 30 | end
|
|
0 commit comments