Added error recovery for missing 'from' keyword in an export declaration.

This commit is contained in:
Daniel Rosenwasser
2015-07-10 16:27:40 -07:00
parent 120d0d11a0
commit 69f93fe116

View File

@@ -4345,6 +4345,10 @@ namespace ts {
}
}
function nextTokenIsStringLiteralOnSameLine() {
return !scanner.hasPrecedingLineBreak() && token === SyntaxKind.StringLiteral;
}
function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral);
@@ -5135,7 +5139,12 @@ namespace ts {
}
else {
node.exportClause = parseNamedImportsOrExports(SyntaxKind.NamedExports);
if (parseOptional(SyntaxKind.FromKeyword)) {
// It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios,
// the 'from' keyword be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`)
// If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect.
if (token === SyntaxKind.FromKeyword || lookAhead(nextTokenIsStringLiteralOnSameLine)) {
parseExpected(SyntaxKind.FromKeyword)
node.moduleSpecifier = parseModuleSpecifier();
}
}