function expect(punc) { return expect_token("punc", punc); };
+ function has_newline_before(token) {
+ return token.nlb || !all(token.comments_before, function(comment) {
+ return !comment.nlb;
+ });
+ }
+
function can_insert_semicolon() {
- return !options.strict && (
- S.token.nlb || is("eof") || is("punc", "}")
- );
+ return !options.strict
+ && (is("eof") || is("punc", "}") || has_newline_before(S.token));
};
function semicolon(optional) {
if (S.in_directives) {
var token = peek();
if (S.token.raw.indexOf("\\") == -1
- && (token.nlb
- || is_token(token, "eof")
- || is_token(token, "punc", ";")
- || is_token(token, "punc", "}"))) {
+ && (is_token(token, "punc", ";")
+ || is_token(token, "punc", "}")
+ || has_newline_before(token)
+ || is_token(token, "eof"))) {
S.input.add_directive(S.token.value);
} else {
S.in_directives = false;
case "throw":
next();
- if (S.token.nlb)
+ if (has_newline_before(S.token))
croak("Illegal newline after 'throw'");
var value = expression(true);
semicolon();
return ex;
}
var val = expr_atom(allow_calls);
- while (is("operator") && UNARY_POSTFIX(S.token.value) && !S.token.nlb) {
+ while (is("operator") && UNARY_POSTFIX(S.token.value) && !has_newline_before(S.token)) {
val = make_unary(AST_UnaryPostfix, S.token, val);
val.start = start;
val.end = S.token;