Fixed null pointer exception for JS

This commit is contained in:
harry-tallbelt 2017-03-08 15:00:14 +02:00
parent b8c74be628
commit 2a118e284f
2 changed files with 8 additions and 1 deletions

View File

@ -138,3 +138,4 @@ YYYY/MM/DD, github id, Full name, email
2017/02/14, xied75, Dong Xie, xied75@gmail.com
2017/02/20, Thomasb81, Thomas Burg, thomasb81@gmail.com
2017/02/26, jvasileff, John Vasileff, john@vasileff.com
2017/03/08, harry-tallbelt, Igor Vysokopoyasny, harry.tallbelt@gmail.com

View File

@ -119,8 +119,11 @@ ParserRuleContext.prototype.addErrorNode = function(badToken) {
ParserRuleContext.prototype.getChild = function(i, type) {
type = type || null;
if (this.children === null || i < 0 || i >= this.children.length) {
return null;
}
if (type === null) {
return this.children.length>=i ? this.children[i] : null;
return this.children[i];
} else {
for(var j=0; j<this.children.length; j++) {
var child = this.children[j];
@ -138,6 +141,9 @@ ParserRuleContext.prototype.getChild = function(i, type) {
ParserRuleContext.prototype.getToken = function(ttype, i) {
if (this.children === null || i < 0 || i >= this.children.length) {
return null;
}
for(var j=0; j<this.children.length; j++) {
var child = this.children[j];
if (child instanceof TerminalNode) {