diff --git a/NEWS.md b/NEWS.md index b76159e4..93b8d15c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,8 @@ ### Bug fixes -* Fixed a problem parsing expression referring to the same object (#293) +* Fixed a problem parsing expression referring to the same object (#293). +* Fixed a problem when a symbol appears alone inside an expression (#299). # teal.code 0.7.2 diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 27094cdb..f7f73882 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -398,7 +398,7 @@ extract_dependency <- function(parsed_code) { while (length(queue) > 0) { current <- queue[[1]] queue <- queue[-1] - if (identical(current[[1L]], as.name("{"))) { + if (typeof(current) == "language" && inherits(current, "{")) { queue <- append(queue, as.list(current)[-1L]) } else { parsed_code <- parse(text = as.expression(current), keep.source = TRUE, encoding = "UTF-8") diff --git a/tests/testthat/test-qenv_within.R b/tests/testthat/test-qenv_within.R index 0df3a5ed..6081c078 100644 --- a/tests/testthat/test-qenv_within.R +++ b/tests/testthat/test-qenv_within.R @@ -166,3 +166,16 @@ test_that("Chinese characters are handled properly (issue 284)", { expect_equal(lengths(strsplit(get_code(q), split = "\n", fixed = TRUE)), 4L) }) + +test_that("handles name expression inside if clause", { + expect_no_error( + within(qenv(), { + if (TRUE) { + table <- iris + } + if (TRUE) { + table + } + }) + ) +})