Merge pull request #11246 from Microsoft/export_in_function

Ensure that `checkGrammarModuleElementContext` reliably returns `true` when there is bad grammar
This commit is contained in:
Andy 2016-09-30 06:03:15 -07:00 committed by GitHub
commit 631ab0abab
4 changed files with 25 additions and 3 deletions

View File

@ -17714,9 +17714,11 @@ namespace ts {
}
function checkGrammarModuleElementContext(node: Statement, errorMessage: DiagnosticMessage): boolean {
if (node.parent.kind !== SyntaxKind.SourceFile && node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.ModuleDeclaration) {
return grammarErrorOnFirstToken(node, errorMessage);
const isInAppropriateContext = node.parent.kind === SyntaxKind.SourceFile || node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.ModuleDeclaration;
if (!isInAppropriateContext) {
grammarErrorOnFirstToken(node, errorMessage);
}
return !isInAppropriateContext;
}
function checkExportSpecifier(node: ExportSpecifier) {
@ -17757,7 +17759,7 @@ namespace ts {
checkExpressionCached(node.expression);
}
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
checkExternalModuleExports(container);
if (node.isExportEquals && !isInAmbientContext(node)) {
if (modulekind === ModuleKind.ES6) {

View File

@ -0,0 +1,9 @@
tests/cases/compiler/exportInFunction.ts(3,1): error TS1005: '}' expected.
==== tests/cases/compiler/exportInFunction.ts (1 errors) ====
function f() {
export = 0;
!!! error TS1005: '}' expected.

View File

@ -0,0 +1,9 @@
//// [exportInFunction.ts]
function f() {
export = 0;
//// [exportInFunction.js]
function f() {
export = 0;
}

View File

@ -0,0 +1,2 @@
function f() {
export = 0;