Browse files

JavaScript parser: fix some unterminated statement corner case issues

This fixes parsing of the following unterminated statements:

	if () {
		foo = 42
	}

	if () {
		foo = new Object()
	}

	if () {
		foo = ({a:1,b:2})
	}
  • Loading branch information...
1 parent 205bab8 commit b9ca95c381624a288a7ea733624f36a9af10212a @b4n b4n committed Sep 25, 2012
Showing with 25 additions and 15 deletions.
  1. +25 −15 tagmanager/ctags/js.c
View
40 tagmanager/ctags/js.c
@@ -1347,6 +1347,8 @@ static boolean parseStatement (tokenInfo *const token, boolean is_inside_class)
makeJsTag (name, JSTAG_METHOD);
parseBlock (token, name);
}
+ else if (isType (token, TOKEN_CLOSE_CURLY))
+ is_terminated = FALSE;
}
else if (isType (token, TOKEN_OPEN_CURLY))
{
@@ -1441,6 +1443,8 @@ static boolean parseStatement (tokenInfo *const token, boolean is_inside_class)
}
}
}
+ else if (isType (token, TOKEN_CLOSE_CURLY))
+ is_terminated = FALSE;
}
}
else if (isKeyword (token, KEYWORD_NONE))
@@ -1486,23 +1490,29 @@ static boolean parseStatement (tokenInfo *const token, boolean is_inside_class)
}
}
}
- findCmdTerm (token);
- /*
- * Statements can be optionally terminated in the case of
- * statement prior to a close curly brace as in the
- * document.write line below:
- *
- * function checkForUpdate() {
- * if( 1==1 ) {
- * document.write("hello from checkForUpdate<br>")
- * }
- * return 1;
- * }
- */
- if ( ! is_terminated && isType (token, TOKEN_CLOSE_CURLY))
- is_terminated = FALSE;
+ /* if we aren't already at the cmd end, advance to it and check whether
+ * the statement was terminated */
+ if (! isType (token, TOKEN_CLOSE_CURLY) &&
+ ! isType (token, TOKEN_SEMICOLON))
+ {
+ findCmdTerm (token);
+ /*
+ * Statements can be optionally terminated in the case of
+ * statement prior to a close curly brace as in the
+ * document.write line below:
+ *
+ * function checkForUpdate() {
+ * if( 1==1 ) {
+ * document.write("hello from checkForUpdate<br>")
+ * }
+ * return 1;
+ * }
+ */
+ if (isType (token, TOKEN_CLOSE_CURLY))
+ is_terminated = FALSE;
+ }
cleanUp:
vStringCopy(token->scope, saveScope);

0 comments on commit b9ca95c

Please sign in to comment.