From ad83f26b5d9a5fc83962d7bef10a84c08a338af8 Mon Sep 17 00:00:00 2001 From: Zefram Lou Date: Wed, 22 Jan 2020 21:32:39 -0800 Subject: [PATCH] Fixed transformAST.TypeName In transformAST.TypeName, it is possible for ctx.children to be null. An example scenario is when the last argument of a function definition has a trailing comma. The existing implementation assumes ctx.children has the property 'length', which causes an exception when ctx.children is null. This commit fixes this issue by adding an if statement. --- src/ASTBuilder.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ASTBuilder.js b/src/ASTBuilder.js index 7c26230..9ea4cef 100644 --- a/src/ASTBuilder.js +++ b/src/ASTBuilder.js @@ -272,23 +272,25 @@ const transformAST = { }, TypeName(ctx) { - if (ctx.children.length > 2) { - let length = null - if (ctx.children.length === 4) { - length = this.visit(ctx.getChild(2)) - } + if (ctx.children) { + if (ctx.children.length > 2) { + let length = null + if (ctx.children.length === 4) { + length = this.visit(ctx.getChild(2)) + } - return { - type: 'ArrayTypeName', - baseTypeName: this.visit(ctx.typeName()), - length + return { + type: 'ArrayTypeName', + baseTypeName: this.visit(ctx.typeName()), + length + } } - } - if (ctx.children.length === 2) { - return { - type: 'ElementaryTypeName', - name: toText(ctx.getChild(0)), - stateMutability: toText(ctx.getChild(1)) + if (ctx.children.length === 2) { + return { + type: 'ElementaryTypeName', + name: toText(ctx.getChild(0)), + stateMutability: toText(ctx.getChild(1)) + } } } return this.visit(ctx.getChild(0))