Skip to content

Commit 2b58896

Browse files
committed
handle changes without a location
1 parent 0d28115 commit 2b58896

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
55

66
[[CSTParser]]
77
deps = ["LibGit2", "Test", "Tokenize"]
8-
git-tree-sha1 = "82be55a328f39a11849569815a9f49911d6d7b58"
8+
git-tree-sha1 = "d878de3315f9b6569851d919f7976fe527d00c24"
99
repo-rev = "location"
1010
repo-url = "https://github.com/MikeInnes/CSTParser.jl"
1111
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"

src/patch/cst.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ end
5959

6060
function replacement(src::SourceFile, p::Replace)
6161
loc = exprloc(src.ast, p.idx)
62+
if loc == nothing
63+
@warn "No location found for $(repr(CSTParser.striploc(expridx(src.ast, p.idx))))"
64+
return
65+
end
6266
prec = precedence_level(src.cst, loc)
6367
_, span = charrange(src.cst, loc)
6468
span => sprint(Base.show_unquoted, p.new, 0, prec)
@@ -90,7 +94,8 @@ function replacement(src::SourceFile, p::Delete)
9094
span => ""
9195
end
9296

93-
replacement(src::SourceFile, p::Patch) = [replacement(src, p) for p in p.ps]
97+
replacement(src::SourceFile, p::Patch) =
98+
filter(x -> x != nothing, [replacement(src, p) for p in p.ps])
9499

95100
function patch(io::IO, src::SourceFile, rs)
96101
rs = sort(rs, by=x->first(x[1]))

0 commit comments

Comments
 (0)