Merge pull request #3461 from Microsoft/parsingModuleElements

Parse module elements in a block context
This commit is contained in:
Jason Freeman 2015-06-10 17:31:02 -07:00
commit f73af3a902
35 changed files with 756 additions and 166 deletions

View file

@ -661,7 +661,11 @@ module ts {
}
function bindExportAssignment(node: ExportAssignment) {
if (node.expression.kind === SyntaxKind.Identifier) {
if (!container.symbol || !container.symbol.exports) {
// Export assignment in some sort of block construct
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
}
else if (node.expression.kind === SyntaxKind.Identifier) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
}
@ -672,7 +676,11 @@ module ts {
}
function bindExportDeclaration(node: ExportDeclaration) {
if (!node.exportClause) {
if (!container.symbol || !container.symbol.exports) {
// Export * in some sort of block construct
bindAnonymousDeclaration(node, SymbolFlags.ExportStar, getDeclarationName(node));
}
else if (!node.exportClause) {
// All export * declarations are collected in an __export symbol
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None);
}

View file

@ -11114,6 +11114,15 @@ module ts {
function checkModuleDeclaration(node: ModuleDeclaration) {
if (produceDiagnostics) {
// Grammar checking
let isAmbientExternalModule = node.name.kind === SyntaxKind.StringLiteral;
let contextErrorMessage = isAmbientExternalModule
? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
: Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
// If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) {
grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names);
@ -11150,7 +11159,7 @@ module ts {
}
// Checks for ambient external modules.
if (node.name.kind === SyntaxKind.StringLiteral) {
if (isAmbientExternalModule) {
if (!isGlobalSourceFile(node.parent)) {
error(node.name, Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules);
}
@ -11226,6 +11235,10 @@ module ts {
}
function checkImportDeclaration(node: ImportDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
}
@ -11248,6 +11261,11 @@ module ts {
}
function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node);
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
checkImportBinding(node);
@ -11279,9 +11297,15 @@ module ts {
}
function checkExportDeclaration(node: ExportDeclaration) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
// If we hit an export in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers);
}
if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
if (node.exportClause) {
// export { x, y }
@ -11303,6 +11327,12 @@ module 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);
}
}
function checkExportSpecifier(node: ExportSpecifier) {
checkAliasSymbol(node);
if (!(<ExportDeclaration>node.parent.parent).moduleSpecifier) {
@ -11311,6 +11341,11 @@ module ts {
}
function checkExportAssignment(node: ExportAssignment) {
if (checkGrammarModuleElementContext(node, Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
return;
}
let container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
if (container.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>container).name.kind === SyntaxKind.Identifier) {
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
@ -11326,7 +11361,8 @@ module ts {
else {
checkExpressionCached(node.expression);
}
checkExternalModuleExports(container);
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
if (node.isExportEquals && !isInAmbientContext(node)) {
if (languageVersion >= ScriptTarget.ES6) {
@ -11340,7 +11376,7 @@ module ts {
}
}
function getModuleStatements(node: Declaration): ModuleElement[] {
function getModuleStatements(node: Declaration): Statement[] {
if (node.kind === SyntaxKind.SourceFile) {
return (<SourceFile>node).statements;
}

View file

@ -186,6 +186,11 @@ module ts {
A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "A type predicate is only allowed in return type position for functions and methods." },
A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." },
A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: DiagnosticCategory.Error, key: "A type predicate cannot reference element '{0}' in a binding pattern." },
An_export_assignment_can_only_be_used_in_a_module: { code: 1231, category: DiagnosticCategory.Error, key: "An export assignment can only be used in a module." },
An_import_declaration_can_only_be_used_in_a_namespace_or_module: { code: 1232, category: DiagnosticCategory.Error, key: "An import declaration can only be used in a namespace or module." },
An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: DiagnosticCategory.Error, key: "An export declaration can only be used in a module." },
An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." },
A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

View file

@ -731,6 +731,26 @@
"category": "Error",
"code": 1230
},
"An export assignment can only be used in a module.": {
"category": "Error",
"code": 1231
},
"An import declaration can only be used in a namespace or module.": {
"category": "Error",
"code": 1232
},
"An export declaration can only be used in a module.": {
"category": "Error",
"code": 1233
},
"An ambient module declaration is only allowed at the top level in a file.": {
"category": "Error",
"code": 1234
},
"A namespace declaration is only allowed in a namespace or module.": {
"category": "Error",
"code": 1235
},
"Duplicate identifier '{0}'.": {

View file

@ -495,13 +495,6 @@ module ts {
// attached to the EOF token.
let parseErrorBeforeNextFinishedNode: boolean = false;
export const enum StatementFlags {
None = 0,
Statement = 1,
ModuleElement = 2,
StatementOrModuleElement = Statement | ModuleElement
}
export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean): SourceFile {
initializeState(fileName, _sourceText, languageVersion, _syntaxCursor);
@ -551,7 +544,7 @@ module ts {
token = nextToken();
processReferenceComments(sourceFile);
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement);
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseStatement);
Debug.assert(token === SyntaxKind.EndOfFileToken);
sourceFile.endOfFileToken = parseTokenNode();
@ -1129,17 +1122,14 @@ module ts {
switch (parsingContext) {
case ParsingContext.SourceElements:
case ParsingContext.ModuleElements:
case ParsingContext.BlockStatements:
case ParsingContext.SwitchClauseStatements:
// If we're in error recovery, then we don't want to treat ';' as an empty statement.
// The problem is that ';' can show up in far too many contexts, and if we see one
// and assume it's a statement, then we may bail out inappropriately from whatever
// we're parsing. For example, if we have a semicolon in the middle of a class, then
// we really don't want to assume the class is over and we're on a statement in the
// outer module. We just want to consume and move on.
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfModuleElement();
case ParsingContext.BlockStatements:
case ParsingContext.SwitchClauseStatements:
// During error recovery we don't treat empty statements as statements
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement();
case ParsingContext.SwitchClauses:
return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword;
@ -1250,7 +1240,6 @@ module ts {
}
switch (kind) {
case ParsingContext.ModuleElements:
case ParsingContext.BlockStatements:
case ParsingContext.SwitchClauses:
case ParsingContext.TypeMembers:
@ -1461,15 +1450,13 @@ module ts {
function canReuseNode(node: Node, parsingContext: ParsingContext): boolean {
switch (parsingContext) {
case ParsingContext.ModuleElements:
return isReusableModuleElement(node);
case ParsingContext.ClassMembers:
return isReusableClassMember(node);
case ParsingContext.SwitchClauses:
return isReusableSwitchClause(node);
case ParsingContext.SourceElements:
case ParsingContext.BlockStatements:
case ParsingContext.SwitchClauseStatements:
return isReusableStatement(node);
@ -1532,26 +1519,6 @@ module ts {
return false;
}
function isReusableModuleElement(node: Node) {
if (node) {
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.ExportDeclaration:
case SyntaxKind.ExportAssignment:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.EnumDeclaration:
return true;
}
return isReusableStatement(node);
}
return false;
}
function isReusableClassMember(node: Node) {
if (node) {
switch (node.kind) {
@ -1604,6 +1571,15 @@ module ts {
case SyntaxKind.LabeledStatement:
case SyntaxKind.DoStatement:
case SyntaxKind.DebuggerStatement:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.ExportDeclaration:
case SyntaxKind.ExportAssignment:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.TypeAliasDeclaration:
return true;
}
}
@ -1677,8 +1653,7 @@ module ts {
function parsingContextErrors(context: ParsingContext): DiagnosticMessage {
switch (context) {
case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected;
case ParsingContext.ModuleElements: return Diagnostics.Declaration_or_statement_expected;
case ParsingContext.BlockStatements: return Diagnostics.Statement_expected;
case ParsingContext.BlockStatements: return Diagnostics.Declaration_or_statement_expected;
case ParsingContext.SwitchClauses: return Diagnostics.case_or_default_expected;
case ParsingContext.SwitchClauseStatements: return Diagnostics.Statement_expected;
case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected;
@ -1795,26 +1770,26 @@ module ts {
}
function parseRightSideOfDot(allowIdentifierNames: boolean): Identifier {
// Technically a keyword is valid here as all keywords are identifier names.
// However, often we'll encounter this in error situations when the keyword
// Technically a keyword is valid here as all identifiers and keywords are identifier names.
// However, often we'll encounter this in error situations when the identifier or keyword
// is actually starting another valid construct.
//
// So, we check for the following specific case:
//
// name.
// keyword identifierNameOrKeyword
// identifierOrKeyword identifierNameOrKeyword
//
// Note: the newlines are important here. For example, if that above code
// were rewritten into:
//
// name.keyword
// name.identifierOrKeyword
// identifierNameOrKeyword
//
// Then we would consider it valid. That's because ASI would take effect and
// the code would be implicitly: "name.keyword; identifierNameOrKeyword".
// the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
// In the first case though, ASI will not take effect because there is not a
// line terminator after the keyword.
if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
// line terminator after the identifier or keyword.
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
if (matchesPattern) {
@ -3811,7 +3786,7 @@ module ts {
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
}
function parseDeclarationFlags(): StatementFlags {
function isDeclaration(): boolean {
while (true) {
switch (token) {
case SyntaxKind.VarKeyword:
@ -3820,7 +3795,7 @@ module ts {
case SyntaxKind.FunctionKeyword:
case SyntaxKind.ClassKeyword:
case SyntaxKind.EnumKeyword:
return StatementFlags.Statement;
return true;
// 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers;
// however, an identifier cannot be followed by another identifier on the same line. This is what we
@ -3845,28 +3820,27 @@ module ts {
// could be legal, it would add complexity for very little gain.
case SyntaxKind.InterfaceKeyword:
case SyntaxKind.TypeKeyword:
return nextTokenIsIdentifierOnSameLine() ? StatementFlags.Statement : StatementFlags.None;
return nextTokenIsIdentifierOnSameLine();
case SyntaxKind.ModuleKeyword:
case SyntaxKind.NamespaceKeyword:
return nextTokenIsIdentifierOrStringLiteralOnSameLine() ? StatementFlags.ModuleElement : StatementFlags.None;
return nextTokenIsIdentifierOrStringLiteralOnSameLine();
case SyntaxKind.DeclareKeyword:
nextToken();
// ASI takes effect for this modifier.
if (scanner.hasPrecedingLineBreak()) {
return StatementFlags.None;
return false;
}
continue;
case SyntaxKind.ImportKeyword:
nextToken();
return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword() ?
StatementFlags.ModuleElement : StatementFlags.None;
token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword();
case SyntaxKind.ExportKeyword:
nextToken();
if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword) {
return StatementFlags.ModuleElement;
return true;
}
continue;
case SyntaxKind.PublicKeyword:
@ -3876,16 +3850,16 @@ module ts {
nextToken();
continue;
default:
return StatementFlags.None;
return false;
}
}
}
function getDeclarationFlags(): StatementFlags {
return lookAhead(parseDeclarationFlags);
function isStartOfDeclaration(): boolean {
return lookAhead(isDeclaration);
}
function getStatementFlags(): StatementFlags {
function isStartOfStatement(): boolean {
switch (token) {
case SyntaxKind.AtToken:
case SyntaxKind.SemicolonToken:
@ -3911,12 +3885,12 @@ module ts {
// however, we say they are here so that we may gracefully parse them and error later.
case SyntaxKind.CatchKeyword:
case SyntaxKind.FinallyKeyword:
return StatementFlags.Statement;
return true;
case SyntaxKind.ConstKeyword:
case SyntaxKind.ExportKeyword:
case SyntaxKind.ImportKeyword:
return getDeclarationFlags();
return isStartOfDeclaration();
case SyntaxKind.DeclareKeyword:
case SyntaxKind.InterfaceKeyword:
@ -3924,7 +3898,7 @@ module ts {
case SyntaxKind.NamespaceKeyword:
case SyntaxKind.TypeKeyword:
// When these don't start a declaration, they're an identifier in an expression statement
return getDeclarationFlags() || StatementFlags.Statement;
return true;
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
@ -3932,22 +3906,13 @@ module ts {
case SyntaxKind.StaticKeyword:
// When these don't start a declaration, they may be the start of a class member if an identifier
// immediately follows. Otherwise they're an identifier in an expression statement.
return getDeclarationFlags() ||
(lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? StatementFlags.None : StatementFlags.Statement);
return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
default:
return isStartOfExpression() ? StatementFlags.Statement : StatementFlags.None;
return isStartOfExpression();
}
}
function isStartOfStatement(): boolean {
return (getStatementFlags() & StatementFlags.Statement) !== 0;
}
function isStartOfModuleElement(): boolean {
return (getStatementFlags() & StatementFlags.StatementOrModuleElement) !== 0;
}
function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() &&
@ -3961,18 +3926,6 @@ module ts {
}
function parseStatement(): Statement {
return <Statement>parseModuleElementOfKind(StatementFlags.Statement);
}
function parseModuleElement(): ModuleElement {
return parseModuleElementOfKind(StatementFlags.StatementOrModuleElement);
}
function parseSourceElement(): ModuleElement {
return parseModuleElementOfKind(StatementFlags.StatementOrModuleElement);
}
function parseModuleElementOfKind(flags: StatementFlags): ModuleElement {
switch (token) {
case SyntaxKind.SemicolonToken:
return parseEmptyStatement();
@ -4032,7 +3985,7 @@ module ts {
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.StaticKeyword:
if (getDeclarationFlags() & flags) {
if (isStartOfDeclaration()) {
return parseDeclaration();
}
break;
@ -4040,7 +3993,7 @@ module ts {
return parseExpressionOrLabeledStatement();
}
function parseDeclaration(): ModuleElement {
function parseDeclaration(): Statement {
let fullStart = getNodePos();
let decorators = parseDecorators();
let modifiers = parseModifiers();
@ -4073,7 +4026,7 @@ module ts {
if (decorators) {
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
let node = <ModuleElement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
let node = <Statement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
node.pos = fullStart;
node.decorators = decorators;
setModifiers(node, modifiers);
@ -4629,7 +4582,7 @@ module ts {
function parseModuleBlock(): ModuleBlock {
let node = <ModuleBlock>createNode(SyntaxKind.ModuleBlock, scanner.getStartPos());
if (parseExpected(SyntaxKind.OpenBraceToken)) {
node.statements = parseList(ParsingContext.ModuleElements, /*checkForStrictMode*/ false, parseModuleElement);
node.statements = parseList(ParsingContext.BlockStatements, /*checkForStrictMode*/ false, parseStatement);
parseExpected(SyntaxKind.CloseBraceToken);
}
else {
@ -4957,7 +4910,6 @@ module ts {
const enum ParsingContext {
SourceElements, // Elements in source file
ModuleElements, // Elements in module declaration
BlockStatements, // Statements in block
SwitchClauses, // Clauses in switch statement
SwitchClauseStatements, // Statements in switch clause

View file

@ -808,7 +808,7 @@ module ts {
expression: UnaryExpression;
}
export interface Statement extends Node, ModuleElement {
export interface Statement extends Node {
_statementBrand: any;
}
@ -911,10 +911,6 @@ module ts {
block: Block;
}
export interface ModuleElement extends Node {
_moduleElementBrand: any;
}
export interface ClassLikeDeclaration extends Declaration {
name?: Identifier;
typeParameters?: NodeArray<TypeParameterDeclaration>;
@ -962,16 +958,16 @@ module ts {
members: NodeArray<EnumMember>;
}
export interface ModuleDeclaration extends Declaration, ModuleElement {
export interface ModuleDeclaration extends Declaration, Statement {
name: Identifier | LiteralExpression;
body: ModuleBlock | ModuleDeclaration;
}
export interface ModuleBlock extends Node, ModuleElement {
statements: NodeArray<ModuleElement>
export interface ModuleBlock extends Node, Statement {
statements: NodeArray<Statement>
}
export interface ImportEqualsDeclaration extends Declaration, ModuleElement {
export interface ImportEqualsDeclaration extends Declaration, Statement {
name: Identifier;
// 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external
@ -987,7 +983,7 @@ module ts {
// import "mod" => importClause = undefined, moduleSpecifier = "mod"
// In rest of the cases, module specifier is string literal corresponding to module
// ImportClause information is shown at its declaration below.
export interface ImportDeclaration extends ModuleElement {
export interface ImportDeclaration extends Statement {
importClause?: ImportClause;
moduleSpecifier: Expression;
}
@ -1007,7 +1003,7 @@ module ts {
name: Identifier;
}
export interface ExportDeclaration extends Declaration, ModuleElement {
export interface ExportDeclaration extends Declaration, Statement {
exportClause?: NamedExports;
moduleSpecifier?: Expression;
}
@ -1027,7 +1023,7 @@ module ts {
export type ImportSpecifier = ImportOrExportSpecifier;
export type ExportSpecifier = ImportOrExportSpecifier;
export interface ExportAssignment extends Declaration, ModuleElement {
export interface ExportAssignment extends Declaration, Statement {
isExportEquals?: boolean;
expression: Expression;
}
@ -1143,7 +1139,7 @@ module ts {
// Source files are declarations when they are external modules.
export interface SourceFile extends Declaration {
statements: NodeArray<ModuleElement>;
statements: NodeArray<Statement>;
endOfFileToken: Node;
fileName: string;

View file

@ -1,10 +1,10 @@
tests/cases/compiler/class2.ts(1,29): error TS1129: Statement expected.
tests/cases/compiler/class2.ts(1,29): error TS1128: Declaration or statement expected.
tests/cases/compiler/class2.ts(1,45): error TS1128: Declaration or statement expected.
==== tests/cases/compiler/class2.ts (2 errors) ====
class foo { constructor() { static f = 3; } }
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1128: Declaration or statement expected.

View file

@ -8,14 +8,14 @@ tests/cases/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrec
tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'.
Property 'p1' is private in type 'M' but not in type 'G'.
tests/cases/compiler/classUpdateTests.ts(70,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.
tests/cases/compiler/classUpdateTests.ts(93,3): error TS1129: Statement expected.
tests/cases/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(99,3): error TS1129: Statement expected.
tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(101,1): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(105,3): error TS1129: Statement expected.
tests/cases/compiler/classUpdateTests.ts(105,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(105,14): error TS1005: ';' expected.
tests/cases/compiler/classUpdateTests.ts(107,1): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(111,3): error TS1129: Statement expected.
tests/cases/compiler/classUpdateTests.ts(111,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/classUpdateTests.ts(111,15): error TS1005: ';' expected.
tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected.
@ -139,7 +139,7 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st
constructor() {
public p1 = 0; // ERROR
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
}
}
~
@ -149,7 +149,7 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st
constructor() {
private p1 = 0; // ERROR
~~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
}
}
~
@ -159,7 +159,7 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st
constructor() {
public this.p1 = 0; // ERROR
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1005: ';' expected.
}
@ -171,7 +171,7 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st
constructor() {
private this.p1 = 0; // ERROR
~~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1005: ';' expected.
}

View file

@ -5,7 +5,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,28): error TS1005: ':' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,29): error TS1005: ',' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,18): error TS1129: Statement expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,18): error TS1128: Declaration or statement expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,26): error TS2304: Cannot find name 'bfs'.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: '=' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1109: Expression expected.
@ -129,7 +129,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS
case = bfs.STATEMENTS(4);
~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~
!!! error TS2304: Cannot find name 'bfs'.
if (retValue != 0) {

View file

@ -0,0 +1,18 @@
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(4,15): error TS1003: Identifier expected.
tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts(9,2): error TS1005: '}' expected.
==== tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts (2 errors) ====
namespace A {
function foo() {
if (true) {
B.
!!! error TS1003: Identifier expected.
namespace B {
export function baz() { }
}
!!! error TS1005: '}' expected.

View file

@ -0,0 +1,26 @@
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.ts]
namespace A {
function foo() {
if (true) {
B.
namespace B {
export function baz() { }
}
//// [errorRecoveryWithDotFollowedByNamespaceKeyword.js]
var A;
(function (A) {
function foo() {
if (true) {
B.
;
var B;
(function (B) {
function baz() { }
B.baz = baz;
})(B || (B = {}));
}
}
})(A || (A = {}));

View file

@ -0,0 +1,87 @@
tests/cases/compiler/moduleElementsInWrongContext.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file.
tests/cases/compiler/moduleElementsInWrongContext.ts(13,5): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext.ts(17,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext.ts(18,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext.ts(19,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext.ts(19,14): error TS2305: Module '"ambient"' has no exported member 'baz'.
tests/cases/compiler/moduleElementsInWrongContext.ts(20,5): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext.ts(21,5): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext.ts(22,5): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module.
==== tests/cases/compiler/moduleElementsInWrongContext.ts (18 errors) ====
{
module M { }
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export namespace N {
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export interface I { }
}
namespace Q.K { }
~~~~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
declare module "ambient" {
~~~~~~~
!!! error TS1234: An ambient module declaration is only allowed at the top level in a file.
}
export = M;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
var v;
function foo() { }
export * from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { foo };
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { baz as b } from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
~~~
!!! error TS2305: Module '"ambient"' has no exported member 'baz'.
export default v;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
export default class C { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
export function bee() { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
import I = M;
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import I2 = require("foo");
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import * as Foo from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import bar from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import { baz } from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
}

View file

@ -0,0 +1,47 @@
//// [moduleElementsInWrongContext.ts]
{
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}
//// [moduleElementsInWrongContext.js]
{
var v;
function foo() { }
__export(require("ambient"));
exports["default"] = v;
var C = (function () {
function C() {
}
return C;
})();
exports["default"] = C;
function bee() { }
exports.bee = bee;
}

View file

@ -0,0 +1,87 @@
tests/cases/compiler/moduleElementsInWrongContext2.ts(2,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(3,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(7,5): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(9,5): error TS1234: An ambient module declaration is only allowed at the top level in a file.
tests/cases/compiler/moduleElementsInWrongContext2.ts(13,5): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(17,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(18,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(19,5): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(19,30): error TS2307: Cannot find module 'ambient'.
tests/cases/compiler/moduleElementsInWrongContext2.ts(20,5): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(21,5): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext2.ts(22,5): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext2.ts(23,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(24,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(25,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(26,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(27,5): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext2.ts(28,5): error TS1232: An import declaration can only be used in a namespace or module.
==== tests/cases/compiler/moduleElementsInWrongContext2.ts (18 errors) ====
function blah () {
module M { }
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export namespace N {
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export interface I { }
}
namespace Q.K { }
~~~~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
declare module "ambient" {
~~~~~~~
!!! error TS1234: An ambient module declaration is only allowed at the top level in a file.
}
export = M;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
var v;
function foo() { }
export * from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { foo };
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { baz as b } from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
~~~~~~~~~
!!! error TS2307: Cannot find module 'ambient'.
export default v;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
export default class C { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
export function bee() { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
import I = M;
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import I2 = require("foo");
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import * as Foo from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import bar from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import { baz } from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
}

View file

@ -0,0 +1,47 @@
//// [moduleElementsInWrongContext2.ts]
function blah () {
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}
//// [moduleElementsInWrongContext2.js]
function blah() {
var v;
function foo() { }
__export(require("ambient"));
exports["default"] = v;
var C = (function () {
function C() {
}
return C;
})();
exports["default"] = C;
function bee() { }
exports.bee = bee;
}

View file

@ -0,0 +1,88 @@
tests/cases/compiler/moduleElementsInWrongContext3.ts(3,9): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(4,9): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(8,9): error TS1235: A namespace declaration is only allowed in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(10,9): error TS1234: An ambient module declaration is only allowed at the top level in a file.
tests/cases/compiler/moduleElementsInWrongContext3.ts(14,9): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(18,9): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(19,9): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(20,9): error TS1233: An export declaration can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(20,34): error TS2307: Cannot find module 'ambient'.
tests/cases/compiler/moduleElementsInWrongContext3.ts(21,9): error TS1231: An export assignment can only be used in a module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(22,9): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext3.ts(23,9): error TS1184: Modifiers cannot appear here.
tests/cases/compiler/moduleElementsInWrongContext3.ts(24,9): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(25,9): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(26,9): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(27,9): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(28,9): error TS1232: An import declaration can only be used in a namespace or module.
tests/cases/compiler/moduleElementsInWrongContext3.ts(29,9): error TS1232: An import declaration can only be used in a namespace or module.
==== tests/cases/compiler/moduleElementsInWrongContext3.ts (18 errors) ====
module P {
{
module M { }
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export namespace N {
~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
export interface I { }
}
namespace Q.K { }
~~~~~~~~~
!!! error TS1235: A namespace declaration is only allowed in a namespace or module.
declare module "ambient" {
~~~~~~~
!!! error TS1234: An ambient module declaration is only allowed at the top level in a file.
}
export = M;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
var v;
function foo() { }
export * from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { foo };
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
export { baz as b } from "ambient";
~~~~~~
!!! error TS1233: An export declaration can only be used in a module.
~~~~~~~~~
!!! error TS2307: Cannot find module 'ambient'.
export default v;
~~~~~~
!!! error TS1231: An export assignment can only be used in a module.
export default class C { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
export function bee() { }
~~~~~~
!!! error TS1184: Modifiers cannot appear here.
import I = M;
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import I2 = require("foo");
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import * as Foo from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import bar from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import { baz } from "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
import "ambient";
~~~~~~
!!! error TS1232: An import declaration can only be used in a namespace or module.
}
}

View file

@ -0,0 +1,51 @@
//// [moduleElementsInWrongContext3.ts]
module P {
{
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}
}
//// [moduleElementsInWrongContext3.js]
var P;
(function (P) {
{
var v;
function foo() { }
__export(require("ambient"));
P["default"] = v;
var C = (function () {
function C() {
}
return C;
})();
exports["default"] = C;
function bee() { }
P.bee = bee;
}
})(P || (P = {}));

View file

@ -1,12 +1,12 @@
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(1,14): error TS1005: '(' expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(2,3): error TS1129: Statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(2,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(2,10): error TS2304: Cannot find name 'test'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,3): error TS1129: Statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,10): error TS2304: Cannot find name 'test'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,15): error TS2304: Cannot find name 'name'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,19): error TS1005: ',' expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(3,20): error TS2304: Cannot find name 'string'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,3): error TS1129: Statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,10): error TS2304: Cannot find name 'test'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,15): error TS2304: Cannot find name 'name'.
tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,20): error TS1109: Expression expected.
@ -20,12 +20,12 @@ tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,25): error TS100
!!! error TS1005: '(' expected.
static test()
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
static test(name:string)
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
~~~~
@ -36,7 +36,7 @@ tests/cases/compiler/overloadingStaticFunctionsInFunctions.ts(4,25): error TS100
!!! error TS2304: Cannot find name 'string'.
static test(name?:any){ }
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
~~~~

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement6.ts(3,9): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement6.ts(5,3): error TS1129: Statement expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement6.ts(5,3): error TS1128: Declaration or statement expected.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErrorRecoveryIfStatement6.ts (2 errors) ====
@ -11,7 +11,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/IfStatements/parserErro
}
public f2() {
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
}
f3() {
}

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block3.ts(2,18): 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/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block3.ts(4,5): error TS1129: Statement expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block3.ts(4,5): error TS1128: Declaration or statement expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block3.ts(4,18): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
@ -11,7 +11,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecov
private b(): boolean {
~~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~~~~
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
}

View file

@ -1,19 +1,13 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2503: Cannot find namespace 'TypeModule1'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(2,8): error TS1005: '=' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(2,8): error TS2304: Cannot find name 'TypeModule2'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(2,20): error TS1005: ',' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,20): error TS1003: Identifier expected.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts (4 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts (2 errors) ====
var x: TypeModule1.
~~~~~~~~~~~
!!! error TS2503: Cannot find namespace 'TypeModule1'.
!!! error TS1003: Identifier expected.
module TypeModule2 {
~~~~~~~~~~~
!!! error TS1005: '=' expected.
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeModule2'.
~
!!! error TS1005: ',' expected.
}

View file

@ -5,4 +5,4 @@ module TypeModule2 {
//// [parserUnfinishedTypeNameBeforeKeyword1.js]
var x = TypeModule2, _a = void 0;
var x;

View file

@ -1,5 +1,5 @@
tests/cases/compiler/propertyWrappedInTry.ts(3,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/compiler/propertyWrappedInTry.ts(5,9): error TS1129: Statement expected.
tests/cases/compiler/propertyWrappedInTry.ts(5,9): error TS1128: Declaration or statement expected.
tests/cases/compiler/propertyWrappedInTry.ts(5,16): error TS2304: Cannot find name 'bar'.
tests/cases/compiler/propertyWrappedInTry.ts(5,22): error TS2304: Cannot find name 'someInitThatMightFail'.
tests/cases/compiler/propertyWrappedInTry.ts(11,5): error TS1128: Declaration or statement expected.
@ -17,7 +17,7 @@ tests/cases/compiler/propertyWrappedInTry.ts(17,1): error TS1128: Declaration or
public bar = someInitThatMightFail();
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~
!!! error TS2304: Cannot find name 'bar'.
~~~~~~~~~~~~~~~~~~~~~

View file

@ -1,4 +1,4 @@
tests/cases/compiler/staticClassProps.ts(4,9): error TS1129: Statement expected.
tests/cases/compiler/staticClassProps.ts(4,9): error TS1128: Declaration or statement expected.
tests/cases/compiler/staticClassProps.ts(6,1): error TS1128: Declaration or statement expected.
@ -8,7 +8,7 @@ tests/cases/compiler/staticClassProps.ts(6,1): error TS1128: Declaration or stat
public foo() {
static z = 1;
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
}
}
~

View file

@ -1,12 +1,12 @@
tests/cases/compiler/staticsInAFunction.ts(1,13): error TS1005: '(' expected.
tests/cases/compiler/staticsInAFunction.ts(2,4): error TS1129: Statement expected.
tests/cases/compiler/staticsInAFunction.ts(2,4): error TS1128: Declaration or statement expected.
tests/cases/compiler/staticsInAFunction.ts(2,11): error TS2304: Cannot find name 'test'.
tests/cases/compiler/staticsInAFunction.ts(3,4): error TS1129: Statement expected.
tests/cases/compiler/staticsInAFunction.ts(3,4): error TS1128: Declaration or statement expected.
tests/cases/compiler/staticsInAFunction.ts(3,11): error TS2304: Cannot find name 'test'.
tests/cases/compiler/staticsInAFunction.ts(3,16): error TS2304: Cannot find name 'name'.
tests/cases/compiler/staticsInAFunction.ts(3,20): error TS1005: ',' expected.
tests/cases/compiler/staticsInAFunction.ts(3,21): error TS2304: Cannot find name 'string'.
tests/cases/compiler/staticsInAFunction.ts(4,4): error TS1129: Statement expected.
tests/cases/compiler/staticsInAFunction.ts(4,4): error TS1128: Declaration or statement expected.
tests/cases/compiler/staticsInAFunction.ts(4,11): error TS2304: Cannot find name 'test'.
tests/cases/compiler/staticsInAFunction.ts(4,16): error TS2304: Cannot find name 'name'.
tests/cases/compiler/staticsInAFunction.ts(4,21): error TS1109: Expression expected.
@ -20,12 +20,12 @@ tests/cases/compiler/staticsInAFunction.ts(4,26): error TS1005: ';' expected.
!!! error TS1005: '(' expected.
static test()
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
static test(name:string)
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
~~~~
@ -36,7 +36,7 @@ tests/cases/compiler/staticsInAFunction.ts(4,26): error TS1005: ';' expected.
!!! error TS2304: Cannot find name 'string'.
static test(name?:any){}
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
~~~~
!!! error TS2304: Cannot find name 'test'.
~~~~

View file

@ -1,4 +1,4 @@
tests/cases/compiler/staticsInConstructorBodies.ts(3,3): error TS1129: Statement expected.
tests/cases/compiler/staticsInConstructorBodies.ts(3,3): error TS1128: Declaration or statement expected.
tests/cases/compiler/staticsInConstructorBodies.ts(6,1): error TS1128: Declaration or statement expected.
@ -7,7 +7,7 @@ tests/cases/compiler/staticsInConstructorBodies.ts(6,1): error TS1128: Declarati
constructor() {
static p1 = 0; // ERROR
~~~~~~
!!! error TS1129: Statement expected.
!!! error TS1128: Declaration or statement expected.
static m1() {} // ERROR
}
}

View file

@ -1,9 +1,7 @@
tests/cases/compiler/withStatementErrors.ts(3,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/compiler/withStatementErrors.ts(15,5): error TS1129: Statement expected.
tests/cases/compiler/withStatementErrors.ts(17,1): error TS1128: Declaration or statement expected.
==== tests/cases/compiler/withStatementErrors.ts (3 errors) ====
==== tests/cases/compiler/withStatementErrors.ts (1 errors) ====
declare var ooo:any;
with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) { // error
@ -21,10 +19,6 @@ tests/cases/compiler/withStatementErrors.ts(17,1): error TS1128: Declaration or
interface I {} // error
module M {} // error
~~~~~~
!!! error TS1129: Statement expected.
}
~
!!! error TS1128: Declaration or statement expected.

View file

@ -29,4 +29,4 @@ with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) {
}
return C;
})(); // error
} // error
}

View file

@ -0,0 +1,9 @@
namespace A {
function foo() {
if (true) {
B.
namespace B {
export function baz() { }
}

View file

@ -0,0 +1,29 @@
{
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}

View file

@ -0,0 +1,29 @@
function blah () {
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}

View file

@ -0,0 +1,31 @@
module P {
{
module M { }
export namespace N {
export interface I { }
}
namespace Q.K { }
declare module "ambient" {
}
export = M;
var v;
function foo() { }
export * from "ambient";
export { foo };
export { baz as b } from "ambient";
export default v;
export default class C { }
export function bee() { }
import I = M;
import I2 = require("foo");
import * as Foo from "ambient";
import bar from "ambient";
import { baz } from "ambient";
import "ambient";
}
}

View file

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts'/>
////namespace A {
//// function foo() {
//// if (true) {
//// B./**/
//// namespace B {
//// export function baz() { }
////}
goTo.marker();
verify.completionListContains("baz", "function B.baz(): void");

View file

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
////function f() {
//// namespace n {
//// interface I {
//// x: number
//// }
//// /*1*/
//// }
//// /*2*/
////}
/////*3*/
goTo.marker('1');
verify.completionListContains("f", "function f(): void");
verify.completionListContains("n", "namespace n");
verify.completionListContains("I", "interface I");
goTo.marker('2');
verify.completionListContains("f", "function f(): void");
verify.completionListContains("n", "namespace n");
goTo.marker('3');
verify.completionListContains("f", "function f(): void");

View file

@ -262,7 +262,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "'strict';\r\n");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 2',() => {
@ -289,7 +289,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, index);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 4',() => {
@ -332,7 +332,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, index);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 24);
});
it('Parenthesized expression to arrow function 1',() => {
@ -545,7 +545,7 @@ module ts {
var index = source.lastIndexOf(";");
var newTextAndChange = withDelete(oldText, index, 1);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 11);
});
it('Edit after empty type parameter list',() => {
@ -579,7 +579,7 @@ var o2 = { set Foo(val:number) { } };";
var index = source.indexOf("set");
var newTextAndChange = withInsert(oldText, index, "public ");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 6);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 14);
});
it('Insert parameter ahead of parameter',() => {
@ -700,7 +700,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, "{".length);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Moving methods from class to object literal',() => {