Move with checks to the grammar checker.
This commit is contained in:
parent
67afd6d570
commit
9ca17f9b29
3 changed files with 31 additions and 13 deletions
|
@ -2896,20 +2896,12 @@ module ts {
|
|||
|
||||
function parseWithStatement(): WithStatement {
|
||||
var node = <WithStatement>createNode(SyntaxKind.WithStatement);
|
||||
var startPos = scanner.getTokenPos();
|
||||
parseExpected(SyntaxKind.WithKeyword);
|
||||
var endPos = scanner.getStartPos();
|
||||
parseExpected(SyntaxKind.OpenParenToken);
|
||||
node.expression = parseExpression();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
node.statement = parseStatement();
|
||||
node = finishNode(node);
|
||||
if (isInStrictMode) {
|
||||
// Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such
|
||||
// a context is an
|
||||
grammarErrorAtPos(startPos, endPos - startPos, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
|
||||
}
|
||||
return node;
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseCaseClause(): CaseOrDefaultClause {
|
||||
|
@ -4019,6 +4011,7 @@ module ts {
|
|||
case SyntaxKind.TypeReference: return visitTypeReference(<TypeReferenceNode>node);
|
||||
case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(<VariableDeclaration>node);
|
||||
case SyntaxKind.VariableStatement: return visitVariableStatement(<VariableStatement>node);
|
||||
case SyntaxKind.WithStatement: return visitWithStatement(<WithStatement>node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4630,8 +4623,8 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function allowLetAndConstDeclarations(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
function allowLetAndConstDeclarations(parent: Node): boolean {
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
|
@ -4640,11 +4633,19 @@ module ts {
|
|||
case SyntaxKind.ForInStatement:
|
||||
return false;
|
||||
case SyntaxKind.LabeledStatement:
|
||||
return allowLetAndConstDeclarations(node.parent);
|
||||
return allowLetAndConstDeclarations(parent.parent);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function visitWithStatement(node: WithStatement): void {
|
||||
if (node.flags & NodeFlags.ParsedInStrictMode) {
|
||||
// Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such
|
||||
// a context is an
|
||||
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program {
|
||||
|
|
13
tests/baselines/reference/methodInAmbientClass1.errors.txt
Normal file
13
tests/baselines/reference/methodInAmbientClass1.errors.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
tests/cases/compiler/methodInAmbientClass1.ts(2,20): error TS1037: A function implementation cannot be declared in an ambient context.
|
||||
tests/cases/compiler/methodInAmbientClass1.ts(2,12): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
||||
|
||||
|
||||
==== tests/cases/compiler/methodInAmbientClass1.ts (2 errors) ====
|
||||
declare class Foo {
|
||||
fn(): boolean {
|
||||
~
|
||||
!!! error TS1037: A function implementation cannot be declared in an ambient context.
|
||||
~~~~~~~
|
||||
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
||||
}
|
||||
}
|
4
tests/cases/compiler/methodInAmbientClass1.ts
Normal file
4
tests/cases/compiler/methodInAmbientClass1.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
declare class Foo {
|
||||
fn(): boolean {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue