Merge branch 'master' of https://github.com/Microsoft/TypeScript into deeplyNestedTypeArgumentInference

This commit is contained in:
Jason Freeman 2015-06-11 11:55:59 -07:00
commit 9f26803242
53 changed files with 777 additions and 202 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

@ -1358,7 +1358,7 @@ module ts {
return result;
}
function signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
function signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
let writer = getSingleLineStringWriter();
getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
let result = writer.string();
@ -3603,7 +3603,8 @@ module ts {
function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments): Type {
let links = getNodeLinks(node);
if (!links.resolvedType) {
// We only support expressions that are simple qualified names. For other expressions this produces undefined. let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (<TypeReferenceNode>node).typeName :
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
let typeNameOrExpression = node.kind === SyntaxKind.TypeReference ? (<TypeReferenceNode>node).typeName :
isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node) ? (<ExpressionWithTypeArguments>node).expression :
undefined;
let symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
@ -5245,14 +5246,14 @@ module ts {
if (source.typePredicate && target.typePredicate) {
if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) {
// Return types from type predicates are treated as booleans. In order to infer types
// from type predicates we would need to infer from the type of type predicates. Since
// we can't infer any type information from the return types — we can just add a return
// statement after the below infer type statement.
// from type predicates we would need to infer using the type within the type predicate
// (i.e. 'Foo' from 'x is Foo').
inferFromTypes(source.typePredicate.type, target.typePredicate.type);
}
return;
}
inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
else {
inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
}
}
function inferFromIndexTypes(source: Type, target: Type, sourceKind: IndexKind, targetKind: IndexKind) {
@ -11103,6 +11104,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);
@ -11139,7 +11149,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);
}
@ -11215,6 +11225,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);
}
@ -11237,6 +11251,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);
@ -11268,9 +11287,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 }
@ -11292,6 +11317,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) {
@ -11300,6 +11331,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);
@ -11315,7 +11351,8 @@ module ts {
else {
checkExpressionCached(node.expression);
}
checkExternalModuleExports(container);
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
if (node.isExportEquals && !isInAmbientContext(node)) {
if (languageVersion >= ScriptTarget.ES6) {
@ -11329,7 +11366,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

@ -1903,23 +1903,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
function emitNewExpression(node: NewExpression) {
write("new ");
// Spread operator logic can be supported in new expressions in ES5 using a combination
// Spread operator logic is supported in new expressions in ES5 using a combination
// of Function.prototype.bind() and Function.prototype.apply().
//
// Example:
//
// var arguments = [1, 2, 3, 4, 5];
// new Array(...arguments);
// var args = [1, 2, 3, 4, 5];
// new Array(...args);
//
// Could be transpiled into ES5:
// is compiled into the following ES5:
//
// var arguments = [1, 2, 3, 4, 5];
// new (Array.bind.apply(Array, [void 0].concat(arguments)));
// var args = [1, 2, 3, 4, 5];
// new (Array.bind.apply(Array, [void 0].concat(args)));
//
// `[void 0]` is the first argument which represents `thisArg` to the bind method above.
// And `thisArg` will be set to the return value of the constructor when instantiated
// with the new operator — regardless of any value we set `thisArg` to. Thus, we set it
// to an undefined, `void 0`.
// The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new',
// Thus, we set it to undefined ('void 0').
if (languageVersion === ScriptTarget.ES5 &&
node.arguments &&
hasSpreadElement(node.arguments)) {

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

@ -6046,8 +6046,8 @@ module ts {
function processNode(node: Node) {
// Only walk into nodes that intersect the requested span.
if (node && textSpanIntersectsWith(span, node.getStart(), node.getWidth())) {
if (node.kind === SyntaxKind.Identifier && node.getWidth() > 0) {
if (node && textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) {
if (node.kind === SyntaxKind.Identifier && !nodeIsMissing(node)) {
let symbol = typeChecker.getSymbolAtLocation(node);
if (symbol) {
let type = classifySymbol(symbol, getMeaningFromLocation(node));

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

@ -28,7 +28,6 @@
// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed
edit.insert('');
debugger;
goTo.marker('1');
verify.completionListContains("multiM", "namespace multiM", "this is multi declare namespace\nthi is multi namespace 2\nthis is multi namespace 3 comment");

View file

@ -7,7 +7,6 @@
//// declare module 'https' {
//// }
//// /*2*/
debugger;
goTo.marker("1");
verify.not.completionListContains("http");
goTo.marker("2");

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

@ -7,6 +7,5 @@
////}
////var enumMember = e./*1*/thirdMember;
debugger;
goTo.marker("1");
verify.verifyDefinitionsName("thirdMember", "e");

View file

@ -34,7 +34,6 @@ goTo.position(0);
// : |--- delete "\n\n///..."
// 1:
// 2:
debugger;
edit.deleteAtCaret(100);

View file

@ -8,7 +8,6 @@
/////*4*/ : T) { }
////}
/////*5*/var x =
debugger;
format.document();
goTo.marker('1');
verify.currentLineContentIs('foo(): Bar { }');

View file

@ -18,5 +18,4 @@
// @Filename: inputFile5.js
//// var x2 = 1000;
debugger;
verify.baselineGetEmitOutput();

View file

@ -12,5 +12,4 @@
// @Filename: inputFile2.ts
//// // File not emitted, and contains semantic errors
//// var semanticError: boolean = "string";
debugger;
verify.baselineGetEmitOutput();

View file

@ -16,7 +16,6 @@
////[|fina/*3*/lly|] {
////}
debugger;
for (var i = 1; i <= test.markers().length; i++) {
goTo.marker("" + i);
verify.occurrencesAtPositionCount(3);

View file

@ -4,7 +4,7 @@
////function foo() {
//// {| "itemName": "d", "kind": "let", "parentName": "foo" |}let d = 10;
////}
debugger;
test.markers().forEach(marker => {
verify.navigationItemsListContains(
marker.data.itemName,

View file

@ -17,7 +17,7 @@
////function distance2(distanceParam1): void {
//// var distanceLocal1;
////}
debugger;
goTo.marker("file1");
verify.navigationItemsListCount(2, "point", "exact");
verify.navigationItemsListCount(5, "distance", "prefix");

View file

@ -8,5 +8,5 @@
////interface I {
//// interfaceMethodSignature(b: boolean): boolean;
////}
debugger;
verify.navigationItemsListCount(2, "interfaceMethodSignature", "exact");

View file

@ -17,7 +17,6 @@
////// Local variables
////{| "itemName": "MymyPointThatIJustInitiated", "kind": "var", "parentName": "", "matchKind": "substring"|}var MymyPointThatIJustInitiated = new Shapes.Point();
debugger;
test.markers().forEach((marker) => {
if (marker.data) {
var name = marker.data.itemName;

View file

@ -17,7 +17,6 @@
//// INITIATED123;
//// public horizon(): void;
////}
debugger;
var notFoundSearchValue = "mPointThatIJustInitiated wrongKeyWord";
goTo.marker("file1");

View file

@ -22,7 +22,6 @@
/////*15*/h(10);
/////*16*/h("hello");
debugger;
var marker = 0;
function verifyConst(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) {
marker++;

View file

@ -15,7 +15,6 @@
////var /*11*/i = /*12*/h;
/////*13*/h(10);
/////*14*/h("hello");
debugger;
var marker = 0;
function verifyVar(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) {
marker++;

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',() => {

View file

@ -66,7 +66,6 @@ describe('Colorization', function () {
describe("test getClassifications", function () {
it("Returns correct token classes", function () {
debugger;
testLexicalClassification("var x: string = \"foo\"; //Hello",
ts.EndOfLineState.None,
keyword("var"),
@ -138,7 +137,6 @@ describe('Colorization', function () {
});
it("correctly classifies the continuing line of a multi-line string ending in one backslash", function () {
debugger;
testLexicalClassification("\\",
ts.EndOfLineState.InDoubleQuoteStringLiteral,
stringLiteral("\\"),