Skip to content

Commit f0706d0

Browse files
committed
Fix nonstdid parsing in import
1 parent 778212a commit f0706d0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/internals.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,12 @@ function parse_importexport_item(ps, is_colon = false)
369369
next(ps)
370370
EXPR(:OPERATOR, ps.nt.startbyte - ps.t.startbyte, 1 + ps.t.endbyte - ps.t.startbyte, val(ps.t, ps))
371371
elseif VERSION > v"1.3.0-" && isidentifier(ps.nt) && isemptyws(ps.nws) && (kindof(ps.nnt) === Tokens.STRING || kindof(ps.nnt) === Tokens.TRIPLE_STRING)
372-
EXPR(:NONSTDIDENTIFIER, EXPR[INSTANCE(next(ps)), INSTANCE(next(ps))])
373-
#TODO fix nonstdid handling
372+
id = INSTANCE(next(ps))
373+
if valof(id) == "var"
374+
EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))])
375+
else
376+
mErrorToken(ps, EXPR(:NONSTDIDENTIFIER, EXPR[id, INSTANCE(next(ps))]), UnexpectedToken)
377+
end
374378
else
375379
INSTANCE(next(ps))
376380
end

test/parser.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,4 +1321,13 @@ end
13211321
x, ps = CSTParser.parse(CSTParser.ParseState(str), true)
13221322
@test ps.errored == false
13231323
end
1324+
1325+
@testset "#310" begin
1326+
@test test_expr("""import a.var"papa" """)
1327+
@test test_expr("""import var"papa" """)
1328+
x, ps = CSTParser.parse(CSTParser.ParseState("""import a.notvar"papa" """), true)
1329+
@test ps.errored == true
1330+
x, ps = CSTParser.parse(CSTParser.ParseState("""import notvar"papa" """), true)
1331+
@test ps.errored == true
1332+
end
13241333
end

0 commit comments

Comments
 (0)