From f74be6248f11ed619ae6e625f2d938467aa8e297 Mon Sep 17 00:00:00 2001 From: Rotem Mizrachi-Meidan Date: Tue, 21 Aug 2018 10:58:15 +0300 Subject: [PATCH 1/2] Support empty header files Fix an issue where the script would fail if header file has no method declarations --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 95a4860..441c962 100644 --- a/index.js +++ b/index.js @@ -64,8 +64,9 @@ function extractNameOfMethodWithoutArguments(methodBody, rawArgs) { const parseMethods = file => { const lines = file.split("\n"); + const methodDeclarations = file.match(methodDeclarationRegex) || []; - return file.match(methodDeclarationRegex).map(methodDeclaration => { + return methodDeclarations.map(methodDeclaration => { const returnType = methodDeclaration.match(matchReturnType); const methodBody = methodDeclaration From 06e41c584c8030611003a4c68ddeba27610e445d Mon Sep 17 00:00:00 2001 From: Rotem M Date: Tue, 21 Aug 2018 11:23:54 +0300 Subject: [PATCH 2/2] added tests --- __tests__/index.js | 7 +++++++ exampleFiles/empty.h | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 exampleFiles/empty.h diff --git a/__tests__/index.js b/__tests__/index.js index 29273a6..3294b79 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -6,6 +6,13 @@ function loadFile(name) { } describe("objective-c-parser", () => { + describe("empty file", () => { + const empty = loadFile("empty"); + it("should return an empty list of methods for an empty header file", () => { + expect(objcToJs(empty).methods).toEqual([]); + }); + }); + describe("basic example", () => { const basic = loadFile("basic"); it("should return name of basic example", () => { diff --git a/exampleFiles/empty.h b/exampleFiles/empty.h new file mode 100644 index 0000000..c81145a --- /dev/null +++ b/exampleFiles/empty.h @@ -0,0 +1,5 @@ +#import + +// just an empty header file + +@end