Bug 1206750 - Don't assert when |export ... from 'str'| is followed by a regular expression literal on a new line, with no intervening semicolon. r=arai

This commit is contained in:
Jeff Walden 2015-09-21 16:56:25 -07:00
parent 6a7fc66bd0
commit b4bd69bb6d
2 changed files with 42 additions and 20 deletions

View File

@ -4867,14 +4867,14 @@ Parser<FullParseHandler>::exportDeclaration()
if (!moduleSpec)
return null();
if (!MatchOrInsertSemicolon(tokenStream))
if (!MatchOrInsertSemicolon(tokenStream, TokenStream::Operand))
return null();
return handler.newExportFromDeclaration(begin, kid, moduleSpec);
} else {
tokenStream.ungetToken();
}
tokenStream.ungetToken();
if (!MatchOrInsertSemicolon(tokenStream, TokenStream::Operand))
return null();
break;
@ -4895,28 +4895,24 @@ Parser<FullParseHandler>::exportDeclaration()
if (!tokenStream.getToken(&tt))
return null();
if (tt == TOK_NAME && tokenStream.currentName() == context->names().from) {
if (!checkUnescapedName())
return null();
MUST_MATCH_TOKEN(TOK_STRING, JSMSG_MODULE_SPEC_AFTER_FROM);
Node moduleSpec = stringLiteral();
if (!moduleSpec)
return null();
if (!MatchOrInsertSemicolon(tokenStream))
return null();
return handler.newExportFromDeclaration(begin, kid, moduleSpec);
} else {
if (tt != TOK_NAME || tokenStream.currentName() != context->names().from) {
report(ParseError, false, null(), JSMSG_FROM_AFTER_EXPORT_STAR);
return null();
}
if (!MatchOrInsertSemicolon(tokenStream))
if (!checkUnescapedName())
return null();
break;
MUST_MATCH_TOKEN(TOK_STRING, JSMSG_MODULE_SPEC_AFTER_FROM);
Node moduleSpec = stringLiteral();
if (!moduleSpec)
return null();
if (!MatchOrInsertSemicolon(tokenStream, TokenStream::Operand))
return null();
return handler.newExportFromDeclaration(begin, kid, moduleSpec);
}
case TOK_FUNCTION:

View File

@ -61,6 +61,32 @@ if (typeof Reflect.parse === "function")
assertEq(oneStatementAST.body.length, 1);
assertEq(oneStatementAST.body[0].type, "ExportDeclaration");
twoStatementAST =
Reflect.parse(`export { x } from "bar"
/bar/g`,
{ target: "module" });
statements = twoStatementAST.body;
assertEq(statements.length, 2,
"should have two items in the module, not one ExportDeclaration");
assertEq(statements[0].type, "ExportDeclaration");
assertEq(statements[1].type, "ExpressionStatement");
assertEq(statements[1].expression.type, "Literal");
assertEq(statements[1].expression.value.toString(), "/bar/g");
twoStatementAST =
Reflect.parse(`export * from "bar"
/bar/g`,
{ target: "module" });
statements = twoStatementAST.body;
assertEq(statements.length, 2,
"should have two items in the module, not one ExportDeclaration");
assertEq(statements[0].type, "ExportDeclaration");
assertEq(statements[1].type, "ExpressionStatement");
assertEq(statements[1].expression.type, "Literal");
assertEq(statements[1].expression.value.toString(), "/bar/g");
}
/******************************************************************************/