mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Move export assignment checks to the grammar checker.
This commit is contained in:
parent
b9353086a4
commit
385fdd5eb2
@ -3421,8 +3421,11 @@ module ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseExportAssignmentTail(pos: number): ExportAssignment {
|
||||
function parseExportAssignmentTail(pos: number, flags: NodeFlags): ExportAssignment {
|
||||
var node = <ExportAssignment>createNode(SyntaxKind.ExportAssignment, pos);
|
||||
if (flags) {
|
||||
node.flags = flags;
|
||||
}
|
||||
node.exportName = parseIdentifier();
|
||||
parseSemicolon();
|
||||
return finishNode(node);
|
||||
@ -3460,19 +3463,13 @@ module ts {
|
||||
|
||||
function parseDeclaration(modifierContext: ModifierContext): Statement {
|
||||
var pos = getNodePos();
|
||||
var errorCountBeforeModifiers = file.parseDiagnostics.length;
|
||||
var flags = parseAndCheckModifiers(modifierContext);
|
||||
|
||||
if (token === SyntaxKind.ExportKeyword) {
|
||||
var modifiersEnd = scanner.getStartPos();
|
||||
nextToken();
|
||||
if (parseOptional(SyntaxKind.EqualsToken)) {
|
||||
var exportAssignmentTail = parseExportAssignmentTail(pos);
|
||||
if (flags !== 0 && errorCountBeforeModifiers === file.parseDiagnostics.length) {
|
||||
var modifiersStart = skipTrivia(sourceText, pos);
|
||||
grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers);
|
||||
}
|
||||
return exportAssignmentTail;
|
||||
return parseExportAssignmentTail(pos, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3753,6 +3750,7 @@ module ts {
|
||||
case SyntaxKind.ConstructSignature: return visitConstructSignature(<SignatureDeclaration>node);
|
||||
case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(<BreakOrContinueStatement>node);
|
||||
case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(<EnumDeclaration>node);
|
||||
case SyntaxKind.ExportAssignment: return visitExportAssignment(<ExportAssignment>node);
|
||||
case SyntaxKind.ForInStatement: return visitForInStatement(<ForInStatement>node);
|
||||
case SyntaxKind.ForStatement: return visitForStatement(<ForStatement>node);
|
||||
case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(<FunctionLikeDeclaration>node);
|
||||
@ -4069,6 +4067,12 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function visitExportAssignment(node: ExportAssignment) {
|
||||
if (node.flags & NodeFlags.Modifier) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
function visitForInStatement(node: ForInStatement) {
|
||||
checkVariableDeclarations(node.declarations) ||
|
||||
checkForMoreThanOneDeclaration(node.declarations);
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts(2,1): error TS1120: An export assignment cannot have modifiers.
|
||||
tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts (2 errors) ====
|
||||
==== tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts (1 errors) ====
|
||||
var x;
|
||||
export declare export = x;
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
~~~~~~
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
@ -1,11 +1,8 @@
|
||||
tests/cases/compiler/exportAssignmentWithDeclareModifier.ts(2,1): error TS1120: An export assignment cannot have modifiers.
|
||||
tests/cases/compiler/exportAssignmentWithDeclareModifier.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportAssignmentWithDeclareModifier.ts (2 errors) ====
|
||||
==== tests/cases/compiler/exportAssignmentWithDeclareModifier.ts (1 errors) ====
|
||||
var x;
|
||||
declare export = x;
|
||||
~~~~~~~
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
@ -1,11 +1,8 @@
|
||||
tests/cases/compiler/exportAssignmentWithExportModifier.ts(2,1): error TS1120: An export assignment cannot have modifiers.
|
||||
tests/cases/compiler/exportAssignmentWithExportModifier.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
|
||||
|
||||
==== tests/cases/compiler/exportAssignmentWithExportModifier.ts (2 errors) ====
|
||||
==== tests/cases/compiler/exportAssignmentWithExportModifier.ts (1 errors) ====
|
||||
var x;
|
||||
export export = x;
|
||||
~~~~~~
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
|
||||
!!! error TS1120: An export assignment cannot have modifiers.
|
||||
@ -1,2 +1,3 @@
|
||||
var x;
|
||||
// @module: commonjs
|
||||
var x;
|
||||
export declare export = x;
|
||||
@ -1,2 +1,3 @@
|
||||
var x;
|
||||
// @module: commonjs
|
||||
var x;
|
||||
declare export = x;
|
||||
@ -1,2 +1,3 @@
|
||||
var x;
|
||||
// @module: commonjs
|
||||
var x;
|
||||
export export = x;
|
||||
Loading…
x
Reference in New Issue
Block a user