diff --git a/README.md b/README.md index cf535c3..491c80b 100644 --- a/README.md +++ b/README.md @@ -244,14 +244,6 @@ Set{Expr} with 1 element: This function is used by Pluto's built-in package manager to learn which packages are used in a notebook. -### `can_be_function_wrapped` - -```julia -can_be_function_wrapped(ex)::Bool -``` - -Is this code simple enough that we can wrap it inside a function, and run the function in global scope instead of running the code directly? Look for `Pluto.PlutoRunner.Computer` to learn more. - ### `get_rootassignee` ```julia get_rootassignee(ex)::Union{Symbol,Nothing} diff --git a/src/Utils.jl b/src/Utils.jl index 9a63f19..8159e76 100644 --- a/src/Utils.jl +++ b/src/Utils.jl @@ -44,41 +44,3 @@ function get_rootassignee(ex::Expr, recurse::Bool = true)::Union{Symbol,Nothing} end get_rootassignee(ex::Any, recuse::Bool = true)::Union{Symbol,Nothing} = nothing - - -######################## - - -""" -```julia -can_be_function_wrapped(ex)::Bool -``` - -Is this code simple enough that we can wrap it inside a function, and run the function in global scope instead of running the code directly? Look for `Pluto.PlutoRunner.Computer` to learn more. -""" -function can_be_function_wrapped(x::Expr) - if x.head === :global || # better safe than sorry - x.head === :using || - x.head === :import || - x.head === :export || - x.head === :public || # Julia 1.11 - x.head === :module || - x.head === :incomplete || - # Only bail on named functions, but anonymous functions (args[1].head == :tuple) are fine. - # TODO Named functions INSIDE other functions should be fine too - (x.head === :function && !Meta.isexpr(x.args[1], :tuple)) || - x.head === :macro || - # Cells containing macrocalls will actually be function wrapped using the expanded version of the expression - # See https://github.com/fonsp/Pluto.jl/pull/1597 - x.head === :macrocall || - x.head === :struct || - x.head === :abstract || - (x.head === :(=) && is_function_assignment(x)) || # f(x) = ... - (x.head === :call && (x.args[1] === :eval || x.args[1] === :include)) - false - else - all(can_be_function_wrapped, x.args) - end -end - -can_be_function_wrapped(x::Any) = true diff --git a/test/Utils.jl b/test/Utils.jl index 64eccd6..0928420 100644 --- a/test/Utils.jl +++ b/test/Utils.jl @@ -10,45 +10,6 @@ end -@testset "can_be_function_wrapped" begin - - c = ExpressionExplorer.can_be_function_wrapped - - - @test c(quote - a = b + C - if d - for i = 1:10 - while Y - end - end - end - end) - - - @test c(quote - map(1:10) do i - i + 1 - end - end) - - - @test !c(quote - function x(x) - X - end - end) - - @test !c(quote - if false - using Asdf - end - end) - - -end - - @testset "is_toplevel_expr" begin