Skip to content

Commit 24651c9

Browse files
authored
fix: Accept imports after declarations (#2178)
1 parent ae48e07 commit 24651c9

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/parse.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,6 @@ function parse(source, root, options) {
967967

968968
case "import":
969969

970-
/* istanbul ignore if */
971-
if (!head)
972-
throw illegal(token);
973-
974970
parseImport();
975971
break;
976972

tests/comp_import-after-decl.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var tape = require("tape");
2+
var protobuf = require("..");
3+
4+
tape.test("imports after declarations", function(test) {
5+
var parsed = protobuf.parse("syntax = \"proto3\";" +
6+
"message Foo { string name = 1; }" +
7+
"import \"bar.proto\";" +
8+
"enum Status { UNKNOWN = 0; }" +
9+
"import weak \"baz.proto\";");
10+
11+
test.deepEqual(parsed.imports, [ "bar.proto" ], "should parse imports after messages");
12+
test.deepEqual(parsed.weakImports, [ "baz.proto" ], "should parse weak imports after enums");
13+
test.end();
14+
});

0 commit comments

Comments
 (0)