mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Ensure that checkGrammarModuleElementContext reliably returns true when there is bad grammar.
This commit is contained in:
parent
60ab007d3a
commit
228ddde66e
@ -17706,9 +17706,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) {
|
||||
@ -17749,7 +17751,7 @@ namespace ts {
|
||||
checkExpressionCached(node.expression);
|
||||
}
|
||||
|
||||
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
|
||||
checkExternalModuleExports(container);
|
||||
|
||||
if (node.isExportEquals && !isInAmbientContext(node)) {
|
||||
if (modulekind === ModuleKind.ES6) {
|
||||
|
||||
9
tests/baselines/reference/exportInFunction.errors.txt
Normal file
9
tests/baselines/reference/exportInFunction.errors.txt
Normal 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.
|
||||
9
tests/baselines/reference/exportInFunction.js
Normal file
9
tests/baselines/reference/exportInFunction.js
Normal file
@ -0,0 +1,9 @@
|
||||
//// [exportInFunction.ts]
|
||||
function f() {
|
||||
export = 0;
|
||||
|
||||
|
||||
//// [exportInFunction.js]
|
||||
function f() {
|
||||
export = 0;
|
||||
}
|
||||
2
tests/cases/compiler/exportInFunction.ts
Normal file
2
tests/cases/compiler/exportInFunction.ts
Normal file
@ -0,0 +1,2 @@
|
||||
function f() {
|
||||
export = 0;
|
||||
Loading…
x
Reference in New Issue
Block a user