From 00a49536fe62fe4eba60a7ac03e0048f7579023a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 15:51:55 -0800 Subject: [PATCH 01/60] Initial refactoring to support doing grammar checks as a separate pass of the tree. Right now, this means hiding 'syntacticDiagnostics' behind a getter function that only computes all the syntactic diagnostics (parser+grammar checks) lazily. This will help incremental parsing out as we can reuse nodes that have grammar errors in them, and we dont' have to even do grammar checks if this is not the full-type-check type-checker. --- src/compiler/binder.ts | 6 +- src/compiler/checker.ts | 2 +- src/compiler/parser.ts | 129 +++++++++++++++++++++++-------------- src/compiler/types.ts | 6 +- src/services/formatting.ts | 2 +- src/services/services.ts | 8 ++- 6 files changed, 96 insertions(+), 57 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3622f4cda2f..1a0b8c21835 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -125,9 +125,9 @@ module ts { : Diagnostics.Duplicate_identifier_0; forEach(symbol.declarations, declaration => { - file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); + file.semanticDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); }); - file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); + file.semanticDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); symbol = createSymbol(0, name); } @@ -148,7 +148,7 @@ module ts { if (node.name) { node.name.parent = node; } - file.semanticErrors.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], + file.semanticDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); } symbol.exports[prototypeSymbol.name] = prototypeSymbol; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e642fcce944..a3b4bbf3f73 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9143,7 +9143,7 @@ module ts { // Bind all source files and propagate errors forEach(program.getSourceFiles(), file => { bindSourceFile(file); - forEach(file.semanticErrors, addDiagnostic); + forEach(file.semanticDiagnostics, addDiagnostic); }); // Initialize global symbol table forEach(program.getSourceFiles(), file => { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f4fedfd949a..2f51cd294e7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -831,8 +831,18 @@ module ts { return false; } + interface SourceFileInternal extends SourceFile { + // Diagnostics produced only by the parser. Does not include any diagnostics produced by + // doing grammar checks. + _parserDiagnostics: Diagnostic[]; + + // All diagnostics for the source file. Should not be accessed directly. Lazily created + // when getSyntacticDiagnostics is called. + _syntacticDiagnostics: Diagnostic[]; + } + export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { - var file: SourceFile; + var file: SourceFileInternal; var scanner: Scanner; var token: SyntaxKind; var parsingContext: ParsingContext; @@ -986,7 +996,7 @@ module ts { var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; var length = span.end - start; - file.syntacticErrors.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } function reportInvalidUseInStrictMode(node: Identifier): void { @@ -997,17 +1007,17 @@ module ts { function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - file.syntacticErrors.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } function errorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - var lastErrorPos = file.syntacticErrors.length - ? file.syntacticErrors[file.syntacticErrors.length - 1].start + var lastErrorPos = file._parserDiagnostics.length + ? file._parserDiagnostics[file._parserDiagnostics.length - 1].start : -1; if (start !== lastErrorPos) { var diagnostic = createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); diagnostic.isParseError = true; - file.syntacticErrors.push(diagnostic); + file._parserDiagnostics.push(diagnostic); } if (lookAheadMode === LookAheadMode.NoErrorYet) { @@ -1056,7 +1066,7 @@ module ts { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). var saveToken = token; - var saveSyntacticErrorsLength = file.syntacticErrors.length; + var saveSyntacticErrorsLength = file._parserDiagnostics.length; // Keep track of the current look ahead mode (this matters if we have nested // speculative parsing). @@ -1078,7 +1088,7 @@ module ts { lookAheadMode = saveLookAheadMode; if (!result || alwaysResetState) { token = saveToken; - file.syntacticErrors.length = saveSyntacticErrorsLength; + file._parserDiagnostics.length = saveSyntacticErrorsLength; } return result; @@ -1384,7 +1394,7 @@ module ts { result.pos = getNodePos(); // Keep track of how many errors we had before the list started. If we don't see any new // errors resulting from the list being malformed, we are free to complain about a trailing comma. - var errorCountBeforeParsingList = file.syntacticErrors.length; + var errorCountBeforeParsingList = file._parserDiagnostics.length; var commaStart = -1; // Meaning the previous token was not a comma while (true) { if (isListElement(kind, /* inErrorRecovery */ false)) { @@ -1418,7 +1428,7 @@ module ts { // Check if the last token was a comma. if (commaStart >= 0) { if (!allowTrailingComma) { - if (file.syntacticErrors.length === errorCountBeforeParsingList) { + if (file._parserDiagnostics.length === errorCountBeforeParsingList) { // Report a grammar error so we don't affect lookahead grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed); } @@ -1747,13 +1757,13 @@ module ts { function parseIndexSignatureMember(): SignatureDeclaration { var node = createNode(SyntaxKind.IndexSignature); - var errorCountBeforeIndexSignature = file.syntacticErrors.length; + var errorCountBeforeIndexSignature = file._parserDiagnostics.length; var indexerStart = scanner.getTokenPos(); node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); var indexerLength = scanner.getStartPos() - indexerStart; node.type = parseTypeAnnotation(); parseSemicolon(); - if (file.syntacticErrors.length === errorCountBeforeIndexSignature) { + if (file._parserDiagnostics.length === errorCountBeforeIndexSignature) { checkIndexSignature(node, indexerStart, indexerLength); } return finishNode(node); @@ -1871,9 +1881,9 @@ module ts { function parseTupleType(): TupleTypeNode { var node = createNode(SyntaxKind.TupleType); var startTokenPos = scanner.getTokenPos(); - var startErrorCount = file.syntacticErrors.length; + var startErrorCount = file._parserDiagnostics.length; node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); - if (!node.elementTypes.length && file.syntacticErrors.length === startErrorCount) { + if (!node.elementTypes.length && file._parserDiagnostics.length === startErrorCount) { grammarErrorAtPos(startTokenPos, scanner.getStartPos() - startTokenPos, Diagnostics.A_tuple_type_element_list_cannot_be_empty); } return finishNode(node); @@ -2629,14 +2639,14 @@ module ts { function parseTypeArguments(): NodeArray { var typeArgumentListStart = scanner.getTokenPos(); - var errorCountBeforeTypeParameterList = file.syntacticErrors.length; + var errorCountBeforeTypeParameterList = file._parserDiagnostics.length; // We pass parseSingleTypeArgument instead of parseType as the element parser // because parseSingleTypeArgument knows how to parse a missing type argument. // This is useful for signature help. parseType has the disadvantage that when // it sees a missing type, it changes the LookAheadMode to Error, and the result // is a broken binary expression, which breaks signature help. var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); - if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { + if (!result.length && file._parserDiagnostics.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty); } return result; @@ -3062,14 +3072,14 @@ module ts { function parseBreakOrContinueStatement(kind: SyntaxKind): BreakOrContinueStatement { var node = createNode(kind); - var errorCountBeforeStatement = file.syntacticErrors.length; + var errorCountBeforeStatement = file._parserDiagnostics.length; parseExpected(kind === SyntaxKind.BreakStatement ? SyntaxKind.BreakKeyword : SyntaxKind.ContinueKeyword); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); finishNode(node); // In an ambient context, we will already give an error for having a statement. - if (!inAmbientContext && errorCountBeforeStatement === file.syntacticErrors.length) { + if (!inAmbientContext && errorCountBeforeStatement === file._parserDiagnostics.length) { if (node.label) { checkBreakOrContinueStatementWithLabel(node); } @@ -3142,7 +3152,7 @@ module ts { function parseReturnStatement(): ReturnStatement { var node = createNode(SyntaxKind.ReturnStatement); - var errorCountBeforeReturnStatement = file.syntacticErrors.length; + var errorCountBeforeReturnStatement = file._parserDiagnostics.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -3151,7 +3161,7 @@ module ts { parseSemicolon(); // In an ambient context, we will already give an error for having a statement. - if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file.syntacticErrors.length) { + if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file._parserDiagnostics.length) { grammarErrorAtPos(returnTokenStart, returnTokenLength, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); } return finishNode(node); @@ -3441,10 +3451,10 @@ module ts { function parseAndCheckFunctionBody(isConstructor: boolean): Block { var initialPosition = scanner.getTokenPos(); - var errorCountBeforeBody = file.syntacticErrors.length; + var errorCountBeforeBody = file._parserDiagnostics.length; if (token === SyntaxKind.OpenBraceToken) { var body = parseBody(/* ignoreMissingOpenBrace */ false); - if (body && inAmbientContext && file.syntacticErrors.length === errorCountBeforeBody) { + if (body && inAmbientContext && file._parserDiagnostics.length === errorCountBeforeBody) { var diagnostic = isConstructor ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; grammarErrorAtPos(initialPosition, 1, diagnostic); } @@ -3462,7 +3472,7 @@ module ts { function parseVariableDeclaration(flags: NodeFlags, noIn?: boolean): VariableDeclaration { var node = createNode(SyntaxKind.VariableDeclaration); node.flags = flags; - var errorCountBeforeVariableDeclaration = file.syntacticErrors.length; + var errorCountBeforeVariableDeclaration = file._parserDiagnostics.length; node.name = parseIdentifier(); node.type = parseTypeAnnotation(); @@ -3471,7 +3481,7 @@ module ts { var initializerFirstTokenLength = scanner.getTextPos() - initializerStart; node.initializer = parseInitializer(/*inParameter*/ false, noIn); - if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { + if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file._parserDiagnostics.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { @@ -3493,7 +3503,7 @@ module ts { function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; - var errorCountBeforeVarStatement = file.syntacticErrors.length; + var errorCountBeforeVarStatement = file._parserDiagnostics.length; if (token === SyntaxKind.LetKeyword) { node.flags |= NodeFlags.Let; } @@ -3507,7 +3517,7 @@ module ts { node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false); parseSemicolon(); finishNode(node); - if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { + if (!node.declarations.length && file._parserDiagnostics.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } if (languageVersion < ScriptTarget.ES6) { @@ -3566,7 +3576,7 @@ module ts { } function parsePropertyMemberDeclaration(pos: number, flags: NodeFlags): Declaration { - var errorCountBeforePropertyDeclaration = file.syntacticErrors.length; + var errorCountBeforePropertyDeclaration = file._parserDiagnostics.length; var name = parsePropertyName(); var questionStart = scanner.getTokenPos(); @@ -3596,7 +3606,7 @@ module ts { property.initializer = parseInitializer(/*inParameter*/ false); parseSemicolon(); - if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file.syntacticErrors.length) { + if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file._parserDiagnostics.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } return finishNode(property); @@ -3604,10 +3614,10 @@ module ts { } function parseAndCheckMemberAccessorDeclaration(kind: SyntaxKind, pos: number, flags: NodeFlags): MethodDeclaration { - var errorCountBeforeAccessor = file.syntacticErrors.length; + var errorCountBeforeAccessor = file._parserDiagnostics.length; var accessor = parseMemberAccessorDeclaration(kind, pos, flags); - if (errorCountBeforeAccessor === file.syntacticErrors.length) { + if (errorCountBeforeAccessor === file._parserDiagnostics.length) { if (languageVersion < ScriptTarget.ES5) { grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } @@ -3901,7 +3911,7 @@ module ts { function parseClassDeclaration(pos: number, flags: NodeFlags): ClassDeclaration { var node = createNode(SyntaxKind.ClassDeclaration, pos); node.flags = flags; - var errorCountBeforeClassDeclaration = file.syntacticErrors.length; + var errorCountBeforeClassDeclaration = file._parserDiagnostics.length; parseExpected(SyntaxKind.ClassKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); @@ -3914,7 +3924,7 @@ module ts { node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference, /*allowTrailingComma*/ false); } - var errorCountBeforeClassBody = file.syntacticErrors.length; + var errorCountBeforeClassBody = file._parserDiagnostics.length; if (parseExpected(SyntaxKind.OpenBraceToken)) { node.members = parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassMemberDeclaration); parseExpected(SyntaxKind.CloseBraceToken); @@ -3931,7 +3941,7 @@ module ts { function parseInterfaceDeclaration(pos: number, flags: NodeFlags): InterfaceDeclaration { var node = createNode(SyntaxKind.InterfaceDeclaration, pos); node.flags = flags; - var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length; + var errorCountBeforeInterfaceDeclaration = file._parserDiagnostics.length; parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); @@ -3943,7 +3953,7 @@ module ts { node.baseTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference, /*allowTrailingComma*/ false); } - var errorCountBeforeInterfaceBody = file.syntacticErrors.length; + var errorCountBeforeInterfaceBody = file._parserDiagnostics.length; node.members = parseTypeLiteral().members; if (node.baseTypes && !node.baseTypes.length && errorCountBeforeInterfaceBody === errorCountBeforeInterfaceDeclaration) { grammarErrorAtPos(extendsKeywordStart, extendsKeywordLength, Diagnostics._0_list_cannot_be_empty, "extends"); @@ -3994,7 +4004,7 @@ module ts { // or any time an integer literal initializer is encountered. function parseAndCheckEnumMember(): EnumMember { var node = createNode(SyntaxKind.EnumMember); - var errorCountBeforeEnumMember = file.syntacticErrors.length; + var errorCountBeforeEnumMember = file._parserDiagnostics.length; node.name = parsePropertyName(); node.initializer = parseInitializer(/*inParameter*/ false); @@ -4002,14 +4012,14 @@ module ts { // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. if (!enumIsConst) { if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer) && errorCountBeforeEnumMember === file.syntacticErrors.length) { + if (node.initializer && !isIntegerLiteral(node.initializer) && errorCountBeforeEnumMember === file._parserDiagnostics.length) { grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers); } } else if (node.initializer) { inConstantEnumMemberSection = isIntegerLiteral(node.initializer); } - else if (!inConstantEnumMemberSection && errorCountBeforeEnumMember === file.syntacticErrors.length) { + else if (!inConstantEnumMemberSection && errorCountBeforeEnumMember === file._parserDiagnostics.length) { grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer); } } @@ -4073,10 +4083,10 @@ module ts { node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { - var errorCount = file.syntacticErrors.length; + var errorCount = file._parserDiagnostics.length; // Only report this error if we have not already errored about a missing declare modifier, // which would have been at or after pos - if (!errorCount || file.syntacticErrors[errorCount - 1].start < getTokenPos(pos)) { + if (!errorCount || file._parserDiagnostics[errorCount - 1].start < getTokenPos(pos)) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } } @@ -4152,7 +4162,7 @@ module ts { function parseDeclaration(modifierContext: ModifierContext): Statement { var pos = getNodePos(); - var errorCountBeforeModifiers = file.syntacticErrors.length; + var errorCountBeforeModifiers = file._parserDiagnostics.length; var flags = parseAndCheckModifiers(modifierContext); if (token === SyntaxKind.ExportKeyword) { @@ -4160,7 +4170,7 @@ module ts { nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { var exportAssignmentTail = parseExportAssignmentTail(pos); - if (flags !== 0 && errorCountBeforeModifiers === file.syntacticErrors.length) { + if (flags !== 0 && errorCountBeforeModifiers === file._parserDiagnostics.length) { var modifiersStart = skipTrivia(sourceText, pos); grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers); } @@ -4236,10 +4246,10 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; - var errorCountBeforeStatement = file.syntacticErrors.length; + var errorCountBeforeStatement = file._parserDiagnostics.length; var statement = parseStatement(/*allowLetAndConstDeclarations*/ true); - if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { + if (inAmbientContext && file._parserDiagnostics.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); } @@ -4302,26 +4312,48 @@ module ts { : undefined); } + function getSyntacticDiagnostics() { + if (file._syntacticDiagnostics === undefined) { + if (file._parserDiagnostics.length > 0) { + // Don't bother doing any grammar checks if there are already parser errors. + // Otherwise we may end up with too many cascading errors. + file._syntacticDiagnostics = file._parserDiagnostics; + } + else { + // No parser errors were reported. Perform our stricted grammar checks. + file._syntacticDiagnostics = []; + performGrammarChecks(file); + } + + file._parserDiagnostics = undefined; + } + + return file._syntacticDiagnostics + } + scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError, onComment); var rootNodeFlags: NodeFlags = 0; if (fileExtensionIs(filename, ".d.ts")) { rootNodeFlags = NodeFlags.DeclarationFile; inAmbientContext = true; } - file = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); + file = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); file.filename = normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; file.getLineStarts = getLineStarts; - file.syntacticErrors = []; - file.semanticErrors = []; + file.getSyntacticDiagnostics = getSyntacticDiagnostics; + file._parserDiagnostics = []; + file.semanticDiagnostics = []; var referenceComments = processReferenceComments(); file.referencedFiles = referenceComments.referencedFiles; file.amdDependencies = referenceComments.amdDependencies; file.amdModuleName = referenceComments.amdModuleName; + file.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); file.externalModuleIndicator = getExternalModuleIndicator(); + file.nodeCount = nodeCount; file.identifierCount = identifierCount; file.version = version; @@ -4331,6 +4363,9 @@ module ts { return file; } + function performGrammarChecks(child: Node) { + } + export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; @@ -4442,7 +4477,7 @@ module ts { else { files.push(file); } - forEach(file.syntacticErrors, e => { + forEach(file.getSyntacticDiagnostics(), e => { errors.push(e); }); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 58b705e3371..1ffbf12284c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -644,8 +644,8 @@ module ts { amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; - syntacticErrors: Diagnostic[]; - semanticErrors: Diagnostic[]; + semanticDiagnostics: Diagnostic[]; + getSyntacticDiagnostics(): Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; // The first node that causes this file to be an external module nodeCount: number; @@ -738,7 +738,7 @@ module ts { getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; - isArgumentsSymbol(symbol: Symbol): boolean; + isArgumentsSymbol(symbol: Symbol): boolean; isEmitBlocked(sourceFile?: SourceFile): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a computed value. getEnumMemberValue(node: EnumMember): number; diff --git a/src/services/formatting.ts b/src/services/formatting.ts index 91a3a362fda..337468803c6 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -252,7 +252,7 @@ module ts.formatting { rulesProvider: RulesProvider, requestKind: FormattingRequestKind): TextChange[] { - var rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.syntacticErrors, originalRange); + var rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.getSyntacticDiagnostics(), originalRange); // formatting context is used by rules provider var formattingContext = new FormattingContext(sourceFile, requestKind); diff --git a/src/services/services.ts b/src/services/services.ts index ca80e5a25a4..287ad437362 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -714,14 +714,18 @@ module ts { class SourceFileObject extends NodeObject implements SourceFile { public filename: string; public text: string; + + // These methods will have their implementation overridden with the implementation the + // compiler actually exports off of SourceFile. public getLineAndCharacterFromPosition(position: number): { line: number; character: number } { return null; } public getPositionFromLineAndCharacter(line: number, character: number): number { return -1; } public getLineStarts(): number[] { return undefined; } + public getSyntacticDiagnostics(): Diagnostic[] { return undefined; } + public amdDependencies: string[]; public amdModuleName: string; public referencedFiles: FileReference[]; - public syntacticErrors: Diagnostic[]; - public semanticErrors: Diagnostic[]; + public semanticDiagnostics: Diagnostic[]; public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module public nodeCount: number; From 6fdc5dc14840e885a659239c92bcf2c9cbd7a899 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 17:01:39 -0800 Subject: [PATCH 02/60] Move parameter name 'strict' checking to the grammar walker. --- src/compiler/parser.ts | 65 +++++++++++++++---- src/compiler/types.ts | 30 +++++---- .../StrictMode/parserStrictMode12.ts | 1 + 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2f51cd294e7..c28cc3818de 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1169,6 +1169,11 @@ module ts { function finishNode(node: T): T { node.end = scanner.getStartPos(); + + if (isInStrictMode) { + node.flags |= NodeFlags.ParsedInStrictMode; + } + return node; } @@ -1703,16 +1708,7 @@ module ts { for (var i = 0; i < parameterCount; i++) { var parameter = parameters[i]; - // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the - // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code - // or if its FunctionBody is strict code(11.1.5). - // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a - // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) - if (isInStrictMode && isEvalOrArgumentsIdentifier(parameter.name)) { - reportInvalidUseInStrictMode(parameter.name); - return; - } - else if (parameter.flags & NodeFlags.Rest) { + if (parameter.flags & NodeFlags.Rest) { if (i !== (parameterCount - 1)) { grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); return; @@ -4322,7 +4318,7 @@ module ts { else { // No parser errors were reported. Perform our stricted grammar checks. file._syntacticDiagnostics = []; - performGrammarChecks(file); + performGrammarChecks(sourceText, file); } file._parserDiagnostics = undefined; @@ -4363,9 +4359,54 @@ module ts { return file; } - function performGrammarChecks(child: Node) { + function performGrammarChecks(sourceText: string, file: SourceFileInternal) { + performNodeChecks(file); + + function performNodeChecks(node: Node) { + // First recurse and perform all grammar checks on the children of this node. If any + // children had an grammar error, then skip reporting errors for this node or anything + // higher. + if (forEachChild(node, performNodeChecks)) { + return true; + } + + // No grammar errors on any of our children. Check this node for grammar errors. + switch (node.kind) { + case SyntaxKind.Parameter: + return performParameterChecks(node); + } + } + + function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { + var span = getErrorSpanForNode(node); + var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; + var length = span.end - start; + + file._syntacticDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + } + + function reportInvalidUseInStrictMode(node: Identifier): void { + // declarationNameToString cannot be used here since it uses a backreference to 'parent' that is not yet set + var name = sourceText.substring(skipTrivia(sourceText, node.pos), node.end); + grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); + } + + function performParameterChecks(node: ParameterDeclaration): boolean { + // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the + // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code + // or if its FunctionBody is strict code(11.1.5). + // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a + // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) + if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { + reportInvalidUseInStrictMode(node.name); + return true; + } + + return false; + } } + export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1ffbf12284c..227034993ca 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -256,19 +256,23 @@ module ts { } export const enum NodeFlags { - Export = 0x00000001, // Declarations - Ambient = 0x00000002, // Declarations - QuestionMark = 0x00000004, // Parameter/Property/Method - Rest = 0x00000008, // Parameter - Public = 0x00000010, // Property/Method - Private = 0x00000020, // Property/Method - Protected = 0x00000040, // Property/Method - Static = 0x00000080, // Property/Method - MultiLine = 0x00000100, // Multi-line array or object literal - Synthetic = 0x00000200, // Synthetic node (for full fidelity) - DeclarationFile = 0x00000400, // Node is a .d.ts file - Let = 0x00000800, // Variable declaration - Const = 0x00001000, // Variable declaration + Export = 0x00000001, // Declarations + Ambient = 0x00000002, // Declarations + QuestionMark = 0x00000004, // Parameter/Property/Method + Rest = 0x00000008, // Parameter + Public = 0x00000010, // Property/Method + Private = 0x00000020, // Property/Method + Protected = 0x00000040, // Property/Method + Static = 0x00000080, // Property/Method + MultiLine = 0x00000100, // Multi-line array or object literal + Synthetic = 0x00000200, // Synthetic node (for full fidelity) + DeclarationFile = 0x00000400, // Node is a .d.ts file + Let = 0x00000800, // Variable declaration + Const = 0x00001000, // Variable declaration + + // Set if this node was parsed in strict mode. Used for grammar error checks, as well as + // checking if the node can be reused in incremental settings. + ParsedInStrictMode = 0x00002000, Modifier = Export | Ambient | Public | Private | Protected | Static, AccessibilityModifier = Public | Private | Protected, diff --git a/tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode12.ts b/tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode12.ts index 5d89dfc3b71..e8374347196 100644 --- a/tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode12.ts +++ b/tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode12.ts @@ -1,2 +1,3 @@ +// @target: ES5 "use strict"; var v = { set foo(eval) { } } \ No newline at end of file From 08f0672b03ac99c37976dd391ecd98f2a095779c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 17:42:32 -0800 Subject: [PATCH 03/60] Move parameter grammar checks to the grammar pass. --- src/compiler/parser.ts | 183 ++++++++++++++---- .../reference/amdModuleName2.errors.txt | 30 +-- .../fatarrowfunctionsOptionalArgs.errors.txt | 23 +-- ...rowfunctionsOptionalArgsErrors1.errors.txt | 8 +- .../reference/parserRealSource11.errors.txt | 5 +- .../reference/parserharness.errors.txt | 5 +- .../fatarrowfunctionsOptionalArgsErrors1.ts | 1 - 7 files changed, 161 insertions(+), 94 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c28cc3818de..1c598e5baa6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1676,7 +1676,6 @@ module ts { } var typeParameters = parseTypeParameters(); var parameters = parseParameterList(SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken); - checkParameterList(parameters); var type: TypeNode; @@ -1702,45 +1701,6 @@ module ts { return parseBracketedList(ParsingContext.Parameters, parseParameter, startDelimiter, endDelimiter); } - function checkParameterList(parameters: NodeArray): void { - var seenOptionalParameter = false; - var parameterCount = parameters.length; - - for (var i = 0; i < parameterCount; i++) { - var parameter = parameters[i]; - if (parameter.flags & NodeFlags.Rest) { - if (i !== (parameterCount - 1)) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); - return; - } - - if (parameter.flags & NodeFlags.QuestionMark) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_be_optional); - return; - } - - if (parameter.initializer) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); - return; - } - } - else if (parameter.flags & NodeFlags.QuestionMark || parameter.initializer) { - seenOptionalParameter = true; - - if (parameter.flags & NodeFlags.QuestionMark && parameter.initializer) { - grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); - return; - } - } - else { - if (seenOptionalParameter) { - grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - return; - } - } - } - } - function parseSignatureMember(kind: SyntaxKind, returnToken: SyntaxKind): SignatureDeclaration { var node = createNode(kind); var sig = parseSignature(kind, returnToken, /* returnTokenRequired */ false); @@ -4372,9 +4332,21 @@ module ts { // No grammar errors on any of our children. Check this node for grammar errors. switch (node.kind) { - case SyntaxKind.Parameter: - return performParameterChecks(node); + case SyntaxKind.ArrowFunction: return performArrowFunctionChecks(node); + case SyntaxKind.CallSignature: return performCallSignatureChecks(node); + case SyntaxKind.Constructor: return performConstructorChecks(node); + case SyntaxKind.ConstructorType: return performConstructorTypeChecks(node); + case SyntaxKind.ConstructSignature: return performConstructSignatureChecks(node); + case SyntaxKind.FunctionDeclaration: return performFunctionDeclarationChecks(node); + case SyntaxKind.FunctionExpression: return performFunctionExpressionChecks(node); + case SyntaxKind.FunctionType: return performFunctionTypeChecks(node); + case SyntaxKind.GetAccessor: return performGetAccessorChecks(node); + case SyntaxKind.Method: return performMethodChecks(node); + case SyntaxKind.Parameter: return performParameterChecks(node); + case SyntaxKind.SetAccessor: return performSetAccessorChecks(node); } + + return false; } function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { @@ -4391,6 +4363,86 @@ module ts { grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } + function performArrowFunctionChecks(node: FunctionExpression) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performCallSignatureChecks(node: ConstructorDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performConstructorChecks(node: ConstructorDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performConstructorTypeChecks(node: SignatureDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performConstructSignatureChecks(node: FunctionLikeDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performFunctionDeclarationChecks(node: FunctionLikeDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performFunctionExpressionChecks(node: FunctionExpression) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performFunctionTypeChecks(node: SignatureDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performGetAccessorChecks(node: MethodDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + + function performMethodChecks(node: MethodDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } + function performParameterChecks(node: ParameterDeclaration): boolean { // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code @@ -4404,6 +4456,53 @@ module ts { return false; } + + function performParameterListChecks(parameters: NodeArray): void { + var seenOptionalParameter = false; + var parameterCount = parameters.length; + + for (var i = 0; i < parameterCount; i++) { + var parameter = parameters[i]; + if (parameter.flags & NodeFlags.Rest) { + if (i !== (parameterCount - 1)) { + grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); + return; + } + + if (parameter.flags & NodeFlags.QuestionMark) { + grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_be_optional); + return; + } + + if (parameter.initializer) { + grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); + return; + } + } + else if (parameter.flags & NodeFlags.QuestionMark || parameter.initializer) { + seenOptionalParameter = true; + + if (parameter.flags & NodeFlags.QuestionMark && parameter.initializer) { + grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); + return; + } + } + else { + if (seenOptionalParameter) { + grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); + return; + } + } + } + } + + function performSetAccessorChecks(node: MethodDeclaration) { + if (performParameterListChecks(node.parameters)) { + return true; + } + + return false; + } } diff --git a/tests/baselines/reference/amdModuleName2.errors.txt b/tests/baselines/reference/amdModuleName2.errors.txt index 911f31a1f4b..cf7fb82ae10 100644 --- a/tests/baselines/reference/amdModuleName2.errors.txt +++ b/tests/baselines/reference/amdModuleName2.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/amdModuleName2.ts(2,1): error TS2458: An AMD module cannot have multiple name assignments. - - -==== tests/cases/compiler/amdModuleName2.ts (1 errors) ==== - /// - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2458: An AMD module cannot have multiple name assignments. - class Foo { - x: number; - constructor() { - this.x = 5; - } - } - export = Foo; +tests/cases/compiler/amdModuleName2.ts(2,1): error TS2458: An AMD module cannot have multiple name assignments. + + +==== tests/cases/compiler/amdModuleName2.ts (1 errors) ==== + /// + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2458: An AMD module cannot have multiple name assignments. + class Foo { + x: number; + constructor() { + this.x = 5; + } + } + export = Foo; \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt index e445a1460f5..db0721c62af 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt @@ -1,15 +1,8 @@ -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(60,10): error TS1015: Parameter cannot have question mark and initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(70,11): error TS1015: Parameter cannot have question mark and initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(80,17): error TS1015: Parameter cannot have question mark and initializer. tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(88,23): error TS1005: ';' expected. tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(106,3): error TS1015: Parameter cannot have question mark and initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(106,35): error TS1015: Parameter cannot have question mark and initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(126,6): error TS1015: Parameter cannot have question mark and initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Parameter cannot have question mark and initializer. -==== tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts (9 errors) ==== +==== tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts (2 errors) ==== // valid // no params @@ -70,8 +63,6 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Para false ? (arg: number) => 45 : null; false ? (arg?: number) => 46 : null; false ? (arg?: number = 0) => 47 : null; - ~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. false ? (...arg: number[]) => 48 : null; // in ternary exression within paren @@ -82,8 +73,6 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Para false ? ((arg: number) => 55) : null; false ? ((arg?: number) => 56) : null; false ? ((arg?: number = 0) => 57) : null; - ~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. false ? ((...arg: number[]) => 58) : null; // ternary exression's else clause @@ -94,8 +83,6 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Para false ? null : (arg: number) => 65; false ? null : (arg?: number) => 66; false ? null : (arg?: number = 0) => 67; - ~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. false ? null : (...arg: number[]) => 68; @@ -126,10 +113,6 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Para ((arg:number) => 0) + '' + ((arg:number) => 104); ((arg:number = 1) => 0) + '' + ((arg:number = 2) => 105); ((arg?:number = 1) => 0) + '' + ((arg?:number = 2) => 106); - ~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. - ~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. ((...arg:number[]) => 0) + '' + ((...arg:number[]) => 107); ((arg1, arg2?) => 0) + '' + ((arg1,arg2?) => 108); ((arg1, ...arg2:number[]) => 0) + '' + ((arg1, ...arg2:number[]) => 108); @@ -150,12 +133,8 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts(128,9): error TS1015: Para (a: number = 0) => 116, (a = 0) => 117, (a?: number = 0) => 118, - ~ -!!! error TS1015: Parameter cannot have question mark and initializer. (...a: number[]) => 119, (a, b? = 0, ...c: number[]) => 120, - ~ -!!! error TS1015: Parameter cannot have question mark and initializer. (a) => (b) => (c) => 121, false? (a) => 0 : (b) => 122 ); \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt index ce937dd55dc..309e731e54f 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt @@ -1,11 +1,10 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(1,9): error TS1016: A required parameter cannot follow an optional parameter. tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(2,5): error TS1047: A rest parameter cannot be optional. tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(4,5): error TS1048: A rest parameter cannot have an initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(5,5): error TS1003: Identifier expected. -tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(8,12): error TS1016: A required parameter cannot follow an optional parameter. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(7,12): error TS1016: A required parameter cannot follow an optional parameter. -==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts (5 errors) ==== +==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts (4 errors) ==== (arg1?, arg2) => 101; ~~~~ !!! error TS1016: A required parameter cannot follow an optional parameter. @@ -16,9 +15,6 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(8,12): error TS1016 (...arg:number [] = []) => 104; ~~~ !!! error TS1048: A rest parameter cannot have an initializer. - (...) => 105; - ~ -!!! error TS1003: Identifier expected. // Non optional parameter following an optional one (arg1 = 1, arg2) => 1; diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index 966da980097..68fe64a63f5 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -1,6 +1,5 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(193,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(867,29): error TS1015: Parameter cannot have question mark and initializer. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1009,45): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1024,47): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(13,22): error TS2304: Cannot find name 'Type'. @@ -515,7 +514,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,30): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error TS2304: Cannot find name 'TokenID'. -==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (515 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (514 errors) ==== // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. @@ -1815,8 +1814,6 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error } public getAliasName(aliasAST?: AST = this.alias) : string { - ~~~~~~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. if (aliasAST.nodeType == NodeType.Name) { ~~~~~~~~ !!! error TS2304: Cannot find name 'NodeType'. diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index 01104e61ea2..4de6566054c 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(17,1): err tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(18,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/services/typescriptServices.ts' not found. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(19,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/RealWorld/diff.ts' not found. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1430,9): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2047,13): error TS1015: Parameter cannot have question mark and initializer. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(21,21): error TS2305: Module 'Harness' has no exported member 'Assert'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(25,17): error TS2304: Cannot find name 'IIO'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(41,12): error TS2304: Cannot find name 'ActiveXObject'. @@ -111,7 +110,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (111 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -2379,8 +2378,6 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): relativeFilename: string, generateContent: () => string, runImmediately? = false, - ~~~~~~~~~~~~~~ -!!! error TS1015: Parameter cannot have question mark and initializer. opts?: BaselineOptions) { var actual = undefined; diff --git a/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts index c684aeca5b3..d8ddcf4bb8f 100644 --- a/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts +++ b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts @@ -2,7 +2,6 @@ (...arg?) => 102; (...arg) => 103; (...arg:number [] = []) => 104; -(...) => 105; // Non optional parameter following an optional one (arg1 = 1, arg2) => 1; \ No newline at end of file From 34bb53f54c942b59c19d39922f0bf799a160a1bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 18:20:41 -0800 Subject: [PATCH 04/60] Use the entire indexer node for grammar error reporting. --- src/compiler/parser.ts | 24 ++++----- ...rowfunctionsOptionalArgsErrors3.errors.txt | 8 +++ ...rowfunctionsOptionalArgsErrors4.errors.txt | 49 +++++++++++++++++++ tests/baselines/reference/giant.errors.txt | 16 +++--- ...SignatureMustHaveTypeAnnotation.errors.txt | 2 +- .../reference/indexTypeCheck.errors.txt | 4 +- .../indexWithoutParamType.errors.txt | 2 +- .../reference/intTypeCheck.errors.txt | 4 +- .../parserIndexSignature11.errors.txt | 2 +- .../parserIndexSignature9.errors.txt | 2 +- .../reference/parserObjectType6.errors.txt | 2 +- .../fatarrowfunctionsOptionalArgsErrors3.ts | 1 + .../fatarrowfunctionsOptionalArgsErrors4.ts | 22 +++++++++ 13 files changed, 106 insertions(+), 32 deletions(-) create mode 100644 tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.errors.txt create mode 100644 tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.errors.txt create mode 100644 tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts create mode 100644 tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1c598e5baa6..7b59aeb724b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1719,52 +1719,46 @@ module ts { var indexerLength = scanner.getStartPos() - indexerStart; node.type = parseTypeAnnotation(); parseSemicolon(); + finishNode(node) + if (file._parserDiagnostics.length === errorCountBeforeIndexSignature) { - checkIndexSignature(node, indexerStart, indexerLength); + checkIndexSignature(node); } - return finishNode(node); + + return node; } - function checkIndexSignature(node: SignatureDeclaration, indexerStart: number, indexerLength: number): void { + function checkIndexSignature(node: SignatureDeclaration): void { var parameter = node.parameters[0]; if (node.parameters.length !== 1) { - var arityDiagnostic = Diagnostics.An_index_signature_must_have_exactly_one_parameter; if (parameter) { - grammarErrorOnNode(parameter.name, arityDiagnostic); + grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_must_have_exactly_one_parameter); } else { - grammarErrorAtPos(indexerStart, indexerLength, arityDiagnostic); + grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_exactly_one_parameter); } - return; } else if (parameter.flags & NodeFlags.Rest) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_cannot_have_a_rest_parameter); - return; } else if (parameter.flags & NodeFlags.Modifier) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); - return; } else if (parameter.flags & NodeFlags.QuestionMark) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); - return; } else if (parameter.initializer) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); - return; } else if (!parameter.type) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); - return; } else if (parameter.type.kind !== SyntaxKind.StringKeyword && parameter.type.kind !== SyntaxKind.NumberKeyword) { grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); - return; } else if (!node.type) { - grammarErrorAtPos(indexerStart, indexerLength, Diagnostics.An_index_signature_must_have_a_type_annotation); - return; + grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation); } } diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.errors.txt new file mode 100644 index 00000000000..631ccc2e221 --- /dev/null +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors3.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts(1,5): error TS1003: Identifier expected. + + +==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts (1 errors) ==== + (...) => 105; + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.errors.txt new file mode 100644 index 00000000000..8de0eb92a02 --- /dev/null +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.errors.txt @@ -0,0 +1,49 @@ +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(1,14): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(2,15): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(3,21): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(4,7): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(4,39): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(17,10): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(19,13): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts(6,5): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts (8 errors) ==== + false ? (arg?: number = 0) => 47 : null; + ~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + false ? ((arg?: number = 0) => 57) : null; + ~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + false ? null : (arg?: number = 0) => 67; + ~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + ((arg?:number = 1) => 0) + '' + ((arg?:number = 2) => 106); + ~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + ~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. + + foo( + ~~~ +!!! error TS2304: Cannot find name 'foo'. + (a) => 110, + ((a) => 111), + (a) => { + return 112; + }, + (a? ) => 113, + (a, b? ) => 114, + (a: number) => 115, + (a: number = 0) => 116, + (a = 0) => 117, + (a?: number = 0) => 118, + ~ +!!! error TS1015: Parameter cannot have question mark and initializer. + (...a: number[]) => 119, + (a, b? = 0, ...c: number[]) => 120, + ~ +!!! error TS1015: Parameter cannot have question mark and initializer. + (a) => (b) => (c) => 121, + false? (a) => 0 : (b) => 122 + ); \ No newline at end of file diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index 5ef1393915d..830fa091ccb 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -388,7 +388,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -502,7 +502,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -633,7 +633,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -866,7 +866,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -980,7 +980,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -1111,7 +1111,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -1380,7 +1380,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -1484,7 +1484,7 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ diff --git a/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt b/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt index 52934b7ae9e..e7437fcb056 100644 --- a/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt +++ b/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(12,5): error TS1021 ~ !!! error TS1022: An index signature parameter must have a type annotation. [x: string]; - ~~~~~~~~~~~ + ~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. } diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 71bc03eca96..efa02c3ff1f 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -11,10 +11,10 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression ==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== interface Red { [n:number]; // ok - ~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [s:string]; // ok - ~~~~~~~~~~ + ~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. } diff --git a/tests/baselines/reference/indexWithoutParamType.errors.txt b/tests/baselines/reference/indexWithoutParamType.errors.txt index 292583302a0..01a5b44a2e0 100644 --- a/tests/baselines/reference/indexWithoutParamType.errors.txt +++ b/tests/baselines/reference/indexWithoutParamType.errors.txt @@ -3,5 +3,5 @@ tests/cases/compiler/indexWithoutParamType.ts(1,10): error TS1096: An index sign ==== tests/cases/compiler/indexWithoutParamType.ts (1 errors) ==== var y: { []; } // Error - ~~ + ~~~ !!! error TS1096: An index signature must have exactly one parameter. \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index e6cfc73230a..d58df0c2ad2 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -130,7 +130,7 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ @@ -171,7 +171,7 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ diff --git a/tests/baselines/reference/parserIndexSignature11.errors.txt b/tests/baselines/reference/parserIndexSignature11.errors.txt index 1aa23b64514..585e72a3516 100644 --- a/tests/baselines/reference/parserIndexSignature11.errors.txt +++ b/tests/baselines/reference/parserIndexSignature11.errors.txt @@ -9,7 +9,7 @@ tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature1 ~ !!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; ~~ diff --git a/tests/baselines/reference/parserIndexSignature9.errors.txt b/tests/baselines/reference/parserIndexSignature9.errors.txt index e7686c22474..1a7034c4f14 100644 --- a/tests/baselines/reference/parserIndexSignature9.errors.txt +++ b/tests/baselines/reference/parserIndexSignature9.errors.txt @@ -4,6 +4,6 @@ tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature9 ==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature9.ts (1 errors) ==== interface I { []: number - ~~ + ~~~~~~~~~~ !!! error TS1096: An index signature must have exactly one parameter. } \ No newline at end of file diff --git a/tests/baselines/reference/parserObjectType6.errors.txt b/tests/baselines/reference/parserObjectType6.errors.txt index 5ad8f5e0053..afdc6b8f4d8 100644 --- a/tests/baselines/reference/parserObjectType6.errors.txt +++ b/tests/baselines/reference/parserObjectType6.errors.txt @@ -8,6 +8,6 @@ tests/cases/conformance/parser/ecmascript5/ObjectTypes/parserObjectType6.ts(2,7) ~ !!! error TS2304: Cannot find name 'B'. []; - ~~ + ~~~ !!! error TS1096: An index signature must have exactly one parameter. }; \ No newline at end of file diff --git a/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts new file mode 100644 index 00000000000..77949419711 --- /dev/null +++ b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors3.ts @@ -0,0 +1 @@ +(...) => 105; diff --git a/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts new file mode 100644 index 00000000000..b4daf2cc3ab --- /dev/null +++ b/tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors4.ts @@ -0,0 +1,22 @@ + false ? (arg?: number = 0) => 47 : null; + false ? ((arg?: number = 0) => 57) : null; + false ? null : (arg?: number = 0) => 67; + ((arg?:number = 1) => 0) + '' + ((arg?:number = 2) => 106); + + foo( + (a) => 110, + ((a) => 111), + (a) => { + return 112; + }, + (a? ) => 113, + (a, b? ) => 114, + (a: number) => 115, + (a: number = 0) => 116, + (a = 0) => 117, + (a?: number = 0) => 118, + (...a: number[]) => 119, + (a, b? = 0, ...c: number[]) => 120, + (a) => (b) => (c) => 121, + false? (a) => 0 : (b) => 122 + ); \ No newline at end of file From 2961d230784f221172f9298f51486a89f75349ca Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 18:44:53 -0800 Subject: [PATCH 05/60] Skip error checks on node if any children produced errors. --- src/compiler/parser.ts | 176 ++++++++---------- .../reference/complicatedPrivacy.errors.txt | 5 +- tests/baselines/reference/giant.errors.txt | 74 +------- .../reference/intTypeCheck.errors.txt | 20 +- .../optionalPropertiesSyntax.errors.txt | 5 +- 5 files changed, 77 insertions(+), 203 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7b59aeb724b..f8c7b2b8d5a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1713,53 +1713,10 @@ module ts { function parseIndexSignatureMember(): SignatureDeclaration { var node = createNode(SyntaxKind.IndexSignature); - var errorCountBeforeIndexSignature = file._parserDiagnostics.length; - var indexerStart = scanner.getTokenPos(); node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); - var indexerLength = scanner.getStartPos() - indexerStart; node.type = parseTypeAnnotation(); parseSemicolon(); - finishNode(node) - - if (file._parserDiagnostics.length === errorCountBeforeIndexSignature) { - checkIndexSignature(node); - } - - return node; - } - - function checkIndexSignature(node: SignatureDeclaration): void { - var parameter = node.parameters[0]; - if (node.parameters.length !== 1) { - if (parameter) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - else { - grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_exactly_one_parameter); - } - } - else if (parameter.flags & NodeFlags.Rest) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_cannot_have_a_rest_parameter); - } - else if (parameter.flags & NodeFlags.Modifier) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); - } - else if (parameter.flags & NodeFlags.QuestionMark) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); - } - else if (parameter.initializer) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); - } - else if (!parameter.type) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); - } - else if (parameter.type.kind !== SyntaxKind.StringKeyword && - parameter.type.kind !== SyntaxKind.NumberKeyword) { - grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); - } - else if (!node.type) { - grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation); - } + return finishNode(node) } function parsePropertyOrMethod(): Declaration { @@ -4314,14 +4271,19 @@ module ts { } function performGrammarChecks(sourceText: string, file: SourceFileInternal) { + var syntacticDiagnostics = file._syntacticDiagnostics; + performNodeChecks(file); - function performNodeChecks(node: Node) { + function performNodeChecks(node: Node): void { // First recurse and perform all grammar checks on the children of this node. If any // children had an grammar error, then skip reporting errors for this node or anything // higher. - if (forEachChild(node, performNodeChecks)) { - return true; + var diagnosticCount = syntacticDiagnostics.length; + forEachChild(node, performNodeChecks); + + if (diagnosticCount !== syntacticDiagnostics.length) { + return; } // No grammar errors on any of our children. Check this node for grammar errors. @@ -4335,12 +4297,11 @@ module ts { case SyntaxKind.FunctionExpression: return performFunctionExpressionChecks(node); case SyntaxKind.FunctionType: return performFunctionTypeChecks(node); case SyntaxKind.GetAccessor: return performGetAccessorChecks(node); + case SyntaxKind.IndexSignature: return performIndexSignatureChecks(node); case SyntaxKind.Method: return performMethodChecks(node); case SyntaxKind.Parameter: return performParameterChecks(node); case SyntaxKind.SetAccessor: return performSetAccessorChecks(node); } - - return false; } function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { @@ -4358,100 +4319,111 @@ module ts { } function performArrowFunctionChecks(node: FunctionExpression) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performCallSignatureChecks(node: ConstructorDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performConstructorChecks(node: ConstructorDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performConstructorTypeChecks(node: SignatureDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performConstructSignatureChecks(node: FunctionLikeDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performFunctionDeclarationChecks(node: FunctionLikeDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performFunctionExpressionChecks(node: FunctionExpression) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performFunctionTypeChecks(node: SignatureDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } function performGetAccessorChecks(node: MethodDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } + } - return false; + function performIndexSignatureChecks(node: SignatureDeclaration): void { + var parameter = node.parameters[0]; + if (node.parameters.length !== 1) { + if (parameter) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + else { + return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_exactly_one_parameter); + } + } + else if (parameter.flags & NodeFlags.Rest) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_cannot_have_a_rest_parameter); + } + else if (parameter.flags & NodeFlags.Modifier) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); + } + else if (parameter.flags & NodeFlags.QuestionMark) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark); + } + else if (parameter.initializer) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_cannot_have_an_initializer); + } + else if (!parameter.type) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); + } + else if (parameter.type.kind !== SyntaxKind.StringKeyword && + parameter.type.kind !== SyntaxKind.NumberKeyword) { + return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); + } + else if (!node.type) { + return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation); + } } function performMethodChecks(node: MethodDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } - function performParameterChecks(node: ParameterDeclaration): boolean { + function performParameterChecks(node: ParameterDeclaration): void { // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { - reportInvalidUseInStrictMode(node.name); - return true; + return reportInvalidUseInStrictMode(node.name); } - - return false; } - function performParameterListChecks(parameters: NodeArray): void { + function checkParameterList(parameters: NodeArray): boolean { var seenOptionalParameter = false; var parameterCount = parameters.length; @@ -4460,17 +4432,17 @@ module ts { if (parameter.flags & NodeFlags.Rest) { if (i !== (parameterCount - 1)) { grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); - return; + return true; } if (parameter.flags & NodeFlags.QuestionMark) { grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_be_optional); - return; + return true; } if (parameter.initializer) { grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); - return; + return true; } } else if (parameter.flags & NodeFlags.QuestionMark || parameter.initializer) { @@ -4478,24 +4450,22 @@ module ts { if (parameter.flags & NodeFlags.QuestionMark && parameter.initializer) { grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); - return; + return true; } } else { if (seenOptionalParameter) { grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - return; + return true; } } } } function performSetAccessorChecks(node: MethodDeclaration) { - if (performParameterListChecks(node.parameters)) { - return true; + if (checkParameterList(node.parameters)) { + return; } - - return false; } } diff --git a/tests/baselines/reference/complicatedPrivacy.errors.txt b/tests/baselines/reference/complicatedPrivacy.errors.txt index e4867f0d2f5..404ee545716 100644 --- a/tests/baselines/reference/complicatedPrivacy.errors.txt +++ b/tests/baselines/reference/complicatedPrivacy.errors.txt @@ -1,10 +1,9 @@ tests/cases/compiler/complicatedPrivacy.ts(11,24): error TS1054: A 'get' accessor cannot have parameters. tests/cases/compiler/complicatedPrivacy.ts(24,38): error TS1005: ';' expected. -tests/cases/compiler/complicatedPrivacy.ts(35,6): error TS1022: An index signature parameter must have a type annotation. tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' has no exported member 'i6'. -==== tests/cases/compiler/complicatedPrivacy.ts (4 errors) ==== +==== tests/cases/compiler/complicatedPrivacy.ts (3 errors) ==== module m1 { export module m2 { @@ -44,8 +43,6 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' export function f4(arg1: { [number]: C1; - ~~~~~~ -!!! error TS1022: An index signature parameter must have a type annotation. }) { } diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index 830fa091ccb..a57c0a42c15 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -4,18 +4,12 @@ tests/cases/compiler/giant.ts(29,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(31,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(35,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(37,1): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(61,6): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(62,5): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(63,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(89,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(91,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(93,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(95,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(99,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(101,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(125,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(126,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(127,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(154,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(168,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(170,9): error TS1005: '{' expected. @@ -23,9 +17,6 @@ tests/cases/compiler/giant.ts(172,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(174,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(178,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(180,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(204,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(205,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(206,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(233,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(238,35): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(240,24): error TS1111: A constructor implementation cannot be declared in an ambient context. @@ -54,18 +45,12 @@ tests/cases/compiler/giant.ts(287,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(289,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(293,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(295,1): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(319,6): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(320,5): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(321,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(347,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(349,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(351,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(353,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(357,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(359,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(383,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(384,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(385,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(412,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(426,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(428,9): error TS1005: '{' expected. @@ -73,9 +58,6 @@ tests/cases/compiler/giant.ts(430,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(432,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(436,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(438,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(462,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(463,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(464,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(491,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(496,35): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(498,24): error TS1111: A constructor implementation cannot be declared in an ambient context. @@ -120,9 +102,6 @@ tests/cases/compiler/giant.ts(556,21): error TS1036: Statements are not allowed tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(561,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(563,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(587,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(588,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(589,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(606,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(606,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(611,30): error TS1037: A function implementation cannot be declared in an ambient context. @@ -138,9 +117,6 @@ tests/cases/compiler/giant.ts(621,29): error TS1036: Statements are not allowed tests/cases/compiler/giant.ts(623,24): error TS1111: A constructor implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(626,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(628,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(653,10): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/giant.ts(654,9): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/giant.ts(655,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(672,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(672,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(676,30): error TS1037: A function implementation cannot be declared in an ambient context. @@ -281,7 +257,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (281 errors) ==== +==== tests/cases/compiler/giant.ts (257 errors) ==== /* Prefixes @@ -385,14 +361,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -499,14 +469,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -630,14 +594,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -863,14 +821,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -977,14 +929,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -1108,14 +1054,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -1377,14 +1317,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -1481,14 +1415,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index d58df0c2ad2..64655f1bd35 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -1,9 +1,3 @@ -tests/cases/compiler/intTypeCheck.ts(35,6): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/intTypeCheck.ts(36,5): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/intTypeCheck.ts(37,6): error TS1096: An index signature must have exactly one parameter. -tests/cases/compiler/intTypeCheck.ts(70,6): error TS1022: An index signature parameter must have a type annotation. -tests/cases/compiler/intTypeCheck.ts(71,5): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/intTypeCheck.ts(72,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/intTypeCheck.ts(104,20): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(118,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(132,21): error TS1109: Expression expected. @@ -91,7 +85,7 @@ tests/cases/compiler/intTypeCheck.ts(202,22): error TS2304: Cannot find name 'i8 tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -==== tests/cases/compiler/intTypeCheck.ts (73 errors) ==== +==== tests/cases/compiler/intTypeCheck.ts (67 errors) ==== interface i1 { //Property Signatures p; @@ -127,14 +121,8 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit interface i4 { //Index Signatures [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. } interface i5 extends i1 { } interface i6 extends i2 { } @@ -168,14 +156,8 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit //Index Signatures [p]; - ~ -!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; - ~~~~~~~~~~~~~ -!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; - ~~ -!!! error TS1096: An index signature must have exactly one parameter. //Property Signatures p; diff --git a/tests/baselines/reference/optionalPropertiesSyntax.errors.txt b/tests/baselines/reference/optionalPropertiesSyntax.errors.txt index 66c1cae2a7e..daeb7c7a268 100644 --- a/tests/baselines/reference/optionalPropertiesSyntax.errors.txt +++ b/tests/baselines/reference/optionalPropertiesSyntax.errors.txt @@ -6,7 +6,6 @@ tests/cases/compiler/optionalPropertiesSyntax.ts(18,12): error TS1131: Property tests/cases/compiler/optionalPropertiesSyntax.ts(32,18): error TS1005: ';' expected. tests/cases/compiler/optionalPropertiesSyntax.ts(32,19): error TS1131: Property or signature expected. tests/cases/compiler/optionalPropertiesSyntax.ts(33,5): error TS1131: Property or signature expected. -tests/cases/compiler/optionalPropertiesSyntax.ts(34,6): error TS1019: An index signature parameter cannot have a question mark. tests/cases/compiler/optionalPropertiesSyntax.ts(4,5): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/optionalPropertiesSyntax.ts(24,5): error TS2300: Duplicate identifier 'prop'. tests/cases/compiler/optionalPropertiesSyntax.ts(25,5): error TS2300: Duplicate identifier 'prop'. @@ -15,7 +14,7 @@ tests/cases/compiler/optionalPropertiesSyntax.ts(33,7): error TS2375: Duplicate tests/cases/compiler/optionalPropertiesSyntax.ts(34,5): error TS2375: Duplicate number index signature. -==== tests/cases/compiler/optionalPropertiesSyntax.ts (15 errors) ==== +==== tests/cases/compiler/optionalPropertiesSyntax.ts (14 errors) ==== interface fnSigs { //functions signatures can be optional fn(): void; @@ -76,8 +75,6 @@ tests/cases/compiler/optionalPropertiesSyntax.ts(34,5): error TS2375: Duplicate ~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. [idx?: number]: any; //err - ~~~ -!!! error TS1019: An index signature parameter cannot have a question mark. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. } \ No newline at end of file From c42b277ed7de584b470573a82ae19afc5e9a1e1a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 20:59:58 -0800 Subject: [PATCH 06/60] Rename and simplify code. --- src/compiler/parser.ts | 81 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f8c7b2b8d5a..bdf598f9b0a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4229,7 +4229,7 @@ module ts { else { // No parser errors were reported. Perform our stricted grammar checks. file._syntacticDiagnostics = []; - performGrammarChecks(sourceText, file); + checkGrammar(sourceText, file); } file._parserDiagnostics = undefined; @@ -4270,17 +4270,17 @@ module ts { return file; } - function performGrammarChecks(sourceText: string, file: SourceFileInternal) { + function checkGrammar(sourceText: string, file: SourceFileInternal) { var syntacticDiagnostics = file._syntacticDiagnostics; - performNodeChecks(file); + visitNode(file); - function performNodeChecks(node: Node): void { + function visitNode(node: Node): void { // First recurse and perform all grammar checks on the children of this node. If any // children had an grammar error, then skip reporting errors for this node or anything // higher. var diagnosticCount = syntacticDiagnostics.length; - forEachChild(node, performNodeChecks); + forEachChild(node, visitNode); if (diagnosticCount !== syntacticDiagnostics.length) { return; @@ -4288,91 +4288,98 @@ module ts { // No grammar errors on any of our children. Check this node for grammar errors. switch (node.kind) { - case SyntaxKind.ArrowFunction: return performArrowFunctionChecks(node); - case SyntaxKind.CallSignature: return performCallSignatureChecks(node); - case SyntaxKind.Constructor: return performConstructorChecks(node); - case SyntaxKind.ConstructorType: return performConstructorTypeChecks(node); - case SyntaxKind.ConstructSignature: return performConstructSignatureChecks(node); - case SyntaxKind.FunctionDeclaration: return performFunctionDeclarationChecks(node); - case SyntaxKind.FunctionExpression: return performFunctionExpressionChecks(node); - case SyntaxKind.FunctionType: return performFunctionTypeChecks(node); - case SyntaxKind.GetAccessor: return performGetAccessorChecks(node); - case SyntaxKind.IndexSignature: return performIndexSignatureChecks(node); - case SyntaxKind.Method: return performMethodChecks(node); - case SyntaxKind.Parameter: return performParameterChecks(node); - case SyntaxKind.SetAccessor: return performSetAccessorChecks(node); + case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.CallSignature: return visitCallSignature(node); + case SyntaxKind.Constructor: return visitConstructor(node); + case SyntaxKind.ConstructorType: return visitConstructorType(node); + case SyntaxKind.ConstructSignature: return visitConstructSignature(node); + case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); + case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); + case SyntaxKind.FunctionType: return visitFunctionType(node); + case SyntaxKind.GetAccessor: return visitGetAccessor(node); + case SyntaxKind.IndexSignature: return visitIndexSignature(node); + case SyntaxKind.Method: return visitMethod(node); + case SyntaxKind.Parameter: return visitParameter(node); + case SyntaxKind.SetAccessor: return visitSetAccessor(node); } } - function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { + function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { var span = getErrorSpanForNode(node); var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; var length = span.end - start; file._syntacticDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + return true; } - function reportInvalidUseInStrictMode(node: Identifier): void { + function reportInvalidUseInStrictMode(node: Identifier): boolean { // declarationNameToString cannot be used here since it uses a backreference to 'parent' that is not yet set var name = sourceText.substring(skipTrivia(sourceText, node.pos), node.end); - grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); + return grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } - function performArrowFunctionChecks(node: FunctionExpression) { + function visitArrowFunction(node: FunctionExpression) { if (checkParameterList(node.parameters)) { return; } } - function performCallSignatureChecks(node: ConstructorDeclaration) { + function visitCallSignature(node: ConstructorDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performConstructorChecks(node: ConstructorDeclaration) { + function visitConstructor(node: ConstructorDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performConstructorTypeChecks(node: SignatureDeclaration) { + function visitConstructorType(node: SignatureDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performConstructSignatureChecks(node: FunctionLikeDeclaration) { + function visitConstructSignature(node: FunctionLikeDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performFunctionDeclarationChecks(node: FunctionLikeDeclaration) { + function visitFunctionDeclaration(node: FunctionLikeDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performFunctionExpressionChecks(node: FunctionExpression) { + function visitFunctionExpression(node: FunctionExpression) { if (checkParameterList(node.parameters)) { return; } } - function performFunctionTypeChecks(node: SignatureDeclaration) { + function visitFunctionType(node: SignatureDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performGetAccessorChecks(node: MethodDeclaration) { + function visitGetAccessor(node: MethodDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performIndexSignatureChecks(node: SignatureDeclaration): void { + function visitIndexSignature(node: SignatureDeclaration): void { + if (checkIndexSignatureParameters(node)) { + return; + } + } + + function checkIndexSignatureParameters(node: SignatureDeclaration): boolean { var parameter = node.parameters[0]; if (node.parameters.length !== 1) { if (parameter) { @@ -4397,8 +4404,7 @@ module ts { else if (!parameter.type) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - else if (parameter.type.kind !== SyntaxKind.StringKeyword && - parameter.type.kind !== SyntaxKind.NumberKeyword) { + else if (parameter.type.kind !== SyntaxKind.StringKeyword && parameter.type.kind !== SyntaxKind.NumberKeyword) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } else if (!node.type) { @@ -4406,20 +4412,21 @@ module ts { } } - function performMethodChecks(node: MethodDeclaration) { + function visitMethod(node: MethodDeclaration) { if (checkParameterList(node.parameters)) { return; } } - function performParameterChecks(node: ParameterDeclaration): void { + function visitParameter(node: ParameterDeclaration): void { // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { - return reportInvalidUseInStrictMode(node.name); + reportInvalidUseInStrictMode(node.name); + return; } } @@ -4462,7 +4469,7 @@ module ts { } } - function performSetAccessorChecks(node: MethodDeclaration) { + function visitSetAccessor(node: MethodDeclaration) { if (checkParameterList(node.parameters)) { return; } From 30ba527177aeec6f62ea1e2787b1c51b6b08548f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 21:29:07 -0800 Subject: [PATCH 07/60] Move accessor grammar errors to the grammar checker. --- src/compiler/parser.ts | 185 ++++++++---------- .../reference/complicatedPrivacy.errors.txt | 5 +- ...torWithIncompleteTypeAnnotation.errors.txt | 5 +- ...perCallsInNonConstructorMembers.errors.txt | 14 +- .../duplicateObjectLiteralProperty.errors.txt | 11 +- .../reference/errorSuperCalls.errors.txt | 20 +- tests/baselines/reference/giant.errors.txt | 56 +----- .../interfaceExtendingClass2.errors.txt | 5 +- .../parserErrantSemicolonInClass1.errors.txt | 14 +- .../twoAccessorsWithSameName.errors.txt | 32 +-- 10 files changed, 93 insertions(+), 254 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bdf598f9b0a..7c3cfb2fa98 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2693,7 +2693,7 @@ module ts { var initialToken = token; if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseAndCheckMemberAccessorDeclaration(kind, initialPos, 0); + return parseMemberAccessorDeclaration(kind, initialPos, 0); } return parsePropertyAssignment(); } @@ -3520,50 +3520,6 @@ module ts { } } - function parseAndCheckMemberAccessorDeclaration(kind: SyntaxKind, pos: number, flags: NodeFlags): MethodDeclaration { - var errorCountBeforeAccessor = file._parserDiagnostics.length; - var accessor = parseMemberAccessorDeclaration(kind, pos, flags); - - if (errorCountBeforeAccessor === file._parserDiagnostics.length) { - if (languageVersion < ScriptTarget.ES5) { - grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (inAmbientContext) { - grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); - } - else if (accessor.typeParameters) { - grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters); - } - else if (kind === SyntaxKind.GetAccessor && accessor.parameters.length) { - grammarErrorOnNode(accessor.name, Diagnostics.A_get_accessor_cannot_have_parameters); - } - else if (kind === SyntaxKind.SetAccessor) { - if (accessor.type) { - grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); - } - else if (accessor.parameters.length !== 1) { - grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_must_have_exactly_one_parameter); - } - else { - var parameter = accessor.parameters[0]; - if (parameter.flags & NodeFlags.Rest) { - grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_rest_parameter); - } - else if (parameter.flags & NodeFlags.Modifier) { - grammarErrorOnNode(accessor.name, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); - } - else if (parameter.flags & NodeFlags.QuestionMark) { - grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); - } - else if (parameter.initializer) { - grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); - } - } - } - } - return accessor; - } - function parseMemberAccessorDeclaration(kind: SyntaxKind, pos: number, flags: NodeFlags): MethodDeclaration { var node = createNode(kind, pos); node.flags = flags; @@ -3791,10 +3747,10 @@ module ts { var pos = getNodePos(); var flags = parseAndCheckModifiers(ModifierContext.ClassMembers); if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseAndCheckMemberAccessorDeclaration(SyntaxKind.GetAccessor, pos, flags); + return parseMemberAccessorDeclaration(SyntaxKind.GetAccessor, pos, flags); } if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseAndCheckMemberAccessorDeclaration(SyntaxKind.SetAccessor, pos, flags); + return parseMemberAccessorDeclaration(SyntaxKind.SetAccessor, pos, flags); } if (token === SyntaxKind.ConstructorKeyword) { return parseConstructorDeclaration(pos, flags); @@ -4229,7 +4185,7 @@ module ts { else { // No parser errors were reported. Perform our stricted grammar checks. file._syntacticDiagnostics = []; - checkGrammar(sourceText, file); + checkGrammar(sourceText, languageVersion, file); } file._parserDiagnostics = undefined; @@ -4270,22 +4226,34 @@ module ts { return file; } - function checkGrammar(sourceText: string, file: SourceFileInternal) { + function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { var syntacticDiagnostics = file._syntacticDiagnostics; + // We're automatically in an ambient context if this is a .d.ts file. + var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); + visitNode(file); function visitNode(node: Node): void { - // First recurse and perform all grammar checks on the children of this node. If any - // children had an grammar error, then skip reporting errors for this node or anything - // higher. + // First recurse and perform all grammar checks on the children of this node. + var savedInAmbientContext = inAmbientContext + if (node.flags & NodeFlags.Ambient) { + inAmbientContext = true; + } + var diagnosticCount = syntacticDiagnostics.length; forEachChild(node, visitNode); - if (diagnosticCount !== syntacticDiagnostics.length) { - return; + // If any children had an grammar error, then skip reporting errors for this node or + // anything higher. + if (diagnosticCount === syntacticDiagnostics.length) { + checkNode(node); } + inAmbientContext = savedInAmbientContext; + } + + function checkNode(node: Node) { // No grammar errors on any of our children. Check this node for grammar errors. switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); @@ -4320,63 +4288,44 @@ module ts { } function visitArrowFunction(node: FunctionExpression) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitCallSignature(node: ConstructorDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitConstructor(node: ConstructorDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitConstructorType(node: SignatureDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitConstructSignature(node: FunctionLikeDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitFunctionDeclaration(node: FunctionLikeDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitFunctionExpression(node: FunctionExpression) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitFunctionType(node: SignatureDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitGetAccessor(node: MethodDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters) || + checkAccessor(node); } function visitIndexSignature(node: SignatureDeclaration): void { - if (checkIndexSignatureParameters(node)) { - return; - } + checkIndexSignatureParameters(node); } function checkIndexSignatureParameters(node: SignatureDeclaration): boolean { @@ -4413,12 +4362,14 @@ module ts { } function visitMethod(node: MethodDeclaration) { - if (checkParameterList(node.parameters)) { - return; - } + checkParameterList(node.parameters); } function visitParameter(node: ParameterDeclaration): void { + checkParameterName(node); + } + + function checkParameterName(node: ParameterDeclaration): boolean { // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). @@ -4426,7 +4377,7 @@ module ts { // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { reportInvalidUseInStrictMode(node.name); - return; + return true; } } @@ -4438,45 +4389,77 @@ module ts { var parameter = parameters[i]; if (parameter.flags & NodeFlags.Rest) { if (i !== (parameterCount - 1)) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); - return true; + return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); } if (parameter.flags & NodeFlags.QuestionMark) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_be_optional); - return true; + return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_be_optional); } if (parameter.initializer) { - grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); - return true; + return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); } } else if (parameter.flags & NodeFlags.QuestionMark || parameter.initializer) { seenOptionalParameter = true; if (parameter.flags & NodeFlags.QuestionMark && parameter.initializer) { - grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); - return true; + return grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); } } else { if (seenOptionalParameter) { - grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - return true; + return grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); } } } } function visitSetAccessor(node: MethodDeclaration) { - if (checkParameterList(node.parameters)) { - return; + checkParameterList(node.parameters) || + checkAccessor(node); + } + + function checkAccessor(accessor: MethodDeclaration): boolean { + var kind = accessor.kind; + if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (inAmbientContext) { + return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); + } + else if (accessor.typeParameters) { + return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters); + } + else if (kind === SyntaxKind.GetAccessor && accessor.parameters.length) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_get_accessor_cannot_have_parameters); + } + else if (kind === SyntaxKind.SetAccessor) { + if (accessor.type) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); + } + else if (accessor.parameters.length !== 1) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_must_have_exactly_one_parameter); + } + else { + var parameter = accessor.parameters[0]; + if (parameter.flags & NodeFlags.Rest) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_rest_parameter); + } + else if (parameter.flags & NodeFlags.Modifier) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); + } + else if (parameter.flags & NodeFlags.QuestionMark) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_cannot_have_an_optional_parameter); + } + else if (parameter.initializer) { + return grammarErrorOnNode(accessor.name, Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer); + } + } } } } - export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { var program: Program; var files: SourceFile[] = []; diff --git a/tests/baselines/reference/complicatedPrivacy.errors.txt b/tests/baselines/reference/complicatedPrivacy.errors.txt index 404ee545716..fd47927f883 100644 --- a/tests/baselines/reference/complicatedPrivacy.errors.txt +++ b/tests/baselines/reference/complicatedPrivacy.errors.txt @@ -1,9 +1,8 @@ -tests/cases/compiler/complicatedPrivacy.ts(11,24): error TS1054: A 'get' accessor cannot have parameters. tests/cases/compiler/complicatedPrivacy.ts(24,38): error TS1005: ';' expected. tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' has no exported member 'i6'. -==== tests/cases/compiler/complicatedPrivacy.ts (3 errors) ==== +==== tests/cases/compiler/complicatedPrivacy.ts (2 errors) ==== module m1 { export module m2 { @@ -15,8 +14,6 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' export class C2 implements m3.i3 { public get p1(arg) { - ~~ -!!! error TS1054: A 'get' accessor cannot have parameters. return new C1(); } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 0e91d11b280..696f173e930 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -30,7 +30,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,30): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(205,28): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,10): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,36): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(219,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(227,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(234,14): error TS1005: '{' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS1128: Declaration or statement expected. @@ -95,7 +94,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (95 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (94 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -420,8 +419,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~~~~~ !!! error TS2304: Cannot find name 'yield'. public get Property() { return 0; } - ~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. public Member() { return 0; } diff --git a/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt b/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt index b58d5ad8ffe..ca589fb13ed 100644 --- a/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt @@ -1,9 +1,5 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,8): error TS1110: Type expected. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(16,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(20,15): error TS1110: Type expected. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(24,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(28,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(8,8): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(10,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(13,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors @@ -14,7 +10,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts(29,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts (14 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsInNonConstructorMembers.ts (10 errors) ==== // error to use super calls outside a constructor class Base { @@ -33,16 +29,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors } get C() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors return 1; } set C(v) { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors @@ -59,16 +51,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors } static get C() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors return 1; } static set C(v) { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt index 4c3f6d1eb7e..05dfdc82404 100644 --- a/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt +++ b/tests/baselines/reference/duplicateObjectLiteralProperty.errors.txt @@ -1,6 +1,3 @@ -tests/cases/compiler/duplicateObjectLiteralProperty.ts(14,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name. tests/cases/compiler/duplicateObjectLiteralProperty.ts(2,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/duplicateObjectLiteralProperty.ts(4,5): error TS2300: Duplicate identifier 'a'. @@ -13,7 +10,7 @@ tests/cases/compiler/duplicateObjectLiteralProperty.ts(15,9): error TS2300: Dupl tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS2300: Duplicate identifier 'a'. -==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (13 errors) ==== +==== tests/cases/compiler/duplicateObjectLiteralProperty.ts (10 errors) ==== var x = { a: 1, ~ @@ -41,18 +38,12 @@ tests/cases/compiler/duplicateObjectLiteralProperty.ts(16,9): error TS2300: Dupl var y = { get a() { return 0; }, ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'a'. set a(v: number) { }, ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'a'. get a() { return 0; } ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS1118: An object literal cannot have multiple get/set accessors with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. diff --git a/tests/baselines/reference/errorSuperCalls.errors.txt b/tests/baselines/reference/errorSuperCalls.errors.txt index 4369b4b4ab2..82c0a4e8279 100644 --- a/tests/baselines/reference/errorSuperCalls.errors.txt +++ b/tests/baselines/reference/errorSuperCalls.errors.txt @@ -1,10 +1,4 @@ -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(13,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(17,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(33,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(37,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(66,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(70,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(4,9): error TS2335: 'super' can only be referenced in a derived class. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2335: 'super' can only be referenced in a derived class. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2335: 'super' can only be referenced in a derived class. @@ -20,7 +14,7 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(67,9): error T tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors -==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (20 errors) ==== +==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (14 errors) ==== //super call in class constructor with no base type class NoBase { constructor() { @@ -38,16 +32,12 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T //super call in class accessor (get and set) with no base type get foo() { - ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2335: 'super' can only be referenced in a derived class. return null; } set foo(v) { - ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2335: 'super' can only be referenced in a derived class. @@ -72,16 +62,12 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T //super call in static class accessor (get and set) with no base type static get q() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2335: 'super' can only be referenced in a derived class. return null; } static set q(n) { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2335: 'super' can only be referenced in a derived class. @@ -119,16 +105,12 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T //super call in class accessor (get and set) of derived type get foo() { - ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors return null; } set foo(n) { - ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index a57c0a42c15..0aa14ee0cd3 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -23,18 +23,12 @@ tests/cases/compiler/giant.ts(240,24): error TS1111: A constructor implementatio tests/cases/compiler/giant.ts(243,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(244,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(245,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(246,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(247,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(248,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(249,23): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(250,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(251,32): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(252,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(254,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(255,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(256,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(257,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(258,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(262,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(262,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(267,30): error TS1037: A function implementation cannot be declared in an ambient context. @@ -64,18 +58,12 @@ tests/cases/compiler/giant.ts(498,24): error TS1111: A constructor implementatio tests/cases/compiler/giant.ts(501,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(502,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(503,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(504,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(505,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(506,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(507,23): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(508,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(509,32): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(510,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(512,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(513,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(514,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(515,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(516,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(520,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(520,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(525,30): error TS1037: A function implementation cannot be declared in an ambient context. @@ -85,18 +73,12 @@ tests/cases/compiler/giant.ts(534,20): error TS1111: A constructor implementatio tests/cases/compiler/giant.ts(537,17): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(538,18): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(539,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(540,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(541,27): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(542,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(543,19): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(544,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(545,28): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(546,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(548,17): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(549,27): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(550,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(551,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(552,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(556,18): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(556,21): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context. @@ -257,7 +239,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (257 errors) ==== +==== tests/cases/compiler/giant.ts (239 errors) ==== /* Prefixes @@ -653,8 +635,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } ~ @@ -663,8 +643,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } ~ @@ -673,8 +651,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } ~ @@ -683,8 +659,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } @@ -697,8 +671,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } ~ @@ -707,8 +679,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { @@ -1113,8 +1083,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } ~ @@ -1123,8 +1091,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } ~ @@ -1133,8 +1099,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } ~ @@ -1143,8 +1107,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } @@ -1157,8 +1119,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } ~ @@ -1167,8 +1127,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { @@ -1215,8 +1173,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } ~ @@ -1225,8 +1181,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } ~ @@ -1235,8 +1189,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } ~ @@ -1245,8 +1197,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } @@ -1259,8 +1209,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } ~ @@ -1269,8 +1217,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { diff --git a/tests/baselines/reference/interfaceExtendingClass2.errors.txt b/tests/baselines/reference/interfaceExtendingClass2.errors.txt index bff97f4c088..83cd97c72c0 100644 --- a/tests/baselines/reference/interfaceExtendingClass2.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClass2.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(13,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(13,13): error TS1131: Property or signature expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(14,9): error TS1128: Declaration or statement expected. @@ -6,13 +5,11 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(11,5): error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to string index type 'Object'. -==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts (6 errors) ==== +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts (5 errors) ==== class Foo { x: string; y() { } get Z() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return 1; } [x: string]: Object; diff --git a/tests/baselines/reference/parserErrantSemicolonInClass1.errors.txt b/tests/baselines/reference/parserErrantSemicolonInClass1.errors.txt index cdbb4dbe9b8..7e71ec8fc61 100644 --- a/tests/baselines/reference/parserErrantSemicolonInClass1.errors.txt +++ b/tests/baselines/reference/parserErrantSemicolonInClass1.errors.txt @@ -1,11 +1,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts(9,21): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts(12,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts(15,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts(18,23): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts(24,24): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts (5 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonInClass1.ts (1 errors) ==== class a { //constructor (); constructor (n: number); @@ -20,26 +16,18 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantSemicolonIn public pv; public get d() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return 30; } public set d() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. } public static get p2() { - ~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return { x: 30, y: 40 }; } private static d2() { } private static get p3() { - ~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return "string"; } private pv3; diff --git a/tests/baselines/reference/twoAccessorsWithSameName.errors.txt b/tests/baselines/reference/twoAccessorsWithSameName.errors.txt index 81da707c566..73261bfa072 100644 --- a/tests/baselines/reference/twoAccessorsWithSameName.errors.txt +++ b/tests/baselines/reference/twoAccessorsWithSameName.errors.txt @@ -1,14 +1,4 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(7,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(24,9): error TS1118: An object literal cannot have multiple get/set accessors with the same name. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(33,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(2,9): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(3,9): error TS2300: Duplicate identifier 'x'. tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(7,9): error TS2300: Duplicate identifier 'x'. @@ -17,49 +7,35 @@ tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameN tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts(24,9): error TS2300: Duplicate identifier 'x'. -==== tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts (17 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts (7 errors) ==== class C { get x() { return 1; } ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'x'. get x() { return 1; } // error ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'x'. } class D { set x(v) { } ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'x'. set x(v) { } // error ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'x'. } class E { get x() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return 1; } set x(v) { } - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. } var x = { get x() { ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS2300: Duplicate identifier 'x'. return 1; }, @@ -67,8 +43,6 @@ tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameN // error get x() { ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ !!! error TS1118: An object literal cannot have multiple get/set accessors with the same name. ~ !!! error TS2300: Duplicate identifier 'x'. @@ -78,11 +52,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameN var y = { get x() { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return 1; }, set x(v) { } - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. } \ No newline at end of file From 0e6aab7c425c67ae59751f0fec126c955c83f961 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 21:41:07 -0800 Subject: [PATCH 08/60] Move object literal checks to the grammar checker. --- src/compiler/parser.ts | 128 +++++++++--------- .../reference/objectLiteralErrors.errors.txt | 56 +------- .../duplicateObjectLiteralProperty.ts | 1 + .../twoAccessorsWithSameName.ts | 1 + 4 files changed, 69 insertions(+), 117 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7c3cfb2fa98..c40178ac7c0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2707,68 +2707,6 @@ module ts { node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember, /*allowTrailingComma*/ true); parseExpected(SyntaxKind.CloseBraceToken); - - var seen: Map = {}; - var Property = 1; - var GetAccessor = 2; - var SetAccesor = 4; - var GetOrSetAccessor = GetAccessor | SetAccesor; - forEach(node.properties, (p: Declaration) => { - // TODO(jfreeman): continue if we have a computed property - if (p.kind === SyntaxKind.OmittedExpression) { - return; - } - - var name = p.name; - - // ECMA-262 11.1.5 Object Initialiser - // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true - // a.This production is contained in strict code and IsDataDescriptor(previous) is true and - // IsDataDescriptor(propId.descriptor) is true. - // b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true. - // c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true. - // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true - // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields - var currentKind: number; - if (p.kind === SyntaxKind.PropertyAssignment) { - currentKind = Property; - } - else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) { - currentKind = Property; - } - else if (p.kind === SyntaxKind.GetAccessor) { - currentKind = GetAccessor; - } - else if (p.kind === SyntaxKind.SetAccessor) { - currentKind = SetAccesor; - } - else { - Debug.fail("Unexpected syntax kind:" + p.kind); - } - - if (!hasProperty(seen, name.text)) { - seen[name.text] = currentKind; - } - else { - var existingKind = seen[name.text]; - if (currentKind === Property && existingKind === Property) { - if (isInStrictMode) { - grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); - } - } - else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { - if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name.text] = currentKind | existingKind; - } - else { - grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } - } - else { - grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); - } - } - }); return finishNode(node); } @@ -4267,6 +4205,7 @@ module ts { case SyntaxKind.GetAccessor: return visitGetAccessor(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); case SyntaxKind.Method: return visitMethod(node); + case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); } @@ -4365,6 +4304,71 @@ module ts { checkParameterList(node.parameters); } + function visitObjectLiteral(node: ObjectLiteral): void { + var seen: Map = {}; + var Property = 1; + var GetAccessor = 2; + var SetAccesor = 4; + var GetOrSetAccessor = GetAccessor | SetAccesor; + var inStrictMode = (node.flags & NodeFlags.ParsedInStrictMode) !== 0; + forEach(node.properties, (p: Declaration) => { + // TODO(jfreeman): continue if we have a computed property + if (p.kind === SyntaxKind.OmittedExpression) { + return; + } + + var name = p.name; + + // ECMA-262 11.1.5 Object Initialiser + // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true + // a.This production is contained in strict code and IsDataDescriptor(previous) is true and + // IsDataDescriptor(propId.descriptor) is true. + // b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true. + // c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true. + // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true + // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields + var currentKind: number; + if (p.kind === SyntaxKind.PropertyAssignment) { + currentKind = Property; + } + else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) { + currentKind = Property; + } + else if (p.kind === SyntaxKind.GetAccessor) { + currentKind = GetAccessor; + } + else if (p.kind === SyntaxKind.SetAccessor) { + currentKind = SetAccesor; + } + else { + Debug.fail("Unexpected syntax kind:" + p.kind); + } + + if (!hasProperty(seen, name.text)) { + seen[name.text] = currentKind; + } + else { + var existingKind = seen[name.text]; + if (currentKind === Property && existingKind === Property) { + if (inStrictMode) { + grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + } + } + else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { + if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { + seen[name.text] = currentKind | existingKind; + } + else { + grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } + } + }); + } + function visitParameter(node: ParameterDeclaration): void { checkParameterName(node); } diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 91b9aaeecdc..8a1774c4525 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -1,23 +1,5 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(23,22): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(24,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(25,22): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(26,25): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(28,22): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,24): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,24): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,24): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,25): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,25): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(34,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,23): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,27): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,26): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(40,46): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,18): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,12): error TS2300: Duplicate identifier 'a'. @@ -97,7 +79,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,12) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51): error TS2380: 'get' and 'set' accessor must have the same type. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (97 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; @@ -195,99 +177,71 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51) // Accessor and property with the same name var f1 = { a: 0, get a() { return 0; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f2 = { a: '', get a() { return ''; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f3 = { a: 0, get a() { return ''; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f4 = { a: true, get a() { return false; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f5 = { a: {}, get a() { return {}; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f6 = { a: 0, get 'a'() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f7 = { 'a': 0, get a() { return 0; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~ !!! error TS2300: Duplicate identifier 'a'. var f8 = { 'a': 0, get "a"() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~~~ !!! error TS2300: Duplicate identifier '"a"'. var f9 = { 'a': 0, get 'a'() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f10 = { "a": 0, get 'a'() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '"a"'. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f11 = { 1.0: 0, get '1'() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '1.0'. ~~~ !!! error TS2300: Duplicate identifier ''1''. var f12 = { 0: 0, get 0() { return 0; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var f13 = { 0: 0, get 0() { return 0; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var f14 = { 0: 0, get 0x0() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~~~ @@ -295,29 +249,21 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51) var f14 = { 0: 0, get 000() { return 0; } }; ~~~ !!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~~~ !!! error TS2300: Duplicate identifier '000'. var f15 = { "100": 0, get 1e2() { return 0; } }; - ~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~~~ !!! error TS2300: Duplicate identifier '"100"'. ~~~ !!! error TS2300: Duplicate identifier '1e2'. var f16 = { 0x20: 0, get 3.2e1() { return 0; } }; - ~~~~~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~~ !!! error TS2300: Duplicate identifier '0x20'. ~~~~~ !!! error TS2300: Duplicate identifier '3.2e1'. var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; - ~ -!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ diff --git a/tests/cases/compiler/duplicateObjectLiteralProperty.ts b/tests/cases/compiler/duplicateObjectLiteralProperty.ts index 1ceb9c3c5dd..2591e6dd78a 100644 --- a/tests/cases/compiler/duplicateObjectLiteralProperty.ts +++ b/tests/cases/compiler/duplicateObjectLiteralProperty.ts @@ -1,3 +1,4 @@ +// @target: ES5 var x = { a: 1, b: true, // OK diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts index 2d802f244d0..5c098643712 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/twoAccessorsWithSameName.ts @@ -1,3 +1,4 @@ +// @target: ES5 class C { get x() { return 1; } get x() { return 1; } // error From 68a3bd8fbc90687441f280fc9222db7862f9ba51 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 21:52:22 -0800 Subject: [PATCH 09/60] Move template version checks to the grammar walk. --- src/compiler/parser.ts | 40 ++++++++++--------- ...tringsWithIncompatibleTypedTags.errors.txt | 11 +---- ...mplateStringsWithTagsTypedAsAny.errors.txt | 8 +--- ...gedTemplateStringsWithTypedTags.errors.txt | 8 +--- .../templateStringInModuleName.errors.txt | 8 +--- .../templateStringInObjectLiteral.errors.txt | 7 +--- .../templateStringInPropertyName1.errors.txt | 6 +-- .../templateStringInPropertyName2.errors.txt | 6 +-- .../templateStringInYieldKeyword.errors.txt | 5 +-- ...eStringWithEmbeddedYieldKeyword.errors.txt | 7 +--- 10 files changed, 30 insertions(+), 76 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c40178ac7c0..4e9f9488111 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2526,11 +2526,6 @@ module ts { ? parseLiteralNode() : parseTemplateExpression(); expr = finishNode(tagExpression); - - if (languageVersion < ScriptTarget.ES6) { - grammarErrorOnNode(expr, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - continue; } @@ -4194,20 +4189,21 @@ module ts { function checkNode(node: Node) { // No grammar errors on any of our children. Check this node for grammar errors. switch (node.kind) { - case SyntaxKind.ArrowFunction: return visitArrowFunction(node); - case SyntaxKind.CallSignature: return visitCallSignature(node); - case SyntaxKind.Constructor: return visitConstructor(node); - case SyntaxKind.ConstructorType: return visitConstructorType(node); - case SyntaxKind.ConstructSignature: return visitConstructSignature(node); - case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); - case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); - case SyntaxKind.FunctionType: return visitFunctionType(node); - case SyntaxKind.GetAccessor: return visitGetAccessor(node); - case SyntaxKind.IndexSignature: return visitIndexSignature(node); - case SyntaxKind.Method: return visitMethod(node); - case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); - case SyntaxKind.Parameter: return visitParameter(node); - case SyntaxKind.SetAccessor: return visitSetAccessor(node); + case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.CallSignature: return visitCallSignature(node); + case SyntaxKind.Constructor: return visitConstructor(node); + case SyntaxKind.ConstructorType: return visitConstructorType(node); + case SyntaxKind.ConstructSignature: return visitConstructSignature(node); + case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); + case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); + case SyntaxKind.FunctionType: return visitFunctionType(node); + case SyntaxKind.GetAccessor: return visitGetAccessor(node); + case SyntaxKind.IndexSignature: return visitIndexSignature(node); + case SyntaxKind.Method: return visitMethod(node); + case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); + case SyntaxKind.Parameter: return visitParameter(node); + case SyntaxKind.SetAccessor: return visitSetAccessor(node); + case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); } } @@ -4462,6 +4458,12 @@ module ts { } } } + + function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { + if (languageVersion < ScriptTarget.ES6) { + grammarErrorOnNode(node, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } } export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt index cf915f36dd8..7dedca9eb32 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -5,10 +5,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. @@ -18,7 +15,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,57): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (18 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (15 errors) ==== interface I { (stringParts: string[], ...rest: boolean[]): I; g: I; @@ -62,24 +59,18 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped f `abc`[0].member `abc${1}def${2}ghi`; ~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${ true }def${ true }ghi`["member"].member `abc${ 1 }def${ 2 }ghi`; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt index a15e0cbb49b..8a334a5611b 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt @@ -7,12 +7,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts (12 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts (10 errors) ==== var f: any; f `abc` @@ -50,14 +48,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts f `abc`["member"].someOtherTag `abc${1}def${2}ghi`; ~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].someOtherTag `abc${1}def${2}ghi`; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt index 0e4f7a63223..41f3492317f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt @@ -5,12 +5,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,1 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts (10 errors) ==== +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts (8 errors) ==== interface I { (stringParts: string[], ...rest: number[]): I; g: I; @@ -49,14 +47,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1 f `abc`[0].member `abc${1}def${2}ghi`; ~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); diff --git a/tests/baselines/reference/templateStringInModuleName.errors.txt b/tests/baselines/reference/templateStringInModuleName.errors.txt index fb6188d9d9a..858bd893164 100644 --- a/tests/baselines/reference/templateStringInModuleName.errors.txt +++ b/tests/baselines/reference/templateStringInModuleName.errors.txt @@ -1,8 +1,6 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,21): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS2304: Cannot find name 'module'. @@ -10,12 +8,10 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,1): error tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS2304: Cannot find name 'module'. -==== tests/cases/conformance/es6/templates/templateStringInModuleName.ts (10 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInModuleName.ts (8 errors) ==== declare module `M1` { ~~~~~~ !!! error TS1005: ';' expected. - ~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1005: ';' expected. ~~~~~~~ @@ -27,8 +23,6 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error declare module `M${2}` { ~~~~~~ !!! error TS1005: ';' expected. - ~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1005: ';' expected. ~~~~~~~ diff --git a/tests/baselines/reference/templateStringInObjectLiteral.errors.txt b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt index b510e46ba6a..5406914163e 100644 --- a/tests/baselines/reference/templateStringInObjectLiteral.errors.txt +++ b/tests/baselines/reference/templateStringInObjectLiteral.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,5): error TS1136: Property assignment expected. tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,8): error TS1005: ',' expected. tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(3,10): error TS1134: Variable declaration expected. @@ -6,16 +5,12 @@ tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(4,1): err tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts(1,9): error TS2349: Cannot invoke an expression whose type lacks a call signature. -==== tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts (6 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInObjectLiteral.ts (5 errors) ==== var x = { ~ - ~ a: `abc${ 123 }def`, - ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ `b`: 321 - ~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~ !!! error TS1136: Property assignment expected. ~ diff --git a/tests/baselines/reference/templateStringInPropertyName1.errors.txt b/tests/baselines/reference/templateStringInPropertyName1.errors.txt index c0b89e02d68..04f53976e65 100644 --- a/tests/baselines/reference/templateStringInPropertyName1.errors.txt +++ b/tests/baselines/reference/templateStringInPropertyName1.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,5): error TS1136: Property assignment expected. tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,8): error TS1005: ',' expected. tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(2,10): error TS1134: Variable declaration expected. @@ -6,13 +5,10 @@ tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(3,1): err tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts(1,9): error TS2349: Cannot invoke an expression whose type lacks a call signature. -==== tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts (6 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInPropertyName1.ts (5 errors) ==== var x = { ~ - ~ `a`: 321 - ~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~ !!! error TS1136: Property assignment expected. ~ diff --git a/tests/baselines/reference/templateStringInPropertyName2.errors.txt b/tests/baselines/reference/templateStringInPropertyName2.errors.txt index d9302d25fa9..7faa04c3240 100644 --- a/tests/baselines/reference/templateStringInPropertyName2.errors.txt +++ b/tests/baselines/reference/templateStringInPropertyName2.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(1,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,5): error TS1136: Property assignment expected. tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,32): error TS1005: ',' expected. tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(2,34): error TS1134: Variable declaration expected. @@ -6,13 +5,10 @@ tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(3,1): err tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts(1,9): error TS2349: Cannot invoke an expression whose type lacks a call signature. -==== tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts (6 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInPropertyName2.ts (5 errors) ==== var x = { ~ - ~ `abc${ 123 }def${ 456 }ghi`: 321 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~ !!! error TS1136: Property assignment expected. ~ diff --git a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt index b70af797c5c..50b780ad3cb 100644 --- a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt @@ -1,11 +1,10 @@ tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,15): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS2304: Cannot find name 'yield'. -==== tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts (5 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts (4 errors) ==== function* gen { ~ !!! error TS1003: Identifier expected. @@ -15,8 +14,6 @@ tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): err !!! error TS2304: Cannot find name 'gen'. // Once this is supported, the inner expression does not need to be parenthesized. var x = yield `abc${ x }def`; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~ !!! error TS2304: Cannot find name 'yield'. } diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt index 3cada665186..3bf910f3690 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt @@ -1,14 +1,13 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,15): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,26): error TS1158: Invalid template literal; expected '}' -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,30): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(5,1): error TS1160: Unterminated template literal. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,20): error TS2304: Cannot find name 'yield'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,30): error TS2304: Cannot find name 'def'. -==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts (8 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts (7 errors) ==== function* gen { ~ !!! error TS1003: Identifier expected. @@ -20,15 +19,11 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts( var x = `abc${ yield 10 }def`; ~~ !!! error TS1158: Invalid template literal; expected '}' - ~~~~~ ~~~~~ !!! error TS2304: Cannot find name 'yield'. ~~~ !!! error TS2304: Cannot find name 'def'. } - ~ -!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. - !!! error TS1160: Unterminated template literal. \ No newline at end of file From e5c3661e304ad75eb54178bc162b049bed36936a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 22:03:07 -0800 Subject: [PATCH 10/60] Move postfix/prefix checks to the grammar check. --- src/compiler/parser.ts | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4e9f9488111..302635aaff9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2373,21 +2373,7 @@ module ts { case SyntaxKind.MinusMinusToken: var operator = token; nextToken(); - var operand = parseUnaryExpression(); - if (isInStrictMode) { - // The identifier eval or arguments may not appear as the LeftHandSideExpression of an - // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression - // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator - if ((operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(operand)) { - reportInvalidUseInStrictMode(operand); - } - else if (operator === SyntaxKind.DeleteKeyword && operand.kind === SyntaxKind.Identifier) { - // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its - // UnaryExpression is a direct reference to a variable, function argument, or function name - grammarErrorOnNode(operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); - } - } - return makeUnaryExpression(SyntaxKind.PrefixOperator, pos, operator, operand); + return makeUnaryExpression(SyntaxKind.PrefixOperator, pos, operator, parseUnaryExpression()); case SyntaxKind.LessThanToken: return parseTypeAssertion(); } @@ -2408,12 +2394,6 @@ module ts { Debug.assert(isLeftHandSideExpression(expr)); if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { - // The identifier eval or arguments may not appear as the LeftHandSideExpression of an - // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression - // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator. - if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) { - reportInvalidUseInStrictMode(expr); - } var operator = token; nextToken(); expr = makeUnaryExpression(SyntaxKind.PostfixOperator, expr.pos, operator, expr); @@ -4202,6 +4182,8 @@ module ts { case SyntaxKind.Method: return visitMethod(node); case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); case SyntaxKind.Parameter: return visitParameter(node); + case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); + case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); } @@ -4415,6 +4397,31 @@ module ts { } } + function visitPostfixOperator(node: UnaryExpression) { + // The identifier eval or arguments may not appear as the LeftHandSideExpression of an + // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression + // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator. + if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.operand)) { + reportInvalidUseInStrictMode(node.operand); + } + } + + function visitPrefixOperator(node: UnaryExpression) { + if (node.flags & NodeFlags.ParsedInStrictMode) { + // The identifier eval or arguments may not appear as the LeftHandSideExpression of an + // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression + // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator + if ((node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(node.operand)) { + reportInvalidUseInStrictMode(node.operand); + } + else if (node.operator === SyntaxKind.DeleteKeyword && node.operand.kind === SyntaxKind.Identifier) { + // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its + // UnaryExpression is a direct reference to a variable, function argument, or function name + grammarErrorOnNode(node.operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); + } + } + } + function visitSetAccessor(node: MethodDeclaration) { checkParameterList(node.parameters) || checkAccessor(node); From 78af519f5fa6dd912d67337e6f92f95ced7c5369 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 22:18:21 -0800 Subject: [PATCH 11/60] Move enum checks to the grammar checker. --- src/compiler/parser.ts | 92 ++++++++++--------- .../reference/ambientEnum1.errors.txt | 17 ++++ .../reference/ambientErrors.errors.txt | 8 +- tests/cases/compiler/ambientEnum1.ts | 8 ++ 4 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 tests/baselines/reference/ambientEnum1.errors.txt create mode 100644 tests/cases/compiler/ambientEnum1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 302635aaff9..6ce63e1a4da 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3750,55 +3750,15 @@ module ts { function parseAndCheckEnumDeclaration(pos: number, flags: NodeFlags): EnumDeclaration { var enumIsConst = flags & NodeFlags.Const; - function isIntegerLiteral(expression: Expression): boolean { - function isInteger(literalExpression: LiteralExpression): boolean { - // Allows for scientific notation since literalExpression.text was formed by - // coercing a number to a string. Sometimes this coercion can yield a string - // in scientific notation. - // We also don't need special logic for hex because a hex integer is converted - // to decimal when it is coerced. - return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); - } - if (expression.kind === SyntaxKind.PrefixOperator) { - var unaryExpression = expression; - if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) { - expression = unaryExpression.operand; - } - } - if (expression.kind === SyntaxKind.NumericLiteral) { - return isInteger(expression); - } - - return false; - } - - var inConstantEnumMemberSection = true; // In an ambient declaration, the grammar only allows integer literals as initializers. // In a non-ambient declaration, the grammar allows uninitialized members only in a // ConstantEnumMemberSection, which starts at the beginning of an enum declaration // or any time an integer literal initializer is encountered. - function parseAndCheckEnumMember(): EnumMember { + function parseEnumMember(): EnumMember { var node = createNode(SyntaxKind.EnumMember); - var errorCountBeforeEnumMember = file._parserDiagnostics.length; node.name = parsePropertyName(); node.initializer = parseInitializer(/*inParameter*/ false); - - // skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions. - // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. - if (!enumIsConst) { - if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer) && errorCountBeforeEnumMember === file._parserDiagnostics.length) { - grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers); - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection && errorCountBeforeEnumMember === file._parserDiagnostics.length) { - grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer); - } - } return finishNode(node); } @@ -3811,7 +3771,7 @@ module ts { node.name = parseIdentifier(); if (parseExpected(SyntaxKind.OpenBraceToken)) { node.members = parseDelimitedList(ParsingContext.EnumMembers, - parseAndCheckEnumMember, /*allowTrailingComma*/ true); + parseEnumMember, /*allowTrailingComma*/ true); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -4174,6 +4134,7 @@ module ts { case SyntaxKind.Constructor: return visitConstructor(node); case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); + case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); case SyntaxKind.FunctionType: return visitFunctionType(node); @@ -4224,6 +4185,53 @@ module ts { checkParameterList(node.parameters); } + function visitEnumDeclaration(enumDecl: EnumDeclaration) { + var enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0; + + // skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions. + // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. + if (!enumIsConst) { + var inConstantEnumMemberSection = true; + for (var i = 0, n = enumDecl.members.length; i < n; i++) { + var node = enumDecl.members[i]; + if (inAmbientContext) { + if (node.initializer && !isIntegerLiteral(node.initializer)) { + grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers); + } + } + else if (node.initializer) { + inConstantEnumMemberSection = isIntegerLiteral(node.initializer); + } + else if (!inConstantEnumMemberSection) { + grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer); + } + } + } + } + + function isIntegerLiteral(expression: Expression): boolean { + function isInteger(literalExpression: LiteralExpression): boolean { + // Allows for scientific notation since literalExpression.text was formed by + // coercing a number to a string. Sometimes this coercion can yield a string + // in scientific notation. + // We also don't need special logic for hex because a hex integer is converted + // to decimal when it is coerced. + return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text); + } + + if (expression.kind === SyntaxKind.PrefixOperator) { + var unaryExpression = expression; + if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) { + expression = unaryExpression.operand; + } + } + if (expression.kind === SyntaxKind.NumericLiteral) { + return isInteger(expression); + } + + return false; + } + function visitFunctionDeclaration(node: FunctionLikeDeclaration) { checkParameterList(node.parameters); } diff --git a/tests/baselines/reference/ambientEnum1.errors.txt b/tests/baselines/reference/ambientEnum1.errors.txt new file mode 100644 index 00000000000..b4bb534f5dd --- /dev/null +++ b/tests/baselines/reference/ambientEnum1.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/ambientEnum1.ts(2,9): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/compiler/ambientEnum1.ts(7,9): error TS1066: Ambient enum elements can only have integer literal initializers. + + +==== tests/cases/compiler/ambientEnum1.ts (2 errors) ==== + declare enum E1 { + y = 4.23 + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + } + + // Ambient enum with computer member + declare enum E2 { + x = 'foo'.length + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + } \ No newline at end of file diff --git a/tests/baselines/reference/ambientErrors.errors.txt b/tests/baselines/reference/ambientErrors.errors.txt index 975dc9ad63a..618829c8bd9 100644 --- a/tests/baselines/reference/ambientErrors.errors.txt +++ b/tests/baselines/reference/ambientErrors.errors.txt @@ -1,7 +1,5 @@ tests/cases/conformance/ambient/ambientErrors.ts(2,15): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/ambient/ambientErrors.ts(24,5): error TS1066: Ambient enum elements can only have integer literal initializers. -tests/cases/conformance/ambient/ambientErrors.ts(29,5): error TS1066: Ambient enum elements can only have integer literal initializers. tests/cases/conformance/ambient/ambientErrors.ts(34,11): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(35,19): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/ambient/ambientErrors.ts(37,18): error TS1039: Initializers are not allowed in ambient contexts. @@ -16,7 +14,7 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient e tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements. -==== tests/cases/conformance/ambient/ambientErrors.ts (16 errors) ==== +==== tests/cases/conformance/ambient/ambientErrors.ts (14 errors) ==== // Ambient variable with an initializer declare var x = 4; ~ @@ -49,15 +47,11 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export // Ambient enum with non - integer literal constant member declare enum E1 { y = 4.23 - ~ -!!! error TS1066: Ambient enum elements can only have integer literal initializers. } // Ambient enum with computer member declare enum E2 { x = 'foo'.length - ~ -!!! error TS1066: Ambient enum elements can only have integer literal initializers. } // Ambient module with initializers for values, bodies for functions / classes diff --git a/tests/cases/compiler/ambientEnum1.ts b/tests/cases/compiler/ambientEnum1.ts new file mode 100644 index 00000000000..05b0cdd3a47 --- /dev/null +++ b/tests/cases/compiler/ambientEnum1.ts @@ -0,0 +1,8 @@ + declare enum E1 { + y = 4.23 + } + + // Ambient enum with computer member + declare enum E2 { + x = 'foo'.length + } \ No newline at end of file From 5a7929aec7451fe255535f6234bd63a396cee6ed Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 22:37:31 -0800 Subject: [PATCH 12/60] Move variable grammar checks to the grammar checker. --- src/compiler/parser.ts | 34 ++++++++++++------- .../reference/ambientErrors.errors.txt | 8 +---- .../reference/ambientErrors1.errors.txt | 7 ++++ .../initializersInDeclarations.errors.txt | 11 +----- .../missingRequiredDeclare.d.errors.txt | 7 ++-- .../parserVariableStatement1.d.errors.txt | 7 ++-- tests/cases/compiler/ambientErrors1.ts | 1 + 7 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 tests/baselines/reference/ambientErrors1.errors.txt create mode 100644 tests/cases/compiler/ambientErrors1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6ce63e1a4da..1cc5e09d680 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1005,7 +1005,6 @@ module ts { grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } - function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } @@ -3292,7 +3291,6 @@ module ts { function parseVariableDeclaration(flags: NodeFlags, noIn?: boolean): VariableDeclaration { var node = createNode(SyntaxKind.VariableDeclaration); node.flags = flags; - var errorCountBeforeVariableDeclaration = file._parserDiagnostics.length; node.name = parseIdentifier(); node.type = parseTypeAnnotation(); @@ -3301,17 +3299,6 @@ module ts { var initializerFirstTokenLength = scanner.getTextPos() - initializerStart; node.initializer = parseInitializer(/*inParameter*/ false, noIn); - if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file._parserDiagnostics.length) { - grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); - } - if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { - // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code - // and its Identifier is eval or arguments - reportInvalidUseInStrictMode(node.name); - } return finishNode(node); } @@ -4147,6 +4134,7 @@ module ts { case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); + case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); } } @@ -4159,6 +4147,11 @@ module ts { return true; } + function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { + file._syntacticDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + return true; + } + function reportInvalidUseInStrictMode(node: Identifier): boolean { // declarationNameToString cannot be used here since it uses a backreference to 'parent' that is not yet set var name = sourceText.substring(skipTrivia(sourceText, node.pos), node.end); @@ -4479,6 +4472,21 @@ module ts { grammarErrorOnNode(node, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } } + + function visitVariableDeclaration(node: VariableDeclaration) { + if (inAmbientContext && node.initializer) { + var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end); + grammarErrorAtPos(equalsPos, "=".length, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + if (!inAmbientContext && !node.initializer && node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + } + if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { + // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code + // and its Identifier is eval or arguments + reportInvalidUseInStrictMode(node.name); + } + } } export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { diff --git a/tests/baselines/reference/ambientErrors.errors.txt b/tests/baselines/reference/ambientErrors.errors.txt index 618829c8bd9..e89586275a3 100644 --- a/tests/baselines/reference/ambientErrors.errors.txt +++ b/tests/baselines/reference/ambientErrors.errors.txt @@ -1,6 +1,4 @@ -tests/cases/conformance/ambient/ambientErrors.ts(2,15): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/ambient/ambientErrors.ts(34,11): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(35,19): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/ambient/ambientErrors.ts(37,18): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(38,11): error TS1039: Initializers are not allowed in ambient contexts. @@ -14,11 +12,9 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient e tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements. -==== tests/cases/conformance/ambient/ambientErrors.ts (14 errors) ==== +==== tests/cases/conformance/ambient/ambientErrors.ts (12 errors) ==== // Ambient variable with an initializer declare var x = 4; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. // Ambient functions with invalid overloads declare function fn(x: number): string; @@ -57,8 +53,6 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export // Ambient module with initializers for values, bodies for functions / classes declare module M1 { var x = 3; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. function fn() { } ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. diff --git a/tests/baselines/reference/ambientErrors1.errors.txt b/tests/baselines/reference/ambientErrors1.errors.txt new file mode 100644 index 00000000000..db7a155cc3f --- /dev/null +++ b/tests/baselines/reference/ambientErrors1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/ambientErrors1.ts(1,15): error TS1039: Initializers are not allowed in ambient contexts. + + +==== tests/cases/compiler/ambientErrors1.ts (1 errors) ==== + declare var x = 4; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file diff --git a/tests/baselines/reference/initializersInDeclarations.errors.txt b/tests/baselines/reference/initializersInDeclarations.errors.txt index 94736957365..49a06cf9a29 100644 --- a/tests/baselines/reference/initializersInDeclarations.errors.txt +++ b/tests/baselines/reference/initializersInDeclarations.errors.txt @@ -1,13 +1,10 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,7): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,14): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(7,16): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(12,15): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(13,15): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(16,2): error TS1036: Statements are not allowed in ambient contexts. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(18,16): error TS1039: Initializers are not allowed in ambient contexts. -==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (7 errors) ==== +==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (4 errors) ==== // Errors: Initializers & statements in declaration file @@ -26,11 +23,7 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(18,16): er } declare var x = []; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. declare var y = {}; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. declare module M1 { while(true); @@ -38,6 +31,4 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(18,16): er !!! error TS1036: Statements are not allowed in ambient contexts. export var v1 = () => false; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. } \ No newline at end of file diff --git a/tests/baselines/reference/missingRequiredDeclare.d.errors.txt b/tests/baselines/reference/missingRequiredDeclare.d.errors.txt index dc713c86d89..1e52fa92fe5 100644 --- a/tests/baselines/reference/missingRequiredDeclare.d.errors.txt +++ b/tests/baselines/reference/missingRequiredDeclare.d.errors.txt @@ -1,10 +1,7 @@ tests/cases/compiler/missingRequiredDeclare.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. -tests/cases/compiler/missingRequiredDeclare.d.ts(1,7): error TS1039: Initializers are not allowed in ambient contexts. -==== tests/cases/compiler/missingRequiredDeclare.d.ts (2 errors) ==== +==== tests/cases/compiler/missingRequiredDeclare.d.ts (1 errors) ==== var x = 1; ~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file +!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableStatement1.d.errors.txt b/tests/baselines/reference/parserVariableStatement1.d.errors.txt index de0bef5288c..7176e5ed69f 100644 --- a/tests/baselines/reference/parserVariableStatement1.d.errors.txt +++ b/tests/baselines/reference/parserVariableStatement1.d.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. -tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts(1,7): error TS1039: Initializers are not allowed in ambient contexts. -==== tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts (1 errors) ==== var v = 1; ~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file +!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. \ No newline at end of file diff --git a/tests/cases/compiler/ambientErrors1.ts b/tests/cases/compiler/ambientErrors1.ts new file mode 100644 index 00000000000..ef249266498 --- /dev/null +++ b/tests/cases/compiler/ambientErrors1.ts @@ -0,0 +1 @@ +declare var x = 4; \ No newline at end of file From 3dfa8bef24f6e736d7bcbdfd58327441bfd000bc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 22:46:35 -0800 Subject: [PATCH 13/60] Move contructor grammar checks into the grammar walker. --- src/compiler/parser.ts | 22 +++++++++++++------ ...torWithIncompleteTypeAnnotation.errors.txt | 5 +---- .../parserConstructorDeclaration11.errors.txt | 5 +---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1cc5e09d680..775ed08ca47 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3373,12 +3373,6 @@ module ts { node.parameters = sig.parameters; node.type = sig.type; node.body = parseAndCheckFunctionBody(/*isConstructor*/ true); - if (node.typeParameters) { - grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); - } - if (node.type) { - grammarErrorOnNode(node.type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); - } return finishNode(node); } @@ -4167,7 +4161,21 @@ module ts { } function visitConstructor(node: ConstructorDeclaration) { - checkParameterList(node.parameters); + checkParameterList(node.parameters) || + checkConstructorTypeParameters(node) || + checkConstructorTypeAnnotation(node); + } + + function checkConstructorTypeParameters(node: ConstructorDeclaration) { + if (node.typeParameters) { + return grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); + } + } + + function checkConstructorTypeAnnotation(node: ConstructorDeclaration) { + if (node.type) { + return grammarErrorOnNode(node.type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration); + } } function visitConstructorType(node: SignatureDeclaration) { diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 696f173e930..c18dfb8e354 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -40,7 +40,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,9): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,26): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(239,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(241,5): error TS1128: Declaration or statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,67): error TS1093: Type annotation cannot appear on a constructor declaration. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,69): error TS1110: Type expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,31): error TS1005: ',' expected. @@ -94,7 +93,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (94 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (93 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -486,8 +485,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T private otherValue = 42; constructor(private value: number, public name: string) : } - -!!! error TS1093: Type annotation cannot appear on a constructor declaration. ~ !!! error TS1110: Type expected. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/parserConstructorDeclaration11.errors.txt b/tests/baselines/reference/parserConstructorDeclaration11.errors.txt index e8a799fc36a..7e5c305fb80 100644 --- a/tests/baselines/reference/parserConstructorDeclaration11.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration11.errors.txt @@ -1,12 +1,9 @@ tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration11.ts(2,14): error TS1098: Type parameter list cannot be empty. -tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration11.ts(2,15): error TS1092: Type parameters cannot appear on a constructor declaration. -==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration11.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration11.ts (1 errors) ==== class C { constructor<>() { } ~~ !!! error TS1098: Type parameter list cannot be empty. - -!!! error TS1092: Type parameters cannot appear on a constructor declaration. } \ No newline at end of file From 6900c8ff81dbc6c14e400c326f6b4473bf016207 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 22:58:11 -0800 Subject: [PATCH 14/60] Move module grammar checks to the grammar checker. --- src/compiler/parser.ts | 24 +++++---- ...DeclarationInModuleDeclaration1.errors.txt | 9 ++++ .../privacyGloImportParseErrors.errors.txt | 26 +--------- .../privacyImportParseErrors.errors.txt | 50 +------------------ .../importDeclarationInModuleDeclaration1.ts | 3 ++ 5 files changed, 29 insertions(+), 83 deletions(-) create mode 100644 tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt create mode 100644 tests/cases/compiler/importDeclarationInModuleDeclaration1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 775ed08ca47..586c9f7e107 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3782,15 +3782,6 @@ module ts { } else { node.body = parseModuleBody(); - forEach((node.body).statements, s => { - if (s.kind === SyntaxKind.ExportAssignment) { - // Export assignments are not allowed in an internal module - grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - else if (s.kind === SyntaxKind.ImportDeclaration && (s).externalModuleName) { - grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); - } - }); } return finishNode(node); } @@ -4122,6 +4113,7 @@ module ts { case SyntaxKind.GetAccessor: return visitGetAccessor(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); case SyntaxKind.Method: return visitMethod(node); + case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); @@ -4291,6 +4283,20 @@ module ts { checkParameterList(node.parameters); } + function visitModuleDeclaration(node: ModuleDeclaration): void { + if (node.name.kind === SyntaxKind.Identifier && node.body.kind === SyntaxKind.ModuleBlock) { + forEach((node.body).statements, s => { + if (s.kind === SyntaxKind.ExportAssignment) { + // Export assignments are not allowed in an internal module + grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + } + else if (s.kind === SyntaxKind.ImportDeclaration && (s).externalModuleName) { + grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + } + }); + } + } + function visitObjectLiteral(node: ObjectLiteral): void { var seen: Map = {}; var Property = 1; diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt new file mode 100644 index 00000000000..82132947ee5 --- /dev/null +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/importDeclarationInModuleDeclaration1.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. + + +==== tests/cases/compiler/importDeclarationInModuleDeclaration1.ts (1 errors) ==== + module m2 { + import m3 = require("use_glo_M1_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. + } \ No newline at end of file diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index b87e6867a8f..0ac0ed35105 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -1,12 +1,4 @@ -tests/cases/compiler/privacyGloImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(69,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(81,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(82,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(121,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(125,13): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/privacyGloImportParseErrors.ts(146,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(149,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -16,7 +8,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambie tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambient external modules cannot be nested in other modules. -==== tests/cases/compiler/privacyGloImportParseErrors.ts (16 errors) ==== +==== tests/cases/compiler/privacyGloImportParseErrors.ts (8 errors) ==== module m1 { export module m1_M1_public { export class c1 { @@ -80,8 +72,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -94,8 +84,6 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie var m1_im3_private_v4_private = m1_im3_private.f1(); import m1_im4_private = require("m1_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M4_private'. export var m1_im4_private_v1_public = m1_im4_private.c1; @@ -110,11 +98,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie export import m1_im1_public = m1_M1_public; export import m1_im2_public = m1_M2_private; export import m1_im3_public = require("m1_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export import m1_im4_public = require("m1_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } module glo_M1_public { @@ -154,14 +138,10 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import errorImport = require("glo_M2_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; module m5 { import m5_errorImport = require("glo_M2_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -191,13 +171,9 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index 3388cdc3b9c..6e901ab2b6d 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -1,22 +1,6 @@ -tests/cases/compiler/privacyImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(69,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(81,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(82,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(143,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(153,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(166,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(167,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(273,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(277,13): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(302,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(306,13): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier. tests/cases/compiler/privacyImportParseErrors.ts(328,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/privacyImportParseErrors.ts(341,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(344,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(350,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(353,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -49,7 +33,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(333,16): error TS2435: Ambient tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient external modules cannot be nested in other modules. -==== tests/cases/compiler/privacyImportParseErrors.ts (49 errors) ==== +==== tests/cases/compiler/privacyImportParseErrors.ts (33 errors) ==== export module m1 { export module m1_M1_public { export class c1 { @@ -113,8 +97,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -127,8 +109,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im3_private_v4_private = m1_im3_private.f1(); import m1_im4_private = require("m1_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M4_private'. export var m1_im4_private_v1_public = m1_im4_private.c1; @@ -143,11 +123,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient export import m1_im1_public = m1_M1_public; export import m1_im2_public = m1_M2_private; export import m1_im3_public = require("m1_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export import m1_im4_public = require("m1_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } module m2 { @@ -213,8 +189,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m2_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm2_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -227,8 +201,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im3_private_v4_private = m1_im3_private.f1(); import m1_im4_private = require("m2_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm2_M4_private'. export var m1_im4_private_v1_public = m1_im4_private.c1; @@ -244,11 +216,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient export import m1_im1_public = m2_M1_public; export import m1_im2_public = m2_M2_private; export import m1_im3_public = require("m2_M3_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export import m1_im4_public = require("m2_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } export module glo_M1_public { @@ -375,14 +343,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M2_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; module m5 { import m5_errorImport = require("glo_M2_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -416,14 +380,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M3_private; module m5 { import m5_errorImport = require("glo_M4_private"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M3_private; } } @@ -481,26 +441,18 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } export module m3 { import m3 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/cases/compiler/importDeclarationInModuleDeclaration1.ts b/tests/cases/compiler/importDeclarationInModuleDeclaration1.ts new file mode 100644 index 00000000000..9f7f9ed7ccd --- /dev/null +++ b/tests/cases/compiler/importDeclarationInModuleDeclaration1.ts @@ -0,0 +1,3 @@ +module m2 { + import m3 = require("use_glo_M1_public"); +} \ No newline at end of file From 07f41dc78690f06bf12962c4a34b0574b44ff9cb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 23:34:26 -0800 Subject: [PATCH 15/60] Move variable statement checks to the grammar checker. --- src/compiler/parser.ts | 128 ++++++++++-------- .../letDeclarations-es5-1.errors.txt | 27 ++++ .../reference/letDeclarations-es5.errors.txt | 20 +-- tests/cases/compiler/letDeclarations-es5-1.ts | 7 + 4 files changed, 110 insertions(+), 72 deletions(-) create mode 100644 tests/baselines/reference/letDeclarations-es5-1.errors.txt create mode 100644 tests/cases/compiler/letDeclarations-es5-1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 586c9f7e107..19f228a2c54 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2721,14 +2721,10 @@ module ts { } // STATEMENTS - function parseStatementAllowingLetDeclaration() { - return parseStatement(/*allowLetAndConstDeclarations*/ true); - } - function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { var node = createNode(SyntaxKind.Block); if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) { - node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatementAllowingLetDeclaration); + node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatement); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -2774,8 +2770,8 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.thenStatement = parseStatement(/*allowLetAndConstDeclarations*/ false); - node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetAndConstDeclarations*/ false) : undefined; + node.thenStatement = parseStatement(); + node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined; return finishNode(node); } @@ -2785,7 +2781,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.statement = parseStatement(); inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); @@ -2810,7 +2806,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.statement = parseStatement(); inIterationStatement = saveInIterationStatement; return finishNode(node); @@ -2883,7 +2879,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - forOrForInStatement.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); + forOrForInStatement.statement = parseStatement(); inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); @@ -2994,7 +2990,7 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.statement = parseStatement(); node = finishNode(node); if (isInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such @@ -3009,7 +3005,7 @@ module ts { parseExpected(SyntaxKind.CaseKeyword); node.expression = parseExpression(); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); return finishNode(node); } @@ -3017,7 +3013,7 @@ module ts { var node = createNode(SyntaxKind.DefaultClause); parseExpected(SyntaxKind.DefaultKeyword); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); return finishNode(node); } @@ -3124,9 +3120,9 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(allowLetAndConstDeclarations: boolean): Statement { + function parseStatementWithLabelSet(): Statement { labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(allowLetAndConstDeclarations); + var statement = parseStatement(); labelledStatementInfo.pop(); return statement; } @@ -3135,7 +3131,7 @@ module ts { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } - function parseLabeledStatement(allowLetAndConstDeclarations: boolean): LabeledStatement { + function parseLabeledStatement(): LabeledStatement { var node = createNode(SyntaxKind.LabeledStatement); node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); @@ -3147,7 +3143,7 @@ module ts { // We only want to call parseStatementWithLabelSet when the label set is complete // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations); + node.statement = isLabel() ? parseLabeledStatement() : parseStatementWithLabelSet(); return finishNode(node); } @@ -3220,7 +3216,7 @@ module ts { } } - function parseStatement(allowLetAndConstDeclarations: boolean): Statement { + function parseStatement(): Statement { switch (token) { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); @@ -3228,7 +3224,7 @@ module ts { case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: // const here should always be parsed as const declaration because of check in 'isStatement' - return parseVariableStatement(allowLetAndConstDeclarations); + return parseVariableStatement(); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); case SyntaxKind.SemicolonToken: @@ -3261,10 +3257,9 @@ module ts { case SyntaxKind.DebuggerKeyword: return parseDebuggerStatement(); default: - if (isLabel()) { - return parseLabeledStatement(allowLetAndConstDeclarations); - } - return parseExpressionStatement(); + return isLabel() + ? parseLabeledStatement() + : parseExpressionStatement(); } } @@ -3307,43 +3302,26 @@ module ts { () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); } - function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { + function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); - if (flags) node.flags = flags; - var errorCountBeforeVarStatement = file._parserDiagnostics.length; + if (flags) { + node.flags = flags; + } + if (token === SyntaxKind.LetKeyword) { node.flags |= NodeFlags.Let; } else if (token === SyntaxKind.ConstKeyword) { node.flags |= NodeFlags.Const; } - else if (token !== SyntaxKind.VarKeyword) { - error(Diagnostics.var_let_or_const_expected); + else { + Debug.assert(token === SyntaxKind.VarKeyword); } + nextToken(); node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false); parseSemicolon(); - finishNode(node); - if (!node.declarations.length && file._parserDiagnostics.length === errorCountBeforeVarStatement) { - grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); - } - if (languageVersion < ScriptTarget.ES6) { - if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } - else if (!allowLetAndConstDeclarations) { - if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); - } - else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); - } - } - return node; + return finishNode(node); } function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionLikeDeclaration { @@ -3895,7 +3873,7 @@ module ts { switch (token) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: - result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags); + result = parseVariableStatement(pos, flags); break; case SyntaxKind.ConstKeyword: var isConstEnum = lookAhead(() => nextToken() === SyntaxKind.EnumKeyword); @@ -3903,7 +3881,7 @@ module ts { result = parseAndCheckEnumDeclaration(pos, flags | NodeFlags.Const); } else { - result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags); + result = parseVariableStatement(pos, flags); } break; case SyntaxKind.FunctionKeyword: @@ -3955,7 +3933,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file._parserDiagnostics.length; - var statement = parseStatement(/*allowLetAndConstDeclarations*/ true); + var statement = parseStatement(); if (inAmbientContext && file._parserDiagnostics.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -4076,10 +4054,14 @@ module ts { // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); - + var parent: Node; visitNode(file); function visitNode(node: Node): void { + var savedParent = parent; + node.parent = parent; + parent = node; + // First recurse and perform all grammar checks on the children of this node. var savedInAmbientContext = inAmbientContext if (node.flags & NodeFlags.Ambient) { @@ -4096,6 +4078,7 @@ module ts { } inAmbientContext = savedInAmbientContext; + parent = savedParent; } function checkNode(node: Node) { @@ -4121,6 +4104,7 @@ module ts { case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); + case SyntaxKind.VariableStatement: return visitVariableStatement(node); } } @@ -4501,6 +4485,44 @@ module ts { reportInvalidUseInStrictMode(node.name); } } + + function visitVariableStatement(node: VariableStatement) { + if (!node.declarations.length) { + grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (!allowLetAndConstDeclarations(node.parent)) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + } + } + } + + function allowLetAndConstDeclarations(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + return false; + case SyntaxKind.LabeledStatement: + return allowLetAndConstDeclarations(node.parent); + } + + return true; + } } export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { diff --git a/tests/baselines/reference/letDeclarations-es5-1.errors.txt b/tests/baselines/reference/letDeclarations-es5-1.errors.txt new file mode 100644 index 00000000000..5eb52d48f52 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5-1.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/letDeclarations-es5-1.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(4,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(5,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/letDeclarations-es5-1.ts (6 errors) ==== + let l1; + ~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l2: number; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l3, l4, l5 :string, l6; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l7 = false; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l8: number = 23; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l9 = 0, l10 :string = "", l11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt index be1a56a8b7f..444bd911124 100644 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -1,34 +1,16 @@ -tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== +==== tests/cases/compiler/letDeclarations-es5.ts (2 errors) ==== let l1; - ~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l2: number; - ~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l3, l4, l5 :string, l6; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l7 = false; - ~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l8: number = 23; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l9 = 0, l10 :string = "", l11 = null; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. for(let l11 in {}) { } ~~~~ diff --git a/tests/cases/compiler/letDeclarations-es5-1.ts b/tests/cases/compiler/letDeclarations-es5-1.ts new file mode 100644 index 00000000000..cd93feeda0d --- /dev/null +++ b/tests/cases/compiler/letDeclarations-es5-1.ts @@ -0,0 +1,7 @@ +// @target: ES5 + let l1; + let l2: number; + let l3, l4, l5 :string, l6; + let l7 = false; + let l8: number = 23; + let l9 = 0, l10 :string = "", l11 = null; \ No newline at end of file From 7fb21a25f692abcb7aa0b67e72ddbe08f403b2e6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 18 Nov 2014 23:43:12 -0800 Subject: [PATCH 16/60] Move catch block checks to the grammar checker. --- src/compiler/parser.ts | 24 ++++++++++++++---------- src/compiler/types.ts | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 19f228a2c54..0a4658f42b5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3089,23 +3089,14 @@ module ts { parseExpected(SyntaxKind.CatchKeyword); parseExpected(SyntaxKind.OpenParenToken); var variable = parseIdentifier(); - var typeAnnotationColonStart = scanner.getTokenPos(); - var typeAnnotationColonLength = scanner.getTextPos() - typeAnnotationColonStart; var typeAnnotation = parseTypeAnnotation(); parseExpected(SyntaxKind.CloseParenToken); var result = parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); result.kind = SyntaxKind.CatchBlock; result.pos = pos; result.variable = variable; + result.type = typeAnnotation; - if (typeAnnotation) { - errorAtPos(typeAnnotationColonStart, typeAnnotationColonLength, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); - } - if (isInStrictMode && isEvalOrArgumentsIdentifier(variable)) { - // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the - // Catch production is eval or arguments - reportInvalidUseInStrictMode(variable); - } return result; } @@ -4086,6 +4077,7 @@ module ts { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.CallSignature: return visitCallSignature(node); + case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.Constructor: return visitConstructor(node); case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); @@ -4136,6 +4128,18 @@ module ts { checkParameterList(node.parameters); } + function visitCatchBlock(node: CatchBlock) { + if (node.type) { + var colonStart = skipTrivia(sourceText, node.variable.end); + grammarErrorAtPos(colonStart, ":".length, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + } + if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.variable)) { + // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the + // Catch production is eval or arguments + reportInvalidUseInStrictMode(node.variable); + } + } + function visitConstructor(node: ConstructorDeclaration) { checkParameterList(node.parameters) || checkConstructorTypeParameters(node) || diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 227034993ca..1e623a26f7e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -584,6 +584,7 @@ module ts { export interface CatchBlock extends Block { variable: Identifier; + type?: TypeNode; } export interface ClassDeclaration extends Declaration { From de63023b1e7c7a007b4451c7e2406cf8f265652f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 00:11:59 -0800 Subject: [PATCH 17/60] Move type parameter checks to the grammar checker. --- src/compiler/parser.ts | 54 +++++++++------- ...ontShowCompilerGeneratedMembers.errors.txt | 8 +-- .../parserConstructorDeclaration12.errors.txt | 61 +++++++++++++++++++ .../parserConstructorDeclaration12.ts | 10 +++ 4 files changed, 105 insertions(+), 28 deletions(-) create mode 100644 tests/baselines/reference/parserConstructorDeclaration12.errors.txt create mode 100644 tests/cases/compiler/parserConstructorDeclaration12.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0a4658f42b5..25b6f11fa5b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1614,14 +1614,7 @@ module ts { function parseTypeParameters(): NodeArray { if (token === SyntaxKind.LessThanToken) { - var pos = getNodePos(); - var result = parseBracketedList(ParsingContext.TypeParameters, parseTypeParameter, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); - if (!result.length) { - var start = getTokenPos(pos); - var length = getNodePos() - start; - errorAtPos(start, length, Diagnostics.Type_parameter_list_cannot_be_empty); - } - return result; + return parseBracketedList(ParsingContext.TypeParameters, parseTypeParameter, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } } @@ -4121,11 +4114,13 @@ module ts { } function visitArrowFunction(node: FunctionExpression) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitCallSignature(node: ConstructorDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitCatchBlock(node: CatchBlock) { @@ -4141,7 +4136,8 @@ module ts { } function visitConstructor(node: ConstructorDeclaration) { - checkParameterList(node.parameters) || + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node); } @@ -4159,11 +4155,13 @@ module ts { } function visitConstructorType(node: SignatureDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitConstructSignature(node: FunctionLikeDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitEnumDeclaration(enumDecl: EnumDeclaration) { @@ -4214,20 +4212,24 @@ module ts { } function visitFunctionDeclaration(node: FunctionLikeDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitFunctionExpression(node: FunctionExpression) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitFunctionType(node: SignatureDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitGetAccessor(node: MethodDeclaration) { - checkParameterList(node.parameters) || - checkAccessor(node); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters) || + checkAccessor(node); } function visitIndexSignature(node: SignatureDeclaration): void { @@ -4268,7 +4270,8 @@ module ts { } function visitMethod(node: MethodDeclaration) { - checkParameterList(node.parameters); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters); } function visitModuleDeclaration(node: ModuleDeclaration): void { @@ -4366,6 +4369,14 @@ module ts { } } + function checkTypeParameterList(typeParameters: NodeArray): boolean { + if (typeParameters && typeParameters.length === 0) { + var start = typeParameters.pos - "<".length; + var end = typeParameters.end + ">".length; + return grammarErrorAtPos(start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); + } + } + function checkParameterList(parameters: NodeArray): boolean { var seenOptionalParameter = false; var parameterCount = parameters.length; @@ -4426,8 +4437,9 @@ module ts { } function visitSetAccessor(node: MethodDeclaration) { - checkParameterList(node.parameters) || - checkAccessor(node); + checkTypeParameterList(node.typeParameters) || + checkParameterList(node.parameters) || + checkAccessor(node); } function checkAccessor(accessor: MethodDeclaration): boolean { diff --git a/tests/baselines/reference/dontShowCompilerGeneratedMembers.errors.txt b/tests/baselines/reference/dontShowCompilerGeneratedMembers.errors.txt index cd2402161c3..5f6f15791f6 100644 --- a/tests/baselines/reference/dontShowCompilerGeneratedMembers.errors.txt +++ b/tests/baselines/reference/dontShowCompilerGeneratedMembers.errors.txt @@ -1,22 +1,16 @@ -tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(3,5): error TS1098: Type parameter list cannot be empty. -tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(3,6): error TS1005: '(' expected. tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(3,6): error TS1139: Type parameter declaration expected. tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(4,1): error TS1109: Expression expected. tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(1,5): error TS2322: Type 'number' is not assignable to type '{ (): any; x: number; }'. Property 'x' is missing in type 'Number'. -==== tests/cases/compiler/dontShowCompilerGeneratedMembers.ts (5 errors) ==== +==== tests/cases/compiler/dontShowCompilerGeneratedMembers.ts (3 errors) ==== var f: { ~ !!! error TS2322: Type 'number' is not assignable to type '{ (): any; x: number; }'. !!! error TS2322: Property 'x' is missing in type 'Number'. x: number; <- - ~ -!!! error TS1098: Type parameter list cannot be empty. - ~ -!!! error TS1005: '(' expected. ~ !!! error TS1139: Type parameter declaration expected. }; diff --git a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt new file mode 100644 index 00000000000..1af651d6ca9 --- /dev/null +++ b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt @@ -0,0 +1,61 @@ +tests/cases/compiler/parserConstructorDeclaration12.ts(2,14): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(3,14): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(4,15): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(5,15): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(6,14): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(7,14): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(8,15): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(9,15): error TS1098: Type parameter list cannot be empty. +tests/cases/compiler/parserConstructorDeclaration12.ts(2,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(3,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(4,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(5,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(6,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(7,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(8,3): error TS2392: Multiple constructor implementations are not allowed. +tests/cases/compiler/parserConstructorDeclaration12.ts(9,3): error TS2392: Multiple constructor implementations are not allowed. + + +==== tests/cases/compiler/parserConstructorDeclaration12.ts (16 errors) ==== + class C { + constructor<>() { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor<> () { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor <>() { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor <> () { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor< >() { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor< > () { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor < >() { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + constructor < > () { } + ~~ +!!! error TS1098: Type parameter list cannot be empty. + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2392: Multiple constructor implementations are not allowed. + } \ No newline at end of file diff --git a/tests/cases/compiler/parserConstructorDeclaration12.ts b/tests/cases/compiler/parserConstructorDeclaration12.ts new file mode 100644 index 00000000000..27d7daff1ef --- /dev/null +++ b/tests/cases/compiler/parserConstructorDeclaration12.ts @@ -0,0 +1,10 @@ +class C { + constructor<>() { } + constructor<> () { } + constructor <>() { } + constructor <> () { } + constructor< >() { } + constructor< > () { } + constructor < >() { } + constructor < > () { } +} \ No newline at end of file From afb035631a104d1016a869719a42f93c479ba4e8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 00:19:26 -0800 Subject: [PATCH 18/60] Move strict check for binary expressions to grammar checker. --- src/compiler/parser.ts | 90 +++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 25b6f11fa5b..c10adae271b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2043,12 +2043,7 @@ module ts { // Now see if we might be in cases '2' or '3'. // If the expression was a LHS expression, and we have an assignment operator, then // we're in '2' or '3'. Consume the assignment and return. - if (isLeftHandSideExpression(expr) && isAssignmentOperator()) { - if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) { - // ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an - // Assignment operator(11.13) or of a PostfixExpression(11.3) - reportInvalidUseInStrictMode(expr); - } + if (isLeftHandSideExpression(expr) && isAssignmentOperator(token)) { var operator = token; nextToken(); return makeBinaryExpression(expr, operator, parseAssignmentExpression(noIn)); @@ -2058,37 +2053,6 @@ module ts { return expr; } - function isLeftHandSideExpression(expr: Expression): boolean { - if (expr) { - switch (expr.kind) { - case SyntaxKind.PropertyAccess: - case SyntaxKind.IndexedAccess: - case SyntaxKind.NewExpression: - case SyntaxKind.CallExpression: - case SyntaxKind.TaggedTemplateExpression: - case SyntaxKind.ArrayLiteral: - case SyntaxKind.ParenExpression: - case SyntaxKind.ObjectLiteral: - case SyntaxKind.FunctionExpression: - case SyntaxKind.Identifier: - case SyntaxKind.Missing: - case SyntaxKind.RegularExpressionLiteral: - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - case SyntaxKind.NoSubstitutionTemplateLiteral: - case SyntaxKind.TemplateExpression: - case SyntaxKind.FalseKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.ThisKeyword: - case SyntaxKind.TrueKeyword: - case SyntaxKind.SuperKeyword: - return true; - } - } - - return false; - } - function parseSimpleArrowFunctionExpression(identifier: Identifier): Expression { Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); parseExpected(SyntaxKind.EqualsGreaterThanToken); @@ -2269,10 +2233,6 @@ module ts { return makeFunctionExpression(SyntaxKind.ArrowFunction, pos, /* name */ undefined, sig, body); } - function isAssignmentOperator(): boolean { - return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment; - } - function parseConditionalExpression(noIn?: boolean): Expression { var expr = parseBinaryExpression(noIn); while (parseOptional(SyntaxKind.QuestionToken)) { @@ -4033,6 +3993,41 @@ module ts { return file; } + function isLeftHandSideExpression(expr: Expression): boolean { + if (expr) { + switch (expr.kind) { + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.NewExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.TaggedTemplateExpression: + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ParenExpression: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.FunctionExpression: + case SyntaxKind.Identifier: + case SyntaxKind.Missing: + case SyntaxKind.RegularExpressionLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateExpression: + case SyntaxKind.FalseKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.ThisKeyword: + case SyntaxKind.TrueKeyword: + case SyntaxKind.SuperKeyword: + return true; + } + } + + return false; + } + + function isAssignmentOperator(token: SyntaxKind): boolean { + return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment; + } + function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { var syntacticDiagnostics = file._syntacticDiagnostics; @@ -4069,6 +4064,7 @@ module ts { // No grammar errors on any of our children. Check this node for grammar errors. switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); case SyntaxKind.CallSignature: return visitCallSignature(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.Constructor: return visitConstructor(node); @@ -4118,6 +4114,18 @@ module ts { checkParameterList(node.parameters); } + function visitBinaryExpression(node: BinaryExpression) { + if (node.flags & NodeFlags.ParsedInStrictMode) { + if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) { + if (isEvalOrArgumentsIdentifier(node.left)) { + // ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an + // Assignment operator(11.13) or of a PostfixExpression(11.3) + reportInvalidUseInStrictMode(node.left); + } + } + } + } + function visitCallSignature(node: ConstructorDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); From cd162cf587e8dd93278431ad2246b63b413e356b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 00:25:37 -0800 Subject: [PATCH 19/60] Move all strict checks to the grammar checker. --- src/compiler/parser.ts | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c10adae271b..71c24e2793c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -999,12 +999,6 @@ module ts { file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } - function reportInvalidUseInStrictMode(node: Identifier): void { - // declarationNameToString cannot be used here since it uses a backreference to 'parent' that is not yet set - var name = sourceText.substring(skipTrivia(sourceText, node.pos), node.end); - grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); - } - function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } @@ -2643,11 +2637,6 @@ module ts { var name = isIdentifier() ? parseIdentifier() : undefined; var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); var body = parseBody(/* ignoreMissingOpenBrace */ false); - if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { - // It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the - // Identifier of a FunctionLikeDeclaration or FunctionExpression or as a formal parameter name(13.1) - reportInvalidUseInStrictMode(name); - } return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body); } @@ -3278,11 +3267,6 @@ module ts { node.parameters = sig.parameters; node.type = sig.type; node.body = parseAndCheckFunctionBody(/*isConstructor*/ false); - if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name) && node.name.kind === SyntaxKind.Identifier) { - // It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the - // Identifier of a FunctionLikeDeclaration or FunctionExpression or as a formal parameter name(13.1) - reportInvalidUseInStrictMode(node.name); - } return finishNode(node); } @@ -4221,12 +4205,22 @@ module ts { function visitFunctionDeclaration(node: FunctionLikeDeclaration) { checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParameterList(node.parameters) || + checkFunctionName(node.name); } function visitFunctionExpression(node: FunctionExpression) { checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParameterList(node.parameters) || + checkFunctionName(node.name); + } + + function checkFunctionName(name: Node) { + if (name && name.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(name)) { + // It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the + // Identifier of a FunctionLikeDeclaration or FunctionExpression or as a formal parameter name(13.1) + return reportInvalidUseInStrictMode(name); + } } function visitFunctionType(node: SignatureDeclaration) { @@ -4372,8 +4366,7 @@ module ts { // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { - reportInvalidUseInStrictMode(node.name); - return true; + return reportInvalidUseInStrictMode(node.name); } } From 7222fd34ecf6334952e20ef98f6aa29f2a1766e2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 00:53:17 -0800 Subject: [PATCH 20/60] Move grammar checking on a trailing comma to the grammar checker. --- src/compiler/parser.ts | 93 +++++++++++++------ ...serErrorRecovery_ParameterList2.errors.txt | 5 +- ...rserErrorRecovery_VariableList1.errors.txt | 5 +- 3 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 71c24e2793c..a7c3c47b62c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1385,14 +1385,12 @@ module ts { } // Parses a comma-delimited list of elements - function parseDelimitedList(kind: ParsingContext, parseElement: () => T, allowTrailingComma: boolean): NodeArray { + function parseDelimitedList(kind: ParsingContext, parseElement: () => T): NodeArray { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = >[]; result.pos = getNodePos(); - // Keep track of how many errors we had before the list started. If we don't see any new - // errors resulting from the list being malformed, we are free to complain about a trailing comma. - var errorCountBeforeParsingList = file._parserDiagnostics.length; + var commaStart = -1; // Meaning the previous token was not a comma while (true) { if (isListElement(kind, /* inErrorRecovery */ false)) { @@ -1425,12 +1423,6 @@ module ts { // was a trailing comma. // Check if the last token was a comma. if (commaStart >= 0) { - if (!allowTrailingComma) { - if (file._parserDiagnostics.length === errorCountBeforeParsingList) { - // Report a grammar error so we don't affect lookahead - grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed); - } - } // Always preserve a trailing comma by marking it on the NodeArray result.hasTrailingComma = true; } @@ -1457,7 +1449,7 @@ module ts { function parseBracketedList(kind: ParsingContext, parseElement: () => T, startToken: SyntaxKind, endToken: SyntaxKind): NodeArray { if (parseExpected(startToken)) { - var result = parseDelimitedList(kind, parseElement, /*allowTrailingComma*/ false); + var result = parseDelimitedList(kind, parseElement); parseExpected(endToken); return result; } @@ -2438,8 +2430,7 @@ module ts { else { parseExpected(SyntaxKind.OpenParenToken); } - callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, - parseArgumentExpression, /*allowTrailingComma*/ false); + callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression); parseExpected(SyntaxKind.CloseParenToken); expr = finishNode(callExpr); continue; @@ -2564,8 +2555,7 @@ module ts { var node = createNode(SyntaxKind.ArrayLiteral); parseExpected(SyntaxKind.OpenBracketToken); if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine; - node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, - parseArrayLiteralElement, /*allowTrailingComma*/ true); + node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArrayLiteralElement); parseExpected(SyntaxKind.CloseBracketToken); return finishNode(node); } @@ -2626,7 +2616,7 @@ module ts { node.flags |= NodeFlags.MultiLine; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember, /*allowTrailingComma*/ true); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -2655,8 +2645,7 @@ module ts { parseExpected(SyntaxKind.NewKeyword); node.func = parseCallAndAccess(parsePrimaryExpression(), /* inNewExpression */ true); if (parseOptional(SyntaxKind.OpenParenToken) || token === SyntaxKind.LessThanToken && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) { - node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, - parseArgumentExpression, /*allowTrailingComma*/ false); + node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression); parseExpected(SyntaxKind.CloseParenToken); } return finishNode(node); @@ -2805,8 +2794,13 @@ module ts { } else { var forStatement = createNode(SyntaxKind.ForStatement, pos); - if (declarations) forStatement.declarations = declarations; - if (varOrInit) forStatement.initializer = varOrInit; + if (declarations) { + forStatement.declarations = declarations; + } + if (varOrInit) { + forStatement.initializer = varOrInit; + } + parseExpected(SyntaxKind.SemicolonToken); if (token !== SyntaxKind.SemicolonToken && token !== SyntaxKind.CloseParenToken) { forStatement.condition = parseExpression(); @@ -3231,8 +3225,7 @@ module ts { } function parseVariableDeclarationList(flags: NodeFlags, noIn?: boolean): NodeArray { - return parseDelimitedList(ParsingContext.VariableDeclarations, - () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); + return parseDelimitedList(ParsingContext.VariableDeclarations, () => parseVariableDeclaration(flags, noIn)); } function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement { @@ -3584,8 +3577,7 @@ module ts { var implementsKeywordLength: number; if (parseOptional(SyntaxKind.ImplementsKeyword)) { implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; - node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, - parseTypeReference, /*allowTrailingComma*/ false); + node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } var errorCountBeforeClassBody = file._parserDiagnostics.length; if (parseExpected(SyntaxKind.OpenBraceToken)) { @@ -3613,8 +3605,7 @@ module ts { var extendsKeywordLength: number; if (parseOptional(SyntaxKind.ExtendsKeyword)) { extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; - node.baseTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, - parseTypeReference, /*allowTrailingComma*/ false); + node.baseTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } var errorCountBeforeInterfaceBody = file._parserDiagnostics.length; node.members = parseTypeLiteral().members; @@ -3657,8 +3648,7 @@ module ts { parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); if (parseExpected(SyntaxKind.OpenBraceToken)) { - node.members = parseDelimitedList(ParsingContext.EnumMembers, - parseEnumMember, /*allowTrailingComma*/ true); + node.members = parseDelimitedList(ParsingContext.EnumMembers, parseEnumMember); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -4049,8 +4039,10 @@ module ts { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); + case SyntaxKind.CallExpression: return visitCallExpression(node); case SyntaxKind.CallSignature: return visitCallSignature(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); + case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); case SyntaxKind.Constructor: return visitConstructor(node); case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); @@ -4060,14 +4052,17 @@ module ts { case SyntaxKind.FunctionType: return visitFunctionType(node); case SyntaxKind.GetAccessor: return visitGetAccessor(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); + case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); case SyntaxKind.Method: return visitMethod(node); case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); + case SyntaxKind.NewExpression: return visitNewExpression(node); case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); + case SyntaxKind.TupleType: return visitTupleType(node); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); case SyntaxKind.VariableStatement: return visitVariableStatement(node); } @@ -4110,6 +4105,19 @@ module ts { } } + function visitCallExpression(node: CallExpression) { + checkForTrailingComma(node.typeArguments) || + checkForTrailingComma(node.arguments); + } + + function checkForTrailingComma(list: NodeArray): boolean { + if (list && list.hasTrailingComma) { + var start = list.end - ",".length; + var end = list.end; + return grammarErrorAtPos(start, end - start, Diagnostics.Trailing_comma_not_allowed); + } + } + function visitCallSignature(node: ConstructorDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); @@ -4127,6 +4135,10 @@ module ts { } } + function visitClassDeclaration(node: ClassDeclaration) { + checkForTrailingComma(node.implementedTypes); + } + function visitConstructor(node: ConstructorDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || @@ -4271,6 +4283,10 @@ module ts { } } + function visitInterfaceDeclaration(node: InterfaceDeclaration) { + checkForTrailingComma(node.baseTypes); + } + function visitMethod(node: MethodDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); @@ -4290,6 +4306,11 @@ module ts { } } + function visitNewExpression(node: NewExpression): void { + checkForTrailingComma(node.typeArguments) || + checkForTrailingComma(node.arguments); + } + function visitObjectLiteral(node: ObjectLiteral): void { var seen: Map = {}; var Property = 1; @@ -4371,6 +4392,10 @@ module ts { } function checkTypeParameterList(typeParameters: NodeArray): boolean { + if (checkForTrailingComma(typeParameters)) { + return true; + } + if (typeParameters && typeParameters.length === 0) { var start = typeParameters.pos - "<".length; var end = typeParameters.end + ">".length; @@ -4379,6 +4404,10 @@ module ts { } function checkParameterList(parameters: NodeArray): boolean { + if (checkForTrailingComma(parameters)) { + return true; + } + var seenOptionalParameter = false; var parameterCount = parameters.length; @@ -4488,6 +4517,10 @@ module ts { } } + function visitTupleType(node: TupleTypeNode) { + checkForTrailingComma(node.elementTypes); + } + function visitVariableDeclaration(node: VariableDeclaration) { if (inAmbientContext && node.initializer) { var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end); @@ -4504,6 +4537,10 @@ module ts { } function visitVariableStatement(node: VariableStatement) { + if (checkForTrailingComma(node.declarations)) { + return; + } + if (!node.declarations.length) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList2.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList2.errors.txt index fd4c286f356..48cd83147d7 100644 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList2.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ParameterList2.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts(1,13): error TS1009: Trailing comma not allowed. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts(1,15): error TS1005: ')' expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts (1 errors) ==== function f(a, { - ~ -!!! error TS1009: Trailing comma not allowed. ~ !!! error TS1005: ')' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt index b69cab688f0..a42ffcdd474 100644 --- a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(1,6): error TS1009: Trailing comma not allowed. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(2,1): error TS1108: A 'return' statement can only be used within a function body. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (1 errors) ==== var a, - ~ -!!! error TS1009: Trailing comma not allowed. return; ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file From 9170962998557a34ab50758e1f1a821b10e3b94d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 02:11:17 -0800 Subject: [PATCH 21/60] Move declaration list checking to the grammar checks. --- src/compiler/checker.ts | 11 ++- src/compiler/emitter.ts | 19 +++-- src/compiler/parser.ts | 81 +++++++++++-------- src/compiler/types.ts | 2 +- .../constDeclarations-es5.errors.txt | 12 +-- .../letDeclarations-es5-1.errors.txt | 24 +++--- .../reference/letDeclarations-es5.errors.txt | 28 +++++-- .../parserForInStatement2.errors.txt | 4 +- .../parserForInStatement3.errors.txt | 4 +- .../parserForInStatement6.errors.txt | 4 +- .../parserForInStatement7.errors.txt | 4 +- .../parserVariableDeclaration6.errors.txt | 4 +- .../parserVariableDeclaration8.errors.txt | 4 +- 13 files changed, 118 insertions(+), 83 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3b4bbf3f73..b947a271be3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7531,10 +7531,13 @@ module ts { // for (var VarDecl in Expr) Statement // VarDecl must be a variable declaration without a type annotation that declares a variable of type Any, // and Expr must be an expression of type Any, an object type, or a type parameter type. - if (node.declaration) { - checkVariableDeclaration(node.declaration); - if (node.declaration.type) { - error(node.declaration, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation); + if (node.declarations) { + if (node.declarations.length >= 1) { + var decl = node.declarations[0]; + checkVariableDeclaration(decl); + if (decl.type) { + error(decl, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation); + } } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1d2274d245c..ef4d02edd14 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1336,15 +1336,18 @@ module ts { var endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); - if (node.declaration) { - if (node.declaration.flags & NodeFlags.Let) { - emitToken(SyntaxKind.LetKeyword, endPos); + if (node.declarations) { + if (node.declarations.length >= 1) { + var decl = node.declarations[0]; + if (decl.flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } + write(" "); + emit(decl); } - else { - emitToken(SyntaxKind.VarKeyword, endPos); - } - write(" "); - emit(node.declaration); } else { emit(node.variable); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a7c3c47b62c..0b4ac1b5cae 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -303,7 +303,7 @@ module ts { child((node).iterator) || child((node).statement); case SyntaxKind.ForInStatement: - return child((node).declaration) || + return children((node).declarations) || child((node).variable) || child((node).expression) || child((node).statement); @@ -2750,27 +2750,12 @@ module ts { if (token !== SyntaxKind.SemicolonToken) { if (parseOptional(SyntaxKind.VarKeyword)) { var declarations = parseVariableDeclarationList(0, /*noIn*/ true); - if (!declarations.length) { - error(Diagnostics.Variable_declaration_list_cannot_be_empty); - } } else if (parseOptional(SyntaxKind.LetKeyword)) { var declarations = parseVariableDeclarationList(NodeFlags.Let, /*noIn*/ true); - if (!declarations.length) { - error(Diagnostics.Variable_declaration_list_cannot_be_empty); - } - if (languageVersion < ScriptTarget.ES6) { - grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } } else if (parseOptional(SyntaxKind.ConstKeyword)) { var declarations = parseVariableDeclarationList(NodeFlags.Const, /*noIn*/ true); - if (!declarations.length) { - error(Diagnostics.Variable_declaration_list_cannot_be_empty); - } - if (languageVersion < ScriptTarget.ES6) { - grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } } else { var varOrInit = parseExpression(true); @@ -2780,10 +2765,7 @@ module ts { if (parseOptional(SyntaxKind.InKeyword)) { var forInStatement = createNode(SyntaxKind.ForInStatement, pos); if (declarations) { - if (declarations.length > 1) { - error(Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); - } - forInStatement.declaration = declarations[0]; + forInStatement.declarations = declarations; } else { forInStatement.variable = varOrInit; @@ -4047,6 +4029,8 @@ module ts { case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); + case SyntaxKind.ForInStatement: return visitForInStatement(node); + case SyntaxKind.ForStatement: return visitForStatement(node); case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); case SyntaxKind.FunctionType: return visitFunctionType(node); @@ -4215,6 +4199,21 @@ module ts { return false; } + function visitForInStatement(node: ForInStatement) { + checkVariableDeclarations(node.declarations) || + checkForMoreThanOneDeclaration(node.declarations); + } + + function visitForStatement(node: ForStatement) { + checkVariableDeclarations(node.declarations); + } + + function checkForMoreThanOneDeclaration(declarations: NodeArray) { + if (declarations && declarations.length > 1) { + return grammarErrorOnNode(declarations[1], Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } + } + function visitFunctionDeclaration(node: FunctionLikeDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || @@ -4536,28 +4535,40 @@ module ts { } } - function visitVariableStatement(node: VariableStatement) { - if (checkForTrailingComma(node.declarations)) { - return; - } + function checkVariableDeclarations(declarations: NodeArray): boolean { + if (declarations) { + if (checkForTrailingComma(declarations)) { + return true; + } - if (!node.declarations.length) { - grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); - } - if (languageVersion < ScriptTarget.ES6) { - if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + if (!declarations.length) { + return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); } - else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + + var decl = declarations[0]; + if (languageVersion < ScriptTarget.ES6) { + if (decl.flags & NodeFlags.Let) { + return grammarErrorOnNode(decl, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (decl.flags & NodeFlags.Const) { + return grammarErrorOnNode(decl, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } } } - else if (!allowLetAndConstDeclarations(node.parent)) { + } + + function visitVariableStatement(node: VariableStatement) { + checkVariableDeclarations(node.declarations) || + checkForDisallowedLetOrConstStatement(node); + } + + function checkForDisallowedLetOrConstStatement(node: VariableStatement) { + if (!allowLetAndConstDeclarations(node.parent)) { if (node.flags & NodeFlags.Let) { - grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + return grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); } else if (node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + return grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1e623a26f7e..17ee1ce6134 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -539,7 +539,7 @@ module ts { } export interface ForInStatement extends IterationStatement { - declaration?: VariableDeclaration; + declarations?: NodeArray; variable?: Expression; expression: Expression; } diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt index 0b830eab05a..c928e6ae48e 100644 --- a/tests/baselines/reference/constDeclarations-es5.errors.txt +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -1,17 +1,17 @@ -tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(2,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(3,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(4,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. ==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== const z7 = false; - ~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. const z8: number = 23; - ~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. const z9 = 0, z10 :string = "", z11 = null; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-es5-1.errors.txt b/tests/baselines/reference/letDeclarations-es5-1.errors.txt index 5eb52d48f52..f0430585a3b 100644 --- a/tests/baselines/reference/letDeclarations-es5-1.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5-1.errors.txt @@ -1,27 +1,27 @@ -tests/cases/compiler/letDeclarations-es5-1.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(4,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(5,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(1,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(2,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(3,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(4,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(5,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5-1.ts(6,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. ==== tests/cases/compiler/letDeclarations-es5-1.ts (6 errors) ==== let l1; - ~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l2: number; - ~~~~~~~~~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l3, l4, l5 :string, l6; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l7 = false; - ~~~~~~~~~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l8: number = 23; - ~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l9 = 0, l10 :string = "", l11 = null; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt index 444bd911124..34bd93dba3c 100644 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -1,22 +1,40 @@ -tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(4,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(7,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(8,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(12,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -==== tests/cases/compiler/letDeclarations-es5.ts (2 errors) ==== +==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== let l1; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l2: number; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l3, l4, l5 :string, l6; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l7 = false; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l8: number = 23; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. let l9 = 0, l10 :string = "", l11 = null; + ~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. for(let l11 in {}) { } - ~~~~ + ~~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. for(let l12 = 0; l12 < 9; l12++) { } - ~~~~~~~~ + ~~~ !!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/parserForInStatement2.errors.txt b/tests/baselines/reference/parserForInStatement2.errors.txt index 30c20036029..1399a323da0 100644 --- a/tests/baselines/reference/parserForInStatement2.errors.txt +++ b/tests/baselines/reference/parserForInStatement2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts(1,10): error TS1123: Variable declaration list cannot be empty. +tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts(1,9): error TS1123: Variable declaration list cannot be empty. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts(1,13): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts (2 errors) ==== for (var in X) { - ~~ + !!! error TS1123: Variable declaration list cannot be empty. ~ !!! error TS2304: Cannot find name 'X'. diff --git a/tests/baselines/reference/parserForInStatement3.errors.txt b/tests/baselines/reference/parserForInStatement3.errors.txt index b3e02edf9f7..aa6eea4397b 100644 --- a/tests/baselines/reference/parserForInStatement3.errors.txt +++ b/tests/baselines/reference/parserForInStatement3.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement3.ts(1,18): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement3.ts(1,13): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement3.ts(1,18): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement3.ts (2 errors) ==== for (var a, b in X) { - ~ + ~ !!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. ~ !!! error TS2304: Cannot find name 'X'. diff --git a/tests/baselines/reference/parserForInStatement6.errors.txt b/tests/baselines/reference/parserForInStatement6.errors.txt index cb04fa4d6f9..a4eaeb12410 100644 --- a/tests/baselines/reference/parserForInStatement6.errors.txt +++ b/tests/baselines/reference/parserForInStatement6.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement6.ts(1,26): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement6.ts(1,17): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement6.ts(1,26): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement6.ts (2 errors) ==== for (var a = 1, b = 2 in X) { - ~ + ~ !!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. ~ !!! error TS2304: Cannot find name 'X'. diff --git a/tests/baselines/reference/parserForInStatement7.errors.txt b/tests/baselines/reference/parserForInStatement7.errors.txt index b351afc8ec5..2371b3453c3 100644 --- a/tests/baselines/reference/parserForInStatement7.errors.txt +++ b/tests/baselines/reference/parserForInStatement7.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,43): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,25): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,43): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts (3 errors) ==== for (var a: number = 1, b: string = "" in X) { - ~ + ~ !!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. ~ !!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. diff --git a/tests/baselines/reference/parserVariableDeclaration6.errors.txt b/tests/baselines/reference/parserVariableDeclaration6.errors.txt index 1dee8ef6820..699f4188c7f 100644 --- a/tests/baselines/reference/parserVariableDeclaration6.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts(1,1): error TS1123: Variable declaration list cannot be empty. +tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts(1,4): error TS1123: Variable declaration list cannot be empty. ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration6.ts (1 errors) ==== var - ~~~ + !!! error TS1123: Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableDeclaration8.errors.txt b/tests/baselines/reference/parserVariableDeclaration8.errors.txt index 77350f226c2..7f14785c1ca 100644 --- a/tests/baselines/reference/parserVariableDeclaration8.errors.txt +++ b/tests/baselines/reference/parserVariableDeclaration8.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts(1,1): error TS1123: Variable declaration list cannot be empty. +tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts(1,4): error TS1123: Variable declaration list cannot be empty. ==== tests/cases/conformance/parser/ecmascript5/VariableDeclarations/parserVariableDeclaration8.ts (1 errors) ==== var ; - ~~~~~ + !!! error TS1123: Variable declaration list cannot be empty. \ No newline at end of file From 90cc44bb2f298cb8f16ec54a7ed0e9ce7777500b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 02:30:16 -0800 Subject: [PATCH 22/60] Move type argument tests to the grammar checker. --- src/compiler/parser.ts | 23 +++++++++++++------ .../instantiateTypeParameter.errors.txt | 5 +--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0b4ac1b5cae..9ec45f91d12 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2457,18 +2457,12 @@ module ts { } function parseTypeArguments(): NodeArray { - var typeArgumentListStart = scanner.getTokenPos(); - var errorCountBeforeTypeParameterList = file._parserDiagnostics.length; // We pass parseSingleTypeArgument instead of parseType as the element parser // because parseSingleTypeArgument knows how to parse a missing type argument. // This is useful for signature help. parseType has the disadvantage that when // it sees a missing type, it changes the LookAheadMode to Error, and the result // is a broken binary expression, which breaks signature help. - var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); - if (!result.length && file._parserDiagnostics.length === errorCountBeforeTypeParameterList) { - grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty); - } - return result; + return parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } function parseSingleTypeArgument(): TypeNode { @@ -4047,6 +4041,7 @@ module ts { case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); case SyntaxKind.TupleType: return visitTupleType(node); + case SyntaxKind.TypeReference: return visitTypeReference(node); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); case SyntaxKind.VariableStatement: return visitVariableStatement(node); } @@ -4091,9 +4086,18 @@ module ts { function visitCallExpression(node: CallExpression) { checkForTrailingComma(node.typeArguments) || + checkForAtLeastOneTypeArgument(node.typeArguments) || checkForTrailingComma(node.arguments); } + function checkForAtLeastOneTypeArgument(typeArguments: NodeArray) { + if (typeArguments && typeArguments.length === 0) { + var start = typeArguments.pos - "<".length; + var end = typeArguments.end + ">".length; + return grammarErrorAtPos(start, end - start, Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function checkForTrailingComma(list: NodeArray): boolean { if (list && list.hasTrailingComma) { var start = list.end - ",".length; @@ -4307,6 +4311,7 @@ module ts { function visitNewExpression(node: NewExpression): void { checkForTrailingComma(node.typeArguments) || + checkForAtLeastOneTypeArgument(node.typeArguments) || checkForTrailingComma(node.arguments); } @@ -4520,6 +4525,10 @@ module ts { checkForTrailingComma(node.elementTypes); } + function visitTypeReference(node: TypeReferenceNode) { + checkForAtLeastOneTypeArgument(node.typeArguments); + } + function visitVariableDeclaration(node: VariableDeclaration) { if (inAmbientContext && node.initializer) { var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end); diff --git a/tests/baselines/reference/instantiateTypeParameter.errors.txt b/tests/baselines/reference/instantiateTypeParameter.errors.txt index 40967ba586f..f56f8a761dd 100644 --- a/tests/baselines/reference/instantiateTypeParameter.errors.txt +++ b/tests/baselines/reference/instantiateTypeParameter.errors.txt @@ -1,16 +1,13 @@ tests/cases/compiler/instantiateTypeParameter.ts(2,5): error TS1131: Property or signature expected. -tests/cases/compiler/instantiateTypeParameter.ts(2,13): error TS1099: Type argument list cannot be empty. tests/cases/compiler/instantiateTypeParameter.ts(3,1): error TS1128: Declaration or statement expected. tests/cases/compiler/instantiateTypeParameter.ts(2,12): error TS2304: Cannot find name 'T'. -==== tests/cases/compiler/instantiateTypeParameter.ts (4 errors) ==== +==== tests/cases/compiler/instantiateTypeParameter.ts (3 errors) ==== interface Foo { var x: T<>; ~~~ !!! error TS1131: Property or signature expected. - ~~ -!!! error TS1099: Type argument list cannot be empty. ~~~ !!! error TS2304: Cannot find name 'T'. } From e5e707709d8b6ff6df136600f53b0ad30cb58892 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 12:26:55 -0800 Subject: [PATCH 23/60] Proper spans for empty type arg/param lists. --- src/compiler/parser.ts | 4 ++-- .../reference/parserConstructorDeclaration12.errors.txt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9ec45f91d12..b27366c953c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4093,7 +4093,7 @@ module ts { function checkForAtLeastOneTypeArgument(typeArguments: NodeArray) { if (typeArguments && typeArguments.length === 0) { var start = typeArguments.pos - "<".length; - var end = typeArguments.end + ">".length; + var end = skipTrivia(sourceText, typeArguments.end) + ">".length; return grammarErrorAtPos(start, end - start, Diagnostics.Type_argument_list_cannot_be_empty); } } @@ -4402,7 +4402,7 @@ module ts { if (typeParameters && typeParameters.length === 0) { var start = typeParameters.pos - "<".length; - var end = typeParameters.end + ">".length; + var end = skipTrivia(sourceText, typeParameters.end) + ">".length; return grammarErrorAtPos(start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); } } diff --git a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt index 1af651d6ca9..949098e91da 100644 --- a/tests/baselines/reference/parserConstructorDeclaration12.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration12.errors.txt @@ -39,22 +39,22 @@ tests/cases/compiler/parserConstructorDeclaration12.ts(9,3): error TS2392: Multi ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor< >() { } - ~~ + ~~~ !!! error TS1098: Type parameter list cannot be empty. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor< > () { } - ~~ + ~~~ !!! error TS1098: Type parameter list cannot be empty. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor < >() { } - ~~ + ~~~ !!! error TS1098: Type parameter list cannot be empty. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. constructor < > () { } - ~~ + ~~~ !!! error TS1098: Type parameter list cannot be empty. ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2392: Multiple constructor implementations are not allowed. From abbd89aa2b11a99a79e2c1440dda24b927bef9d8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 12:43:19 -0800 Subject: [PATCH 24/60] MOve switch checks to the grammar checker. --- src/compiler/parser.ts | 30 ++++++++++++------- ...hStatementsWithMultipleDefaults.errors.txt | 26 +--------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b27366c953c..4b3443334fd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2947,16 +2947,6 @@ module ts { inSwitchStatement = saveInSwitchStatement; parseExpected(SyntaxKind.CloseBraceToken); - - // Error on duplicate 'default' clauses. - var defaultClauses: CaseOrDefaultClause[] = filter(node.clauses, clause => clause.kind === SyntaxKind.DefaultClause); - for (var i = 1, n = defaultClauses.length; i < n; i++) { - var clause = defaultClauses[i]; - var start = skipTrivia(file.text, clause.pos); - var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; - grammarErrorAtPos(start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); - } - return finishNode(node); } @@ -4039,6 +4029,7 @@ module ts { case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); + case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); case SyntaxKind.TupleType: return visitTupleType(node); case SyntaxKind.TypeReference: return visitTypeReference(node); @@ -4515,6 +4506,25 @@ module ts { } } + function visitSwitchStatement(node: SwitchStatement) { + var firstDefaultClause: CaseOrDefaultClause; + + // Error on duplicate 'default' clauses. + for (var i = 0, n = node.clauses.length; i < n; i++) { + var clause = node.clauses[i]; + if (clause.kind === SyntaxKind.DefaultClause) { + if (firstDefaultClause === undefined) { + firstDefaultClause = clause; + } + else { + var start = skipTrivia(file.text, clause.pos); + var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; + grammarErrorAtPos(start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); + } + } + } + } + function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { if (languageVersion < ScriptTarget.ES6) { grammarErrorOnNode(node, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt index 28c86a7f0f2..cd892f5faa2 100644 --- a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt @@ -1,15 +1,7 @@ -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(9,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(10,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(21,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(25,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(26,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,22): error TS1108: A 'return' statement can only be used within a function body. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (9 errors) ==== +==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (1 errors) ==== var x = 10; @@ -19,11 +11,7 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS111 default: // No issues. break; default: // Error; second 'default' clause. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: // Error; third 'default' clause. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. case 3: x *= x; } @@ -35,27 +23,15 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS111 switch (x * x) { default: // No issues. default: // Error; second 'default' clause. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. break; case 10000: x /= x; default: // Error, third 'default' clause - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. def\u0061ult: // Error, fourth 'default' clause. - ~~~~~~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. // Errors on fifth-seventh default: return; - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. default: default: - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. } } \ No newline at end of file From 8b832a57137f3feb435f46d4f5233395c7163eef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 13:26:15 -0800 Subject: [PATCH 25/60] Move ambient statement checks to the grammar checker. --- src/compiler/parser.ts | 85 +++++++++++++------ .../accessorsInAmbientContext.errors.txt | 24 +++--- .../reference/ambientGetters.errors.txt | 6 +- .../reference/ambientStatement1.errors.txt | 14 +++ tests/baselines/reference/giant.errors.txt | 35 +------- .../initializersInDeclarations.errors.txt | 5 +- .../reference/parserAccessors5.errors.txt | 6 +- ...StatementsWithMultipleDefaults1.errors.txt | 21 +++++ tests/cases/compiler/ambientStatement1.ts | 5 ++ .../switchStatementsWithMultipleDefaults1.ts | 12 +++ 10 files changed, 133 insertions(+), 80 deletions(-) create mode 100644 tests/baselines/reference/ambientStatement1.errors.txt create mode 100644 tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt create mode 100644 tests/cases/compiler/ambientStatement1.ts create mode 100644 tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4b3443334fd..cbe589f5f04 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3810,20 +3810,9 @@ module ts { } function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement { - if (isDeclarationStart()) { - return parseDeclaration(modifierContext); - } - - var statementStart = scanner.getTokenPos(); - var statementFirstTokenLength = scanner.getTextPos() - statementStart; - var errorCountBeforeStatement = file._parserDiagnostics.length; - var statement = parseStatement(); - - if (inAmbientContext && file._parserDiagnostics.length === errorCountBeforeStatement) { - grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); - } - - return statement; + return isDeclarationStart() + ? parseDeclaration(modifierContext) + : parseStatement(); } function processReferenceComments(): ReferenceComments { @@ -3970,6 +3959,7 @@ module ts { function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { var syntacticDiagnostics = file._syntacticDiagnostics; + var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText); // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); @@ -3977,31 +3967,44 @@ module ts { visitNode(file); function visitNode(node: Node): void { + // Store and restore our recursive state here. var savedParent = parent; node.parent = parent; parent = node; - // First recurse and perform all grammar checks on the children of this node. var savedInAmbientContext = inAmbientContext if (node.flags & NodeFlags.Ambient) { inAmbientContext = true; } - var diagnosticCount = syntacticDiagnostics.length; - forEachChild(node, visitNode); - - // If any children had an grammar error, then skip reporting errors for this node or - // anything higher. - if (diagnosticCount === syntacticDiagnostics.length) { - checkNode(node); - } + checkNode(node); inAmbientContext = savedInAmbientContext; parent = savedParent; } function checkNode(node: Node) { - // No grammar errors on any of our children. Check this node for grammar errors. + // First, check if you have a statement in a place where it is not allowed. We want + // to do this before recursing, because we'd prefer to report these errors at the top + // level instead of at some nested level. + if (checkForStatementInAmbientContext(node)) { + return; + } + + // Now recurse and perform all grammar checks on the children of this node. + var diagnosticCount = syntacticDiagnostics.length; + forEachChild(node, visitNode); + + // if we got any errors, just stop performing any more checks on this node or higher. + if (diagnosticCount !== syntacticDiagnostics.length) { + return; + } + + // Now do node specific checks. + dispatch(node); + } + + function dispatch(node: Node) { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); @@ -4038,6 +4041,15 @@ module ts { } } + function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { + var start = skipTrivia(sourceText, node.pos); + scanner.setTextPos(start); + scanner.scan(); + var end = scanner.getTextPos(); + file._syntacticDiagnostics.push(createFileDiagnostic(file, start, end - start, message, arg0, arg1, arg2)); + return true; + } + function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { var span = getErrorSpanForNode(node); var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; @@ -4058,6 +4070,31 @@ module ts { return grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } + function checkForStatementInAmbientContext(node: Node): boolean { + if (inAmbientContext) { + switch (node.kind) { + case SyntaxKind.Block: + case SyntaxKind.EmptyStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ContinueStatement: + case SyntaxKind.BreakStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.DebuggerStatement: + case SyntaxKind.LabeledStatement: + case SyntaxKind.ExpressionStatement: + return grammarErrorOnFirstToken(node, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); + } + } + } + function visitArrowFunction(node: FunctionExpression) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); diff --git a/tests/baselines/reference/accessorsInAmbientContext.errors.txt b/tests/baselines/reference/accessorsInAmbientContext.errors.txt index ada59f21f65..6028dc898f6 100644 --- a/tests/baselines/reference/accessorsInAmbientContext.errors.txt +++ b/tests/baselines/reference/accessorsInAmbientContext.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/accessorsInAmbientContext.ts(4,13): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/compiler/accessorsInAmbientContext.ts(4,19): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/accessorsInAmbientContext.ts(5,13): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(7,20): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/compiler/accessorsInAmbientContext.ts(7,26): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/accessorsInAmbientContext.ts(8,20): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(13,9): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/compiler/accessorsInAmbientContext.ts(13,15): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/accessorsInAmbientContext.ts(14,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(16,16): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/compiler/accessorsInAmbientContext.ts(16,22): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An accessor cannot be declared in an ambient context. @@ -13,15 +13,15 @@ tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An acces declare module M { class C { get X() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. set X(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. static get Y() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. static set Y(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. @@ -30,15 +30,15 @@ tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An acces declare class C { get X() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. set X(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. static get Y() { return 1; } - ~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. static set Y(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. diff --git a/tests/baselines/reference/ambientGetters.errors.txt b/tests/baselines/reference/ambientGetters.errors.txt index a56020c41fb..085b30b758e 100644 --- a/tests/baselines/reference/ambientGetters.errors.txt +++ b/tests/baselines/reference/ambientGetters.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/ambientGetters.ts(3,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/ambientGetters.ts(7,9): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/compiler/ambientGetters.ts(7,20): error TS1036: Statements are not allowed in ambient contexts. ==== tests/cases/compiler/ambientGetters.ts (2 errors) ==== @@ -12,6 +12,6 @@ tests/cases/compiler/ambientGetters.ts(7,9): error TS1086: An accessor cannot be declare class B { get length() { return 0; } - ~~~~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. } \ No newline at end of file diff --git a/tests/baselines/reference/ambientStatement1.errors.txt b/tests/baselines/reference/ambientStatement1.errors.txt new file mode 100644 index 00000000000..be7c7bb750c --- /dev/null +++ b/tests/baselines/reference/ambientStatement1.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/ambientStatement1.ts(2,6): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/ambientStatement1.ts(4,20): error TS1039: Initializers are not allowed in ambient contexts. + + +==== tests/cases/compiler/ambientStatement1.ts (2 errors) ==== + declare module M1 { + while(true); + ~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. + + export var v1 = () => false; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + } \ No newline at end of file diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index 0aa14ee0cd3..e7785cb0cda 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -30,9 +30,7 @@ tests/cases/compiler/giant.ts(254,21): error TS1037: A function implementation c tests/cases/compiler/giant.ts(255,31): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(257,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(262,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(262,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(267,30): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(267,33): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(283,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(285,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(287,5): error TS1005: '{' expected. @@ -65,9 +63,7 @@ tests/cases/compiler/giant.ts(512,21): error TS1037: A function implementation c tests/cases/compiler/giant.ts(513,31): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(515,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(520,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(520,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(525,30): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(525,33): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(532,31): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(534,20): error TS1111: A constructor implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(537,17): error TS1037: A function implementation cannot be declared in an ambient context. @@ -80,29 +76,22 @@ tests/cases/compiler/giant.ts(548,17): error TS1037: A function implementation c tests/cases/compiler/giant.ts(549,27): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(551,18): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(556,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(556,21): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(561,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(563,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(606,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(606,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(611,30): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(611,33): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(615,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(616,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(616,39): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(616,42): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(617,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(618,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(621,26): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(621,29): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(623,24): error TS1111: A constructor implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(626,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(628,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(672,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(672,25): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(676,30): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(676,33): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(23,12): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. @@ -239,7 +228,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (239 errors) ==== +==== tests/cases/compiler/giant.ts (228 errors) ==== /* Prefixes @@ -686,8 +675,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all function F() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } @@ -695,8 +682,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export function eF() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } @@ -1134,8 +1119,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all function F() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } @@ -1143,8 +1126,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export function eF() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } @@ -1224,8 +1205,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all function F() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. class C { constructor () { } ~ @@ -1286,8 +1265,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all function F() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } @@ -1295,8 +1272,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export function eF() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } @@ -1308,8 +1283,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export declare class eaC { } ~~~~~~~ !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. @@ -1321,8 +1294,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export function eF() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { constructor () { } ~ @@ -1384,16 +1355,12 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all function F() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. class C { } module M { } export var eV; export function eF() { }; ~ !!! error TS1037: A function implementation cannot be declared in an ambient context. - ~ -!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } diff --git a/tests/baselines/reference/initializersInDeclarations.errors.txt b/tests/baselines/reference/initializersInDeclarations.errors.txt index 49a06cf9a29..f91220c91a1 100644 --- a/tests/baselines/reference/initializersInDeclarations.errors.txt +++ b/tests/baselines/reference/initializersInDeclarations.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,7): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,14): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(7,16): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(16,2): error TS1036: Statements are not allowed in ambient contexts. -==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (4 errors) ==== +==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (3 errors) ==== // Errors: Initializers & statements in declaration file @@ -27,8 +26,6 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(16,2): err declare module M1 { while(true); - ~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. export var v1 = () => false; } \ No newline at end of file diff --git a/tests/baselines/reference/parserAccessors5.errors.txt b/tests/baselines/reference/parserAccessors5.errors.txt index b7dcd8ef923..f2e3d8c8d37 100644 --- a/tests/baselines/reference/parserAccessors5.errors.txt +++ b/tests/baselines/reference/parserAccessors5.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,15): error TS1036: Statements are not allowed in ambient contexts. ==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts (1 errors) ==== declare class C { get foo() { return 0; } - ~~~ -!!! error TS1086: An accessor cannot be declared in an ambient context. + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. } \ No newline at end of file diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt new file mode 100644 index 00000000000..80b0560445a --- /dev/null +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts(8,9): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts(9,9): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. + + +==== tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts (2 errors) ==== + var x = 10; + + switch (x) { + case 1: + case 2: + default: // No issues. + break; + default: // Error; second 'default' clause. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. + default: // Error; third 'default' clause. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. + case 3: + x *= x; + } \ No newline at end of file diff --git a/tests/cases/compiler/ambientStatement1.ts b/tests/cases/compiler/ambientStatement1.ts new file mode 100644 index 00000000000..b2d1bb9d499 --- /dev/null +++ b/tests/cases/compiler/ambientStatement1.ts @@ -0,0 +1,5 @@ + declare module M1 { + while(true); + + export var v1 = () => false; + } \ No newline at end of file diff --git a/tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts b/tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts new file mode 100644 index 00000000000..f449cf9beb7 --- /dev/null +++ b/tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts @@ -0,0 +1,12 @@ + var x = 10; + + switch (x) { + case 1: + case 2: + default: // No issues. + break; + default: // Error; second 'default' clause. + default: // Error; third 'default' clause. + case 3: + x *= x; + } \ No newline at end of file From 65918be5e154cdf5afb42261056990871122baee Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 13:36:13 -0800 Subject: [PATCH 26/60] Move heritage checks to the grammar checker. --- src/compiler/parser.ts | 28 ++++++++----------- ...very_ExtendsOrImplementsClause4.errors.txt | 4 +-- ...very_ExtendsOrImplementsClause6.errors.txt | 4 +-- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cbe589f5f04..54f7a806f3d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3533,16 +3533,13 @@ module ts { function parseClassDeclaration(pos: number, flags: NodeFlags): ClassDeclaration { var node = createNode(SyntaxKind.ClassDeclaration, pos); node.flags = flags; - var errorCountBeforeClassDeclaration = file._parserDiagnostics.length; parseExpected(SyntaxKind.ClassKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); // TODO(jfreeman): Parse arbitrary sequence of heritage clauses and error for order and duplicates + node.baseType = parseOptional(SyntaxKind.ExtendsKeyword) ? parseTypeReference() : undefined; - var implementsKeywordStart = scanner.getTokenPos(); - var implementsKeywordLength: number; if (parseOptional(SyntaxKind.ImplementsKeyword)) { - implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart; node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } var errorCountBeforeClassBody = file._parserDiagnostics.length; @@ -3553,31 +3550,20 @@ module ts { else { node.members = createMissingList(); } - if (node.implementedTypes && !node.implementedTypes.length && errorCountBeforeClassBody === errorCountBeforeClassDeclaration) { - grammarErrorAtPos(implementsKeywordStart, implementsKeywordLength, Diagnostics._0_list_cannot_be_empty, "implements"); - } return finishNode(node); } function parseInterfaceDeclaration(pos: number, flags: NodeFlags): InterfaceDeclaration { var node = createNode(SyntaxKind.InterfaceDeclaration, pos); node.flags = flags; - var errorCountBeforeInterfaceDeclaration = file._parserDiagnostics.length; parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); // TODO(jfreeman): Parse arbitrary sequence of heritage clauses and error for order and duplicates - var extendsKeywordStart = scanner.getTokenPos(); - var extendsKeywordLength: number; if (parseOptional(SyntaxKind.ExtendsKeyword)) { - extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart; node.baseTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } - var errorCountBeforeInterfaceBody = file._parserDiagnostics.length; node.members = parseTypeLiteral().members; - if (node.baseTypes && !node.baseTypes.length && errorCountBeforeInterfaceBody === errorCountBeforeInterfaceDeclaration) { - grammarErrorAtPos(extendsKeywordStart, extendsKeywordLength, Diagnostics._0_list_cannot_be_empty, "extends"); - } return finishNode(node); } @@ -4152,7 +4138,14 @@ module ts { } function visitClassDeclaration(node: ClassDeclaration) { - checkForTrailingComma(node.implementedTypes); + checkForTrailingComma(node.implementedTypes) || + checkForAtLeastOneHeritageClause(node.implementedTypes, "implements"); + } + + function checkForAtLeastOneHeritageClause(types: NodeArray, listType: string): boolean { + if (types && types.length === 0) { + return grammarErrorAtPos(types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType) + } } function visitConstructor(node: ConstructorDeclaration) { @@ -4315,7 +4308,8 @@ module ts { } function visitInterfaceDeclaration(node: InterfaceDeclaration) { - checkForTrailingComma(node.baseTypes); + checkForTrailingComma(node.baseTypes) || + checkForAtLeastOneHeritageClause(node.baseTypes, "extends"); } function visitMethod(node: MethodDeclaration) { diff --git a/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause4.errors.txt b/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause4.errors.txt index 6ec231b9336..6d637831c45 100644 --- a/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause4.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause4.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,19): error TS1097: 'implements' list cannot be empty. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,29): error TS1097: 'implements' list cannot be empty. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,17): error TS2304: Cannot find name 'A'. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts (2 errors) ==== class C extends A implements { - ~~~~~~~~~~ + !!! error TS1097: 'implements' list cannot be empty. ~ !!! error TS2304: Cannot find name 'A'. diff --git a/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause6.errors.txt b/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause6.errors.txt index 1f235691df8..2f7ca3d99ae 100644 --- a/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause6.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ExtendsOrImplementsClause6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause6.ts(1,13): error TS1097: 'extends' list cannot be empty. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause6.ts(1,20): error TS1097: 'extends' list cannot be empty. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause6.ts (1 errors) ==== interface I extends { } - ~~~~~~~ + !!! error TS1097: 'extends' list cannot be empty. \ No newline at end of file From 67afd6d570b5f7fabd93ed7517e60e66e4672dd8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 14:01:03 -0800 Subject: [PATCH 27/60] Move ambient function block checks to the grammar checker. --- src/compiler/parser.ts | 37 ++-- .../reference/ambientErrors.errors.txt | 17 +- .../reference/exportDeclareClass1.errors.txt | 8 +- tests/baselines/reference/giant.errors.txt | 164 +----------------- .../initializersInDeclarations.errors.txt | 5 +- .../parserFunctionDeclaration2.d.errors.txt | 5 +- 6 files changed, 27 insertions(+), 209 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 54f7a806f3d..610288da1a7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3156,21 +3156,16 @@ module ts { } } - function parseAndCheckFunctionBody(isConstructor: boolean): Block { - var initialPosition = scanner.getTokenPos(); - var errorCountBeforeBody = file._parserDiagnostics.length; + function parseFunctionBlockOrSemicolon(): Block { if (token === SyntaxKind.OpenBraceToken) { - var body = parseBody(/* ignoreMissingOpenBrace */ false); - if (body && inAmbientContext && file._parserDiagnostics.length === errorCountBeforeBody) { - var diagnostic = isConstructor ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; - grammarErrorAtPos(initialPosition, 1, diagnostic); - } - return body; + return parseBody(/* ignoreMissingOpenBrace */ false); } + if (canParseSemicolon()) { parseSemicolon(); return undefined; } + error(Diagnostics.Block_or_expected); // block or ';' expected } @@ -3225,7 +3220,7 @@ module ts { node.typeParameters = sig.typeParameters; node.parameters = sig.parameters; node.type = sig.type; - node.body = parseAndCheckFunctionBody(/*isConstructor*/ false); + node.body = parseFunctionBlockOrSemicolon(); return finishNode(node); } @@ -3237,7 +3232,7 @@ module ts { node.typeParameters = sig.typeParameters; node.parameters = sig.parameters; node.type = sig.type; - node.body = parseAndCheckFunctionBody(/*isConstructor*/ true); + node.body = parseFunctionBlockOrSemicolon(); return finishNode(node); } @@ -3258,7 +3253,7 @@ module ts { method.typeParameters = sig.typeParameters; method.parameters = sig.parameters; method.type = sig.type; - method.body = parseAndCheckFunctionBody(/*isConstructor*/ false); + method.body = parseFunctionBlockOrSemicolon(); return finishNode(method); } else { @@ -4152,7 +4147,8 @@ module ts { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || checkConstructorTypeParameters(node) || - checkConstructorTypeAnnotation(node); + checkConstructorTypeAnnotation(node) || + checkForBodyInAmbientContext(node.body, /*isConstructor:*/ true); } function checkConstructorTypeParameters(node: ConstructorDeclaration) { @@ -4242,7 +4238,8 @@ module ts { function visitFunctionDeclaration(node: FunctionLikeDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || - checkFunctionName(node.name); + checkFunctionName(node.name) || + checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false); } function visitFunctionExpression(node: FunctionExpression) { @@ -4314,7 +4311,17 @@ module ts { function visitMethod(node: MethodDeclaration) { checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParameterList(node.parameters) || + checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false); + } + + function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean { + if (inAmbientContext && body && body.kind === SyntaxKind.FunctionBlock) { + var diagnostic = isConstructor + ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context + : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; + return grammarErrorOnFirstToken(body, diagnostic); + } } function visitModuleDeclaration(node: ModuleDeclaration): void { diff --git a/tests/baselines/reference/ambientErrors.errors.txt b/tests/baselines/reference/ambientErrors.errors.txt index e89586275a3..a1e85be7401 100644 --- a/tests/baselines/reference/ambientErrors.errors.txt +++ b/tests/baselines/reference/ambientErrors.errors.txt @@ -1,10 +1,5 @@ -tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/ambient/ambientErrors.ts(35,19): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/ambient/ambientErrors.ts(37,18): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(38,11): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/ambient/ambientErrors.ts(39,23): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/conformance/ambient/ambientErrors.ts(40,14): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/conformance/ambient/ambientErrors.ts(41,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/ambient/ambientErrors.ts(6,1): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/ambient/ambientErrors.ts(17,22): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/ambient/ambientErrors.ts(47,20): error TS2435: Ambient external modules cannot be nested in other modules. @@ -12,7 +7,7 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient e tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements. -==== tests/cases/conformance/ambient/ambientErrors.ts (12 errors) ==== +==== tests/cases/conformance/ambient/ambientErrors.ts (7 errors) ==== // Ambient variable with an initializer declare var x = 4; @@ -37,8 +32,6 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export // Ambient function with function body declare function fn4() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. // Ambient enum with non - integer literal constant member declare enum E1 { @@ -54,8 +47,6 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export declare module M1 { var x = 3; function fn() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { static x = 3; ~ @@ -64,14 +55,8 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export ~ !!! error TS1039: Initializers are not allowed in ambient contexts. constructor() { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. fn() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static sfn() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. } } diff --git a/tests/baselines/reference/exportDeclareClass1.errors.txt b/tests/baselines/reference/exportDeclareClass1.errors.txt index 36103269f83..c93dc5d0b01 100644 --- a/tests/baselines/reference/exportDeclareClass1.errors.txt +++ b/tests/baselines/reference/exportDeclareClass1.errors.txt @@ -1,19 +1,13 @@ -tests/cases/compiler/exportDeclareClass1.ts(2,21): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/exportDeclareClass1.ts(2,24): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/exportDeclareClass1.ts(3,31): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/exportDeclareClass1.ts(3,34): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -==== tests/cases/compiler/exportDeclareClass1.ts (4 errors) ==== +==== tests/cases/compiler/exportDeclareClass1.ts (2 errors) ==== export declare class eaC { static tF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. static tsF(param:any) { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. }; diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index e7785cb0cda..d70ac7013dd 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -10,27 +10,12 @@ tests/cases/compiler/giant.ts(93,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(95,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(99,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(101,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(154,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(168,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(170,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(172,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(174,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(178,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(180,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(233,39): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(238,35): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(240,24): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(243,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(244,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(245,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(247,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(249,23): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(251,32): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(254,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(255,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(257,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(262,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(267,30): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(283,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(285,5): error TS1005: '{' expected. tests/cases/compiler/giant.ts(287,5): error TS1005: '{' expected. @@ -43,55 +28,16 @@ tests/cases/compiler/giant.ts(351,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(353,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(357,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(359,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(412,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(426,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(428,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(430,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(432,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(436,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(438,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(491,39): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(496,35): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(498,24): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(501,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(502,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(503,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(505,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(507,23): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(509,32): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(512,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(513,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(515,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(520,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(525,30): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(532,31): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(534,20): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(537,17): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(538,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(539,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(541,27): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(543,19): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(545,28): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(548,17): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(549,27): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(551,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(556,18): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(561,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(563,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(606,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(611,30): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(615,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(616,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/giant.ts(616,39): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(617,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(618,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/giant.ts(621,26): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(623,24): error TS1111: A constructor implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(626,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(628,21): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(672,22): error TS1037: A function implementation cannot be declared in an ambient context. -tests/cases/compiler/giant.ts(676,30): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/compiler/giant.ts(23,12): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. @@ -228,7 +174,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (228 errors) ==== +==== tests/cases/compiler/giant.ts (174 errors) ==== /* Prefixes @@ -471,8 +417,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } @@ -596,54 +540,36 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) @@ -651,19 +577,13 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() @@ -673,15 +593,11 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export declare module eaM { var V; function F() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { } interface I { } module M { } export var eV; export function eF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export class eC { } export interface eI { } export module eM { } @@ -915,8 +831,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } @@ -1040,54 +954,36 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) @@ -1095,19 +991,13 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() @@ -1117,15 +1007,11 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export declare module eaM { var V; function F() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { } interface I { } module M { } export var eV; export function eF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export class eC { } export interface eI { } export module eM { } @@ -1133,47 +1019,31 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all } export declare var eaV; export declare function eaF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) @@ -1181,19 +1051,13 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() @@ -1203,21 +1067,13 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export declare module eaM { var V; function F() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { constructor () { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static tV; static tF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. } interface I { //Call Signature @@ -1263,15 +1119,11 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all module M { var V; function F() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { } interface I { } module M { } export var eV; export function eF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export class eC { } export interface eI { } export module eM { } @@ -1281,8 +1133,6 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export declare function eaF() { }; ~~~~~~~ !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { } ~~~~~~~ !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. @@ -1292,21 +1142,13 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all } export var eV; export function eF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export class eC { constructor () { } - ~ -!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. static tV static tF() { } - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. } export interface eI { //Call Signature @@ -1353,14 +1195,10 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { var V; function F() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. class C { } module M { } export var eV; export function eF() { }; - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. export class eC { } export interface eI { } export module eM { } diff --git a/tests/baselines/reference/initializersInDeclarations.errors.txt b/tests/baselines/reference/initializersInDeclarations.errors.txt index f91220c91a1..9e02a1cd747 100644 --- a/tests/baselines/reference/initializersInDeclarations.errors.txt +++ b/tests/baselines/reference/initializersInDeclarations.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,7): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,14): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(7,16): error TS1037: A function implementation cannot be declared in an ambient context. -==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (3 errors) ==== +==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (2 errors) ==== // Errors: Initializers & statements in declaration file @@ -15,8 +14,6 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(7,16): err ~ !!! error TS1039: Initializers are not allowed in ambient contexts. fn(): boolean { - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. return false; } } diff --git a/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt b/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt index 76d47a0a9d4..f623642e827 100644 --- a/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt +++ b/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt @@ -1,11 +1,8 @@ tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. -tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts(1,14): error TS1037: A function implementation cannot be declared in an ambient context. -==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts (1 errors) ==== function F() { ~~~~~~~~ !!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - ~ -!!! error TS1037: A function implementation cannot be declared in an ambient context. } \ No newline at end of file From 9ca17f9b2940e21a4172a81e28b0facd4963b162 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 14:07:25 -0800 Subject: [PATCH 28/60] Move with checks to the grammar checker. --- src/compiler/parser.ts | 27 ++++++++++--------- .../methodInAmbientClass1.errors.txt | 13 +++++++++ tests/cases/compiler/methodInAmbientClass1.ts | 4 +++ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 tests/baselines/reference/methodInAmbientClass1.errors.txt create mode 100644 tests/cases/compiler/methodInAmbientClass1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 610288da1a7..b20c8959307 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2896,20 +2896,12 @@ module ts { function parseWithStatement(): WithStatement { var node = createNode(SyntaxKind.WithStatement); - var startPos = scanner.getTokenPos(); parseExpected(SyntaxKind.WithKeyword); - var endPos = scanner.getStartPos(); parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); node.statement = parseStatement(); - node = finishNode(node); - if (isInStrictMode) { - // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such - // a context is an - grammarErrorAtPos(startPos, endPos - startPos, Diagnostics.with_statements_are_not_allowed_in_strict_mode); - } - return node; + return finishNode(node); } function parseCaseClause(): CaseOrDefaultClause { @@ -4019,6 +4011,7 @@ module ts { case SyntaxKind.TypeReference: return visitTypeReference(node); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); case SyntaxKind.VariableStatement: return visitVariableStatement(node); + case SyntaxKind.WithStatement: return visitWithStatement(node); } } @@ -4630,8 +4623,8 @@ module ts { } } - function allowLetAndConstDeclarations(node: Node): boolean { - switch (node.kind) { + function allowLetAndConstDeclarations(parent: Node): boolean { + switch (parent.kind) { case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: @@ -4640,11 +4633,19 @@ module ts { case SyntaxKind.ForInStatement: return false; case SyntaxKind.LabeledStatement: - return allowLetAndConstDeclarations(node.parent); + return allowLetAndConstDeclarations(parent.parent); } return true; - } + } + + function visitWithStatement(node: WithStatement): void { + if (node.flags & NodeFlags.ParsedInStrictMode) { + // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such + // a context is an + grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode); + } + } } export function createProgram(rootNames: string[], options: CompilerOptions, host: CompilerHost): Program { diff --git a/tests/baselines/reference/methodInAmbientClass1.errors.txt b/tests/baselines/reference/methodInAmbientClass1.errors.txt new file mode 100644 index 00000000000..3bf8f8af12a --- /dev/null +++ b/tests/baselines/reference/methodInAmbientClass1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/methodInAmbientClass1.ts(2,20): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/methodInAmbientClass1.ts(2,12): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. + + +==== tests/cases/compiler/methodInAmbientClass1.ts (2 errors) ==== + declare class Foo { + fn(): boolean { + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~~~~~~~ +!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. + } + } \ No newline at end of file diff --git a/tests/cases/compiler/methodInAmbientClass1.ts b/tests/cases/compiler/methodInAmbientClass1.ts new file mode 100644 index 00000000000..8590977f89b --- /dev/null +++ b/tests/cases/compiler/methodInAmbientClass1.ts @@ -0,0 +1,4 @@ + declare class Foo { + fn(): boolean { + } + } \ No newline at end of file From 4ba3bf5784af5ca139dc0dbc31ef572d3de26b24 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 19 Nov 2014 14:19:59 -0800 Subject: [PATCH 29/60] move break\continue checks out of parser --- src/compiler/parser.ts | 326 +++++------------- .../reference/parserPublicBreak1.errors.txt | 5 +- .../reference/standaloneBreak.errors.txt | 7 + tests/cases/compiler/standaloneBreak.ts | 1 + 4 files changed, 103 insertions(+), 236 deletions(-) create mode 100644 tests/baselines/reference/standaloneBreak.errors.txt create mode 100644 tests/cases/compiler/standaloneBreak.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9ec45f91d12..25f470d5919 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -739,22 +739,6 @@ module ts { Parameters, // Parameters in parameter list } - // Tracks whether we nested (directly or indirectly) in a certain control block. - // Used for validating break and continue statements. - const enum ControlBlockContext { - NotNested, - Nested, - CrossingFunctionBoundary - } - - interface LabelledStatementInfo { - addLabel(label: Identifier): void; - pushCurrentLabelSet(isIterationStatement: boolean): void; - pushFunctionBoundary(): void; - pop(): void; - nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext; - } - export interface ReferencePathMatchResult { fileReference?: FileReference diagnostic?: DiagnosticMessage @@ -856,112 +840,6 @@ module ts { var lookAheadMode = LookAheadMode.NotLookingAhead; var inAmbientContext = false; var inFunctionBody = false; - var inSwitchStatement = ControlBlockContext.NotNested; - var inIterationStatement = ControlBlockContext.NotNested; - - // The following is a state machine that tracks what labels are in our current parsing - // context. So if we are parsing a node that is nested (arbitrarily deeply) in a label, - // it will be tracked in this data structure. It is used for checking break/continue - // statements, and checking for duplicate labels. - var labelledStatementInfo: LabelledStatementInfo = (() => { - // These are initialized on demand because labels are rare, so it is usually - // not even necessary to allocate these. - var functionBoundarySentinel: StringSet; - var currentLabelSet: StringSet; - var labelSetStack: StringSet[]; - var isIterationStack: boolean[]; - - function addLabel(label: Identifier): void { - if (!currentLabelSet) { - currentLabelSet = {}; - } - currentLabelSet[label.text] = true; - } - - function pushCurrentLabelSet(isIterationStatement: boolean): void { - if (!labelSetStack && !isIterationStack) { - labelSetStack = []; - isIterationStack = []; - } - Debug.assert(currentLabelSet !== undefined); - labelSetStack.push(currentLabelSet); - isIterationStack.push(isIterationStatement); - currentLabelSet = undefined; - } - - function pushFunctionBoundary(): void { - if (!functionBoundarySentinel) { - functionBoundarySentinel = {}; - if (!labelSetStack && !isIterationStack) { - labelSetStack = []; - isIterationStack = []; - } - } - Debug.assert(currentLabelSet === undefined); - labelSetStack.push(functionBoundarySentinel); - - // It does not matter what we push here, since we will never ask if a function boundary - // is an iteration statement - isIterationStack.push(false); - } - - function pop(): void { - // Assert that we are in a "pushed" state - Debug.assert(labelSetStack.length && isIterationStack.length && currentLabelSet === undefined); - labelSetStack.pop(); - isIterationStack.pop(); - } - - function nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext { - if (!requireIterationStatement && currentLabelSet && hasProperty(currentLabelSet, label.text)) { - return ControlBlockContext.Nested; - } - - if (!labelSetStack) { - return ControlBlockContext.NotNested; - } - - // We want to start searching for the label at the lowest point in the tree, - // and climb up from there. So we start at the end of the labelSetStack array. - var crossedFunctionBoundary = false; - for (var i = labelSetStack.length - 1; i >= 0; i--) { - var labelSet = labelSetStack[i]; - // Not allowed to cross function boundaries, so stop if we encounter one - if (labelSet === functionBoundarySentinel) { - if (stopAtFunctionBoundary) { - break; - } - else { - crossedFunctionBoundary = true; - continue; - } - } - - // If we require an iteration statement, only search in the current - // statement if it is an iteration statement - if (requireIterationStatement && isIterationStack[i] === false) { - continue; - } - - if (hasProperty(labelSet, label.text)) { - return crossedFunctionBoundary ? ControlBlockContext.CrossingFunctionBoundary : ControlBlockContext.Nested; - } - } - - // This is a bit of a misnomer. If the caller passed true for stopAtFunctionBoundary, - // there actually may be an enclosing label across a function boundary, but we will - // just return NotNested - return ControlBlockContext.NotNested; - } - - return { - addLabel: addLabel, - pushCurrentLabelSet: pushCurrentLabelSet, - pushFunctionBoundary: pushFunctionBoundary, - pop: pop, - nodeIsNestedInLabel: nodeIsNestedInLabel, - }; - })(); function getLineStarts(): number[] { return lineStarts || (lineStarts = computeLineStarts(sourceText)); @@ -2660,25 +2538,11 @@ module ts { function parseBody(ignoreMissingOpenBrace: boolean): Block { var saveInFunctionBody = inFunctionBody; - var saveInSwitchStatement = inSwitchStatement; - var saveInIterationStatement = inIterationStatement; inFunctionBody = true; - if (inSwitchStatement === ControlBlockContext.Nested) { - inSwitchStatement = ControlBlockContext.CrossingFunctionBoundary; - } - if (inIterationStatement === ControlBlockContext.Nested) { - inIterationStatement = ControlBlockContext.CrossingFunctionBoundary; - } - labelledStatementInfo.pushFunctionBoundary(); - var block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true); block.kind = SyntaxKind.FunctionBlock; - - labelledStatementInfo.pop(); inFunctionBody = saveInFunctionBody; - inSwitchStatement = saveInSwitchStatement; - inIterationStatement = saveInIterationStatement; return block; } @@ -2704,10 +2568,7 @@ module ts { var node = createNode(SyntaxKind.DoStatement); parseExpected(SyntaxKind.DoKeyword); - var saveInIterationStatement = inIterationStatement; - inIterationStatement = ControlBlockContext.Nested; node.statement = parseStatement(); - inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); parseExpected(SyntaxKind.OpenParenToken); @@ -2729,10 +2590,7 @@ module ts { node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - var saveInIterationStatement = inIterationStatement; - inIterationStatement = ControlBlockContext.Nested; node.statement = parseStatement(); - inIterationStatement = saveInIterationStatement; return finishNode(node); } @@ -2789,10 +2647,7 @@ module ts { forOrForInStatement = forStatement; } - var saveInIterationStatement = inIterationStatement; - inIterationStatement = ControlBlockContext.Nested; forOrForInStatement.statement = parseStatement(); - inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); } @@ -2805,78 +2660,9 @@ module ts { parseSemicolon(); finishNode(node); - // In an ambient context, we will already give an error for having a statement. - if (!inAmbientContext && errorCountBeforeStatement === file._parserDiagnostics.length) { - if (node.label) { - checkBreakOrContinueStatementWithLabel(node); - } - else { - checkBareBreakOrContinueStatement(node); - } - } return node; } - function checkBareBreakOrContinueStatement(node: BreakOrContinueStatement): void { - if (node.kind === SyntaxKind.BreakStatement) { - if (inIterationStatement === ControlBlockContext.Nested - || inSwitchStatement === ControlBlockContext.Nested) { - return; - } - else if (inIterationStatement === ControlBlockContext.NotNested - && inSwitchStatement === ControlBlockContext.NotNested) { - grammarErrorOnNode(node, Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement); - return; - } - // Fall through - } - else if (node.kind === SyntaxKind.ContinueStatement) { - if (inIterationStatement === ControlBlockContext.Nested) { - return; - } - else if (inIterationStatement === ControlBlockContext.NotNested) { - grammarErrorOnNode(node, Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement); - return; - } - // Fall through - } - else { - Debug.fail("checkAnonymousBreakOrContinueStatement"); - } - - Debug.assert(inIterationStatement === ControlBlockContext.CrossingFunctionBoundary - || inSwitchStatement === ControlBlockContext.CrossingFunctionBoundary); - grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); - } - - function checkBreakOrContinueStatementWithLabel(node: BreakOrContinueStatement): void { - // For error specificity, if the label is not found, we want to distinguish whether it is because - // it crossed a function boundary or it was simply not found. To do this, we pass false for - // stopAtFunctionBoundary. - var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, - /*requireIterationStatement*/ node.kind === SyntaxKind.ContinueStatement, - /*stopAtFunctionBoundary*/ false); - if (nodeIsNestedInLabel === ControlBlockContext.Nested) { - return; - } - - if (nodeIsNestedInLabel === ControlBlockContext.CrossingFunctionBoundary) { - grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); - return; - } - - // It is NotNested - if (node.kind === SyntaxKind.ContinueStatement) { - grammarErrorOnNode(node, Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); - } - else if (node.kind === SyntaxKind.BreakStatement) { - grammarErrorOnNode(node, Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement); - } - else { - Debug.fail("checkBreakOrContinueStatementWithLabel"); - } - } - function parseReturnStatement(): ReturnStatement { var node = createNode(SyntaxKind.ReturnStatement); var errorCountBeforeReturnStatement = file._parserDiagnostics.length; @@ -2941,10 +2727,7 @@ module ts { parseExpected(SyntaxKind.CloseParenToken); parseExpected(SyntaxKind.OpenBraceToken); - var saveInSwitchStatement = inSwitchStatement; - inSwitchStatement = ControlBlockContext.Nested; node.clauses = parseList(ParsingContext.SwitchClauses, /*checkForStrictMode*/ false, parseCaseOrDefaultClause); - inSwitchStatement = saveInSwitchStatement; parseExpected(SyntaxKind.CloseBraceToken); @@ -3023,13 +2806,6 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(): Statement { - labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(); - labelledStatementInfo.pop(); - return statement; - } - function isLabel(): boolean { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } @@ -3039,14 +2815,7 @@ module ts { node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); - if (labelledStatementInfo.nodeIsNestedInLabel(node.label, /*requireIterationStatement*/ false, /*stopAtFunctionBoundary*/ true)) { - grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); - } - labelledStatementInfo.addLabel(node.label); - - // We only want to call parseStatementWithLabelSet when the label set is complete - // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabeledStatement() : parseStatementWithLabelSet(); + node.statement = isLabel() ? parseLabeledStatement() : parseStatement(); return finishNode(node); } @@ -4015,6 +3784,7 @@ module ts { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); + case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); case SyntaxKind.CallExpression: return visitCallExpression(node); case SyntaxKind.CallSignature: return visitCallSignature(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); @@ -4022,6 +3792,7 @@ module ts { case SyntaxKind.Constructor: return visitConstructor(node); case SyntaxKind.ConstructorType: return visitConstructorType(node); case SyntaxKind.ConstructSignature: return visitConstructSignature(node); + case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); case SyntaxKind.ForInStatement: return visitForInStatement(node); case SyntaxKind.ForStatement: return visitForStatement(node); @@ -4031,6 +3802,7 @@ module ts { case SyntaxKind.GetAccessor: return visitGetAccessor(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); + case SyntaxKind.LabeledStatement: return visitLabeledStatement(node); case SyntaxKind.Method: return visitMethod(node); case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); case SyntaxKind.NewExpression: return visitNewExpression(node); @@ -4084,6 +3856,96 @@ module ts { } } + function visitBreakOrContinueStatement(node: BreakOrContinueStatement): void { + checkBreakOrContinueStatement(node); + } + + function visitLabeledStatement(node: LabeledStatement): void { + checkLabeledStatement(node); + } + + function isIterationStatement(node: Node, lookInLabeledStatements: boolean): boolean { + switch (node.kind) { + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + return true; + case SyntaxKind.LabeledStatement: + return lookInLabeledStatements && isIterationStatement((node).statement, lookInLabeledStatements); + } + + return false; + } + + function checkLabeledStatement(node: LabeledStatement): boolean { + // ensure that label is unique + var current = node.parent; + while (current) { + if (isAnyFunction(current)) { + break; + } + if (current.kind === SyntaxKind.LabeledStatement && (current).label.text === node.label.text) { + return grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label)); + } + current = current.parent; + } + } + + function checkBreakOrContinueStatement(node: BreakOrContinueStatement): boolean { + var current = node; + while (current) { + if (isAnyFunction(current)) { + return grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); + } + + switch (current.kind) { + case SyntaxKind.LabeledStatement: + if (node.label && (current).label.text === node.label.text) { + // found matching label - verify that label usage is correct + // continue can only target labels that are on iteration statements + var isMisplacedContinueLabel = node.kind === SyntaxKind.ContinueStatement + && !isIterationStatement((current).statement, /*lookInLabeledStatement*/ true); + + if (isMisplacedContinueLabel) { + return grammarErrorOnNode(node, Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); + } + + return false; + } + break; + case SyntaxKind.SwitchStatement: + if (node.kind === SyntaxKind.BreakStatement && !node.label) { + // unlabeled break within switch statement - ok + return false; + } + break; + default: + if (isIterationStatement(current, /*lookInLabeledStatement*/ false) && !node.label) { + // unlabeled break or continue within iteration statement - ok + return false; + } + break; + } + + current = current.parent; + } + + if (node.label) { + var message = node.kind === SyntaxKind.BreakStatement + ? Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement + : Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + + return grammarErrorOnNode(node, message) + } + else { + var message = node.kind === SyntaxKind.BreakStatement + ? Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement + : Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + return grammarErrorOnNode(node, message) + } + } + function visitCallExpression(node: CallExpression) { checkForTrailingComma(node.typeArguments) || checkForAtLeastOneTypeArgument(node.typeArguments) || diff --git a/tests/baselines/reference/parserPublicBreak1.errors.txt b/tests/baselines/reference/parserPublicBreak1.errors.txt index b96046d8e21..429a63ace4b 100644 --- a/tests/baselines/reference/parserPublicBreak1.errors.txt +++ b/tests/baselines/reference/parserPublicBreak1.errors.txt @@ -1,11 +1,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts(1,8): error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts (1 errors) ==== public break; ~~~~~~ !!! error TS1128: Declaration or statement expected. - ~~~~~~ -!!! error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement. \ No newline at end of file diff --git a/tests/baselines/reference/standaloneBreak.errors.txt b/tests/baselines/reference/standaloneBreak.errors.txt new file mode 100644 index 00000000000..86e5d719a94 --- /dev/null +++ b/tests/baselines/reference/standaloneBreak.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/standaloneBreak.ts(1,1): error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement. + + +==== tests/cases/compiler/standaloneBreak.ts (1 errors) ==== + break; + ~~~~~~ +!!! error TS1105: A 'break' statement can only be used within an enclosing iteration or switch statement. \ No newline at end of file diff --git a/tests/cases/compiler/standaloneBreak.ts b/tests/cases/compiler/standaloneBreak.ts new file mode 100644 index 00000000000..8cb76cf02d7 --- /dev/null +++ b/tests/cases/compiler/standaloneBreak.ts @@ -0,0 +1 @@ +break; \ No newline at end of file From f634bc19d867fed057cc8fa7ebee6da7382a31b7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 14:29:20 -0800 Subject: [PATCH 30/60] Expose parse errors and grammar errors off the source file. --- src/compiler/parser.ts | 70 +++++++++++++++++++--------------------- src/compiler/types.ts | 9 ++++++ src/services/services.ts | 2 ++ 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b20c8959307..073feeaa493 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -832,10 +832,6 @@ module ts { } interface SourceFileInternal extends SourceFile { - // Diagnostics produced only by the parser. Does not include any diagnostics produced by - // doing grammar checks. - _parserDiagnostics: Diagnostic[]; - // All diagnostics for the source file. Should not be accessed directly. Lazily created // when getSyntacticDiagnostics is called. _syntacticDiagnostics: Diagnostic[]; @@ -996,21 +992,21 @@ module ts { var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; var length = span.end - start; - file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + file.parseDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - file._parserDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + file.parseDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } function errorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - var lastErrorPos = file._parserDiagnostics.length - ? file._parserDiagnostics[file._parserDiagnostics.length - 1].start + var lastErrorPos = file.parseDiagnostics.length + ? file.parseDiagnostics[file.parseDiagnostics.length - 1].start : -1; if (start !== lastErrorPos) { var diagnostic = createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); diagnostic.isParseError = true; - file._parserDiagnostics.push(diagnostic); + file.parseDiagnostics.push(diagnostic); } if (lookAheadMode === LookAheadMode.NoErrorYet) { @@ -1059,7 +1055,7 @@ module ts { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). var saveToken = token; - var saveSyntacticErrorsLength = file._parserDiagnostics.length; + var saveSyntacticErrorsLength = file.parseDiagnostics.length; // Keep track of the current look ahead mode (this matters if we have nested // speculative parsing). @@ -1081,7 +1077,7 @@ module ts { lookAheadMode = saveLookAheadMode; if (!result || alwaysResetState) { token = saveToken; - file._parserDiagnostics.length = saveSyntacticErrorsLength; + file.parseDiagnostics.length = saveSyntacticErrorsLength; } return result; @@ -1766,9 +1762,9 @@ module ts { function parseTupleType(): TupleTypeNode { var node = createNode(SyntaxKind.TupleType); var startTokenPos = scanner.getTokenPos(); - var startErrorCount = file._parserDiagnostics.length; + var startErrorCount = file.parseDiagnostics.length; node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); - if (!node.elementTypes.length && file._parserDiagnostics.length === startErrorCount) { + if (!node.elementTypes.length && file.parseDiagnostics.length === startErrorCount) { grammarErrorAtPos(startTokenPos, scanner.getStartPos() - startTokenPos, Diagnostics.A_tuple_type_element_list_cannot_be_empty); } return finishNode(node); @@ -2799,14 +2795,14 @@ module ts { function parseBreakOrContinueStatement(kind: SyntaxKind): BreakOrContinueStatement { var node = createNode(kind); - var errorCountBeforeStatement = file._parserDiagnostics.length; + var errorCountBeforeStatement = file.parseDiagnostics.length; parseExpected(kind === SyntaxKind.BreakStatement ? SyntaxKind.BreakKeyword : SyntaxKind.ContinueKeyword); if (!canParseSemicolon()) node.label = parseIdentifier(); parseSemicolon(); finishNode(node); // In an ambient context, we will already give an error for having a statement. - if (!inAmbientContext && errorCountBeforeStatement === file._parserDiagnostics.length) { + if (!inAmbientContext && errorCountBeforeStatement === file.parseDiagnostics.length) { if (node.label) { checkBreakOrContinueStatementWithLabel(node); } @@ -2879,7 +2875,7 @@ module ts { function parseReturnStatement(): ReturnStatement { var node = createNode(SyntaxKind.ReturnStatement); - var errorCountBeforeReturnStatement = file._parserDiagnostics.length; + var errorCountBeforeReturnStatement = file.parseDiagnostics.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; @@ -2888,7 +2884,7 @@ module ts { parseSemicolon(); // In an ambient context, we will already give an error for having a statement. - if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file._parserDiagnostics.length) { + if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file.parseDiagnostics.length) { grammarErrorAtPos(returnTokenStart, returnTokenLength, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); } return finishNode(node); @@ -3229,7 +3225,7 @@ module ts { } function parsePropertyMemberDeclaration(pos: number, flags: NodeFlags): Declaration { - var errorCountBeforePropertyDeclaration = file._parserDiagnostics.length; + var errorCountBeforePropertyDeclaration = file.parseDiagnostics.length; var name = parsePropertyName(); var questionStart = scanner.getTokenPos(); @@ -3259,7 +3255,7 @@ module ts { property.initializer = parseInitializer(/*inParameter*/ false); parseSemicolon(); - if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file._parserDiagnostics.length) { + if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file.parseDiagnostics.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } return finishNode(property); @@ -3529,7 +3525,7 @@ module ts { if (parseOptional(SyntaxKind.ImplementsKeyword)) { node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } - var errorCountBeforeClassBody = file._parserDiagnostics.length; + var errorCountBeforeClassBody = file.parseDiagnostics.length; if (parseExpected(SyntaxKind.OpenBraceToken)) { node.members = parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassMemberDeclaration); parseExpected(SyntaxKind.CloseBraceToken); @@ -3626,10 +3622,10 @@ module ts { node.flags = flags; node.name = parseStringLiteral(); if (!inAmbientContext) { - var errorCount = file._parserDiagnostics.length; + var errorCount = file.parseDiagnostics.length; // Only report this error if we have not already errored about a missing declare modifier, // which would have been at or after pos - if (!errorCount || file._parserDiagnostics[errorCount - 1].start < getTokenPos(pos)) { + if (!errorCount || file.parseDiagnostics[errorCount - 1].start < getTokenPos(pos)) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } } @@ -3705,7 +3701,7 @@ module ts { function parseDeclaration(modifierContext: ModifierContext): Statement { var pos = getNodePos(); - var errorCountBeforeModifiers = file._parserDiagnostics.length; + var errorCountBeforeModifiers = file.parseDiagnostics.length; var flags = parseAndCheckModifiers(modifierContext); if (token === SyntaxKind.ExportKeyword) { @@ -3713,7 +3709,7 @@ module ts { nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { var exportAssignmentTail = parseExportAssignmentTail(pos); - if (flags !== 0 && errorCountBeforeModifiers === file._parserDiagnostics.length) { + if (flags !== 0 && errorCountBeforeModifiers === file.parseDiagnostics.length) { var modifiersStart = skipTrivia(sourceText, pos); grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers); } @@ -3846,20 +3842,19 @@ module ts { function getSyntacticDiagnostics() { if (file._syntacticDiagnostics === undefined) { - if (file._parserDiagnostics.length > 0) { + if (file.parseDiagnostics.length > 0) { // Don't bother doing any grammar checks if there are already parser errors. // Otherwise we may end up with too many cascading errors. - file._syntacticDiagnostics = file._parserDiagnostics; + file._syntacticDiagnostics = file.parseDiagnostics; } else { - // No parser errors were reported. Perform our stricted grammar checks. - file._syntacticDiagnostics = []; + // No parser errors were reported. Perform our stricter grammar checks. + file._syntacticDiagnostics = file.grammarDiagnostics; checkGrammar(sourceText, languageVersion, file); } - - file._parserDiagnostics = undefined; } + Debug.assert(file._syntacticDiagnostics !== undefined); return file._syntacticDiagnostics } @@ -3876,7 +3871,8 @@ module ts { file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; file.getLineStarts = getLineStarts; file.getSyntacticDiagnostics = getSyntacticDiagnostics; - file._parserDiagnostics = []; + file.parseDiagnostics = []; + file.grammarDiagnostics = []; file.semanticDiagnostics = []; var referenceComments = processReferenceComments(); file.referencedFiles = referenceComments.referencedFiles; @@ -3931,7 +3927,7 @@ module ts { } function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { - var syntacticDiagnostics = file._syntacticDiagnostics; + var grammarDiagnostics = file.grammarDiagnostics; var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText); // We're automatically in an ambient context if this is a .d.ts file. @@ -3965,11 +3961,11 @@ module ts { } // Now recurse and perform all grammar checks on the children of this node. - var diagnosticCount = syntacticDiagnostics.length; + var diagnosticCount = grammarDiagnostics.length; forEachChild(node, visitNode); // if we got any errors, just stop performing any more checks on this node or higher. - if (diagnosticCount !== syntacticDiagnostics.length) { + if (diagnosticCount !== grammarDiagnostics.length) { return; } @@ -4020,7 +4016,7 @@ module ts { scanner.setTextPos(start); scanner.scan(); var end = scanner.getTextPos(); - file._syntacticDiagnostics.push(createFileDiagnostic(file, start, end - start, message, arg0, arg1, arg2)); + grammarDiagnostics.push(createFileDiagnostic(file, start, end - start, message, arg0, arg1, arg2)); return true; } @@ -4029,12 +4025,12 @@ module ts { var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; var length = span.end - start; - file._syntacticDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + grammarDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); return true; } function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { - file._syntacticDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); + grammarDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); return true; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 17ee1ce6134..7865a4f2463 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -650,6 +650,15 @@ module ts { amdModuleName: string; referencedFiles: FileReference[]; semanticDiagnostics: Diagnostic[]; + + // Parse errors refer specifically to things the parser could not understand at all (like + // missing tokens, or tokens it didn't know how to deal with). Grammar errors are for + // things the parser understood, but either the ES6 or TS grammars do not allow (like + // putting an 'public' modifier on a 'class declaration'). + parseDiagnostics: Diagnostic[]; + grammarDiagnostics: Diagnostic[]; + + // Returns all getSyntacticDiagnostics(): Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; // The first node that causes this file to be an external module diff --git a/src/services/services.ts b/src/services/services.ts index 287ad437362..f05f9dd77b8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -725,6 +725,8 @@ module ts { public amdDependencies: string[]; public amdModuleName: string; public referencedFiles: FileReference[]; + public parseDiagnostics: Diagnostic[]; + public grammarDiagnostics: Diagnostic[]; public semanticDiagnostics: Diagnostic[]; public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module From 90b7a1c40aee5381b30af0d5c4e7637d8a4d51fa Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 14:38:53 -0800 Subject: [PATCH 31/60] Move tuple checks to the grammar checker. --- src/compiler/parser.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fcea7adcfff..6a25699f0b9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1639,12 +1639,7 @@ module ts { function parseTupleType(): TupleTypeNode { var node = createNode(SyntaxKind.TupleType); - var startTokenPos = scanner.getTokenPos(); - var startErrorCount = file.parseDiagnostics.length; node.elementTypes = parseBracketedList(ParsingContext.TupleElementTypes, parseType, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); - if (!node.elementTypes.length && file.parseDiagnostics.length === startErrorCount) { - grammarErrorAtPos(startTokenPos, scanner.getStartPos() - startTokenPos, Diagnostics.A_tuple_type_element_list_cannot_be_empty); - } return finishNode(node); } @@ -4422,7 +4417,14 @@ module ts { } function visitTupleType(node: TupleTypeNode) { - checkForTrailingComma(node.elementTypes); + checkForTrailingComma(node.elementTypes) || + checkForAtLeastOneType(node); + } + + function checkForAtLeastOneType(node: TupleTypeNode): boolean { + if (node.elementTypes.length === 0) { + return grammarErrorOnNode(node, Diagnostics.A_tuple_type_element_list_cannot_be_empty) + } } function visitTypeReference(node: TypeReferenceNode) { From cd75243d83a67490d9b71180e84c2dd419307ee9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 15:00:45 -0800 Subject: [PATCH 32/60] Move optional property checking to the grammar checker. --- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 11 +- src/compiler/parser.ts | 100 +++++++++++------- ...objectTypeWithOptionalProperty1.errors.txt | 9 ++ ...jectTypesWithOptionalProperties.errors.txt | 5 +- .../objectTypeWithOptionalProperty1.ts | 3 + 6 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt create mode 100644 tests/cases/compiler/objectTypeWithOptionalProperty1.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 213661fdd60..a87b1f8cc28 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -124,7 +124,7 @@ module ts { Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, - A_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "A object member cannot be declared optional." }, + An_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, 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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cd2e209e3eb..c05770bdd8e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -479,18 +479,17 @@ "category": "Error", "code": 1159 }, - "Unterminated template literal.": { + "An object member cannot be declared optional.": { "category": "Error", - "code": 1160 + "code": 1160 }, - "Unterminated regular expression literal.": { + "Unterminated template literal.": { "category": "Error", "code": 1161 }, - - "A object member cannot be declared optional.": { + "Unterminated regular expression literal.": { "category": "Error", - "code": 1160 + "code": 1162 }, "Duplicate identifier '{0}'.": { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6a25699f0b9..5818929d6e8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2264,7 +2264,6 @@ module ts { } if (parseOptional(SyntaxKind.OpenBracketToken)) { - var indexedAccess = createNode(SyntaxKind.IndexedAccess, expr.pos); indexedAccess.object = expr; @@ -2441,10 +2440,12 @@ module ts { (node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, undefined, sig, body); return finishNode(node); } - // Disallow optional property assignment + + var flags: NodeFlags = 0; + + // Disallowing of optional property assignments happens in the grammar checker. if (token === SyntaxKind.QuestionToken) { - var questionStart = scanner.getTokenPos(); - grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_object_member_cannot_be_declared_optional); + flags |= NodeFlags.QuestionMark; nextToken(); } @@ -2459,6 +2460,8 @@ module ts { parseExpected(SyntaxKind.ColonToken); (node).initializer = parseAssignmentExpression(false); } + + node.flags = flags; return finishNode(node); } @@ -3740,42 +3743,44 @@ module ts { function dispatch(node: Node) { switch (node.kind) { - case SyntaxKind.ArrowFunction: return visitArrowFunction(node); - case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); - case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); - case SyntaxKind.CallExpression: return visitCallExpression(node); - case SyntaxKind.CallSignature: return visitCallSignature(node); - case SyntaxKind.CatchBlock: return visitCatchBlock(node); - case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); - case SyntaxKind.Constructor: return visitConstructor(node); - case SyntaxKind.ConstructorType: return visitConstructorType(node); - case SyntaxKind.ConstructSignature: return visitConstructSignature(node); - case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); - case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); - case SyntaxKind.ForInStatement: return visitForInStatement(node); - case SyntaxKind.ForStatement: return visitForStatement(node); - case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); - case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); - case SyntaxKind.FunctionType: return visitFunctionType(node); - case SyntaxKind.GetAccessor: return visitGetAccessor(node); - case SyntaxKind.IndexSignature: return visitIndexSignature(node); - case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); - case SyntaxKind.LabeledStatement: return visitLabeledStatement(node); - case SyntaxKind.Method: return visitMethod(node); - case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); - case SyntaxKind.NewExpression: return visitNewExpression(node); - case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); - case SyntaxKind.Parameter: return visitParameter(node); - case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); - case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); - case SyntaxKind.SetAccessor: return visitSetAccessor(node); - case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); - case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); - case SyntaxKind.TupleType: return visitTupleType(node); - case SyntaxKind.TypeReference: return visitTypeReference(node); - case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); - case SyntaxKind.VariableStatement: return visitVariableStatement(node); - case SyntaxKind.WithStatement: return visitWithStatement(node); + case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); + case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); + case SyntaxKind.CallExpression: return visitCallExpression(node); + case SyntaxKind.CallSignature: return visitCallSignature(node); + case SyntaxKind.CatchBlock: return visitCatchBlock(node); + case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); + case SyntaxKind.Constructor: return visitConstructor(node); + case SyntaxKind.ConstructorType: return visitConstructorType(node); + case SyntaxKind.ConstructSignature: return visitConstructSignature(node); + case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); + case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); + case SyntaxKind.ForInStatement: return visitForInStatement(node); + case SyntaxKind.ForStatement: return visitForStatement(node); + case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); + case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); + case SyntaxKind.FunctionType: return visitFunctionType(node); + case SyntaxKind.GetAccessor: return visitGetAccessor(node); + case SyntaxKind.IndexSignature: return visitIndexSignature(node); + case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); + case SyntaxKind.LabeledStatement: return visitLabeledStatement(node); + case SyntaxKind.Method: return visitMethod(node); + case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); + case SyntaxKind.NewExpression: return visitNewExpression(node); + case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); + case SyntaxKind.Parameter: return visitParameter(node); + case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); + case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); + case SyntaxKind.PropertyAssignment: return visitPropertyAssignment(node); + case SyntaxKind.SetAccessor: return visitSetAccessor(node); + case SyntaxKind.ShorthandPropertyAssignment: return visitShorthandPropertyAssignment(node); + case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); + case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); + case SyntaxKind.TupleType: return visitTupleType(node); + case SyntaxKind.TypeReference: return visitTypeReference(node); + case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); + case SyntaxKind.VariableStatement: return visitVariableStatement(node); + case SyntaxKind.WithStatement: return visitWithStatement(node); } } @@ -4346,6 +4351,17 @@ module ts { } } + function visitPropertyAssignment(node: PropertyDeclaration) { + checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); + } + + function checkForInvalidQuestionMark(node: Declaration, message: DiagnosticMessage) { + if (node.flags & NodeFlags.QuestionMark) { + var pos = skipTrivia(sourceText, node.name.end); + return grammarErrorAtPos(pos, "?".length, message); + } + } + function visitSetAccessor(node: MethodDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || @@ -4391,6 +4407,10 @@ module ts { } } + function visitShorthandPropertyAssignment(node: ShortHandPropertyDeclaration): void { + checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); + } + function visitSwitchStatement(node: SwitchStatement) { var firstDefaultClause: CaseOrDefaultClause; diff --git a/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt b/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt new file mode 100644 index 00000000000..7e17563873a --- /dev/null +++ b/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/objectTypeWithOptionalProperty1.ts(2,10): error TS1160: An object member cannot be declared optional. + + +==== tests/cases/compiler/objectTypeWithOptionalProperty1.ts (1 errors) ==== + var b = { + x?: 1 // error + ~ +!!! error TS1160: An object member cannot be declared optional. + } \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt index e73e8adc930..669fbfb595b 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt +++ b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional. -tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: A object member cannot be declared optional. -==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (2 errors) ==== // Basic uses of optional properties var a: { @@ -32,6 +31,4 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith var b = { x?: 1 // error - -!!! error TS1160: A object member cannot be declared optional. } \ No newline at end of file diff --git a/tests/cases/compiler/objectTypeWithOptionalProperty1.ts b/tests/cases/compiler/objectTypeWithOptionalProperty1.ts new file mode 100644 index 00000000000..69f6e1f51ec --- /dev/null +++ b/tests/cases/compiler/objectTypeWithOptionalProperty1.ts @@ -0,0 +1,3 @@ + var b = { + x?: 1 // error + } \ No newline at end of file From b9353086a4ed3dbbd0b8f958a8a7f391b0f666bb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 15:30:35 -0800 Subject: [PATCH 33/60] Move return checks to the grammar checker. --- src/compiler/parser.ts | 87 ++++++++++--------- ...torWithIncompleteTypeAnnotation.errors.txt | 17 +--- .../interfaceExtendingClass2.errors.txt | 5 +- ...overloadOnConstAsTypeAnnotation.errors.txt | 5 +- ...serErrorRecovery_ModuleElement1.errors.txt | 8 +- ...rserErrorRecovery_VariableList1.errors.txt | 5 +- .../reference/propertyWrappedInTry.errors.txt | 5 +- ...hStatementsWithMultipleDefaults.errors.txt | 8 +- 8 files changed, 61 insertions(+), 79 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5818929d6e8..b6455304cdc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -835,7 +835,6 @@ module ts { var lookAheadMode = LookAheadMode.NotLookingAhead; var inAmbientContext = false; - var inFunctionBody = false; function getLineStarts(): number[] { return lineStarts || (lineStarts = computeLineStarts(sourceText)); @@ -2062,7 +2061,7 @@ module ts { var body: Node; if (token === SyntaxKind.OpenBraceToken) { - body = parseBody(/* ignoreMissingOpenBrace */ false); + body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false); } else if (isStatement(/* inErrorRecovery */ true) && !isStartOfExpressionStatement() && token !== SyntaxKind.FunctionKeyword) { // Check if we got a plain statement (i.e. no expression-statements, no functions expressions/declarations) @@ -2079,7 +2078,7 @@ module ts { // up preemptively closing the containing construct. // // Note: even when 'ignoreMissingOpenBrace' is passed as true, parseBody will still error. - body = parseBody(/* ignoreMissingOpenBrace */ true); + body = parseFunctionBlock(/* ignoreMissingOpenBrace */ true); } else { body = parseAssignmentExpression(noIn); @@ -2431,7 +2430,7 @@ module ts { node = createNode(SyntaxKind.PropertyAssignment, nodePos); node.name = propertyName; var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); - var body = parseBody(/* ignoreMissingOpenBrace */ false); + var body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false); // do not propagate property name as name for function expression // for scenarios like // var x = 1; @@ -2492,7 +2491,7 @@ module ts { parseExpected(SyntaxKind.FunctionKeyword); var name = isIdentifier() ? parseIdentifier() : undefined; var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); - var body = parseBody(/* ignoreMissingOpenBrace */ false); + var body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false); return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body); } @@ -2530,13 +2529,9 @@ module ts { return finishNode(node); } - function parseBody(ignoreMissingOpenBrace: boolean): Block { - var saveInFunctionBody = inFunctionBody; - - inFunctionBody = true; + function parseFunctionBlock(ignoreMissingOpenBrace: boolean): Block { var block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true); block.kind = SyntaxKind.FunctionBlock; - inFunctionBody = saveInFunctionBody; return block; } @@ -2660,18 +2655,15 @@ module ts { function parseReturnStatement(): ReturnStatement { var node = createNode(SyntaxKind.ReturnStatement); - var errorCountBeforeReturnStatement = file.parseDiagnostics.length; var returnTokenStart = scanner.getTokenPos(); var returnTokenLength = scanner.getTextPos() - returnTokenStart; parseExpected(SyntaxKind.ReturnKeyword); - if (!canParseSemicolon()) node.expression = parseExpression(); - parseSemicolon(); - - // In an ambient context, we will already give an error for having a statement. - if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file.parseDiagnostics.length) { - grammarErrorAtPos(returnTokenStart, returnTokenLength, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); + if (!canParseSemicolon()) { + node.expression = parseExpression(); } + + parseSemicolon(); return finishNode(node); } @@ -2914,7 +2906,7 @@ module ts { function parseFunctionBlockOrSemicolon(): Block { if (token === SyntaxKind.OpenBraceToken) { - return parseBody(/* ignoreMissingOpenBrace */ false); + return parseFunctionBlock(/* ignoreMissingOpenBrace */ false); } if (canParseSemicolon()) { @@ -3045,7 +3037,7 @@ module ts { node.body = createMissingNode(); } else { - node.body = parseBody(/* ignoreMissingOpenBrace */ false); + node.body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false); } return finishNode(node); @@ -3293,7 +3285,6 @@ module ts { if (parseOptional(SyntaxKind.ImplementsKeyword)) { node.implementedTypes = parseDelimitedList(ParsingContext.BaseTypeReferences, parseTypeReference); } - var errorCountBeforeClassBody = file.parseDiagnostics.length; if (parseExpected(SyntaxKind.OpenBraceToken)) { node.members = parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassMemberDeclaration); parseExpected(SyntaxKind.CloseBraceToken); @@ -3700,6 +3691,7 @@ module ts { // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); + var inFunctionBlock = false; var parent: Node; visitNode(file); @@ -3709,6 +3701,11 @@ module ts { node.parent = parent; parent = node; + var savedInFunctionBlock = inFunctionBlock; + if (node.kind === SyntaxKind.FunctionBlock) { + inFunctionBlock = true; + } + var savedInAmbientContext = inAmbientContext if (node.flags & NodeFlags.Ambient) { inAmbientContext = true; @@ -3717,6 +3714,7 @@ module ts { checkNode(node); inAmbientContext = savedInAmbientContext; + inFunctionBlock = savedInFunctionBlock; parent = savedParent; } @@ -3724,7 +3722,7 @@ module ts { // First, check if you have a statement in a place where it is not allowed. We want // to do this before recursing, because we'd prefer to report these errors at the top // level instead of at some nested level. - if (checkForStatementInAmbientContext(node)) { + if (inAmbientContext && checkForStatementInAmbientContext(node)) { return; } @@ -3772,6 +3770,7 @@ module ts { case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.PropertyAssignment: return visitPropertyAssignment(node); + case SyntaxKind.ReturnStatement: return visitReturnStatement(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); case SyntaxKind.ShorthandPropertyAssignment: return visitShorthandPropertyAssignment(node); case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); @@ -3814,27 +3813,25 @@ module ts { } function checkForStatementInAmbientContext(node: Node): boolean { - if (inAmbientContext) { - switch (node.kind) { - case SyntaxKind.Block: - case SyntaxKind.EmptyStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ContinueStatement: - case SyntaxKind.BreakStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.WithStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.ThrowStatement: - case SyntaxKind.TryStatement: - case SyntaxKind.DebuggerStatement: - case SyntaxKind.LabeledStatement: - case SyntaxKind.ExpressionStatement: - return grammarErrorOnFirstToken(node, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); - } + switch (node.kind) { + case SyntaxKind.Block: + case SyntaxKind.EmptyStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ContinueStatement: + case SyntaxKind.BreakStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.DebuggerStatement: + case SyntaxKind.LabeledStatement: + case SyntaxKind.ExpressionStatement: + return grammarErrorOnFirstToken(node, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); } } @@ -4362,6 +4359,12 @@ module ts { } } + function visitReturnStatement(node: ReturnStatement) { + if (!inFunctionBlock) { + grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); + } + } + function visitSetAccessor(node: MethodDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index c18dfb8e354..53d24b3d0f8 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -7,14 +7,11 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,33): error TS1138: Parameter declaration expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,34): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,36): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(30,21): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1129: Statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(38,17): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,41): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,45): error TS1002: Unterminated string literal. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(43,21): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(46,13): error TS1005: 'try' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(55,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. @@ -35,10 +32,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(234,14): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,27): error TS1005: ',' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,36): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(236,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,26): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(239,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(241,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(254,69): error TS1110: Type expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,9): error TS1128: Declaration or statement expected. @@ -93,7 +88,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (93 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (88 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -153,8 +148,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2391: Function implementation is missing or not immediately following the declaration. return 1; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. ^ ~ !!! error TS1129: Statement expected. @@ -188,8 +181,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'retValue'. return 1; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } } catch (e) { @@ -208,8 +199,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'console'. return 0; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } } @@ -453,8 +442,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~~~~~~ !!! error TS2304: Cannot find name 'number'. return val; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } public method2() { ~~~~~~ @@ -464,8 +451,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~~~~~~~ !!! error TS2304: Cannot find name 'method2'. return 2 * this.method1(2); - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } } ~ diff --git a/tests/baselines/reference/interfaceExtendingClass2.errors.txt b/tests/baselines/reference/interfaceExtendingClass2.errors.txt index 83cd97c72c0..1e07199686b 100644 --- a/tests/baselines/reference/interfaceExtendingClass2.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClass2.errors.txt @@ -1,11 +1,10 @@ -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(13,13): error TS1108: A 'return' statement can only be used within a function body. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(13,13): error TS1131: Property or signature expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(14,9): error TS1128: Declaration or statement expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(15,5): error TS1128: Declaration or statement expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(11,5): error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to string index type 'Object'. -==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts (5 errors) ==== +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts (4 errors) ==== class Foo { x: string; y() { } @@ -23,8 +22,6 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending !!! error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to string index type 'Object'. return 1; ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. - ~~~~~~ !!! error TS1131: Property or signature expected. }; ~ diff --git a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt index 0d4cd775c56..70530d409b3 100644 --- a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt +++ b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt @@ -1,13 +1,10 @@ tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts(1,37): error TS1005: ';' expected. -tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts(1,42): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts(1,8): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -==== tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts (3 errors) ==== +==== tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts (2 errors) ==== var f: (x: 'hi') => number = ('hi') => { return 1; }; ~~ !!! error TS1005: ';' expected. - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. ~~~~~~~~~~~~~~~~~~~ !!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ModuleElement1.errors.txt b/tests/baselines/reference/parserErrorRecovery_ModuleElement1.errors.txt index ad23c21ec1b..4b8be3e17ad 100644 --- a/tests/baselines/reference/parserErrorRecovery_ModuleElement1.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ModuleElement1.errors.txt @@ -1,19 +1,13 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts(2,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts(3,1): error TS1108: A 'return' statement can only be used within a function body. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts(4,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts (4 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts (2 errors) ==== return foo; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } ~ !!! error TS1128: Declaration or statement expected. return bar; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt index a42ffcdd474..b69cab688f0 100644 --- a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt @@ -1,8 +1,11 @@ +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(1,6): error TS1009: Trailing comma not allowed. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(2,1): error TS1108: A 'return' statement can only be used within a function body. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (2 errors) ==== var a, + ~ +!!! error TS1009: Trailing comma not allowed. return; ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file diff --git a/tests/baselines/reference/propertyWrappedInTry.errors.txt b/tests/baselines/reference/propertyWrappedInTry.errors.txt index 36608ca7d86..0809067b33b 100644 --- a/tests/baselines/reference/propertyWrappedInTry.errors.txt +++ b/tests/baselines/reference/propertyWrappedInTry.errors.txt @@ -2,14 +2,13 @@ tests/cases/compiler/propertyWrappedInTry.ts(3,5): error TS1068: Unexpected toke tests/cases/compiler/propertyWrappedInTry.ts(5,9): error TS1129: Statement expected. tests/cases/compiler/propertyWrappedInTry.ts(11,5): error TS1128: Declaration or statement expected. tests/cases/compiler/propertyWrappedInTry.ts(11,18): error TS1005: ';' expected. -tests/cases/compiler/propertyWrappedInTry.ts(13,9): error TS1108: A 'return' statement can only be used within a function body. tests/cases/compiler/propertyWrappedInTry.ts(17,1): 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,12): error TS2304: Cannot find name 'baz'. -==== tests/cases/compiler/propertyWrappedInTry.ts (9 errors) ==== +==== tests/cases/compiler/propertyWrappedInTry.ts (8 errors) ==== class Foo { try { @@ -37,8 +36,6 @@ tests/cases/compiler/propertyWrappedInTry.ts(11,12): error TS2304: Cannot find n !!! error TS2304: Cannot find name 'baz'. return this.bar; // doesn't get rewritten to Foo.bar. - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. } diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt index cd892f5faa2..9c46389e906 100644 --- a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt @@ -1,7 +1,9 @@ +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(9,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(10,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,22): error TS1108: A 'return' statement can only be used within a function body. -==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (1 errors) ==== +==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (3 errors) ==== var x = 10; @@ -11,7 +13,11 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,22): error TS110 default: // No issues. break; default: // Error; second 'default' clause. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: // Error; third 'default' clause. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. case 3: x *= x; } From 385fdd5eb2d03b7bc13c32771eb848516081684e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 16:10:27 -0800 Subject: [PATCH 34/60] Move export assignment checks to the grammar checker. --- src/compiler/parser.ts | 20 +++++++++++-------- ...ntWithDeclareAndExportModifiers.errors.txt | 9 +++------ ...rtAssignmentWithDeclareModifier.errors.txt | 7 ++----- ...ortAssignmentWithExportModifier.errors.txt | 7 ++----- ...AssignmentWithDeclareAndExportModifiers.ts | 3 ++- .../exportAssignmentWithDeclareModifier.ts | 3 ++- .../exportAssignmentWithExportModifier.ts | 3 ++- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6455304cdc..871e5d60ea7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3421,8 +3421,11 @@ module ts { return finishNode(node); } - function parseExportAssignmentTail(pos: number): ExportAssignment { + function parseExportAssignmentTail(pos: number, flags: NodeFlags): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, pos); + if (flags) { + node.flags = flags; + } node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -3460,19 +3463,13 @@ module ts { function parseDeclaration(modifierContext: ModifierContext): Statement { var pos = getNodePos(); - var errorCountBeforeModifiers = file.parseDiagnostics.length; var flags = parseAndCheckModifiers(modifierContext); if (token === SyntaxKind.ExportKeyword) { var modifiersEnd = scanner.getStartPos(); nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { - var exportAssignmentTail = parseExportAssignmentTail(pos); - if (flags !== 0 && errorCountBeforeModifiers === file.parseDiagnostics.length) { - var modifiersStart = skipTrivia(sourceText, pos); - grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers); - } - return exportAssignmentTail; + return parseExportAssignmentTail(pos, flags); } } @@ -3753,6 +3750,7 @@ module ts { case SyntaxKind.ConstructSignature: return visitConstructSignature(node); case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); + case SyntaxKind.ExportAssignment: return visitExportAssignment(node); case SyntaxKind.ForInStatement: return visitForInStatement(node); case SyntaxKind.ForStatement: return visitForStatement(node); case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); @@ -4069,6 +4067,12 @@ module ts { return false; } + function visitExportAssignment(node: ExportAssignment) { + if (node.flags & NodeFlags.Modifier) { + grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); + } + } + function visitForInStatement(node: ForInStatement) { checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations); diff --git a/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt b/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt index 20355aec05c..f8dc0114593 100644 --- a/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt +++ b/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt @@ -1,11 +1,8 @@ tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts(2,1): error TS1120: An export assignment cannot have modifiers. -tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -==== tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts (2 errors) ==== +==== tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts (1 errors) ==== var x; export declare export = x; - ~~~~~~~~~~~~~~ -!!! error TS1120: An export assignment cannot have modifiers. - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file + ~~~~~~ +!!! error TS1120: An export assignment cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt b/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt index 1d2f2e265d3..2f9d8d801af 100644 --- a/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt +++ b/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt @@ -1,11 +1,8 @@ tests/cases/compiler/exportAssignmentWithDeclareModifier.ts(2,1): error TS1120: An export assignment cannot have modifiers. -tests/cases/compiler/exportAssignmentWithDeclareModifier.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -==== tests/cases/compiler/exportAssignmentWithDeclareModifier.ts (2 errors) ==== +==== tests/cases/compiler/exportAssignmentWithDeclareModifier.ts (1 errors) ==== var x; declare export = x; ~~~~~~~ -!!! error TS1120: An export assignment cannot have modifiers. - ~~~~~~~~~~~~~~~~~~~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file +!!! error TS1120: An export assignment cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt b/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt index e19ce5bc856..275f4b0ba1f 100644 --- a/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt +++ b/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt @@ -1,11 +1,8 @@ tests/cases/compiler/exportAssignmentWithExportModifier.ts(2,1): error TS1120: An export assignment cannot have modifiers. -tests/cases/compiler/exportAssignmentWithExportModifier.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -==== tests/cases/compiler/exportAssignmentWithExportModifier.ts (2 errors) ==== +==== tests/cases/compiler/exportAssignmentWithExportModifier.ts (1 errors) ==== var x; export export = x; ~~~~~~ -!!! error TS1120: An export assignment cannot have modifiers. - ~~~~~~~~~~~~~~~~~~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file +!!! error TS1120: An export assignment cannot have modifiers. \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts b/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts index 02e40fd3645..c3295440986 100644 --- a/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts +++ b/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts @@ -1,2 +1,3 @@ -var x; +// @module: commonjs +var x; export declare export = x; \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts b/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts index e38f7fa8d38..0cd0625e120 100644 --- a/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts +++ b/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts @@ -1,2 +1,3 @@ -var x; +// @module: commonjs +var x; declare export = x; \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithExportModifier.ts b/tests/cases/compiler/exportAssignmentWithExportModifier.ts index c6b543caeec..9d940eb2789 100644 --- a/tests/cases/compiler/exportAssignmentWithExportModifier.ts +++ b/tests/cases/compiler/exportAssignmentWithExportModifier.ts @@ -1,2 +1,3 @@ -var x; +// @module: commonjs +var x; export export = x; \ No newline at end of file From 75977add21be4bdd4d59d64c1795aa25997f6dbe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 16:32:27 -0800 Subject: [PATCH 35/60] Move octal checks to the grammar checker. --- src/compiler/parser.ts | 25 +++++---- src/compiler/types.ts | 1 + .../reference/objectLiteralErrors.errors.txt | 53 ++++++++++++++++++- .../scannerNumericLiteral3.errors.txt | 5 +- .../scannerNumericLiteral9.errors.txt | 5 +- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 871e5d60ea7..96a1534e77f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1403,16 +1403,11 @@ module ts { // never get a token like this. Instead, we would get 00 and 9 as two separate tokens. // We also do not need to check for negatives because any prefix operator would be part of a // parent unary expression. - if (node.kind === SyntaxKind.NumericLiteral - && sourceText.charCodeAt(tokenPos) === CharacterCodes._0 - && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { + if (node.kind === SyntaxKind.NumericLiteral && + sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && + isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - if (isInStrictMode) { - grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); - } - else if (languageVersion >= ScriptTarget.ES5) { - grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); - } + node.flags |= NodeFlags.OctalLiteral; } return node; @@ -3764,6 +3759,7 @@ module ts { case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); case SyntaxKind.NewExpression: return visitNewExpression(node); case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); + case SyntaxKind.NumericLiteral: return visitNumericLiteral(node); case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); @@ -4262,6 +4258,17 @@ module ts { }); } + function visitNumericLiteral(node: LiteralExpression): void { + if (node.flags & NodeFlags.OctalLiteral) { + if (node.flags & NodeFlags.ParsedInStrictMode) { + grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); + } + else if (languageVersion >= ScriptTarget.ES5) { + grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + } + } + } + function visitParameter(node: ParameterDeclaration): void { checkParameterName(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7865a4f2463..81e2375780d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -273,6 +273,7 @@ module ts { // Set if this node was parsed in strict mode. Used for grammar error checks, as well as // checking if the node can be reused in incremental settings. ParsedInStrictMode = 0x00002000, + OctalLiteral = 0x00004000, Modifier = Export | Ambient | Public | Private | Protected | Static, AccessibilityModifier = Public | Private | Protected, diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 8a1774c4525..d27823a30a3 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -1,5 +1,22 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(23,22): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(24,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(25,22): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(26,25): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(27,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(28,22): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(29,24): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(30,24): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(31,24): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(32,25): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,25): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(34,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,23): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,27): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,26): error TS1119: An object literal cannot have property and accessor with the same name. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(40,46): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,12): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(3,18): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(4,12): error TS2300: Duplicate identifier 'a'. @@ -79,7 +96,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,12) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51): error TS2380: 'get' and 'set' accessor must have the same type. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (96 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; @@ -177,71 +194,99 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51) // Accessor and property with the same name var f1 = { a: 0, get a() { return 0; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f2 = { a: '', get a() { return ''; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f3 = { a: 0, get a() { return ''; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f4 = { a: true, get a() { return false; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f5 = { a: {}, get a() { return {}; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2300: Duplicate identifier 'a'. var f6 = { a: 0, get 'a'() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f7 = { 'a': 0, get a() { return 0; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~ !!! error TS2300: Duplicate identifier 'a'. var f8 = { 'a': 0, get "a"() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~~~ !!! error TS2300: Duplicate identifier '"a"'. var f9 = { 'a': 0, get 'a'() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier ''a''. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f10 = { "a": 0, get 'a'() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '"a"'. ~~~ !!! error TS2300: Duplicate identifier ''a''. var f11 = { 1.0: 0, get '1'() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '1.0'. ~~~ !!! error TS2300: Duplicate identifier ''1''. var f12 = { 0: 0, get 0() { return 0; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var f13 = { 0: 0, get 0() { return 0; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~ !!! error TS2300: Duplicate identifier '0'. var f14 = { 0: 0, get 0x0() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~~~ @@ -254,16 +299,22 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51) ~~~ !!! error TS2300: Duplicate identifier '000'. var f15 = { "100": 0, get 1e2() { return 0; } }; + ~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~~~ !!! error TS2300: Duplicate identifier '"100"'. ~~~ !!! error TS2300: Duplicate identifier '1e2'. var f16 = { 0x20: 0, get 3.2e1() { return 0; } }; + ~~~~~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~~ !!! error TS2300: Duplicate identifier '0x20'. ~~~~~ !!! error TS2300: Duplicate identifier '3.2e1'. var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } }; + ~ +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier 'a'. ~ diff --git a/tests/baselines/reference/scannerNumericLiteral3.errors.txt b/tests/baselines/reference/scannerNumericLiteral3.errors.txt index 4bfbbd3b42a..894eb391f60 100644 --- a/tests/baselines/reference/scannerNumericLiteral3.errors.txt +++ b/tests/baselines/reference/scannerNumericLiteral3.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral3.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral3.ts(1,3): error TS1005: ';' expected. -==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral3.ts (2 errors) ==== +==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral3.ts (1 errors) ==== 01.0 - ~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. ~~ !!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/scannerNumericLiteral9.errors.txt b/tests/baselines/reference/scannerNumericLiteral9.errors.txt index 3bcf3a34d80..7f53ca111d9 100644 --- a/tests/baselines/reference/scannerNumericLiteral9.errors.txt +++ b/tests/baselines/reference/scannerNumericLiteral9.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts(1,3): error TS1005: ';' expected. -==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts (2 errors) ==== +==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral9.ts (1 errors) ==== 009 - ~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. ~ !!! error TS1005: ';' expected. \ No newline at end of file From b2112f863affbe556d587208bea45df13701b969 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 16:47:43 -0800 Subject: [PATCH 36/60] Move module name checks to the grammar checker. Make some errors shorter. --- src/compiler/parser.ts | 42 ++++--- ...DeclarationInModuleDeclaration1.errors.txt | 2 +- .../reference/importInsideModule.errors.txt | 2 +- .../parserExportAssignment5.errors.txt | 2 +- .../amd/intReferencingExtAndInt.errors.txt | 2 +- .../node/intReferencingExtAndInt.errors.txt | 2 +- .../nestedLocalModuleSimpleCase.errors.txt | 2 +- .../nestedLocalModuleSimpleCase.errors.txt | 2 +- ...calModuleWithRecursiveTypecheck.errors.txt | 2 +- ...calModuleWithRecursiveTypecheck.errors.txt | 2 +- ...dModuleDeclarationsInsideModule.errors.txt | 7 +- ...dModuleDeclarationsInsideModule.errors.txt | 7 +- ...arationsInsideNonExportedModule.errors.txt | 7 +- ...arationsInsideNonExportedModule.errors.txt | 7 +- ...leImportStatementInParentModule.errors.txt | 7 +- ...leImportStatementInParentModule.errors.txt | 7 +- ...ateStringsTypeArgumentInference.errors.txt | 112 +++++++++--------- ...tringsWithIncompatibleTypedTags.errors.txt | 36 +++--- ...ithManyCallAndMemberExpressions.errors.txt | 4 +- ...eStringsWithOverloadResolution1.errors.txt | 24 ++-- ...eStringsWithOverloadResolution2.errors.txt | 8 +- ...eStringsWithOverloadResolution3.errors.txt | 88 +++++++------- ...mplateStringsWithTagsTypedAsAny.errors.txt | 40 +++---- ...gedTemplateStringsWithTypedTags.errors.txt | 32 ++--- ...tringsArrayTypeDefinedInES5Mode.errors.txt | 4 +- ...ringsArrayTypeNotDefinedES5Mode.errors.txt | 4 +- 26 files changed, 221 insertions(+), 233 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 96a1534e77f..696b3986c54 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3375,14 +3375,6 @@ module ts { var node = createNode(SyntaxKind.ModuleDeclaration, pos); node.flags = flags; node.name = parseStringLiteral(); - if (!inAmbientContext) { - var errorCount = file.parseDiagnostics.length; - // Only report this error if we have not already errored about a missing declare modifier, - // which would have been at or after pos - if (!errorCount || file.parseDiagnostics[errorCount - 1].start < getTokenPos(pos)) { - grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); - } - } // For error recovery, just in case the user forgot the declare modifier on this ambient // external module, treat it as ambient anyway. @@ -4080,7 +4072,7 @@ module ts { function checkForMoreThanOneDeclaration(declarations: NodeArray) { if (declarations && declarations.length > 1) { - return grammarErrorOnNode(declarations[1], Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + return grammarErrorOnFirstToken(declarations[1], Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); } } @@ -4174,16 +4166,30 @@ module ts { } function visitModuleDeclaration(node: ModuleDeclaration): void { + checkModuleDeclarationName(node) || + checkModuleDeclarationStatements(node); + } + + function checkModuleDeclarationName(node: ModuleDeclaration) { + if (!inAmbientContext && node.name.kind === SyntaxKind.StringLiteral) { + return grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); + } + } + + function checkModuleDeclarationStatements(node: ModuleDeclaration): boolean { if (node.name.kind === SyntaxKind.Identifier && node.body.kind === SyntaxKind.ModuleBlock) { - forEach((node.body).statements, s => { - if (s.kind === SyntaxKind.ExportAssignment) { + var statements = (node.body).statements; + for (var i = 0, n = statements.length; i < n; i++) { + var statement = statements[i]; + + if (statement.kind === SyntaxKind.ExportAssignment) { // Export assignments are not allowed in an internal module - grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return grammarErrorOnFirstToken(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (s.kind === SyntaxKind.ImportDeclaration && (s).externalModuleName) { - grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + else if (statement.kind === SyntaxKind.ImportDeclaration && (statement).externalModuleName) { + return grammarErrorOnFirstToken(statement, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } - }); + } } } @@ -4446,7 +4452,7 @@ module ts { function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { if (languageVersion < ScriptTarget.ES6) { - grammarErrorOnNode(node, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } } @@ -4493,10 +4499,10 @@ module ts { var decl = declarations[0]; if (languageVersion < ScriptTarget.ES6) { if (decl.flags & NodeFlags.Let) { - return grammarErrorOnNode(decl, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + return grammarErrorOnFirstToken(decl, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (decl.flags & NodeFlags.Const) { - return grammarErrorOnNode(decl, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + return grammarErrorOnFirstToken(decl, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } } } diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt index 82132947ee5..ba6aae1e361 100644 --- a/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt @@ -4,6 +4,6 @@ tests/cases/compiler/importDeclarationInModuleDeclaration1.ts(2,5): error TS1147 ==== tests/cases/compiler/importDeclarationInModuleDeclaration1.ts (1 errors) ==== module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. } \ No newline at end of file diff --git a/tests/baselines/reference/importInsideModule.errors.txt b/tests/baselines/reference/importInsideModule.errors.txt index dc89bb5e9ca..4a7ab9d5b78 100644 --- a/tests/baselines/reference/importInsideModule.errors.txt +++ b/tests/baselines/reference/importInsideModule.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/importInsideModule_file2.ts(2,26): error TS2307: Cannot fin ==== tests/cases/compiler/importInsideModule_file2.ts (2 errors) ==== export module myModule { import foo = require("importInsideModule_file1"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'importInsideModule_file1'. diff --git a/tests/baselines/reference/parserExportAssignment5.errors.txt b/tests/baselines/reference/parserExportAssignment5.errors.txt index b463034f621..16c4188bc08 100644 --- a/tests/baselines/reference/parserExportAssignment5.errors.txt +++ b/tests/baselines/reference/parserExportAssignment5.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignm ==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment5.ts (2 errors) ==== module M { export = A; - ~~~~~~~~~~~ + ~~~~~~ !!! error TS1063: An export assignment cannot be used in an internal module. ~~~~~~~~~~~ !!! error TS2304: Cannot find name 'A'. diff --git a/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt b/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt index 29925d22556..59cbb44a3c5 100644 --- a/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt +++ b/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt @@ -4,7 +4,7 @@ internal2.ts(2,2): error TS1147: Import declarations in an internal module canno ==== internal2.ts (1 errors) ==== module outer { import g = require("external2") - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var a = g.square(5); export var b = "foo"; diff --git a/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt b/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt index 29925d22556..59cbb44a3c5 100644 --- a/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt +++ b/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt @@ -4,7 +4,7 @@ internal2.ts(2,2): error TS1147: Import declarations in an internal module canno ==== internal2.ts (1 errors) ==== module outer { import g = require("external2") - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var a = g.square(5); export var b = "foo"; diff --git a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt index b2bc48b4543..43f02e4fb9d 100644 --- a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt @@ -4,7 +4,7 @@ test1.ts(2,2): error TS1147: Import declarations in an internal module cannot re ==== test1.ts (1 errors) ==== export module myModule { import foo = require("test2"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); } diff --git a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt index b2bc48b4543..43f02e4fb9d 100644 --- a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt @@ -4,7 +4,7 @@ test1.ts(2,2): error TS1147: Import declarations in an internal module cannot re ==== test1.ts (1 errors) ==== export module myModule { import foo = require("test2"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); } diff --git a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt index d40bca73971..35c81a722d1 100644 --- a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt @@ -5,7 +5,7 @@ test1.ts(3,2): error TS1147: Import declarations in an internal module cannot re module myModule { import foo = require("test2"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); diff --git a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt index d40bca73971..35c81a722d1 100644 --- a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt @@ -5,7 +5,7 @@ test1.ts(3,2): error TS1147: Import declarations in an internal module cannot re module myModule { import foo = require("test2"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index b92bb48308d..09f7aed73fb 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,11 +1,10 @@ testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== testGlo.ts (2 errors) ==== +==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { @@ -26,8 +25,6 @@ testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index b92bb48308d..09f7aed73fb 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,11 +1,10 @@ testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== testGlo.ts (2 errors) ==== +==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { @@ -26,8 +25,6 @@ testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index bbf4831914b..ad44386dcd1 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,14 +1,13 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m1 { } module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { @@ -29,8 +28,6 @@ test.ts(24,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index bbf4831914b..ad44386dcd1 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,14 +1,13 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m1 { } module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { @@ -29,8 +28,6 @@ test.ts(24,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index ff9a9f604a3..0d281b950f4 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,11 +1,10 @@ test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M1 { @@ -47,8 +46,6 @@ test.ts(42,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M3 { export var c3 = new mNonExported.mne.class1; export function f3() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index ff9a9f604a3..0d281b950f4 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,11 +1,10 @@ test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M1 { @@ -47,8 +46,6 @@ test.ts(42,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M3 { export var c3 = new mNonExported.mne.class1; export function f3() { diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index c4a34fccd95..ac184e9489f 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -1,31 +1,31 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(5,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(9,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(13,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(16,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(23,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(27,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(28,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(29,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(33,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(34,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(35,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(39,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(40,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(41,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(45,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(46,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(47,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(51,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(52,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(53,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(57,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(58,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,11): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,11): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(81,11): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(86,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(90,11): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(5,10): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(9,17): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(13,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(16,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(20,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(23,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(27,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(28,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(29,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(33,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(34,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(35,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(39,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(40,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(41,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(45,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(46,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(47,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(51,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(52,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(53,15): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(57,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(58,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(81,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(86,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(90,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. @@ -38,104 +38,104 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference // Generic tag with one parameter function noParams(n: T) { } noParams ``; - ~~~~~~~~~~~ + ~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with parameter which does not use type parameter function noGenericParams(n: string[]) { } noGenericParams ``; - ~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. function someGenerics1b(n: string[], m: U) { } someGenerics1b `${3}`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of function type whose parameter is of type parameter type function someGenerics2a(strs: string[], n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter function someGenerics3(strs: string[], producer: () => T) { } someGenerics3 `${() => ''}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics3 `${() => undefined}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics3 `${() => 3}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics4 `${''}${ () => 3 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics4 `${ null }${ null }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics5 `${ '' }${ () => 3 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics5 `${null}${null}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics6 `${ n => n }${ n => n}${ n => n}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple arguments of function types that each have parameters of different generic type function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics7 `${ n => n }${ n => n }${ n => n }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with argument of generic function type function someGenerics8(strs: string[], n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. x `${null}${null}${null}`; - ~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic tag with multiple parameters of generic type passed arguments with no best common type @@ -143,7 +143,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. @@ -161,7 +161,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference } var a9e = someGenerics9 `${ undefined }${ { x: 6, z: new Date() } }${ { x: 6, y: '' } }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. @@ -170,20 +170,20 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference // Generic tag with multiple parameters of generic type passed arguments with a single best common type var a9d = someGenerics9 `${ { x: 3 }}${ { x: 6 }}${ { x: 6 } }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a9d: { x: number; }; // Generic tag with multiple parameters of generic type where one argument is of type 'any' var anyVar: any; var a = someGenerics9 `${ 7 }${ anyVar }${ 4 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a: any; // Generic tag with multiple parameters of generic type where one argument is [] and the other is not 'any' var arr = someGenerics9 `${ [] }${ null }${ undefined }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var arr: any[]; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt index 7dedca9eb32..6676a6d8a81 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(12,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(16,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(12,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(16,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. @@ -28,49 +28,49 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped var f: I; f `abc` - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`.member - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`.member; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`["member"]; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"]; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${ true }def${ true }ghi`["member"].member `abc${ 1 }def${ 2 }ghi`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt index f6300855a1c..17c0b330dbb 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts(13,21): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts(13,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts (1 errors) ==== @@ -15,7 +15,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMember var f: I; var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt index d49ec4b716d..bb5b56578df 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(16,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(17,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(18,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(20,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(21,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(16,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(17,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(18,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(20,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(21,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(12,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(14,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. @@ -31,24 +31,24 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio !!! error TS2346: Supplied parameters do not match any signature of call target. var u = foo ``; // number - ~~~~~~ + ~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var v = foo `${1}`; // string - ~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var w = foo `${1}${2}`; // boolean - ~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var x = foo `${1}${true}`; // boolean (with error) - ~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. var y = foo `${1}${"2"}`; // {} - ~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var z = foo `${1}${2}${3}`; // any (with error) - ~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt index fcde15afc27..3bf4af39779 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(8,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(17,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(8,14): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts(17,14): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts (2 errors) ==== @@ -11,7 +11,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio } var a = foo1 `${1}`; // string - ~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var b = foo1([], 1); // number @@ -22,6 +22,6 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio } var c = foo2 `${1}`; // number - ~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var d = foo2([], 1); // number \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt index dd943e518f3..3ffe3d5820d 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution3.errors.txt @@ -1,25 +1,25 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(7,17): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(10,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(16,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(17,16): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(23,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(34,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(35,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(36,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(40,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(41,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(42,9): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(45,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(54,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(55,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(56,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(57,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(60,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(63,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(64,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(70,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(71,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(7,21): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(10,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(16,20): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(17,20): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(23,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(26,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(34,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(35,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(36,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(40,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(41,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(42,13): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(45,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(54,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(55,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(56,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(57,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(60,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(63,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(64,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(70,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(71,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(10,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(19,4): error TS2339: Property 'foo' does not exist on type 'Date'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution3.ts(45,1): error TS2346: Supplied parameters do not match any signature of call target. @@ -36,12 +36,12 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn1() { return null; } var s: string = fn1 `${ undefined }`; - ~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // No candidate overloads found fn1 `${ {} }`; // Error - ~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~ !!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. @@ -51,10 +51,10 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn2() { return undefined; } var d1: Date = fn2 `${ 0 }${ undefined }`; // contextually typed - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var d2 = fn2 `${ 0 }${ undefined }`; // any - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. d1.foo(); // error @@ -64,12 +64,12 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio // Generic and non-generic overload where generic overload is the only candidate fn2 `${ 0 }${ '' }`; // OK - ~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic and non-generic overload where non-generic overload is the only candidate fn2 `${ '' }${ 0 }`; // OK - ~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with differing arity @@ -79,30 +79,30 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn3() { return null; } var s = fn3 `${ 3 }`; - ~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var s = fn3 `${'' }${ 3 }${ '' }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n = fn3 `${ 5 }${ 5 }${ 5 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n: number; // Generic overloads with differing arity tagging with arguments matching each overload type parameter count var s = fn3 `${ 4 }` - ~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var s = fn3 `${ '' }${ '' }${ '' }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var n = fn3 `${ '' }${ '' }${ 3 }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with differing arity tagging with argument count that doesn't match any overload fn3 ``; // Error - ~~~~~~ + ~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. @@ -115,31 +115,31 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio // Generic overloads with constraints tagged with types that satisfy the constraints fn4 `${ '' }${ 3 }`; - ~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ 3 }${ '' }`; - ~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ 3 }${ undefined }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. fn4 `${ '' }${ null }`; - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with constraints called with type arguments that do not satisfy the constraints fn4 `${ null }${ null }`; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. // Generic overloads with constraints called without type arguments but with types that do not satisfy the constraints fn4 `${ true }${ null }`; - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'. fn4 `${ null }${ true }`; - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. @@ -149,12 +149,12 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolutio function fn5(strs: TemplateStringsArray, f: (n: number) => void): number; function fn5() { return undefined; } fn5 `${ (n) => n.toFixed() }`; // will error; 'n' should have type 'string'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~ !!! error TS2339: Property 'toFixed' does not exist on type 'string'. fn5 `${ (n) => n.substr(0) }`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt index 8a334a5611b..a50339adf11 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt @@ -1,56 +1,56 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(3,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(5,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(7,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(9,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(11,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(13,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(3,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(5,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(7,7): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(9,7): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(11,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(13,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts (10 errors) ==== var f: any; f `abc` - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.g.h `abc` - ~~~~~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.g.h `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`.member - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`.member; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`["member"]; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"]; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt index 41f3492317f..02de690a22b 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(12,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(14,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(16,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(12,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(14,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(16,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts (8 errors) ==== @@ -21,35 +21,35 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,1 var f: I; f `abc` - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`.member - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`.member; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`["member"]; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"]; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index a5e05d986c1..572ddfbd683 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. lib.d.ts(502,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. @@ -21,5 +21,5 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2 !!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. f `abcdef${ 1234 }${ 5678 }ghijkl`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt index 6b2d29139ed..56793bf95ad 100644 --- a/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeNotDefinedES5Mode.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(7,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(7,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. @@ -14,5 +14,5 @@ tests/cases/compiler/templateStringsArrayTypeNotDefinedES5Mode.ts(5,3): error TS !!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. f `abcdef${ 1234 }${ 5678 }ghijkl`; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. \ No newline at end of file From 1a0f32213f885a55439348d4e89df5961b21f2a8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 16:55:18 -0800 Subject: [PATCH 37/60] Move type parameter error handling code to the grammar checker. --- src/compiler/parser.ts | 27 ++++++------------- src/compiler/types.ts | 3 +++ .../typeParameterConstraints1.errors.txt | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 696b3986c54..34b49c5b07d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -855,23 +855,6 @@ module ts { errorAtPos(start, length, message, arg0, arg1, arg2); } - // This is just like createDiagnosticForNode except that it uses the current file - // being parsed instead of the file containing the node. This is because during - // parse, the nodes do not have parent pointers to get to the file. - // - // It is very intentional that we are not checking or changing the lookAheadMode value - // here. 'grammarErrorOnNode' is called when we are doing extra grammar checks and not - // when we are doing the actual parsing to determine what the user wrote. In other - // words, this function is called once we have already parsed the node, and are just - // applying some stricter checks on that node. - function grammarErrorOnNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - var span = getErrorSpanForNode(node); - var start = span.end > span.pos ? skipTrivia(file.text, span.pos) : span.pos; - var length = span.end - start; - - file.parseDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - } - function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { file.parseDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); } @@ -1458,8 +1441,7 @@ module ts { // // // We do *not* want to consume the > as we're consuming the expression for "". - var expr = parseUnaryExpression(); - grammarErrorOnNode(expr, Diagnostics.Type_expected); + node.expression = parseUnaryExpression(); } } @@ -3762,6 +3744,7 @@ module ts { case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); case SyntaxKind.TupleType: return visitTupleType(node); + case SyntaxKind.TypeParameter: return visitTypeParameter(node); case SyntaxKind.TypeReference: return visitTypeReference(node); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); case SyntaxKind.VariableStatement: return visitVariableStatement(node); @@ -4467,6 +4450,12 @@ module ts { } } + function visitTypeParameter(node: TypeParameterDeclaration) { + if (node.expression) { + grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected); + } + } + function visitTypeReference(node: TypeReferenceNode) { checkForAtLeastOneTypeArgument(node.typeArguments); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 81e2375780d..97db90ea048 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -326,6 +326,9 @@ module ts { export interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; + + // For error recovery purposes. + expression?: Expression; } export interface SignatureDeclaration extends Declaration, ParsedSignature { } diff --git a/tests/baselines/reference/typeParameterConstraints1.errors.txt b/tests/baselines/reference/typeParameterConstraints1.errors.txt index e081f3c6ce6..d2e1f505c83 100644 --- a/tests/baselines/reference/typeParameterConstraints1.errors.txt +++ b/tests/baselines/reference/typeParameterConstraints1.errors.txt @@ -23,7 +23,7 @@ tests/cases/compiler/typeParameterConstraints1.ts(12,26): error TS2304: Cannot f ~ !!! error TS1110: Type expected. function foo10 (test: T) { } - ~~~ + ~ !!! error TS1110: Type expected. function foo11 (test: T) { } ~~~~ From cfb74249c895bed48215f7c81bec0ea93fbfe12d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 17:15:25 -0800 Subject: [PATCH 38/60] Don't report a grammar error for a real parse error. --- src/compiler/parser.ts | 24 ++++++++++++------- ...umConflictsWithGlobalIdentifier.errors.txt | 4 ++-- .../reference/enumMemberResolution.errors.txt | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 34b49c5b07d..7c6942960ad 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1010,7 +1010,10 @@ module ts { function createNode(kind: SyntaxKind, pos?: number): Node { nodeCount++; var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)))(); - if (!(pos >= 0)) pos = scanner.getStartPos(); + if (!(pos >= 0)) { + pos = scanner.getStartPos(); + } + node.pos = pos; node.end = pos; return node; @@ -2225,16 +2228,21 @@ module ts { // the code would be implicitly: "name.keyword; 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() && lookAhead(() => scanner.isReservedWord())) { - grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.Identifier_expected); - var id = createMissingNode(); - } - else { - var id = parseIdentifierName(); + var id: Identifier; + if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) { + var matchesPattern = lookAhead(() => { + nextToken(); + return !scanner.hasPrecedingLineBreak() && (scanner.isIdentifier() || scanner.isReservedWord); + }); + + if (matchesPattern) { + errorAtPos(dotOrBracketStart + 1, 0, Diagnostics.Identifier_expected); + id = createMissingNode(); + } } propertyAccess.left = expr; - propertyAccess.right = id; + propertyAccess.right = id || parseIdentifierName(); expr = finishNode(propertyAccess); continue; } diff --git a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.errors.txt b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.errors.txt index 235b665cdc0..e6859558f74 100644 --- a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.errors.txt +++ b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,28): error TS1003: Identifier expected. +tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,29): error TS1003: Identifier expected. tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,9): error TS2304: Cannot find name 'IgnoreRulesSpecific'. @@ -7,7 +7,7 @@ tests/cases/compiler/enumConflictsWithGlobalIdentifier.ts(4,9): error TS2304: Ca IgnoreRulesSpecific = 0, } var x = IgnoreRulesSpecific. - ~ + !!! error TS1003: Identifier expected. ~~~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'IgnoreRulesSpecific'. diff --git a/tests/baselines/reference/enumMemberResolution.errors.txt b/tests/baselines/reference/enumMemberResolution.errors.txt index 5c84c08d984..f446c0d7909 100644 --- a/tests/baselines/reference/enumMemberResolution.errors.txt +++ b/tests/baselines/reference/enumMemberResolution.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/enumMemberResolution.ts(4,28): error TS1003: Identifier expected. +tests/cases/compiler/enumMemberResolution.ts(4,29): error TS1003: Identifier expected. tests/cases/compiler/enumMemberResolution.ts(4,9): error TS2304: Cannot find name 'IgnoreRulesSpecific'. @@ -7,7 +7,7 @@ tests/cases/compiler/enumMemberResolution.ts(4,9): error TS2304: Cannot find nam IgnoreRulesSpecific = 0 } var x = IgnoreRulesSpecific. // error - ~ + !!! error TS1003: Identifier expected. ~~~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'IgnoreRulesSpecific'. From 4a76206e0c8cbcdfab9518601f841e6cb9822bf0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 17:19:03 -0800 Subject: [PATCH 39/60] Move away from a grammar error when a real parse error occurs. --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7c6942960ad..e1e2cd28a00 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2255,7 +2255,7 @@ module ts { // Check for that common pattern and report a better error message. if (inNewExpression && parseOptional(SyntaxKind.CloseBracketToken)) { indexedAccess.index = createMissingNode(); - grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + errorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); } else { indexedAccess.index = parseExpression(); From 7a414fc308ba9730c5bce0b2cb64f1b54d63dd5f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 17:43:08 -0800 Subject: [PATCH 40/60] Move parser error to the grammar checker. --- src/compiler/parser.ts | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9e13f50cd88..0b974a35200 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2317,10 +2317,11 @@ module ts { } function parseSingleTypeArgument(): TypeNode { + // Be resilient to something like: Foo<,,>(); + // We want to parse this out as a type argument list (esp. for signature help), and we + // don't want to rollback just because we were missing a type arg. The grammar checker + // will report the actual error later on. if (token === SyntaxKind.CommaToken) { - var errorStart = scanner.getTokenPos(); - var errorLength = scanner.getTextPos() - errorStart; - grammarErrorAtPos(errorStart, errorLength, Diagnostics.Type_expected); return createNode(SyntaxKind.Missing); } @@ -3920,11 +3921,27 @@ module ts { } function visitCallExpression(node: CallExpression) { - checkForTrailingComma(node.typeArguments) || - checkForAtLeastOneTypeArgument(node.typeArguments) || + checkTypeArguments(node.typeArguments) || checkForTrailingComma(node.arguments); } + function checkTypeArguments(typeArguments: NodeArray) { + return checkForTrailingComma(typeArguments) || + checkForAtLeastOneTypeArgument(typeArguments) || + checkForMissingTypeArgument(typeArguments); + } + + function checkForMissingTypeArgument(typeArguments: NodeArray) { + if (typeArguments) { + for (var i = 0, n = typeArguments.length; i < n; i++) { + var arg = typeArguments[i]; + if (arg.kind === SyntaxKind.Missing) { + return grammarErrorAtPos(arg.pos, 0, Diagnostics.Type_expected); + } + } + } + } + function checkForAtLeastOneTypeArgument(typeArguments: NodeArray) { if (typeArguments && typeArguments.length === 0) { var start = typeArguments.pos - "<".length; @@ -4185,8 +4202,7 @@ module ts { } function visitNewExpression(node: NewExpression): void { - checkForTrailingComma(node.typeArguments) || - checkForAtLeastOneTypeArgument(node.typeArguments) || + checkTypeArguments(node.typeArguments) || checkForTrailingComma(node.arguments); } @@ -4465,7 +4481,7 @@ module ts { } function visitTypeReference(node: TypeReferenceNode) { - checkForAtLeastOneTypeArgument(node.typeArguments); + checkTypeArguments(node.typeArguments); } function visitVariableDeclaration(node: VariableDeclaration) { From 76f88392a4d0b7d157747a2799c3f43d2ede498e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 17:57:35 -0800 Subject: [PATCH 41/60] Move missing argument checks to the grammar walker. --- src/compiler/parser.ts | 39 ++++++++++++------- .../reference/missingArgument1.errors.txt | 16 ++++++++ ...rserErrorRecovery_ArgumentList6.errors.txt | 5 +-- ...rserErrorRecovery_ArgumentList7.errors.txt | 5 +-- tests/cases/compiler/missingArgument1.ts | 1 + 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 tests/baselines/reference/missingArgument1.errors.txt create mode 100644 tests/cases/compiler/missingArgument1.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0b974a35200..2fe60edd4c7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2376,25 +2376,18 @@ module ts { return finishNode(node); } - function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic: DiagnosticMessage): Expression { - if (token === SyntaxKind.CommaToken) { - if (omittedExpressionDiagnostic) { - var errorStart = scanner.getTokenPos(); - var errorLength = scanner.getTextPos() - errorStart; - grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic); - } - return createNode(SyntaxKind.OmittedExpression); - } - - return parseAssignmentExpression(); + function parseAssignmentExpressionOrOmittedExpression(): Expression { + return token === SyntaxKind.CommaToken + ? createNode(SyntaxKind.OmittedExpression) + : parseAssignmentExpression(); } function parseArrayLiteralElement(): Expression { - return parseAssignmentExpressionOrOmittedExpression(/*omittedExpressionDiagnostic*/ undefined); + return parseAssignmentExpressionOrOmittedExpression(); } function parseArgumentExpression(): Expression { - return parseAssignmentExpressionOrOmittedExpression(Diagnostics.Argument_expression_expected); + return parseAssignmentExpressionOrOmittedExpression(); } function parseArrayLiteral(): ArrayLiteral { @@ -3922,7 +3915,12 @@ module ts { function visitCallExpression(node: CallExpression) { checkTypeArguments(node.typeArguments) || - checkForTrailingComma(node.arguments); + checkArguments(node.arguments); + } + + function checkArguments(arguments: NodeArray) { + return checkForTrailingComma(arguments) || + checkForOmittedArgument(arguments); } function checkTypeArguments(typeArguments: NodeArray) { @@ -3931,6 +3929,17 @@ module ts { checkForMissingTypeArgument(typeArguments); } + function checkForOmittedArgument(arguments: NodeArray) { + if (arguments) { + for (var i = 0, n = arguments.length; i < n; i++) { + var arg = arguments[i]; + if (arg.kind === SyntaxKind.OmittedExpression) { + return grammarErrorAtPos(arg.pos, 0, Diagnostics.Argument_expression_expected); + } + } + } + } + function checkForMissingTypeArgument(typeArguments: NodeArray) { if (typeArguments) { for (var i = 0, n = typeArguments.length; i < n; i++) { @@ -4203,7 +4212,7 @@ module ts { function visitNewExpression(node: NewExpression): void { checkTypeArguments(node.typeArguments) || - checkForTrailingComma(node.arguments); + checkArguments(node.arguments); } function visitObjectLiteral(node: ObjectLiteral): void { diff --git a/tests/baselines/reference/missingArgument1.errors.txt b/tests/baselines/reference/missingArgument1.errors.txt new file mode 100644 index 00000000000..02911e3c9b5 --- /dev/null +++ b/tests/baselines/reference/missingArgument1.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/missingArgument1.ts(1,7): error TS1135: Argument expression expected. +tests/cases/compiler/missingArgument1.ts(1,1): error TS2304: Cannot find name 'foo'. +tests/cases/compiler/missingArgument1.ts(1,5): error TS2304: Cannot find name 'a'. +tests/cases/compiler/missingArgument1.ts(1,8): error TS2304: Cannot find name 'b'. + + +==== tests/cases/compiler/missingArgument1.ts (4 errors) ==== + foo(a,,b); + +!!! error TS1135: Argument expression expected. + ~~~ +!!! error TS2304: Cannot find name 'foo'. + ~ +!!! error TS2304: Cannot find name 'a'. + ~ +!!! error TS2304: Cannot find name 'b'. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ArgumentList6.errors.txt b/tests/baselines/reference/parserErrorRecovery_ArgumentList6.errors.txt index 799c67593e0..cf6f7b10938 100644 --- a/tests/baselines/reference/parserErrorRecovery_ArgumentList6.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ArgumentList6.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,5): error TS1135: Argument expression expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,6): error TS1005: ')' expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,1): error TS2304: Cannot find name 'Foo'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts (2 errors) ==== Foo(, - ~ -!!! error TS1135: Argument expression expected. !!! error TS1005: ')' expected. ~~~ diff --git a/tests/baselines/reference/parserErrorRecovery_ArgumentList7.errors.txt b/tests/baselines/reference/parserErrorRecovery_ArgumentList7.errors.txt index 95f4febf447..67602cb11af 100644 --- a/tests/baselines/reference/parserErrorRecovery_ArgumentList7.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ArgumentList7.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,7): error TS1135: Argument expression expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,8): error TS1005: ')' expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,1): error TS2304: Cannot find name 'Foo'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,5): error TS2304: Cannot find name 'a'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts (4 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts (3 errors) ==== Foo(a,, - ~ -!!! error TS1135: Argument expression expected. !!! error TS1005: ')' expected. ~~~ diff --git a/tests/cases/compiler/missingArgument1.ts b/tests/cases/compiler/missingArgument1.ts new file mode 100644 index 00000000000..27408bc2cd8 --- /dev/null +++ b/tests/cases/compiler/missingArgument1.ts @@ -0,0 +1 @@ +foo(a,,b); \ No newline at end of file From 9751dca80962409aadc9c3b9b4a8e8158ca90bdb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 18:06:01 -0800 Subject: [PATCH 42/60] Move property initializer checks to the grammar checker. --- src/compiler/parser.ts | 10 +++-- .../reference/ambientErrors.errors.txt | 45 +++++++++++++++---- .../initializersInDeclarations.errors.txt | 25 ++++++++--- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2fe60edd4c7..12712fcf805 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2994,9 +2994,6 @@ module ts { property.initializer = parseInitializer(/*inParameter*/ false); parseSemicolon(); - if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file.parseDiagnostics.length) { - grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } return finishNode(property); } } @@ -3739,6 +3736,7 @@ module ts { case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); + case SyntaxKind.Property: return visitProperty(node); case SyntaxKind.PropertyAssignment: return visitPropertyAssignment(node); case SyntaxKind.ReturnStatement: return visitReturnStatement(node); case SyntaxKind.SetAccessor: return visitSetAccessor(node); @@ -4381,6 +4379,12 @@ module ts { } } + function visitProperty(node: PropertyDeclaration) { + if (inAmbientContext && node.initializer) { + grammarErrorOnFirstToken(node.initializer, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + function visitPropertyAssignment(node: PropertyDeclaration) { checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); } diff --git a/tests/baselines/reference/ambientErrors.errors.txt b/tests/baselines/reference/ambientErrors.errors.txt index a1e85be7401..6fe7a25dfe9 100644 --- a/tests/baselines/reference/ambientErrors.errors.txt +++ b/tests/baselines/reference/ambientErrors.errors.txt @@ -1,5 +1,14 @@ -tests/cases/conformance/ambient/ambientErrors.ts(37,18): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/ambient/ambientErrors.ts(38,11): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/ambient/ambientErrors.ts(2,15): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/conformance/ambient/ambientErrors.ts(24,5): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/conformance/ambient/ambientErrors.ts(29,5): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/conformance/ambient/ambientErrors.ts(34,11): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/ambient/ambientErrors.ts(35,19): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/conformance/ambient/ambientErrors.ts(37,20): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/ambient/ambientErrors.ts(38,13): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/ambient/ambientErrors.ts(39,23): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/conformance/ambient/ambientErrors.ts(40,14): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/conformance/ambient/ambientErrors.ts(41,22): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/ambient/ambientErrors.ts(6,1): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/ambient/ambientErrors.ts(17,22): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/ambient/ambientErrors.ts(47,20): error TS2435: Ambient external modules cannot be nested in other modules. @@ -7,9 +16,11 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient e tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements. -==== tests/cases/conformance/ambient/ambientErrors.ts (7 errors) ==== +==== tests/cases/conformance/ambient/ambientErrors.ts (16 errors) ==== // Ambient variable with an initializer declare var x = 4; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. // Ambient functions with invalid overloads declare function fn(x: number): string; @@ -32,31 +43,47 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export // Ambient function with function body declare function fn4() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. // Ambient enum with non - integer literal constant member declare enum E1 { y = 4.23 + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. } // Ambient enum with computer member declare enum E2 { x = 'foo'.length + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. } // Ambient module with initializers for values, bodies for functions / classes declare module M1 { var x = 3; - function fn() { } - class C { - static x = 3; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. - y = 4; ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + function fn() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + class C { + static x = 3; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + y = 4; + ~ !!! error TS1039: Initializers are not allowed in ambient contexts. constructor() { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. fn() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static sfn() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. } } diff --git a/tests/baselines/reference/initializersInDeclarations.errors.txt b/tests/baselines/reference/initializersInDeclarations.errors.txt index 9e02a1cd747..99798d749c2 100644 --- a/tests/baselines/reference/initializersInDeclarations.errors.txt +++ b/tests/baselines/reference/initializersInDeclarations.errors.txt @@ -1,28 +1,43 @@ -tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,7): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,14): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,9): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,16): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(8,3): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(12,15): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(13,15): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(16,2): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(18,16): error TS1039: Initializers are not allowed in ambient contexts. -==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (2 errors) ==== +==== tests/cases/conformance/externalModules/initializersInDeclarations.ts (7 errors) ==== // Errors: Initializers & statements in declaration file declare class Foo { name = "test"; - ~ + ~~~~~~ !!! error TS1039: Initializers are not allowed in ambient contexts. "some prop" = 42; - ~ + ~~ !!! error TS1039: Initializers are not allowed in ambient contexts. fn(): boolean { return false; + ~~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. } } declare var x = []; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. declare var y = {}; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. declare module M1 { while(true); + ~~~~~ +!!! error TS1036: Statements are not allowed in ambient contexts. export var v1 = () => false; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. } \ No newline at end of file From bffd1d2ae25329c2927ffd237552d33476dd5cad Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 18:36:05 -0800 Subject: [PATCH 43/60] Move errors about "new Foo[]" to the grammar checker. --- src/compiler/parser.ts | 17 ++++++++++--- .../reference/badArraySyntax.errors.txt | 25 ++++++++----------- ...annotInvokeNewOnErrorExpression.errors.txt | 4 +-- .../reference/createArray.errors.txt | 16 ++++++------ .../baselines/reference/libMembers.errors.txt | 4 +-- .../reference/newOperator.errors.txt | 12 +++++---- ...rserObjectCreationArrayLiteral1.errors.txt | 4 +-- ...rserObjectCreationArrayLiteral3.errors.txt | 4 +-- .../reference/parserRealSource10.errors.txt | 20 +++++++-------- .../reference/parserRealSource11.errors.txt | 17 +++++++------ .../reference/parserRealSource4.errors.txt | 4 +-- .../reference/parserRealSource7.errors.txt | 4 +-- .../reference/parserRealSource9.errors.txt | 4 +-- 13 files changed, 74 insertions(+), 61 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 12712fcf805..0bd407fc951 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1028,8 +1028,8 @@ module ts { return node; } - function createMissingNode(): Node { - return createNode(SyntaxKind.Missing); + function createMissingNode(pos?: number): Node { + return createNode(SyntaxKind.Missing, pos); } function internIdentifier(text: string): string { @@ -2254,7 +2254,6 @@ module ts { // Check for that common pattern and report a better error message. if (inNewExpression && parseOptional(SyntaxKind.CloseBracketToken)) { indexedAccess.index = createMissingNode(); - errorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); } else { indexedAccess.index = parseExpression(); @@ -3725,6 +3724,7 @@ module ts { case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); case SyntaxKind.FunctionType: return visitFunctionType(node); case SyntaxKind.GetAccessor: return visitGetAccessor(node); + case SyntaxKind.IndexedAccess: return visitIndexedAccess(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return visitLabeledStatement(node); @@ -4123,6 +4123,17 @@ module ts { checkAccessor(node); } + function visitIndexedAccess(node: IndexedAccess): void { + if (node.index.kind === SyntaxKind.Missing && + node.parent.kind === SyntaxKind.NewExpression && + (node.parent).func === node) { + + var start = skipTrivia(sourceText, node.parent.pos); + var end = node.end; + grammarErrorAtPos(start, end - start, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + } + } + function visitIndexSignature(node: SignatureDeclaration): void { checkIndexSignatureParameters(node); } diff --git a/tests/baselines/reference/badArraySyntax.errors.txt b/tests/baselines/reference/badArraySyntax.errors.txt index 8c9bd45fba1..500a89d85a9 100644 --- a/tests/baselines/reference/badArraySyntax.errors.txt +++ b/tests/baselines/reference/badArraySyntax.errors.txt @@ -1,32 +1,29 @@ -tests/cases/compiler/badArraySyntax.ts(6,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/badArraySyntax.ts(7,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/badArraySyntax.ts(8,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/badArraySyntax.ts(9,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/badArraySyntax.ts(10,29): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/badArraySyntax.ts(10,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/badArraySyntax.ts(6,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/badArraySyntax.ts(7,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/badArraySyntax.ts(8,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/badArraySyntax.ts(9,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/badArraySyntax.ts(10,17): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -==== tests/cases/compiler/badArraySyntax.ts (6 errors) ==== +==== tests/cases/compiler/badArraySyntax.ts (5 errors) ==== class Z { public x = ""; } var a1: Z[] = []; var a2 = new Z[]; - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. var a3 = new Z[](); - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. var a4: Z[] = new Z[]; - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. var a5: Z[] = new Z[](); - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. var a6: Z[][] = new Z [ ] [ ]; - ~~~~~~~~ -!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. - ~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. \ No newline at end of file diff --git a/tests/baselines/reference/cannotInvokeNewOnErrorExpression.errors.txt b/tests/baselines/reference/cannotInvokeNewOnErrorExpression.errors.txt index cfb9287cdbc..f0397f5ee60 100644 --- a/tests/baselines/reference/cannotInvokeNewOnErrorExpression.errors.txt +++ b/tests/baselines/reference/cannotInvokeNewOnErrorExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,21): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,9): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,15): error TS2339: Property 'ClassA' does not exist on type 'typeof M'. @@ -8,7 +8,7 @@ tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,15): error TS2339: Pr class ClassA {} } var t = new M.ClassA[]; - ~~ + ~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2339: Property 'ClassA' does not exist on type 'typeof M'. \ No newline at end of file diff --git a/tests/baselines/reference/createArray.errors.txt b/tests/baselines/reference/createArray.errors.txt index 6f79c4b47d2..2e2b4567567 100644 --- a/tests/baselines/reference/createArray.errors.txt +++ b/tests/baselines/reference/createArray.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/createArray.ts(1,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/createArray.ts(6,6): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/createArray.ts(7,19): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/createArray.ts(8,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/createArray.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/createArray.ts(6,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/createArray.ts(7,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/createArray.ts(8,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/compiler/createArray.ts(1,12): error TS2304: Cannot find name 'number'. tests/cases/compiler/createArray.ts(7,12): error TS2304: Cannot find name 'boolean'. tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'string'. @@ -9,7 +9,7 @@ tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'strin ==== tests/cases/compiler/createArray.ts (7 errors) ==== var na=new number[]; - ~~ + ~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2304: Cannot find name 'number'. @@ -18,15 +18,15 @@ tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'strin } new C[]; - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. var ba=new boolean[]; - ~~ + ~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~~ !!! error TS2304: Cannot find name 'boolean'. var sa=new string[]; - ~~ + ~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2304: Cannot find name 'string'. diff --git a/tests/baselines/reference/libMembers.errors.txt b/tests/baselines/reference/libMembers.errors.txt index a6af67821b3..73f5c945f70 100644 --- a/tests/baselines/reference/libMembers.errors.txt +++ b/tests/baselines/reference/libMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/libMembers.ts(9,16): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/libMembers.ts(9,11): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/compiler/libMembers.ts(4,3): error TS2339: Property 'subby' does not exist on type 'string'. tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' does not exist on type 'C'. @@ -15,7 +15,7 @@ tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' do export class C { } var a=new C[]; - ~~ + ~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. a.length; a.push(new C()); diff --git a/tests/baselines/reference/newOperator.errors.txt b/tests/baselines/reference/newOperator.errors.txt index 2d3fd005448..47f0a68b683 100644 --- a/tests/baselines/reference/newOperator.errors.txt +++ b/tests/baselines/reference/newOperator.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/newOperator.ts(18,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/newOperator.ts(22,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/newOperator.ts(45,23): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/newOperator.ts(18,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/newOperator.ts(20,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/newOperator.ts(45,16): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'. tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -38,14 +38,16 @@ tests/cases/compiler/newOperator.ts(31,10): error TS2351: Cannot use 'new' with // Various spacing var t3 = new string[]( ); - ~~ + ~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2304: Cannot find name 'string'. var t4 = new + ~~~ string ~~~~~~ + ~~~~~~ !!! error TS2304: Cannot find name 'string'. [ ~ @@ -78,7 +80,7 @@ tests/cases/compiler/newOperator.ts(31,10): error TS2351: Cannot use 'new' with class S { public get xs(): M.T[] { return new M.T[]; - ~~ + ~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. } } diff --git a/tests/baselines/reference/parserObjectCreationArrayLiteral1.errors.txt b/tests/baselines/reference/parserObjectCreationArrayLiteral1.errors.txt index 04be3a6d041..f0ca8d45b7a 100644 --- a/tests/baselines/reference/parserObjectCreationArrayLiteral1.errors.txt +++ b/tests/baselines/reference/parserObjectCreationArrayLiteral1.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,5): error TS2304: Cannot find name 'Foo'. ==== tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts (2 errors) ==== new Foo[]; - ~~ + ~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~ !!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/parserObjectCreationArrayLiteral3.errors.txt b/tests/baselines/reference/parserObjectCreationArrayLiteral3.errors.txt index 89f861cfcdb..3187d985cc2 100644 --- a/tests/baselines/reference/parserObjectCreationArrayLiteral3.errors.txt +++ b/tests/baselines/reference/parserObjectCreationArrayLiteral3.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,5): error TS2304: Cannot find name 'Foo'. ==== tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts (2 errors) ==== new Foo[](); - ~~ + ~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~ !!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/parserRealSource10.errors.txt b/tests/baselines/reference/parserRealSource10.errors.txt index aabafd751e7..4184d9ac23e 100644 --- a/tests/baselines/reference/parserRealSource10.errors.txt +++ b/tests/baselines/reference/parserRealSource10.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. -tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(127,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,47): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(449,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(127,29): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,32): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,37): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(449,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,36): error TS2304: Cannot find name 'string'. tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,41): error TS2304: Cannot find name 'number'. tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,35): error TS2304: Cannot find name 'boolean'. @@ -472,20 +472,20 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(356,53): error } export var tokenTable = new TokenInfo[]; - ~~ + ~~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. export var nodeTypeTable = new string[]; - ~~ + ~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2304: Cannot find name 'string'. export var nodeTypeToTokTable = new number[]; - ~~ + ~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~ !!! error TS2304: Cannot find name 'number'. export var noRegexTable = new boolean[]; - ~~ + ~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~~ !!! error TS2304: Cannot find name 'boolean'. @@ -1474,7 +1474,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(356,53): error // TODO: new with length TokenID.LimFixed export var staticTokens = new Token[]; - ~~ + ~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. export function initializeStaticTokens() { for (var i = 0; i <= TokenID.LimFixed; i++) { diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index 68fe64a63f5..c76206b821f 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -1,7 +1,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(193,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1009,45): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1024,47): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(193,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(867,29): error TS1015: Parameter cannot have question mark and initializer. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1009,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1024,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(13,22): error TS2304: Cannot find name 'Type'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(14,24): error TS2304: Cannot find name 'ASTFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(17,38): error TS2304: Cannot find name 'CompilerDiagnostics'. @@ -514,7 +515,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,30): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error TS2304: Cannot find name 'TokenID'. -==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (514 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (515 errors) ==== // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. @@ -792,7 +793,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error ~~~~~~~~~~~ !!! error TS2304: Cannot find name 'SymbolScope'. public members: AST[] = new AST[]; - ~~ + ~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. constructor () { @@ -1814,6 +1815,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error } public getAliasName(aliasAST?: AST = this.alias) : string { + ~~~~~~~~ +!!! error TS1015: Parameter cannot have question mark and initializer. if (aliasAST.nodeType == NodeType.Name) { ~~~~~~~~ !!! error TS2304: Cannot find name 'NodeType'. @@ -2026,7 +2029,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error !!! error TS2304: Cannot find name 'Symbol'. if (this.envids == null) { this.envids = new Identifier[]; - ~~ + ~~~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. } this.envids[this.envids.length] = id; @@ -2045,7 +2048,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error !!! error TS2304: Cannot find name 'Symbol'. if (this.jumpRefs == null) { this.jumpRefs = new Identifier[]; - ~~ + ~~~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. } var id = new Identifier(sym.name); diff --git a/tests/baselines/reference/parserRealSource4.errors.txt b/tests/baselines/reference/parserRealSource4.errors.txt index e0ae0d2221e..5974d62df47 100644 --- a/tests/baselines/reference/parserRealSource4.errors.txt +++ b/tests/baselines/reference/parserRealSource4.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. -tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,37): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,24): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ==== tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts (2 errors) ==== @@ -200,7 +200,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,37): error T export class HashTable { public itemCount: number = 0; public table = new HashEntry[]; - ~~ + ~~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. constructor (public size: number, public hashFn: (key) =>number, diff --git a/tests/baselines/reference/parserRealSource7.errors.txt b/tests/baselines/reference/parserRealSource7.errors.txt index 7fddac2c467..773dd499425 100644 --- a/tests/baselines/reference/parserRealSource7.errors.txt +++ b/tests/baselines/reference/parserRealSource7.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. -tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,45): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(12,38): error TS2304: Cannot find name 'ASTList'. tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(12,62): error TS2304: Cannot find name 'TypeLink'. tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,37): error TS2304: Cannot find name 'TypeLink'. @@ -326,7 +326,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(828,13): error T var len = bases.members.length; if (baseTypeLinks == null) { baseTypeLinks = new TypeLink[]; - ~~ + ~~~~~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~~~~~ !!! error TS2304: Cannot find name 'TypeLink'. diff --git a/tests/baselines/reference/parserRealSource9.errors.txt b/tests/baselines/reference/parserRealSource9.errors.txt index 1880a72f189..0dc0de6c12c 100644 --- a/tests/baselines/reference/parserRealSource9.errors.txt +++ b/tests/baselines/reference/parserRealSource9.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found. -tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(12,39): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(12,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(8,38): error TS2304: Cannot find name 'TypeChecker'. tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(9,48): error TS2304: Cannot find name 'TypeLink'. tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(9,67): error TS2304: Cannot find name 'SymbolScope'. @@ -56,7 +56,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(200,48): error T !!! error TS2304: Cannot find name 'Type'. if (typeLinks) { extendsList = new Type[]; - ~~ + ~~~~~~~~~~ !!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. ~~~~ !!! error TS2304: Cannot find name 'Type'. From 77165355112f3491d3068036a49142ceb5277c25 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 18:52:37 -0800 Subject: [PATCH 44/60] Move optional method/property checking to the grammar checker. --- src/compiler/parser.ts | 14 +++++++++++--- .../objectTypesWithOptionalProperties.errors.txt | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0bd407fc951..565320d3ebd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2968,7 +2968,9 @@ module ts { var questionStart = scanner.getTokenPos(); if (parseOptional(SyntaxKind.QuestionToken)) { - errorAtPos(questionStart, scanner.getStartPos() - questionStart, Diagnostics.A_class_member_cannot_be_declared_optional); + // Note: this is not legal as per the grammar. But we allow it in the parser and + // report an error in the grammar checker. + flags |= NodeFlags.QuestionMark; } if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { @@ -4179,7 +4181,8 @@ module ts { function visitMethod(node: MethodDeclaration) { checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters) || - checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false); + checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || + (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)); } function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean { @@ -4391,8 +4394,13 @@ module ts { } function visitProperty(node: PropertyDeclaration) { + (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)) || + checkForInitializerInAmbientContext(node); + } + + function checkForInitializerInAmbientContext(node: PropertyDeclaration) { if (inAmbientContext && node.initializer) { - grammarErrorOnFirstToken(node.initializer, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + return grammarErrorOnFirstToken(node.initializer, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } } diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt index 669fbfb595b..d33a5e35b63 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt +++ b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt @@ -1,8 +1,9 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional. +tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: An object member cannot be declared optional. -==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (2 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ==== // Basic uses of optional properties var a: { @@ -31,4 +32,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith var b = { x?: 1 // error + ~ +!!! error TS1160: An object member cannot be declared optional. } \ No newline at end of file From 6b866e719e0c1291b87ac7dcdac4cdf1bc8cdb3f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 19:04:21 -0800 Subject: [PATCH 45/60] Move indexer modifier checks to the grammar checker. --- src/compiler/parser.ts | 26 ++++++++++++------- .../parserIndexMemberDeclaration10.errors.txt | 5 +--- .../reference/staticIndexers.errors.txt | 5 +++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 565320d3ebd..724f4ea5810 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1541,8 +1541,12 @@ module ts { return finishNode(node); } - function parseIndexSignatureMember(): SignatureDeclaration { - var node = createNode(SyntaxKind.IndexSignature); + function parseIndexSignatureMember(flags: NodeFlags, pos?: number): SignatureDeclaration { + var node = createNode(SyntaxKind.IndexSignature, pos); + if (flags) { + node.flags = flags; + } + node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); parseSemicolon(); @@ -1588,7 +1592,7 @@ module ts { case SyntaxKind.LessThanToken: return parseSignatureMember(SyntaxKind.CallSignature, SyntaxKind.ColonToken); case SyntaxKind.OpenBracketToken: - return parseIndexSignatureMember(); + return parseIndexSignatureMember(/*flags:*/ 0); case SyntaxKind.NewKeyword: if (lookAhead(() => nextToken() === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken)) { return parseSignatureMember(SyntaxKind.ConstructSignature, SyntaxKind.ColonToken); @@ -3238,12 +3242,7 @@ module ts { return parsePropertyMemberDeclaration(pos, flags); } if (token === SyntaxKind.OpenBracketToken) { - if (flags) { - var start = getTokenPos(pos); - var length = getNodePos() - start; - errorAtPos(start, length, Diagnostics.Modifiers_not_permitted_on_index_signature_members); - } - return parseIndexSignatureMember(); + return parseIndexSignatureMember(flags, pos); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -4137,7 +4136,14 @@ module ts { } function visitIndexSignature(node: SignatureDeclaration): void { - checkIndexSignatureParameters(node); + checkIndexSignatureParameters(node) || + checkForIndexSignatureModifiers(node); + } + + function checkForIndexSignatureModifiers(node: SignatureDeclaration): boolean { + if (node.flags & NodeFlags.Modifier) { + return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_not_permitted_on_index_signature_members); + } } function checkIndexSignatureParameters(node: SignatureDeclaration): boolean { diff --git a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt index e85a4817d85..d448aaa3f29 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1145: Modifiers not permitted on index signature members. tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen. -==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ==== class C { static static [x: string]: string; - ~~~~~~~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. ~~~~~~ !!! error TS1030: 'static' modifier already seen. } \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexers.errors.txt b/tests/baselines/reference/staticIndexers.errors.txt index 708c505841a..29c46d0ce8c 100644 --- a/tests/baselines/reference/staticIndexers.errors.txt +++ b/tests/baselines/reference/staticIndexers.errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1145: Modifiers not permitted on index signature members. tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1145: Modifiers not permitted on index signature members. tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25): error TS2302: Static members cannot reference class type parameters. -==== tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts (3 errors) ==== +==== tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts (4 errors) ==== // static indexers not allowed class C { @@ -22,4 +23,6 @@ tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): static [x: string]: T; ~~~~~~ !!! error TS1145: Modifiers not permitted on index signature members. + ~ +!!! error TS2302: Static members cannot reference class type parameters. } \ No newline at end of file From 20f418833a35c09328935f6c6b5c2316c916b23e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 19:15:01 -0800 Subject: [PATCH 46/60] Remove forEach call in the grammar checker. --- src/compiler/parser.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 724f4ea5810..4bc565205a4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4240,12 +4240,15 @@ module ts { var SetAccesor = 4; var GetOrSetAccessor = GetAccessor | SetAccesor; var inStrictMode = (node.flags & NodeFlags.ParsedInStrictMode) !== 0; - forEach(node.properties, (p: Declaration) => { + + for (var i = 0, n = node.properties.length; i < n; i++) { + var prop = node.properties[i]; // TODO(jfreeman): continue if we have a computed property - if (p.kind === SyntaxKind.OmittedExpression) { - return; + if (prop.kind === SyntaxKind.OmittedExpression) { + continue; } + var p = prop; var name = p.name; // ECMA-262 11.1.5 Object Initialiser @@ -4295,7 +4298,7 @@ module ts { grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } - }); + } } function visitNumericLiteral(node: LiteralExpression): void { From 4fb489e64bf34b3626c48e8bd16be2e2a9ca7400 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 19 Nov 2014 19:22:39 -0800 Subject: [PATCH 47/60] move checking modifiers out of parser --- src/compiler/parser.ts | 401 ++++++++++-------- src/compiler/types.ts | 5 + .../accessibilityModifiers.errors.txt | 5 +- .../reference/exportAlreadySeen.errors.txt | 14 +- tests/baselines/reference/giant.errors.txt | 14 +- .../importDeclWithDeclareModifier.errors.txt | 5 +- ...DeclareModifierInAmbientContext.errors.txt | 8 +- .../parserConstructorDeclaration7.errors.txt | 5 +- .../parserIndexMemberDeclaration10.errors.txt | 5 +- .../parserIndexMemberDeclaration9.errors.txt | 4 +- .../parserModuleDeclaration4.d.errors.txt | 5 +- .../privacyGloImportParseErrors.errors.txt | 11 +- .../privacyImportParseErrors.errors.txt | 23 +- ...dModuleDeclarationsInsideModule.errors.txt | 5 +- ...dModuleDeclarationsInsideModule.errors.txt | 5 +- ...arationsInsideNonExportedModule.errors.txt | 5 +- ...arationsInsideNonExportedModule.errors.txt | 5 +- ...leImportStatementInParentModule.errors.txt | 5 +- ...leImportStatementInParentModule.errors.txt | 5 +- 19 files changed, 279 insertions(+), 256 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fcea7adcfff..5b0e48593a7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -821,6 +821,18 @@ module ts { _syntacticDiagnostics: Diagnostic[]; } + function modifierToFlag(token: SyntaxKind): NodeFlags { + switch (token) { + case SyntaxKind.StaticKeyword: return NodeFlags.Static; + case SyntaxKind.PublicKeyword: return NodeFlags.Public; + case SyntaxKind.ProtectedKeyword: return NodeFlags.Protected; + case SyntaxKind.PrivateKeyword: return NodeFlags.Private; + case SyntaxKind.ExportKeyword: return NodeFlags.Export; + case SyntaxKind.DeclareKeyword: return NodeFlags.Ambient; + } + return 0; + } + export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { var file: SourceFileInternal; var scanner: Scanner; @@ -1488,7 +1500,11 @@ module ts { function parseParameter(flags: NodeFlags = 0): ParameterDeclaration { var node = createNode(SyntaxKind.Parameter); - node.flags |= parseAndCheckModifiers(ModifierContext.Parameters); + var modifiers = parseModifiers(ModifierContext.Parameters); + if (modifiers) { + node.flags |= modifiers.flags; + node.modifiers = modifiers; + } if (parseOptional(SyntaxKind.DotDotDotToken)) { node.flags |= NodeFlags.Rest; } @@ -2472,7 +2488,7 @@ module ts { var initialToken = token; if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseMemberAccessorDeclaration(kind, initialPos, 0); + return parseMemberAccessorDeclaration(kind, initialPos, /*modifiers*/ undefined); } return parsePropertyAssignment(); } @@ -2982,19 +2998,23 @@ module ts { return finishNode(node); } - function parseConstructorDeclaration(pos: number, flags: NodeFlags): ConstructorDeclaration { + function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { var node = createNode(SyntaxKind.Constructor, pos); - node.flags = flags; + if (modifiers) { + node.modifiers = modifiers; + node.flags = modifiers.flags; + } parseExpected(SyntaxKind.ConstructorKeyword); var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); node.typeParameters = sig.typeParameters; node.parameters = sig.parameters; node.type = sig.type; node.body = parseFunctionBlockOrSemicolon(); + return finishNode(node); } - function parsePropertyMemberDeclaration(pos: number, flags: NodeFlags): Declaration { + function parsePropertyMemberDeclaration(pos: number, modifiers: ModifiersArray): Declaration { var errorCountBeforePropertyDeclaration = file.parseDiagnostics.length; var name = parsePropertyName(); @@ -3005,18 +3025,25 @@ module ts { if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { var method = createNode(SyntaxKind.Method, pos); - method.flags = flags; + if (modifiers) { + method.modifiers = modifiers; + method.flags = modifiers.flags; + } method.name = name; var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); method.typeParameters = sig.typeParameters; method.parameters = sig.parameters; method.type = sig.type; method.body = parseFunctionBlockOrSemicolon(); + return finishNode(method); } else { var property = createNode(SyntaxKind.Property, pos); - property.flags = flags; + if (modifiers) { + property.modifiers = modifiers; + property.flags = modifiers.flags; + } property.name = name; property.type = parseTypeAnnotation(); @@ -3032,9 +3059,12 @@ module ts { } } - function parseMemberAccessorDeclaration(kind: SyntaxKind, pos: number, flags: NodeFlags): MethodDeclaration { + function parseMemberAccessorDeclaration(kind: SyntaxKind, pos: number, modifiers: ModifiersArray): MethodDeclaration { var node = createNode(kind, pos); - node.flags = flags; + if (modifiers) { + node.modifiers = modifiers; + node.flags = modifiers.flags; + } node.name = parsePropertyName(); var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); node.typeParameters = sig.typeParameters; @@ -3103,175 +3133,44 @@ module ts { return false; } - function parseAndCheckModifiers(context: ModifierContext): number { + function parseModifiers(context: ModifierContext): ModifiersArray { var flags = 0; - var lastStaticModifierStart: number; - var lastStaticModifierLength: number; - var lastDeclareModifierStart: number; - var lastDeclareModifierLength: number; - var lastPrivateModifierStart: number; - var lastPrivateModifierLength: number; - var lastProtectedModifierStart: number; - var lastProtectedModifierLength: number; - + var modifiers: ModifiersArray; while (true) { var modifierStart = scanner.getTokenPos(); var modifierToken = token; - // Try to parse the modifier if (!parseAnyContextualModifier()) break; - var modifierLength = scanner.getStartPos() - modifierStart; - - switch (modifierToken) { - case SyntaxKind.PublicKeyword: - if (flags & NodeFlags.AccessibilityModifier) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); - } - else if (flags & NodeFlags.Static) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "public", "static"); - } - else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "public"); - } - flags |= NodeFlags.Public; - break; - - case SyntaxKind.PrivateKeyword: - if (flags & NodeFlags.AccessibilityModifier) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); - } - else if (flags & NodeFlags.Static) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "private", "static"); - } - else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "private"); - } - lastPrivateModifierStart = modifierStart; - lastPrivateModifierLength = modifierLength; - flags |= NodeFlags.Private; - break; - - case SyntaxKind.ProtectedKeyword: - if (flags & NodeFlags.Public || flags & NodeFlags.Private || flags & NodeFlags.Protected) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); - } - else if (flags & NodeFlags.Static) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "protected", "static"); - } - else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "protected"); - } - lastProtectedModifierStart = modifierStart; - lastProtectedModifierLength = modifierLength; - flags |= NodeFlags.Protected; - break; - - case SyntaxKind.StaticKeyword: - if (flags & NodeFlags.Static) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_already_seen, "static"); - } - else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); - } - else if (context === ModifierContext.Parameters) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); - } - lastStaticModifierStart = modifierStart; - lastStaticModifierLength = modifierLength; - flags |= NodeFlags.Static; - break; - - case SyntaxKind.ExportKeyword: - if (flags & NodeFlags.Export) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_already_seen, "export"); - } - else if (flags & NodeFlags.Ambient) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); - } - else if (context === ModifierContext.ClassMembers) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); - } - else if (context === ModifierContext.Parameters) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); - } - flags |= NodeFlags.Export; - break; - - case SyntaxKind.DeclareKeyword: - if (flags & NodeFlags.Ambient) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_already_seen, "declare"); - } - else if (context === ModifierContext.ClassMembers) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); - } - else if (context === ModifierContext.Parameters) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); - } - else if (inAmbientContext && context === ModifierContext.ModuleElements) { - grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); - } - lastDeclareModifierStart = modifierStart; - lastDeclareModifierLength = modifierLength; - flags |= NodeFlags.Ambient; - break; + if (!modifiers) { + modifiers = []; } + flags |= modifierToFlag(modifierToken); + modifiers.push(finishNode(createNode(modifierToken, modifierStart))); } - - if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Static) { - grammarErrorAtPos(lastStaticModifierStart, lastStaticModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); + if (modifiers) { + modifiers.flags = flags; } - else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Private) { - grammarErrorAtPos(lastPrivateModifierStart, lastPrivateModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); - } - else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Protected) { - grammarErrorAtPos(lastProtectedModifierStart, lastProtectedModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); - } - else if (token === SyntaxKind.ImportKeyword) { - if (flags & NodeFlags.Ambient) { - grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); - } - } - else if (token === SyntaxKind.InterfaceKeyword) { - if (flags & NodeFlags.Ambient) { - grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } - } - else if (token !== SyntaxKind.ExportKeyword && !(flags & NodeFlags.Ambient) && inAmbientContext && context === ModifierContext.SourceElements) { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: - // - // DeclarationElement: - // ExportAssignment - // export_opt InterfaceDeclaration - // export_opt ImportDeclaration - // export_opt ExternalImportDeclaration - // export_opt AmbientDeclaration - // - var declarationStart = scanner.getTokenPos(); - var declarationFirstTokenLength = scanner.getTextPos() - declarationStart; - grammarErrorAtPos(declarationStart, declarationFirstTokenLength, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); - } - return flags; + return modifiers; } function parseClassMemberDeclaration(): Declaration { var pos = getNodePos(); - var flags = parseAndCheckModifiers(ModifierContext.ClassMembers); + var modifiers = parseModifiers(ModifierContext.ClassMembers); if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.GetAccessor, pos, flags); + return parseMemberAccessorDeclaration(SyntaxKind.GetAccessor, pos, modifiers); } if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.SetAccessor, pos, flags); + return parseMemberAccessorDeclaration(SyntaxKind.SetAccessor, pos, modifiers); } if (token === SyntaxKind.ConstructorKeyword) { - return parseConstructorDeclaration(pos, flags); + return parseConstructorDeclaration(pos, modifiers); } if (token >= SyntaxKind.Identifier || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) { - return parsePropertyMemberDeclaration(pos, flags); + return parsePropertyMemberDeclaration(pos, modifiers); } if (token === SyntaxKind.OpenBracketToken) { - if (flags) { + if (modifiers) { var start = getTokenPos(pos); var length = getNodePos() - start; errorAtPos(start, length, Diagnostics.Modifiers_not_permitted_on_index_signature_members); @@ -3472,14 +3371,13 @@ module ts { function parseDeclaration(modifierContext: ModifierContext): Statement { var pos = getNodePos(); var errorCountBeforeModifiers = file.parseDiagnostics.length; - var flags = parseAndCheckModifiers(modifierContext); - + var modifiers = parseModifiers(modifierContext); if (token === SyntaxKind.ExportKeyword) { var modifiersEnd = scanner.getStartPos(); nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { var exportAssignmentTail = parseExportAssignmentTail(pos); - if (flags !== 0 && errorCountBeforeModifiers === file.parseDiagnostics.length) { + if (modifiers && errorCountBeforeModifiers === file.parseDiagnostics.length) { var modifiersStart = skipTrivia(sourceText, pos); grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers); } @@ -3488,10 +3386,10 @@ module ts { } var saveInAmbientContext = inAmbientContext; - if (flags & NodeFlags.Ambient) { + if (modifiers && modifiers.flags & NodeFlags.Ambient) { inAmbientContext = true; } - + var flags = modifiers ? modifiers.flags : 0; var result: Declaration; switch (token) { case SyntaxKind.VarKeyword: @@ -3532,6 +3430,10 @@ module ts { error(Diagnostics.Declaration_expected); } + if (modifiers) { + result.modifiers = modifiers; + } + inAmbientContext = saveInAmbientContext; return result; } @@ -3711,14 +3613,17 @@ module ts { node.parent = parent; parent = node; - var savedInAmbientContext = inAmbientContext - if (node.flags & NodeFlags.Ambient) { - inAmbientContext = true; + if (!checkModifiers(node)) { + var savedInAmbientContext = inAmbientContext + if (node.flags & NodeFlags.Ambient) { + inAmbientContext = true; + } + + checkNode(node); + + inAmbientContext = savedInAmbientContext; } - checkNode(node); - - inAmbientContext = savedInAmbientContext; parent = savedParent; } @@ -3743,7 +3648,7 @@ module ts { dispatch(node); } - function dispatch(node: Node) { + function dispatch(node: Node): void { switch (node.kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); @@ -4026,8 +3931,13 @@ module ts { } function visitEnumDeclaration(enumDecl: EnumDeclaration) { + checkEnumInitializer(enumDecl); + } + + function checkEnumInitializer(enumDecl: EnumDeclaration): boolean { var enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0; + var hasError = false; // skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions. // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. if (!enumIsConst) { @@ -4036,17 +3946,18 @@ module ts { var node = enumDecl.members[i]; if (inAmbientContext) { if (node.initializer && !isIntegerLiteral(node.initializer)) { - grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers); + hasError = grammarErrorOnNode(node.name, Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; } } else if (node.initializer) { inConstantEnumMemberSection = isIntegerLiteral(node.initializer); } else if (!inConstantEnumMemberSection) { - grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer); + hasError = grammarErrorOnNode(node.name, Diagnostics.Enum_member_must_have_initializer) || hasError; } } } + return hasError; } function isIntegerLiteral(expression: Expression): boolean { @@ -4177,14 +4088,18 @@ module ts { } function visitModuleDeclaration(node: ModuleDeclaration): void { + checkInternalModule(node); + } + + function checkInternalModule(node: ModuleDeclaration): boolean { if (node.name.kind === SyntaxKind.Identifier && node.body.kind === SyntaxKind.ModuleBlock) { - forEach((node.body).statements, s => { + return forEach((node.body).statements, s => { if (s.kind === SyntaxKind.ExportAssignment) { // Export assignments are not allowed in an internal module - grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return grammarErrorOnNode(s, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } else if (s.kind === SyntaxKind.ImportDeclaration && (s).externalModuleName) { - grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + return grammarErrorOnNode(s, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } }); } @@ -4261,6 +4176,148 @@ module ts { }); } + function checkTopLevelDeclareModifierInAmbientContext(node: Node): boolean { + // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: + // categories: + // + // DeclarationElement: + // ExportAssignment + // export_opt InterfaceDeclaration + // export_opt ImportDeclaration + // export_opt ExternalImportDeclaration + // export_opt AmbientDeclaration + // + + if (!inAmbientContext || + !(isDeclaration(node) || node.kind === SyntaxKind.VariableStatement) || + !node.parent || + node.parent.kind !== SyntaxKind.SourceFile) { + return false; + } + + if (node.kind === SyntaxKind.InterfaceDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ExportAssignment || + (node.flags & NodeFlags.Ambient) || + (node.flags & NodeFlags.Export)) { + + return false; + } + + return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + } + + + function checkModifiers(node: Node): boolean { + if (!node.modifiers) { + return checkTopLevelDeclareModifierInAmbientContext(node); + } + var lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node; + var flags = 0; + var hasErrors = forEach(node.modifiers, m => { + switch (m.kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.PrivateKeyword: + var text: string; + if (m.kind === SyntaxKind.PublicKeyword) { + text = "public"; + } + else if (m.kind === SyntaxKind.ProtectedKeyword) { + text = "protected"; + lastProtected = m; + } + else { + text = "private"; + lastPrivate = m; + } + + if (flags & NodeFlags.AccessibilityModifier) { + return grammarErrorOnNode(m, Diagnostics.Accessibility_modifier_already_seen); + } + else if (flags & NodeFlags.Static) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); + } + else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); + } + flags |= modifierToFlag(m.kind); + break; + + case SyntaxKind.StaticKeyword: + if (flags & NodeFlags.Static) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "static"); + } + else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); + } + else if (node.kind === SyntaxKind.Parameter) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); + } + flags |= NodeFlags.Static; + lastStatic = m; + break; + + case SyntaxKind.ExportKeyword: + if (flags & NodeFlags.Export) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "export"); + } + else if (flags & NodeFlags.Ambient) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); + } + else if (node.kind === SyntaxKind.Parameter) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); + } + flags |= NodeFlags.Export; + break; + + case SyntaxKind.DeclareKeyword: + if (flags & NodeFlags.Ambient) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "declare"); + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); + } + else if (node.kind === SyntaxKind.Parameter) { + return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); + } + else if (inAmbientContext && node.parent.kind === SyntaxKind.ModuleBlock) { + return grammarErrorOnNode(m, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); + } + flags |= NodeFlags.Ambient; + lastDeclare = m; + break; + } + }); + + if (hasErrors) { + return true; + } + + if (node.kind === SyntaxKind.Constructor) { + if (flags & NodeFlags.Static) { + return grammarErrorOnNode(lastStatic, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); + } + else if (flags & NodeFlags.Protected) { + return grammarErrorOnNode(lastProtected, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); + } + else if (flags & NodeFlags.Private) { + return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); + } + } + else if (node.kind === SyntaxKind.ImportDeclaration && flags & NodeFlags.Ambient) { + return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); + } + else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { + return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); + } + + return checkTopLevelDeclareModifierInAmbientContext(node); + } + function visitParameter(node: ParameterDeclaration): void { checkParameterName(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7865a4f2463..6e7beb531fc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -288,12 +288,17 @@ module ts { locals?: SymbolTable; // Locals associated with node (initialized by binding) nextContainer?: Node; // Next container in declaration order (initialized by binding) localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + modifiers?: ModifiersArray; // Array of modifiers } export interface NodeArray extends Array, TextRange { hasTrailingComma?: boolean; } + export interface ModifiersArray extends Array { + flags: number; + } + export interface Identifier extends Node { text: string; // Text of identifier (with escapes converted to characters) } diff --git a/tests/baselines/reference/accessibilityModifiers.errors.txt b/tests/baselines/reference/accessibilityModifiers.errors.txt index 137da7f982c..1bf92139761 100644 --- a/tests/baselines/reference/accessibilityModifiers.errors.txt +++ b/tests/baselines/reference/accessibilityModifiers.errors.txt @@ -11,13 +11,12 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(34,12): error TS1029: 'public' modifier must precede 'static' modifier. tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(35,12): error TS1029: 'public' modifier must precede 'static' modifier. tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,13): error TS1028: Accessibility modifier already seen. -tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,20): error TS1028: Accessibility modifier already seen. tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(41,12): error TS1028: Accessibility modifier already seen. tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(42,13): error TS1028: Accessibility modifier already seen. tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(43,12): error TS1028: Accessibility modifier already seen. -==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (17 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (16 errors) ==== // No errors class C { @@ -83,8 +82,6 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifier class E { private public protected property; ~~~~~~ -!!! error TS1028: Accessibility modifier already seen. - ~~~~~~~~~ !!! error TS1028: Accessibility modifier already seen. public protected method() { } ~~~~~~~~~ diff --git a/tests/baselines/reference/exportAlreadySeen.errors.txt b/tests/baselines/reference/exportAlreadySeen.errors.txt index eb9f0ce1a95..707b34c8d25 100644 --- a/tests/baselines/reference/exportAlreadySeen.errors.txt +++ b/tests/baselines/reference/exportAlreadySeen.errors.txt @@ -1,16 +1,12 @@ tests/cases/compiler/exportAlreadySeen.ts(2,12): error TS1030: 'export' modifier already seen. tests/cases/compiler/exportAlreadySeen.ts(3,12): error TS1030: 'export' modifier already seen. tests/cases/compiler/exportAlreadySeen.ts(5,12): error TS1030: 'export' modifier already seen. -tests/cases/compiler/exportAlreadySeen.ts(6,16): error TS1030: 'export' modifier already seen. -tests/cases/compiler/exportAlreadySeen.ts(7,16): error TS1030: 'export' modifier already seen. tests/cases/compiler/exportAlreadySeen.ts(12,12): error TS1030: 'export' modifier already seen. tests/cases/compiler/exportAlreadySeen.ts(13,12): error TS1030: 'export' modifier already seen. tests/cases/compiler/exportAlreadySeen.ts(15,12): error TS1030: 'export' modifier already seen. -tests/cases/compiler/exportAlreadySeen.ts(16,16): error TS1030: 'export' modifier already seen. -tests/cases/compiler/exportAlreadySeen.ts(17,16): error TS1030: 'export' modifier already seen. -==== tests/cases/compiler/exportAlreadySeen.ts (10 errors) ==== +==== tests/cases/compiler/exportAlreadySeen.ts (6 errors) ==== module M { export export var x = 1; ~~~~~~ @@ -23,11 +19,7 @@ tests/cases/compiler/exportAlreadySeen.ts(17,16): error TS1030: 'export' modifie ~~~~~~ !!! error TS1030: 'export' modifier already seen. export export class C { } - ~~~~~~ -!!! error TS1030: 'export' modifier already seen. export export interface I { } - ~~~~~~ -!!! error TS1030: 'export' modifier already seen. } } @@ -43,10 +35,6 @@ tests/cases/compiler/exportAlreadySeen.ts(17,16): error TS1030: 'export' modifie ~~~~~~ !!! error TS1030: 'export' modifier already seen. export export class C { } - ~~~~~~ -!!! error TS1030: 'export' modifier already seen. export export interface I { } - ~~~~~~ -!!! error TS1030: 'export' modifier already seen. } } \ No newline at end of file diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index d70ac7013dd..d9d96f5abf7 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -34,10 +34,6 @@ tests/cases/compiler/giant.ts(430,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(432,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(436,9): error TS1005: '{' expected. tests/cases/compiler/giant.ts(438,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(615,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/giant.ts(616,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/giant.ts(617,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/giant.ts(618,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/giant.ts(23,12): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. @@ -174,7 +170,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (174 errors) ==== +==== tests/cases/compiler/giant.ts (170 errors) ==== /* Prefixes @@ -1128,17 +1124,9 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export interface eI { } export module eM { } export declare var eaV - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. export declare function eaF() { }; - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. export declare class eaC { } - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. export declare module eaM { } - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. } export var eV; export function eF() { }; diff --git a/tests/baselines/reference/importDeclWithDeclareModifier.errors.txt b/tests/baselines/reference/importDeclWithDeclareModifier.errors.txt index 8aeb64291a6..35c91e38dc5 100644 --- a/tests/baselines/reference/importDeclWithDeclareModifier.errors.txt +++ b/tests/baselines/reference/importDeclWithDeclareModifier.errors.txt @@ -1,17 +1,14 @@ -tests/cases/compiler/importDeclWithDeclareModifier.ts(5,1): error TS1079: A 'declare' modifier cannot be used with an import declaration. tests/cases/compiler/importDeclWithDeclareModifier.ts(5,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. tests/cases/compiler/importDeclWithDeclareModifier.ts(5,9): error TS1029: 'export' modifier must precede 'declare' modifier. tests/cases/compiler/importDeclWithDeclareModifier.ts(5,1): error TS2305: Module 'x' has no exported member 'c'. -==== tests/cases/compiler/importDeclWithDeclareModifier.ts (4 errors) ==== +==== tests/cases/compiler/importDeclWithDeclareModifier.ts (3 errors) ==== module x { interface c { } } declare export import a = x.c; - ~~~~~~~ -!!! error TS1079: A 'declare' modifier cannot be used with an import declaration. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. ~~~~~~ diff --git a/tests/baselines/reference/importDeclWithDeclareModifierInAmbientContext.errors.txt b/tests/baselines/reference/importDeclWithDeclareModifierInAmbientContext.errors.txt index 9773b293037..47d9eb1eec3 100644 --- a/tests/baselines/reference/importDeclWithDeclareModifierInAmbientContext.errors.txt +++ b/tests/baselines/reference/importDeclWithDeclareModifierInAmbientContext.errors.txt @@ -1,9 +1,7 @@ tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts(6,5): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts(6,5): error TS1079: A 'declare' modifier cannot be used with an import declaration. -tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts(6,13): error TS1029: 'export' modifier must precede 'declare' modifier. -==== tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts (3 errors) ==== +==== tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts (1 errors) ==== declare module "m" { module x { interface c { @@ -12,10 +10,6 @@ tests/cases/compiler/importDeclWithDeclareModifierInAmbientContext.ts(6,13): err declare export import a = x.c; ~~~~~~~ !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. - ~~~~~~~ -!!! error TS1079: A 'declare' modifier cannot be used with an import declaration. - ~~~~~~ -!!! error TS1029: 'export' modifier must precede 'declare' modifier. var b: a; } \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorDeclaration7.errors.txt b/tests/baselines/reference/parserConstructorDeclaration7.errors.txt index 49645ac1239..7b3f033e3cd 100644 --- a/tests/baselines/reference/parserConstructorDeclaration7.errors.txt +++ b/tests/baselines/reference/parserConstructorDeclaration7.errors.txt @@ -1,12 +1,9 @@ tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts(2,10): error TS1028: Accessibility modifier already seen. -tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts(2,10): error TS1089: 'private' modifier cannot appear on a constructor declaration. -==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ConstructorDeclarations/parserConstructorDeclaration7.ts (1 errors) ==== class C { public private constructor() { } ~~~~~~~ !!! error TS1028: Accessibility modifier already seen. - ~~~~~~~ -!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt index e85a4817d85..dc4da35ebce 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt @@ -1,12 +1,9 @@ tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen. -==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ==== class C { static static [x: string]: string; ~~~~~~~~~~~~~ !!! error TS1145: Modifiers not permitted on index signature members. - ~~~~~~ -!!! error TS1030: 'static' modifier already seen. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt index 493a7894499..00ae01b12dc 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1031: 'export' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1145: Modifiers not permitted on index signature members. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts (1 errors) ==== class C { export [x: string]: string; ~~~~~~ -!!! error TS1031: 'export' modifier cannot appear on a class element. +!!! error TS1145: Modifiers not permitted on index signature members. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt b/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt index 2e75c6cbc50..3f7cc9c53d3 100644 --- a/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt +++ b/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt @@ -1,13 +1,10 @@ tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. -tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts(2,3): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts (1 errors) ==== module M { ~~~~~~ !!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. declare module M1 { - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. } } \ No newline at end of file diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index 0ac0ed35105..4b7cbfa744f 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -1,4 +1,7 @@ +tests/cases/compiler/privacyGloImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(125,13): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/privacyGloImportParseErrors.ts(149,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -8,7 +11,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambie tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambient external modules cannot be nested in other modules. -==== tests/cases/compiler/privacyGloImportParseErrors.ts (8 errors) ==== +==== tests/cases/compiler/privacyGloImportParseErrors.ts (11 errors) ==== module m1 { export module m1_M1_public { export class c1 { @@ -72,6 +75,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -142,6 +147,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m5 { import m5_errorImport = require("glo_M2_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -174,6 +181,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m4 { var a = 10; import m2 = require("use_glo_M1_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index 6e901ab2b6d..81f0d3fd27a 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -1,6 +1,11 @@ +tests/cases/compiler/privacyImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(143,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(277,13): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(306,13): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier. -tests/cases/compiler/privacyImportParseErrors.ts(328,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/privacyImportParseErrors.ts(344,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(353,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -33,7 +38,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(333,16): error TS2435: Ambient tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient external modules cannot be nested in other modules. -==== tests/cases/compiler/privacyImportParseErrors.ts (33 errors) ==== +==== tests/cases/compiler/privacyImportParseErrors.ts (38 errors) ==== export module m1 { export module m1_M1_public { export class c1 { @@ -97,6 +102,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -189,6 +196,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m2_M3_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm2_M3_public'. export var m1_im3_private_v1_public = m1_im3_private.c1; @@ -347,6 +356,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m5 { import m5_errorImport = require("glo_M2_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -384,6 +395,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m5 { import m5_errorImport = require("glo_M4_private"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M3_private; } } @@ -420,8 +433,6 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient !!! error TS2435: Ambient external modules cannot be nested in other modules. module m2 { declare module "abc" { - ~~~~~~~ -!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. ~~~~~ !!! error TS2435: Ambient external modules cannot be nested in other modules. } @@ -444,6 +455,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m4 { var a = 10; import m2 = require("use_glo_M1_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } @@ -453,6 +466,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m4 { var a = 10; import m2 = require("use_glo_M1_public"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index b92bb48308d..cb53bb47832 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,8 +1,7 @@ testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== testGlo.ts (2 errors) ==== +==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -26,8 +25,6 @@ testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index b92bb48308d..cb53bb47832 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,8 +1,7 @@ testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== testGlo.ts (2 errors) ==== +==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -26,8 +25,6 @@ testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index bbf4831914b..6be6fe0f92a 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,8 +1,7 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m1 { } @@ -29,8 +28,6 @@ test.ts(24,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index bbf4831914b..6be6fe0f92a 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,8 +1,7 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m1 { } @@ -29,8 +28,6 @@ test.ts(24,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c3 = new mNonExported.mne.class1; export function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index ff9a9f604a3..24ce0e94beb 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,8 +1,7 @@ test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -47,8 +46,6 @@ test.ts(42,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M3 { export var c3 = new mNonExported.mne.class1; export function f3() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index ff9a9f604a3..24ce0e94beb 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,8 +1,7 @@ test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. -test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module. -==== test.ts (2 errors) ==== +==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -47,8 +46,6 @@ test.ts(42,5): error TS1147: Import declarations in an internal module cannot re } import mNonExported = require("mNonExported"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M3 { export var c3 = new mNonExported.mne.class1; export function f3() { From 76e01396c1951fea9a792fa35d5d30b7bd4fb1ce Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 20:55:11 -0800 Subject: [PATCH 48/60] use a normal for loop instead of a forEach --- src/compiler/parser.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e418858b891..5b338017ead 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4263,9 +4263,12 @@ module ts { if (!node.modifiers) { return checkTopLevelDeclareModifierInAmbientContext(node); } + var lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node; var flags = 0; - var hasErrors = forEach(node.modifiers, m => { + for (var i = 0, n = node.modifiers.length; i < n; i++) { + var m = node.modifiers[i]; + switch (m.kind) { case SyntaxKind.PublicKeyword: case SyntaxKind.ProtectedKeyword: @@ -4342,10 +4345,6 @@ module ts { lastDeclare = m; break; } - }); - - if (hasErrors) { - return true; } if (node.kind === SyntaxKind.Constructor) { From 3be19d6ada794e60a8477bbd3fcddc08e1eadfd6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 21:21:46 -0800 Subject: [PATCH 49/60] Simplify grammar checker. --- src/compiler/parser.ts | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5b338017ead..a3662b2524c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3717,7 +3717,11 @@ module ts { } function visitArrowFunction(node: FunctionExpression) { - checkTypeParameterList(node.typeParameters) || + checkParsedSignature(node); + } + + function checkParsedSignature(node: ParsedSignature): boolean { + return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); } @@ -3878,8 +3882,7 @@ module ts { } function visitCallSignature(node: ConstructorDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParsedSignature(node); } function visitCatchBlock(node: CatchBlock) { @@ -3906,8 +3909,7 @@ module ts { } function visitConstructor(node: ConstructorDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ true); @@ -3926,13 +3928,11 @@ module ts { } function visitConstructorType(node: SignatureDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParsedSignature(node); } function visitConstructSignature(node: FunctionLikeDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParsedSignature(node); } function visitEnumDeclaration(enumDecl: EnumDeclaration) { @@ -4010,15 +4010,13 @@ module ts { } function visitFunctionDeclaration(node: FunctionLikeDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false); } function visitFunctionExpression(node: FunctionExpression) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkFunctionName(node.name); } @@ -4031,13 +4029,11 @@ module ts { } function visitFunctionType(node: SignatureDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters); + checkParsedSignature(node); } function visitGetAccessor(node: MethodDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkAccessor(node); } @@ -4102,8 +4098,7 @@ module ts { } function visitMethod(node: MethodDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)); } @@ -4487,8 +4482,7 @@ module ts { } function visitSetAccessor(node: MethodDeclaration) { - checkTypeParameterList(node.typeParameters) || - checkParameterList(node.parameters) || + checkParsedSignature(node) || checkAccessor(node); } From c011550558dd2c3fd48faf07d3b16cadaa31abdf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 21:42:52 -0800 Subject: [PATCH 50/60] Simplify grammar checker. --- src/compiler/parser.ts | 109 ++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 40 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a3662b2524c..19486a52379 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3564,6 +3564,10 @@ module ts { // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); + if (inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file)) { + return; + } + var inFunctionBlock = false; var parent: Node; visitNode(file); @@ -3595,10 +3599,11 @@ module ts { } function checkNode(node: Node) { + var nodeKind = node.kind; // First, check if you have a statement in a place where it is not allowed. We want // to do this before recursing, because we'd prefer to report these errors at the top // level instead of at some nested level. - if (inAmbientContext && checkForStatementInAmbientContext(node)) { + if (inAmbientContext && checkForStatementInAmbientContext(node, nodeKind)) { return; } @@ -3612,11 +3617,11 @@ module ts { } // Now do node specific checks. - dispatch(node); + dispatch(node, nodeKind); } - function dispatch(node: Node): void { - switch (node.kind) { + function dispatch(node: Node, kind: SyntaxKind): void { + switch (kind) { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); @@ -3693,8 +3698,43 @@ module ts { return grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } - function checkForStatementInAmbientContext(node: Node): boolean { - switch (node.kind) { + function checkTopLevelElementsForRequiredDeclareModifier(file: SourceFile): boolean { + for (var i = 0, n = file.statements.length; i < n; i++) { + var decl = file.statements[i]; + if (isDeclaration(decl) || decl.kind === SyntaxKind.VariableStatement) { + if (checkTopLevelElementForRequiredDeclareModifier(decl)) { + return true; + } + } + } + } + + function checkTopLevelElementForRequiredDeclareModifier(node: Node): boolean { + // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: + // categories: + // + // DeclarationElement: + // ExportAssignment + // export_opt InterfaceDeclaration + // export_opt ImportDeclaration + // export_opt ExternalImportDeclaration + // export_opt AmbientDeclaration + // + if (node.kind === SyntaxKind.InterfaceDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ExportAssignment || + (node.flags & NodeFlags.Ambient) /* + (node.flags & NodeFlags.Export) */) { + + return false; + } + + return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + } + + + function checkForStatementInAmbientContext(node: Node, kind: SyntaxKind): boolean { + switch (kind) { case SyntaxKind.Block: case SyntaxKind.EmptyStatement: case SyntaxKind.IfStatement: @@ -4221,42 +4261,33 @@ module ts { grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } - } - function checkTopLevelDeclareModifierInAmbientContext(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: - // - // DeclarationElement: - // ExportAssignment - // export_opt InterfaceDeclaration - // export_opt ImportDeclaration - // export_opt ExternalImportDeclaration - // export_opt AmbientDeclaration - // - - if (!inAmbientContext || - !(isDeclaration(node) || node.kind === SyntaxKind.VariableStatement) || - !node.parent || - node.parent.kind !== SyntaxKind.SourceFile) { - return false; - } - - if (node.kind === SyntaxKind.InterfaceDeclaration || - node.kind === SyntaxKind.ImportDeclaration || - node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient) || - (node.flags & NodeFlags.Export)) { - - return false; - } - - return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); } - function checkModifiers(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + case SyntaxKind.Property: + case SyntaxKind.Method: + case SyntaxKind.IndexSignature: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.VariableStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.Parameter: + break; + default: + return false; + } + if (!node.modifiers) { - return checkTopLevelDeclareModifierInAmbientContext(node); + return; } var lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node; @@ -4359,8 +4390,6 @@ module ts { else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } - - return checkTopLevelDeclareModifierInAmbientContext(node); } function visitParameter(node: ParameterDeclaration): void { From a882b74eadf1844fe61ef518d724c0d2b49bdf28 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 21:49:25 -0800 Subject: [PATCH 51/60] Simplify checker. --- src/compiler/parser.ts | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 19486a52379..d6e5bbf7d10 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3622,16 +3622,19 @@ module ts { function dispatch(node: Node, kind: SyntaxKind): void { switch (kind) { - case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.ArrowFunction: + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructorType: + case SyntaxKind.ConstructSignature: + case SyntaxKind.FunctionType: + checkParsedSignature(node); + break; case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); case SyntaxKind.CallExpression: return visitCallExpression(node); - case SyntaxKind.CallSignature: return visitCallSignature(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); case SyntaxKind.Constructor: return visitConstructor(node); - case SyntaxKind.ConstructorType: return visitConstructorType(node); - case SyntaxKind.ConstructSignature: return visitConstructSignature(node); case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); case SyntaxKind.ExportAssignment: return visitExportAssignment(node); @@ -3639,7 +3642,6 @@ module ts { case SyntaxKind.ForStatement: return visitForStatement(node); case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); - case SyntaxKind.FunctionType: return visitFunctionType(node); case SyntaxKind.GetAccessor: return visitGetAccessor(node); case SyntaxKind.IndexedAccess: return visitIndexedAccess(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); @@ -3723,8 +3725,7 @@ module ts { if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient) /* - (node.flags & NodeFlags.Export) */) { + (node.flags & NodeFlags.Ambient)) { return false; } @@ -3756,10 +3757,6 @@ module ts { } } - function visitArrowFunction(node: FunctionExpression) { - checkParsedSignature(node); - } - function checkParsedSignature(node: ParsedSignature): boolean { return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); @@ -3921,10 +3918,6 @@ module ts { } } - function visitCallSignature(node: ConstructorDeclaration) { - checkParsedSignature(node); - } - function visitCatchBlock(node: CatchBlock) { if (node.type) { var colonStart = skipTrivia(sourceText, node.variable.end); @@ -3967,14 +3960,6 @@ module ts { } } - function visitConstructorType(node: SignatureDeclaration) { - checkParsedSignature(node); - } - - function visitConstructSignature(node: FunctionLikeDeclaration) { - checkParsedSignature(node); - } - function visitEnumDeclaration(enumDecl: EnumDeclaration) { checkEnumInitializer(enumDecl); } @@ -4068,10 +4053,6 @@ module ts { } } - function visitFunctionType(node: SignatureDeclaration) { - checkParsedSignature(node); - } - function visitGetAccessor(node: MethodDeclaration) { checkParsedSignature(node) || checkAccessor(node); From e4f7822774d02086bd3a9b193723a8bb11459c89 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 21:57:13 -0800 Subject: [PATCH 52/60] Inline some checker logic. --- src/compiler/parser.ts | 51 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d6e5bbf7d10..affc4fd8663 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3629,14 +3629,27 @@ module ts { case SyntaxKind.FunctionType: checkParsedSignature(node); break; + case SyntaxKind.BreakStatement: + case SyntaxKind.ContinueStatement: + checkBreakOrContinueStatement(node); + break; + case SyntaxKind.LabeledStatement: + checkLabeledStatement(node); + break; + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + checkCallOrNewExpression(node); + break; + case SyntaxKind.EnumDeclaration: + checkEnumInitializer(node); + break; + case SyntaxKind.Parameter: + checkParameter(node); + break; case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); - case SyntaxKind.BreakStatement: return visitBreakOrContinueStatement(node); - case SyntaxKind.CallExpression: return visitCallExpression(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); case SyntaxKind.Constructor: return visitConstructor(node); - case SyntaxKind.ContinueStatement: return visitBreakOrContinueStatement(node); - case SyntaxKind.EnumDeclaration: return visitEnumDeclaration(node); case SyntaxKind.ExportAssignment: return visitExportAssignment(node); case SyntaxKind.ForInStatement: return visitForInStatement(node); case SyntaxKind.ForStatement: return visitForStatement(node); @@ -3646,13 +3659,10 @@ module ts { case SyntaxKind.IndexedAccess: return visitIndexedAccess(node); case SyntaxKind.IndexSignature: return visitIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); - case SyntaxKind.LabeledStatement: return visitLabeledStatement(node); case SyntaxKind.Method: return visitMethod(node); case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); - case SyntaxKind.NewExpression: return visitNewExpression(node); case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); case SyntaxKind.NumericLiteral: return visitNumericLiteral(node); - case SyntaxKind.Parameter: return visitParameter(node); case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); case SyntaxKind.Property: return visitProperty(node); @@ -3733,7 +3743,6 @@ module ts { return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); } - function checkForStatementInAmbientContext(node: Node, kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.Block: @@ -3774,14 +3783,6 @@ module ts { } } - function visitBreakOrContinueStatement(node: BreakOrContinueStatement): void { - checkBreakOrContinueStatement(node); - } - - function visitLabeledStatement(node: LabeledStatement): void { - checkLabeledStatement(node); - } - function isIterationStatement(node: Node, lookInLabeledStatements: boolean): boolean { switch (node.kind) { case SyntaxKind.ForStatement: @@ -3864,7 +3865,7 @@ module ts { } } - function visitCallExpression(node: CallExpression) { + function checkCallOrNewExpression(node: CallExpression) { checkTypeArguments(node.typeArguments) || checkArguments(node.arguments); } @@ -3960,10 +3961,6 @@ module ts { } } - function visitEnumDeclaration(enumDecl: EnumDeclaration) { - checkEnumInitializer(enumDecl); - } - function checkEnumInitializer(enumDecl: EnumDeclaration): boolean { var enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0; @@ -4161,11 +4158,6 @@ module ts { } } - function visitNewExpression(node: NewExpression): void { - checkTypeArguments(node.typeArguments) || - checkArguments(node.arguments); - } - function visitObjectLiteral(node: ObjectLiteral): void { var seen: Map = {}; var Property = 1; @@ -4233,6 +4225,7 @@ module ts { } } } + function visitNumericLiteral(node: LiteralExpression): void { if (node.flags & NodeFlags.OctalLiteral) { if (node.flags & NodeFlags.ParsedInStrictMode) { @@ -4373,11 +4366,7 @@ module ts { } } - function visitParameter(node: ParameterDeclaration): void { - checkParameterName(node); - } - - function checkParameterName(node: ParameterDeclaration): boolean { + function checkParameter(node: ParameterDeclaration): boolean { // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). From c7c1d6b03b98572769374fec46dd9433abc817eb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 22:15:32 -0800 Subject: [PATCH 53/60] Remove unnecessary state from the parser. --- src/compiler/checker.ts | 2 +- src/compiler/parser.ts | 29 +- tests/baselines/reference/giant.errors.txt | 602 +++++++++++++----- ...tiesErrorFromNotUsingIdentifier.errors.txt | 5 +- 4 files changed, 446 insertions(+), 192 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 117422366aa..db368213101 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1784,7 +1784,7 @@ module ts { } else { // If there are no specified types, try to infer it from the body of the get accessor if it exists. - if (getter) { + if (getter && getter.body) { type = getReturnTypeFromBody(getter); } // Otherwise, fall back to 'any'. diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index affc4fd8663..56dc06250f8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -842,10 +842,9 @@ module ts { var identifierCount = 0; var nodeCount = 0; var lineStarts: number[]; - var isInStrictMode = false; + var isInStrictMode = false; var lookAheadMode = LookAheadMode.NotLookingAhead; - var inAmbientContext = false; function getLineStarts(): number[] { return lineStarts || (lineStarts = computeLineStarts(sourceText)); @@ -3046,16 +3045,7 @@ module ts { node.typeParameters = sig.typeParameters; node.parameters = sig.parameters; node.type = sig.type; - - // A common error is to try to declare an accessor in an ambient class. - if (inAmbientContext && canParseSemicolon()) { - parseSemicolon(); - node.body = createMissingNode(); - } - else { - node.body = parseFunctionBlock(/* ignoreMissingOpenBrace */ false); - } - + node.body = parseFunctionBlockOrSemicolon(); return finishNode(node); } @@ -3260,13 +3250,7 @@ module ts { var node = createNode(SyntaxKind.ModuleDeclaration, pos); node.flags = flags; node.name = parseStringLiteral(); - - // For error recovery, just in case the user forgot the declare modifier on this ambient - // external module, treat it as ambient anyway. - var saveInAmbientContext = inAmbientContext; - inAmbientContext = true; node.body = parseModuleBody(); - inAmbientContext = saveInAmbientContext; return finishNode(node); } @@ -3345,10 +3329,6 @@ module ts { } } - var saveInAmbientContext = inAmbientContext; - if (modifiers && modifiers.flags & NodeFlags.Ambient) { - inAmbientContext = true; - } var flags = modifiers ? modifiers.flags : 0; var result: Declaration; switch (token) { @@ -3394,7 +3374,6 @@ module ts { result.modifiers = modifiers; } - inAmbientContext = saveInAmbientContext; return result; } @@ -3494,7 +3473,6 @@ module ts { var rootNodeFlags: NodeFlags = 0; if (fileExtensionIs(filename, ".d.ts")) { rootNodeFlags = NodeFlags.DeclarationFile; - inAmbientContext = true; } file = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); file.filename = normalizePath(filename); @@ -4493,6 +4471,9 @@ module ts { else if (inAmbientContext) { return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); } + else if (accessor.body === undefined) { + return grammarErrorAtPos(accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters); } diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index d9d96f5abf7..767c419952c 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -1,86 +1,187 @@ -tests/cases/compiler/giant.ts(25,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(27,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(29,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(31,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(35,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(37,1): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(89,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(91,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(93,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(95,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(99,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(101,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(168,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(170,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(172,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(174,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(178,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(180,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(283,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(285,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(287,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(289,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(293,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(295,1): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(347,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(349,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(351,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(353,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(357,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(359,5): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(426,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(428,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(430,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(432,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(436,9): error TS1005: '{' expected. -tests/cases/compiler/giant.ts(438,5): error TS1005: '{' expected. +tests/cases/compiler/giant.ts(24,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(26,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(28,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(30,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(34,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(61,6): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(62,5): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(63,6): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(88,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(90,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(92,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(94,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(98,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(100,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(125,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(126,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(127,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(154,39): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(167,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(169,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(171,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(173,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(177,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(179,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(204,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(205,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(206,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(233,39): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(238,35): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(240,24): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(243,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(244,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(245,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(246,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(247,31): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(248,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(249,23): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(250,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(251,32): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(252,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(254,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(255,31): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(256,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(257,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(258,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(262,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(262,25): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(267,30): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(267,33): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(282,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(284,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(286,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(288,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(292,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(294,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(319,6): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(320,5): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(321,6): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(346,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(348,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(350,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(352,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(356,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(358,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(383,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(384,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(385,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(412,39): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(425,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(427,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(429,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(431,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(435,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(437,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(462,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(463,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(464,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(491,39): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(496,35): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(498,24): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(501,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(502,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(503,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(504,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(505,31): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(506,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(507,23): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(508,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(509,32): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(510,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(512,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(513,31): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(514,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(515,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(516,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(520,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(520,25): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(525,30): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(525,33): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(532,31): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(534,20): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(537,17): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(538,18): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(539,18): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(540,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(541,27): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(542,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(543,19): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(544,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(545,28): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(546,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(548,17): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(549,27): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(550,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(551,18): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(552,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/giant.ts(556,18): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(556,21): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(561,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(563,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(587,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(588,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(589,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(606,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(606,25): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(611,30): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(611,33): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(615,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/giant.ts(616,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/giant.ts(616,42): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(617,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/giant.ts(618,16): error TS1038: A 'declare' modifier cannot be used in an already ambient context. +tests/cases/compiler/giant.ts(621,26): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(621,29): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(623,24): error TS1111: A constructor implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(626,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(628,21): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(653,10): error TS1022: An index signature parameter must have a type annotation. +tests/cases/compiler/giant.ts(654,9): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/giant.ts(655,10): error TS1096: An index signature must have exactly one parameter. +tests/cases/compiler/giant.ts(672,22): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(672,25): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/giant.ts(676,30): error TS1037: A function implementation cannot be declared in an ambient context. +tests/cases/compiler/giant.ts(676,33): error TS1036: Statements are not allowed in ambient contexts. tests/cases/compiler/giant.ts(23,12): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(24,16): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(24,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(25,12): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(26,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(27,13): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(28,17): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(28,17): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(29,13): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(30,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(33,12): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(34,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(35,12): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(36,16): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(36,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(76,5): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(87,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(88,20): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(88,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(89,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(90,20): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(91,17): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(92,21): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(92,21): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(93,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(94,21): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(97,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(98,20): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(99,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(100,20): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(100,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(140,9): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(166,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(167,20): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(167,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(168,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(169,20): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(170,17): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(171,21): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(171,21): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(172,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(173,21): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(176,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(177,20): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(178,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(179,20): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(179,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(219,9): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(245,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(246,20): error TS2300: Duplicate identifier 'pgF'. @@ -96,51 +197,42 @@ tests/cases/compiler/giant.ts(257,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(258,20): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(281,12): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(282,16): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(282,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(283,12): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(284,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(285,13): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(286,17): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(286,17): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(287,13): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(288,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(291,12): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(292,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(293,12): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(294,16): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(294,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(334,5): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(345,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(346,20): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(346,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(347,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(348,20): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(349,17): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(350,21): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(350,21): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(351,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(352,21): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(355,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(356,20): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(357,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(358,20): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(358,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(398,9): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(424,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(425,20): error TS2300: Duplicate identifier 'pgF'. -tests/cases/compiler/giant.ts(425,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(426,16): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(427,20): error TS2300: Duplicate identifier 'psF'. tests/cases/compiler/giant.ts(428,17): error TS2300: Duplicate identifier 'rgF'. tests/cases/compiler/giant.ts(429,21): error TS2300: Duplicate identifier 'rgF'. -tests/cases/compiler/giant.ts(429,21): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(430,17): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(431,21): error TS2300: Duplicate identifier 'rsF'. tests/cases/compiler/giant.ts(434,16): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(435,20): error TS2300: Duplicate identifier 'tsF'. tests/cases/compiler/giant.ts(436,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(437,20): error TS2300: Duplicate identifier 'tgF'. -tests/cases/compiler/giant.ts(437,20): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/compiler/giant.ts(477,9): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/giant.ts(503,16): error TS2300: Duplicate identifier 'pgF'. tests/cases/compiler/giant.ts(504,20): error TS2300: Duplicate identifier 'pgF'. @@ -170,7 +262,7 @@ tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. -==== tests/cases/compiler/giant.ts (170 errors) ==== +==== tests/cases/compiler/giant.ts (262 errors) ==== /* Prefixes @@ -198,58 +290,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. interface I { //Call Signature (); @@ -274,8 +360,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -306,58 +398,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. interface I { //Call Signature (); @@ -382,8 +468,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -413,6 +505,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } @@ -429,58 +523,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. export interface eI { //Call Signature (); @@ -505,8 +593,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -536,64 +630,108 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { var V; function F() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } export var eV; export function eF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } @@ -612,58 +750,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. export interface eI { //Call Signature (); @@ -688,8 +820,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -720,58 +858,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. interface I { //Call Signature (); @@ -796,8 +928,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -827,6 +965,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } @@ -843,58 +983,52 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ -!!! error TS2300: Duplicate identifier 'pgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ -!!! error TS2300: Duplicate identifier 'rgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } - ~~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; - ~~~~~~ -!!! error TS1005: '{' expected. static tF() { } static tsF(param:any) { } ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } - ~~~~~~ -!!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ -!!! error TS2300: Duplicate identifier 'tgF'. +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +!!! error TS2300: Duplicate identifier 'tgF'. } - ~ -!!! error TS1005: '{' expected. export interface eI { //Call Signature (); @@ -919,8 +1053,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -950,64 +1090,108 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { }; export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { }; export declare module eaM { }; } export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { var V; function F() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } export var eV; export function eF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } @@ -1015,61 +1199,105 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all } export declare var eaV; export declare function eaF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. export declare class eaC { constructor () { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. private rF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. public pgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public get pgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'pgF'. public psF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'psF'. public set psF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'psF'. private rgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private get rgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rgF'. private rsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'rsF'. private set rsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'rsF'. static tV; static tF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static tsF(param:any) { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static set tsF(param:any) ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tsF'. static tgF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. ~~~ !!! error TS2300: Duplicate identifier 'tgF'. static get tgF() ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~ !!! error TS2300: Duplicate identifier 'tgF'. } export declare module eaM { var V; function F() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. class C { constructor () { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static tV; static tF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. } interface I { //Call Signature @@ -1094,8 +1322,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -1115,28 +1349,56 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all module M { var V; function F() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. class C { } interface I { } module M { } export var eV; export function eF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } export declare var eaV + ~~~~~~~ +!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. export declare function eaF() { }; + ~~~~~~~ +!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export declare class eaC { } + ~~~~~~~ +!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. export declare module eaM { } + ~~~~~~~ +!!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. } export var eV; export function eF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { constructor () { } + ~ +!!! error TS1111: A constructor implementation cannot be declared in an ambient context. public pV; private rV; public pF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. static tV static tF() { } + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. } export interface eI { //Call Signature @@ -1162,8 +1424,14 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all //Index Signature [p]; + ~ +!!! error TS1022: An index signature parameter must have a type annotation. [p1: string]; + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. [p2: string, p3: number]; + ~~ +!!! error TS1096: An index signature must have exactly one parameter. //Property Signature p; @@ -1183,10 +1451,18 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all export module eM { var V; function F() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. class C { } module M { } export var eV; export function eF() { }; + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. + ~ +!!! error TS1036: Statements are not allowed in ambient contexts. export class eC { } export interface eI { } export module eM { } diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt index 33672c3d54c..cc92b9a0381 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.errors.txt @@ -11,13 +11,12 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,6): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,6): error TS1005: ':' expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(20,17): error TS1005: ':' expected. -tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(15,5): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(16,5): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts(17,5): error TS2300: Duplicate identifier 'a'. -==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (17 errors) ==== +==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesErrorFromNotUsingIdentifier.ts (16 errors) ==== // errors var y = { "stringLiteral", @@ -29,8 +28,6 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr get e, ~ !!! error TS1005: '(' expected. - ~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. set f, ~ !!! error TS1005: '(' expected. From c3840ef0b8cfe47364c2a3fff2b76c674caa9c41 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 19 Nov 2014 22:45:27 -0800 Subject: [PATCH 54/60] Simplify code. --- src/compiler/parser.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 56dc06250f8..28791118d38 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -865,10 +865,6 @@ module ts { errorAtPos(start, length, message, arg0, arg1, arg2); } - function grammarErrorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { - file.parseDiagnostics.push(createFileDiagnostic(file, start, length, message, arg0, arg1, arg2)); - } - function errorAtPos(start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { var lastErrorPos = file.parseDiagnostics.length ? file.parseDiagnostics[file.parseDiagnostics.length - 1].start @@ -2987,7 +2983,6 @@ module ts { } function parsePropertyMemberDeclaration(pos: number, modifiers: ModifiersArray): Declaration { - var errorCountBeforePropertyDeclaration = file.parseDiagnostics.length; var name = parsePropertyName(); var flags = modifiers ? modifiers.flags : 0; var questionStart = scanner.getTokenPos(); @@ -3595,11 +3590,7 @@ module ts { } // Now do node specific checks. - dispatch(node, nodeKind); - } - - function dispatch(node: Node, kind: SyntaxKind): void { - switch (kind) { + switch (nodeKind) { case SyntaxKind.ArrowFunction: case SyntaxKind.CallSignature: case SyntaxKind.ConstructorType: From bb35fc886b070a7a20ab60f2cd960bbbe8aa8376 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 12:54:00 -0800 Subject: [PATCH 55/60] Code review feedback. --- src/compiler/parser.ts | 113 +++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 28791118d38..477c414790d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1395,9 +1395,9 @@ module ts { // never get a token like this. Instead, we would get 00 and 9 as two separate tokens. // We also do not need to check for negatives because any prefix operator would be part of a // parent unary expression. - if (node.kind === SyntaxKind.NumericLiteral && - sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && - isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { + if (node.kind === SyntaxKind.NumericLiteral + && sourceText.charCodeAt(tokenPos) === CharacterCodes._0 + && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { node.flags |= NodeFlags.OctalLiteral; } @@ -1471,13 +1471,17 @@ module ts { return token === SyntaxKind.DotDotDotToken || isIdentifier() || isModifier(token); } - function parseParameter(flags: NodeFlags = 0): ParameterDeclaration { - var node = createNode(SyntaxKind.Parameter); - var modifiers = parseModifiers(ModifierContext.Parameters); + function setModifiers(node: Node, modifiers: ModifiersArray) { if (modifiers) { node.flags |= modifiers.flags; node.modifiers = modifiers; } + } + + function parseParameter(flags: NodeFlags = 0): ParameterDeclaration { + var node = createNode(SyntaxKind.Parameter); + var modifiers = parseModifiers(ModifierContext.Parameters); + setModifiers(node, modifiers); if (parseOptional(SyntaxKind.DotDotDotToken)) { node.flags |= NodeFlags.Rest; } @@ -1554,10 +1558,7 @@ module ts { function parseIndexSignatureMember(modifiers: ModifiersArray, pos?: number): SignatureDeclaration { var node = createNode(SyntaxKind.IndexSignature, pos); - if (modifiers) { - node.modifiers = modifiers; - node.flags = modifiers.flags; - } + setModifiers(node, modifiers); node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2968,10 +2969,8 @@ module ts { function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { var node = createNode(SyntaxKind.Constructor, pos); - if (modifiers) { - node.modifiers = modifiers; - node.flags = modifiers.flags; - } + setModifiers(node, modifiers); + parseExpected(SyntaxKind.ConstructorKeyword); var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); node.typeParameters = sig.typeParameters; @@ -2994,9 +2993,8 @@ module ts { if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { var method = createNode(SyntaxKind.Method, pos); - if (modifiers) { - method.modifiers = modifiers; - } + setModifiers(method, modifiers); + if (flags) { method.flags = flags; } @@ -3011,9 +3009,8 @@ module ts { } else { var property = createNode(SyntaxKind.Property, pos); - if (modifiers) { - property.modifiers = modifiers; - } + setModifiers(property, modifiers); + if (flags) { property.flags = flags; } @@ -3031,10 +3028,8 @@ module ts { function parseMemberAccessorDeclaration(kind: SyntaxKind, pos: number, modifiers: ModifiersArray): MethodDeclaration { var node = createNode(kind, pos); - if (modifiers) { - node.modifiers = modifiers; - node.flags = modifiers.flags; - } + setModifiers(node, modifiers); + node.name = parsePropertyName(); var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken, /* returnTokenRequired */ false); node.typeParameters = sig.typeParameters; @@ -3274,10 +3269,8 @@ module ts { function parseExportAssignmentTail(pos: number, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, pos); - if (modifiers) { - node.modifiers = modifiers - node.flags = modifiers.flags; - } + setModifiers(node, modifiers); + node.exportName = parseIdentifier(); parseSemicolon(); return finishNode(node); @@ -3840,12 +3833,12 @@ module ts { } function checkArguments(arguments: NodeArray) { - return checkForTrailingComma(arguments) || + return checkForDisallowedTrailingComma(arguments) || checkForOmittedArgument(arguments); } function checkTypeArguments(typeArguments: NodeArray) { - return checkForTrailingComma(typeArguments) || + return checkForDisallowedTrailingComma(typeArguments) || checkForAtLeastOneTypeArgument(typeArguments) || checkForMissingTypeArgument(typeArguments); } @@ -3880,7 +3873,7 @@ module ts { } } - function checkForTrailingComma(list: NodeArray): boolean { + function checkForDisallowedTrailingComma(list: NodeArray): boolean { if (list && list.hasTrailingComma) { var start = list.end - ",".length; var end = list.end; @@ -3901,7 +3894,7 @@ module ts { } function visitClassDeclaration(node: ClassDeclaration) { - checkForTrailingComma(node.implementedTypes) || + checkForDisallowedTrailingComma(node.implementedTypes) || checkForAtLeastOneHeritageClause(node.implementedTypes, "implements"); } @@ -4080,7 +4073,7 @@ module ts { } function visitInterfaceDeclaration(node: InterfaceDeclaration) { - checkForTrailingComma(node.baseTypes) || + checkForDisallowedTrailingComma(node.baseTypes) || checkForAtLeastOneHeritageClause(node.baseTypes, "extends"); } @@ -4236,82 +4229,82 @@ module ts { var lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node; var flags = 0; for (var i = 0, n = node.modifiers.length; i < n; i++) { - var m = node.modifiers[i]; + var modifier = node.modifiers[i]; - switch (m.kind) { + switch (modifier.kind) { case SyntaxKind.PublicKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PrivateKeyword: var text: string; - if (m.kind === SyntaxKind.PublicKeyword) { + if (modifier.kind === SyntaxKind.PublicKeyword) { text = "public"; } - else if (m.kind === SyntaxKind.ProtectedKeyword) { + else if (modifier.kind === SyntaxKind.ProtectedKeyword) { text = "protected"; - lastProtected = m; + lastProtected = modifier; } else { text = "private"; - lastPrivate = m; + lastPrivate = modifier; } if (flags & NodeFlags.AccessibilityModifier) { - return grammarErrorOnNode(m, Diagnostics.Accessibility_modifier_already_seen); + return grammarErrorOnNode(modifier, Diagnostics.Accessibility_modifier_already_seen); } else if (flags & NodeFlags.Static) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } - flags |= modifierToFlag(m.kind); + flags |= modifierToFlag(modifier.kind); break; case SyntaxKind.StaticKeyword: if (flags & NodeFlags.Static) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "static"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "static"); } else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } else if (node.kind === SyntaxKind.Parameter) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } flags |= NodeFlags.Static; - lastStatic = m; + lastStatic = modifier; break; case SyntaxKind.ExportKeyword: if (flags & NodeFlags.Export) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "export"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "export"); } else if (flags & NodeFlags.Ambient) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } else if (node.kind === SyntaxKind.Parameter) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= NodeFlags.Export; break; case SyntaxKind.DeclareKeyword: if (flags & NodeFlags.Ambient) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_already_seen, "declare"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "declare"); } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } else if (node.kind === SyntaxKind.Parameter) { - return grammarErrorOnNode(m, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } else if (inAmbientContext && node.parent.kind === SyntaxKind.ModuleBlock) { - return grammarErrorOnNode(m, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); + return grammarErrorOnNode(modifier, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= NodeFlags.Ambient; - lastDeclare = m; + lastDeclare = modifier; break; } } @@ -4347,7 +4340,7 @@ module ts { } function checkTypeParameterList(typeParameters: NodeArray): boolean { - if (checkForTrailingComma(typeParameters)) { + if (checkForDisallowedTrailingComma(typeParameters)) { return true; } @@ -4359,7 +4352,7 @@ module ts { } function checkParameterList(parameters: NodeArray): boolean { - if (checkForTrailingComma(parameters)) { + if (checkForDisallowedTrailingComma(parameters)) { return true; } @@ -4526,7 +4519,7 @@ module ts { } function visitTupleType(node: TupleTypeNode) { - checkForTrailingComma(node.elementTypes) || + checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node); } @@ -4563,7 +4556,7 @@ module ts { function checkVariableDeclarations(declarations: NodeArray): boolean { if (declarations) { - if (checkForTrailingComma(declarations)) { + if (checkForDisallowedTrailingComma(declarations)) { return true; } From 2b189b035aa9f482c490dc7b339da7a7e9626846 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 13:36:43 -0800 Subject: [PATCH 56/60] Revert changes to resources. --- src/compiler/diagnosticInformationMap.generated.ts | 6 +++--- src/compiler/diagnosticMessages.json | 10 +++++----- .../objectTypeWithOptionalProperty1.errors.txt | 4 ++-- .../objectTypesWithOptionalProperties.errors.txt | 4 ++-- tests/baselines/reference/parser645086_1.errors.txt | 4 ++-- tests/baselines/reference/parser645086_2.errors.txt | 4 ++-- .../baselines/reference/parserMissingToken2.errors.txt | 4 ++-- .../parserRegularExpressionDivideAmbiguity4.errors.txt | 4 ++-- ...tesWithIncompleteNoSubstitutionTemplate1.errors.txt | 4 ++-- ...tesWithIncompleteNoSubstitutionTemplate2.errors.txt | 4 ++-- .../templateStringInTaggedTemplate.errors.txt | 4 ++-- .../templateStringWithEmbeddedYieldKeyword.errors.txt | 4 ++-- ...emplateStringWithEmbeddedYieldKeywordES6.errors.txt | 4 ++-- .../unterminatedRegexAtEndOfSource1.errors.txt | 4 ++-- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 80a32ba330a..402fcbe93e7 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -122,9 +122,9 @@ module ts { let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, Invalid_template_literal_expected: { code: 1158, category: DiagnosticCategory.Error, key: "Invalid template literal; expected '}'" }, Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, - An_object_member_cannot_be_declared_optional: { code: 1160, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - Unterminated_template_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, - Unterminated_regular_expression_literal: { code: 1162, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, + Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, + Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, + An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, 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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c05770bdd8e..353f0390145 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -479,15 +479,15 @@ "category": "Error", "code": 1159 }, - "An object member cannot be declared optional.": { - "category": "Error", - "code": 1160 - }, "Unterminated template literal.": { + "category": "Error", + "code": 1160 + }, + "Unterminated regular expression literal.": { "category": "Error", "code": 1161 }, - "Unterminated regular expression literal.": { + "An object member cannot be declared optional.": { "category": "Error", "code": 1162 }, diff --git a/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt b/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt index 7e17563873a..e2e1c05ea1e 100644 --- a/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt +++ b/tests/baselines/reference/objectTypeWithOptionalProperty1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/objectTypeWithOptionalProperty1.ts(2,10): error TS1160: An object member cannot be declared optional. +tests/cases/compiler/objectTypeWithOptionalProperty1.ts(2,10): error TS1162: An object member cannot be declared optional. ==== tests/cases/compiler/objectTypeWithOptionalProperty1.ts (1 errors) ==== var b = { x?: 1 // error ~ -!!! error TS1160: An object member cannot be declared optional. +!!! error TS1162: An object member cannot be declared optional. } \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt index d33a5e35b63..a2269c29d11 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt +++ b/tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional. -tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: An object member cannot be declared optional. +tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1162: An object member cannot be declared optional. ==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ==== @@ -33,5 +33,5 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith var b = { x?: 1 // error ~ -!!! error TS1160: An object member cannot be declared optional. +!!! error TS1162: An object member cannot be declared optional. } \ No newline at end of file diff --git a/tests/baselines/reference/parser645086_1.errors.txt b/tests/baselines/reference/parser645086_1.errors.txt index f6b76cf26b6..d326fa23973 100644 --- a/tests/baselines/reference/parser645086_1.errors.txt +++ b/tests/baselines/reference/parser645086_1.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts(1,13): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts(1,14): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts(1,15): error TS1162: Unterminated regular expression literal. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts(1,15): error TS1161: Unterminated regular expression literal. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts (3 errors) ==== @@ -10,4 +10,4 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_1.ts(1,1 ~ !!! error TS1134: Variable declaration expected. -!!! error TS1162: Unterminated regular expression literal. \ No newline at end of file +!!! error TS1161: Unterminated regular expression literal. \ No newline at end of file diff --git a/tests/baselines/reference/parser645086_2.errors.txt b/tests/baselines/reference/parser645086_2.errors.txt index 558ff5964e0..2d40b3c8f78 100644 --- a/tests/baselines/reference/parser645086_2.errors.txt +++ b/tests/baselines/reference/parser645086_2.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts(1,14): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts(1,15): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts(1,16): error TS1162: Unterminated regular expression literal. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts(1,16): error TS1161: Unterminated regular expression literal. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts (3 errors) ==== @@ -10,4 +10,4 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser645086_2.ts(1,1 ~ !!! error TS1134: Variable declaration expected. -!!! error TS1162: Unterminated regular expression literal. \ No newline at end of file +!!! error TS1161: Unterminated regular expression literal. \ No newline at end of file diff --git a/tests/baselines/reference/parserMissingToken2.errors.txt b/tests/baselines/reference/parserMissingToken2.errors.txt index 8ac17692335..31012c0865e 100644 --- a/tests/baselines/reference/parserMissingToken2.errors.txt +++ b/tests/baselines/reference/parserMissingToken2.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/MissingTokens/parserMissingToken2.ts(1,2): error TS1162: Unterminated regular expression literal. +tests/cases/conformance/parser/ecmascript5/MissingTokens/parserMissingToken2.ts(1,2): error TS1161: Unterminated regular expression literal. ==== tests/cases/conformance/parser/ecmascript5/MissingTokens/parserMissingToken2.ts (1 errors) ==== / b; -!!! error TS1162: Unterminated regular expression literal. \ No newline at end of file +!!! error TS1161: Unterminated regular expression literal. \ No newline at end of file diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt index cbe05bd1735..7ea76fc24d1 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity4.ts(1,6): error TS1162: Unterminated regular expression literal. +tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity4.ts(1,6): error TS1161: Unterminated regular expression literal. tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity4.ts(1,17): error TS1005: ')' expected. tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity4.ts(1,1): error TS2304: Cannot find name 'foo'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpre ==== tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity4.ts (3 errors) ==== foo(/notregexp); -!!! error TS1162: Unterminated regular expression literal. +!!! error TS1161: Unterminated regular expression literal. !!! error TS1005: ')' expected. ~~~ diff --git a/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.errors.txt b/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.errors.txt index 97e424c01aa..a64f5379e47 100644 --- a/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.errors.txt +++ b/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.ts(6,15): error TS1161: Unterminated template literal. +tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.ts(6,15): error TS1160: Unterminated template literal. ==== tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.ts (1 errors) ==== @@ -9,4 +9,4 @@ tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate1.ts(6,1 // Incomplete call, not enough parameters. f `123qdawdrqw -!!! error TS1161: Unterminated template literal. \ No newline at end of file +!!! error TS1160: Unterminated template literal. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.errors.txt b/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.errors.txt index cce51b90ef0..fab10f8a888 100644 --- a/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.errors.txt +++ b/tests/baselines/reference/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.ts(6,4): error TS1161: Unterminated template literal. +tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.ts(6,4): error TS1160: Unterminated template literal. ==== tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.ts (1 errors) ==== @@ -9,4 +9,4 @@ tests/cases/compiler/taggedTemplatesWithIncompleteNoSubstitutionTemplate2.ts(6,4 // Incomplete call, not enough parameters, at EOF. f ` -!!! error TS1161: Unterminated template literal. \ No newline at end of file +!!! error TS1160: Unterminated template literal. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt b/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt index 1bad2f0bf5b..45f860bc9a3 100644 --- a/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt +++ b/tests/baselines/reference/templateStringInTaggedTemplate.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts(1,1): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts(1,42): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts(1,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. ==== tests/cases/conformance/es6/templates/templateStringInTaggedTemplate.ts (2 errors) ==== `I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION` - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2349: Cannot invoke an expression whose type lacks a call signature. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt index 675a987192f..3bf910f3690 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeyword.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,15): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,26): error TS1158: Invalid template literal; expected '}' -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(5,1): error TS1161: Unterminated template literal. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(5,1): error TS1160: Unterminated template literal. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,20): error TS2304: Cannot find name 'yield'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts(3,30): error TS2304: Cannot find name 'def'. @@ -26,4 +26,4 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeyword.ts( } -!!! error TS1161: Unterminated template literal. \ No newline at end of file +!!! error TS1160: Unterminated template literal. \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt index ff81519d360..4e62197e031 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,9): error TS1003: Identifier expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,17): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,26): error TS1158: Invalid template literal; expected '}' -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(5,1): error TS1161: Unterminated template literal. +tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(5,1): error TS1160: Unterminated template literal. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,11): error TS2304: Cannot find name 'gen'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,20): error TS2304: Cannot find name 'yield'. tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,30): error TS2304: Cannot find name 'def'. @@ -26,4 +26,4 @@ tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6. } -!!! error TS1161: Unterminated template literal. \ No newline at end of file +!!! error TS1160: Unterminated template literal. \ No newline at end of file diff --git a/tests/baselines/reference/unterminatedRegexAtEndOfSource1.errors.txt b/tests/baselines/reference/unterminatedRegexAtEndOfSource1.errors.txt index 271a1a3074e..fa8959e90bf 100644 --- a/tests/baselines/reference/unterminatedRegexAtEndOfSource1.errors.txt +++ b/tests/baselines/reference/unterminatedRegexAtEndOfSource1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/unterminatedRegexAtEndOfSource1.ts(1,10): error TS1162: Unterminated regular expression literal. +tests/cases/compiler/unterminatedRegexAtEndOfSource1.ts(1,10): error TS1161: Unterminated regular expression literal. ==== tests/cases/compiler/unterminatedRegexAtEndOfSource1.ts (1 errors) ==== var a = / -!!! error TS1162: Unterminated regular expression literal. \ No newline at end of file +!!! error TS1161: Unterminated regular expression literal. \ No newline at end of file From ed22f1ca3eede649e0ec26c7ed79616a193d7b1a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 13:48:23 -0800 Subject: [PATCH 57/60] Check node for errors before recursing. --- src/compiler/parser.ts | 41 +++++++++---------- .../accessorsInAmbientContext.errors.txt | 24 +++++------ .../reference/ambientGetters.errors.txt | 6 +-- .../initializersInDeclarations.errors.txt | 6 +-- .../reference/newOperator.errors.txt | 6 +-- .../reference/objectLiteralErrors.errors.txt | 4 +- .../reference/parserAccessors5.errors.txt | 6 +-- .../privacyGloImportParseErrors.errors.txt | 12 +++--- .../privacyImportParseErrors.errors.txt | 24 +++++------ ...hStatementsWithMultipleDefaults.errors.txt | 23 +++++++++-- ...tringsWithIncompatibleTypedTags.errors.txt | 12 +++--- ...mplateStringsWithTagsTypedAsAny.errors.txt | 8 ++-- ...gedTemplateStringsWithTypedTags.errors.txt | 8 ++-- 13 files changed, 96 insertions(+), 84 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 477c414790d..29214121c07 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3555,7 +3555,7 @@ module ts { inAmbientContext = true; } - checkNode(node); + checkNodeAndChildren(node); inAmbientContext = savedInAmbientContext; inFunctionBlock = savedInFunctionBlock; @@ -3564,7 +3564,7 @@ module ts { parent = savedParent; } - function checkNode(node: Node) { + function checkNodeAndChildren(node: Node) { var nodeKind = node.kind; // First, check if you have a statement in a place where it is not allowed. We want // to do this before recursing, because we'd prefer to report these errors at the top @@ -3573,41 +3573,38 @@ module ts { return; } - // Now recurse and perform all grammar checks on the children of this node. var diagnosticCount = grammarDiagnostics.length; - forEachChild(node, visitNode); + checkNode(node, nodeKind); // if we got any errors, just stop performing any more checks on this node or higher. if (diagnosticCount !== grammarDiagnostics.length) { return; } + // Otherwise, recurse and see if we have any errors below us. + forEachChild(node, visitNode); + } + + function checkNode(node: Node, nodeKind: SyntaxKind): any { // Now do node specific checks. switch (nodeKind) { - case SyntaxKind.ArrowFunction: + case SyntaxKind.ArrowFunction: case SyntaxKind.CallSignature: case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: - checkParsedSignature(node); - break; - case SyntaxKind.BreakStatement: - case SyntaxKind.ContinueStatement: - checkBreakOrContinueStatement(node); - break; + return checkParsedSignature(node); + case SyntaxKind.BreakStatement: + case SyntaxKind.ContinueStatement: + return checkBreakOrContinueStatement(node); case SyntaxKind.LabeledStatement: - checkLabeledStatement(node); - break; - case SyntaxKind.CallExpression: + return checkLabeledStatement(node); + case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: - checkCallOrNewExpression(node); - break; - case SyntaxKind.EnumDeclaration: - checkEnumInitializer(node); - break; - case SyntaxKind.Parameter: - checkParameter(node); - break; + return checkCallOrNewExpression(node); + + case SyntaxKind.EnumDeclaration: return checkEnumInitializer(node); + case SyntaxKind.Parameter: return checkParameter(node); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); case SyntaxKind.CatchBlock: return visitCatchBlock(node); case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); diff --git a/tests/baselines/reference/accessorsInAmbientContext.errors.txt b/tests/baselines/reference/accessorsInAmbientContext.errors.txt index 6028dc898f6..ada59f21f65 100644 --- a/tests/baselines/reference/accessorsInAmbientContext.errors.txt +++ b/tests/baselines/reference/accessorsInAmbientContext.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/accessorsInAmbientContext.ts(4,19): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/accessorsInAmbientContext.ts(4,13): error TS1086: An accessor cannot be declared in an ambient context. tests/cases/compiler/accessorsInAmbientContext.ts(5,13): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(7,26): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/accessorsInAmbientContext.ts(7,20): error TS1086: An accessor cannot be declared in an ambient context. tests/cases/compiler/accessorsInAmbientContext.ts(8,20): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(13,15): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/accessorsInAmbientContext.ts(13,9): error TS1086: An accessor cannot be declared in an ambient context. tests/cases/compiler/accessorsInAmbientContext.ts(14,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/accessorsInAmbientContext.ts(16,22): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/accessorsInAmbientContext.ts(16,16): error TS1086: An accessor cannot be declared in an ambient context. tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An accessor cannot be declared in an ambient context. @@ -13,15 +13,15 @@ tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An acces declare module M { class C { get X() { return 1; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~ +!!! error TS1086: An accessor cannot be declared in an ambient context. set X(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. static get Y() { return 1; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~ +!!! error TS1086: An accessor cannot be declared in an ambient context. static set Y(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. @@ -30,15 +30,15 @@ tests/cases/compiler/accessorsInAmbientContext.ts(17,16): error TS1086: An acces declare class C { get X() { return 1; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~ +!!! error TS1086: An accessor cannot be declared in an ambient context. set X(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. static get Y() { return 1; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~ +!!! error TS1086: An accessor cannot be declared in an ambient context. static set Y(v) { } ~ !!! error TS1086: An accessor cannot be declared in an ambient context. diff --git a/tests/baselines/reference/ambientGetters.errors.txt b/tests/baselines/reference/ambientGetters.errors.txt index 085b30b758e..a56020c41fb 100644 --- a/tests/baselines/reference/ambientGetters.errors.txt +++ b/tests/baselines/reference/ambientGetters.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/ambientGetters.ts(3,9): error TS1086: An accessor cannot be declared in an ambient context. -tests/cases/compiler/ambientGetters.ts(7,20): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/compiler/ambientGetters.ts(7,9): error TS1086: An accessor cannot be declared in an ambient context. ==== tests/cases/compiler/ambientGetters.ts (2 errors) ==== @@ -12,6 +12,6 @@ tests/cases/compiler/ambientGetters.ts(7,20): error TS1036: Statements are not a declare class B { get length() { return 0; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~~~~~~ +!!! error TS1086: An accessor cannot be declared in an ambient context. } \ No newline at end of file diff --git a/tests/baselines/reference/initializersInDeclarations.errors.txt b/tests/baselines/reference/initializersInDeclarations.errors.txt index 99798d749c2..5ab9ae5d2bc 100644 --- a/tests/baselines/reference/initializersInDeclarations.errors.txt +++ b/tests/baselines/reference/initializersInDeclarations.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(5,9): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(6,16): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/externalModules/initializersInDeclarations.ts(8,3): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/externalModules/initializersInDeclarations.ts(7,16): error TS1037: A function implementation cannot be declared in an ambient context. tests/cases/conformance/externalModules/initializersInDeclarations.ts(12,15): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(13,15): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/externalModules/initializersInDeclarations.ts(16,2): error TS1036: Statements are not allowed in ambient contexts. @@ -19,9 +19,9 @@ tests/cases/conformance/externalModules/initializersInDeclarations.ts(18,16): er ~~ !!! error TS1039: Initializers are not allowed in ambient contexts. fn(): boolean { + ~ +!!! error TS1037: A function implementation cannot be declared in an ambient context. return false; - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. } } diff --git a/tests/baselines/reference/newOperator.errors.txt b/tests/baselines/reference/newOperator.errors.txt index 47f0a68b683..9232b865648 100644 --- a/tests/baselines/reference/newOperator.errors.txt +++ b/tests/baselines/reference/newOperator.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/newOperator.ts(18,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. tests/cases/compiler/newOperator.ts(20,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. -tests/cases/compiler/newOperator.ts(45,16): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. +tests/cases/compiler/newOperator.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'. tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -79,9 +79,9 @@ tests/cases/compiler/newOperator.ts(31,10): error TS2351: Cannot use 'new' with class S { public get xs(): M.T[] { + ~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return new M.T[]; - ~~~~~~~~~ -!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array()' instead. } } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index d27823a30a3..97cbdc32266 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -13,7 +13,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(33,25) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(34,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1119: An object literal cannot have property and accessor with the same name. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,23): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,27): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,26): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(40,46): error TS1119: An object literal cannot have property and accessor with the same name. @@ -293,7 +293,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,51) !!! error TS2300: Duplicate identifier '0x0'. var f14 = { 0: 0, get 000() { return 0; } }; ~~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +!!! error TS1119: An object literal cannot have property and accessor with the same name. ~ !!! error TS2300: Duplicate identifier '0'. ~~~ diff --git a/tests/baselines/reference/parserAccessors5.errors.txt b/tests/baselines/reference/parserAccessors5.errors.txt index f2e3d8c8d37..b7dcd8ef923 100644 --- a/tests/baselines/reference/parserAccessors5.errors.txt +++ b/tests/baselines/reference/parserAccessors5.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,15): error TS1036: Statements are not allowed in ambient contexts. +tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context. ==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts (1 errors) ==== declare class C { get foo() { return 0; } - ~~~~~~ -!!! error TS1036: Statements are not allowed in ambient contexts. + ~~~ +!!! error TS1086: An accessor cannot be declared in an ambient context. } \ No newline at end of file diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index a2f2843e4bb..0e3ec1def23 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(125,13): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(121,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/privacyGloImportParseErrors.ts(149,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(146,5): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -143,12 +143,12 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import errorImport = require("glo_M2_public"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; module m5 { import m5_errorImport = require("glo_M2_public"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -178,11 +178,11 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import m3 = require("use_glo_M1_public"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index 7ba28a25146..4f54c660979 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/privacyImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(143,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(277,13): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(306,13): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(273,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(302,9): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier. -tests/cases/compiler/privacyImportParseErrors.ts(344,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(353,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(341,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(350,5): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -352,12 +352,12 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M2_public"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; module m5 { import m5_errorImport = require("glo_M2_public"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M1_public; } } @@ -391,12 +391,12 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M4_private"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M3_private; module m5 { import m5_errorImport = require("glo_M4_private"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. import m5_nonerrorImport = glo_M3_private; } } @@ -452,22 +452,22 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import m3 = require("use_glo_M1_public"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } export module m3 { import m3 = require("use_glo_M1_public"); + ~~~~~~ +!!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; import m2 = require("use_glo_M1_public"); - ~~~~~~ -!!! error TS1147: Import declarations in an internal module cannot reference an external module. } } \ No newline at end of file diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt index 9c46389e906..084ed1f357e 100644 --- a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt @@ -1,9 +1,14 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(9,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(10,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,22): error TS1108: A 'return' statement can only be used within a function body. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(21,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(25,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(26,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. +tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (3 errors) ==== +==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (8 errors) ==== var x = 10; @@ -29,15 +34,25 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,22): error TS110 switch (x * x) { default: // No issues. default: // Error; second 'default' clause. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. break; case 10000: x /= x; default: // Error, third 'default' clause + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. def\u0061ult: // Error, fourth 'default' clause. + ~~~~~~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. // Errors on fifth-seventh default: return; - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: default: + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. + ~~~~~~~~ +!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. } } \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt index 6676a6d8a81..910e1ce8c27 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -4,9 +4,9 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(24,19): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(26,40): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(28,50): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(14,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(18,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts(22,9): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. @@ -58,19 +58,19 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. f `abc${ true }def${ true }ghi`["member"].member `abc${ 1 }def${ 2 }ghi`; - ~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'. diff --git a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt index a50339adf11..4ea0304f421 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTagsTypedAsAny.errors.txt @@ -6,8 +6,8 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(13,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(15,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(17,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(19,32): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts(21,46): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts (10 errors) ==== @@ -46,11 +46,11 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagsTypedAsAny.ts !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].someOtherTag `abc${1}def${2}ghi`; - ~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt index 02de690a22b..173d3a6b741 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(16,3 tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(18,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(20,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(22,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(24,19): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,40): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts (8 errors) ==== @@ -45,11 +45,11 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts(26,3 !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc`[0].member `abc${1}def${2}ghi`; - ~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f `abc${1}def${2}ghi`["member"].member `abc${1}def${2}ghi`; - ~~~~~~ + ~~~~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. f.thisIsNotATag(`abc`); From 32864f47cac8892a8759bedd84aa86eda10cb91c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 14:10:08 -0800 Subject: [PATCH 58/60] Simplify grammar check pass. --- src/compiler/parser.ts | 302 +++++++++--------- ...hStatementsWithMultipleDefaults.errors.txt | 20 +- ...StatementsWithMultipleDefaults1.errors.txt | 5 +- 3 files changed, 153 insertions(+), 174 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 29214121c07..88c823fa977 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3526,14 +3526,12 @@ module ts { function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { var grammarDiagnostics = file.grammarDiagnostics; + + // Create a scanner so we can find the start of tokens to report errors on. var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText); // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); - if (inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file)) { - return; - } - var inFunctionBlock = false; var parent: Node; visitNode(file); @@ -3573,11 +3571,8 @@ module ts { return; } - var diagnosticCount = grammarDiagnostics.length; - checkNode(node, nodeKind); - // if we got any errors, just stop performing any more checks on this node or higher. - if (diagnosticCount !== grammarDiagnostics.length) { + if (checkNode(node, nodeKind)) { return; } @@ -3585,7 +3580,7 @@ module ts { forEachChild(node, visitNode); } - function checkNode(node: Node, nodeKind: SyntaxKind): any { + function checkNode(node: Node, nodeKind: SyntaxKind): boolean { // Now do node specific checks. switch (nodeKind) { case SyntaxKind.ArrowFunction: @@ -3593,50 +3588,50 @@ module ts { case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: - return checkParsedSignature(node); + return checkAnyParsedSignature(node); case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: return checkBreakOrContinueStatement(node); - case SyntaxKind.LabeledStatement: - return checkLabeledStatement(node); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return checkCallOrNewExpression(node); - case SyntaxKind.EnumDeclaration: return checkEnumInitializer(node); + case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(node); case SyntaxKind.Parameter: return checkParameter(node); - case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); - case SyntaxKind.CatchBlock: return visitCatchBlock(node); - case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); - case SyntaxKind.Constructor: return visitConstructor(node); - case SyntaxKind.ExportAssignment: return visitExportAssignment(node); - case SyntaxKind.ForInStatement: return visitForInStatement(node); - case SyntaxKind.ForStatement: return visitForStatement(node); - case SyntaxKind.FunctionDeclaration: return visitFunctionDeclaration(node); - case SyntaxKind.FunctionExpression: return visitFunctionExpression(node); - case SyntaxKind.GetAccessor: return visitGetAccessor(node); - case SyntaxKind.IndexedAccess: return visitIndexedAccess(node); - case SyntaxKind.IndexSignature: return visitIndexSignature(node); - case SyntaxKind.InterfaceDeclaration: return visitInterfaceDeclaration(node); - case SyntaxKind.Method: return visitMethod(node); - case SyntaxKind.ModuleDeclaration: return visitModuleDeclaration(node); - case SyntaxKind.ObjectLiteral: return visitObjectLiteral(node); - case SyntaxKind.NumericLiteral: return visitNumericLiteral(node); - case SyntaxKind.PostfixOperator: return visitPostfixOperator(node); - case SyntaxKind.PrefixOperator: return visitPrefixOperator(node); - case SyntaxKind.Property: return visitProperty(node); - case SyntaxKind.PropertyAssignment: return visitPropertyAssignment(node); - case SyntaxKind.ReturnStatement: return visitReturnStatement(node); - case SyntaxKind.SetAccessor: return visitSetAccessor(node); - case SyntaxKind.ShorthandPropertyAssignment: return visitShorthandPropertyAssignment(node); - case SyntaxKind.SwitchStatement: return visitSwitchStatement(node); - case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node); - case SyntaxKind.TupleType: return visitTupleType(node); - case SyntaxKind.TypeParameter: return visitTypeParameter(node); - case SyntaxKind.TypeReference: return visitTypeReference(node); - case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node); - case SyntaxKind.VariableStatement: return visitVariableStatement(node); - case SyntaxKind.WithStatement: return visitWithStatement(node); + case SyntaxKind.BinaryExpression: return checkBinaryExpression(node); + case SyntaxKind.CatchBlock: return checkCatchBlock(node); + case SyntaxKind.ClassDeclaration: return checkClassDeclaration(node); + case SyntaxKind.Constructor: return checkConstructor(node); + case SyntaxKind.ExportAssignment: return checkExportAssignment(node); + case SyntaxKind.ForInStatement: return checkForInStatement(node); + case SyntaxKind.ForStatement: return checkForStatement(node); + case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); + case SyntaxKind.FunctionExpression: return checkFunctionExpression(node); + case SyntaxKind.GetAccessor: return checkGetAccessor(node); + case SyntaxKind.IndexedAccess: return checkIndexedAccess(node); + case SyntaxKind.IndexSignature: return checkIndexSignature(node); + case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); + case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); + case SyntaxKind.Method: return checkMethod(node); + case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); + case SyntaxKind.ObjectLiteral: return checkObjectLiteral(node); + case SyntaxKind.NumericLiteral: return checkNumericLiteral(node); + case SyntaxKind.PostfixOperator: return checkPostfixOperator(node); + case SyntaxKind.PrefixOperator: return checkPrefixOperator(node); + case SyntaxKind.Property: return checkProperty(node); + case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); + case SyntaxKind.ReturnStatement: return checkReturnStatement(node); + case SyntaxKind.SetAccessor: return checkSetAccessor(node); + case SyntaxKind.SourceFile: return checkSourceFile(node); + case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(node); + case SyntaxKind.SwitchStatement: return checkSwitchStatement(node); + case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); + case SyntaxKind.TupleType: return checkTupleType(node); + case SyntaxKind.TypeParameter: return checkTypeParameter(node); + case SyntaxKind.TypeReference: return checkTypeReference(node); + case SyntaxKind.VariableDeclaration: return checkVariableDeclaration(node); + case SyntaxKind.VariableStatement: return checkVariableStatement(node); + case SyntaxKind.WithStatement: return checkWithStatement(node); } } @@ -3669,39 +3664,6 @@ module ts { return grammarErrorOnNode(node, Diagnostics.Invalid_use_of_0_in_strict_mode, name); } - function checkTopLevelElementsForRequiredDeclareModifier(file: SourceFile): boolean { - for (var i = 0, n = file.statements.length; i < n; i++) { - var decl = file.statements[i]; - if (isDeclaration(decl) || decl.kind === SyntaxKind.VariableStatement) { - if (checkTopLevelElementForRequiredDeclareModifier(decl)) { - return true; - } - } - } - } - - function checkTopLevelElementForRequiredDeclareModifier(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: - // - // DeclarationElement: - // ExportAssignment - // export_opt InterfaceDeclaration - // export_opt ImportDeclaration - // export_opt ExternalImportDeclaration - // export_opt AmbientDeclaration - // - if (node.kind === SyntaxKind.InterfaceDeclaration || - node.kind === SyntaxKind.ImportDeclaration || - node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient)) { - - return false; - } - - return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); - } - function checkForStatementInAmbientContext(node: Node, kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.Block: @@ -3725,18 +3687,18 @@ module ts { } } - function checkParsedSignature(node: ParsedSignature): boolean { + function checkAnyParsedSignature(node: ParsedSignature): boolean { return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); } - function visitBinaryExpression(node: BinaryExpression) { + function checkBinaryExpression(node: BinaryExpression) { if (node.flags & NodeFlags.ParsedInStrictMode) { if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) { if (isEvalOrArgumentsIdentifier(node.left)) { // ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an // Assignment operator(11.13) or of a PostfixExpression(11.3) - reportInvalidUseInStrictMode(node.left); + return reportInvalidUseInStrictMode(node.left); } } } @@ -3825,7 +3787,7 @@ module ts { } function checkCallOrNewExpression(node: CallExpression) { - checkTypeArguments(node.typeArguments) || + return checkTypeArguments(node.typeArguments) || checkArguments(node.arguments); } @@ -3878,20 +3840,20 @@ module ts { } } - function visitCatchBlock(node: CatchBlock) { + function checkCatchBlock(node: CatchBlock) { if (node.type) { var colonStart = skipTrivia(sourceText, node.variable.end); - grammarErrorAtPos(colonStart, ":".length, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + return grammarErrorAtPos(colonStart, ":".length, Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); } if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.variable)) { // It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the // Catch production is eval or arguments - reportInvalidUseInStrictMode(node.variable); + return reportInvalidUseInStrictMode(node.variable); } } - function visitClassDeclaration(node: ClassDeclaration) { - checkForDisallowedTrailingComma(node.implementedTypes) || + function checkClassDeclaration(node: ClassDeclaration) { + return checkForDisallowedTrailingComma(node.implementedTypes) || checkForAtLeastOneHeritageClause(node.implementedTypes, "implements"); } @@ -3901,8 +3863,8 @@ module ts { } } - function visitConstructor(node: ConstructorDeclaration) { - checkParsedSignature(node) || + function checkConstructor(node: ConstructorDeclaration) { + return checkAnyParsedSignature(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ true); @@ -3920,7 +3882,7 @@ module ts { } } - function checkEnumInitializer(enumDecl: EnumDeclaration): boolean { + function checkEnumDeclaration(enumDecl: EnumDeclaration): boolean { var enumIsConst = (enumDecl.flags & NodeFlags.Const) !== 0; var hasError = false; @@ -3943,6 +3905,7 @@ module ts { } } } + return hasError; } @@ -3969,19 +3932,19 @@ module ts { return false; } - function visitExportAssignment(node: ExportAssignment) { + function checkExportAssignment(node: ExportAssignment) { if (node.flags & NodeFlags.Modifier) { - grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); + return grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } } - function visitForInStatement(node: ForInStatement) { - checkVariableDeclarations(node.declarations) || + function checkForInStatement(node: ForInStatement) { + return checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations); } - function visitForStatement(node: ForStatement) { - checkVariableDeclarations(node.declarations); + function checkForStatement(node: ForStatement) { + return checkVariableDeclarations(node.declarations); } function checkForMoreThanOneDeclaration(declarations: NodeArray) { @@ -3990,14 +3953,14 @@ module ts { } } - function visitFunctionDeclaration(node: FunctionLikeDeclaration) { - checkParsedSignature(node) || + function checkFunctionDeclaration(node: FunctionLikeDeclaration) { + return checkAnyParsedSignature(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false); } - function visitFunctionExpression(node: FunctionExpression) { - checkParsedSignature(node) || + function checkFunctionExpression(node: FunctionExpression) { + return checkAnyParsedSignature(node) || checkFunctionName(node.name); } @@ -4009,24 +3972,24 @@ module ts { } } - function visitGetAccessor(node: MethodDeclaration) { - checkParsedSignature(node) || + function checkGetAccessor(node: MethodDeclaration) { + return checkAnyParsedSignature(node) || checkAccessor(node); } - function visitIndexedAccess(node: IndexedAccess): void { + function checkIndexedAccess(node: IndexedAccess) { if (node.index.kind === SyntaxKind.Missing && node.parent.kind === SyntaxKind.NewExpression && (node.parent).func === node) { var start = skipTrivia(sourceText, node.parent.pos); var end = node.end; - grammarErrorAtPos(start, end - start, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); + return grammarErrorAtPos(start, end - start, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); } } - function visitIndexSignature(node: SignatureDeclaration): void { - checkIndexSignatureParameters(node) || + function checkIndexSignature(node: SignatureDeclaration): boolean { + return checkIndexSignatureParameters(node) || checkForIndexSignatureModifiers(node); } @@ -4069,13 +4032,13 @@ module ts { } } - function visitInterfaceDeclaration(node: InterfaceDeclaration) { - checkForDisallowedTrailingComma(node.baseTypes) || + function checkInterfaceDeclaration(node: InterfaceDeclaration) { + return checkForDisallowedTrailingComma(node.baseTypes) || checkForAtLeastOneHeritageClause(node.baseTypes, "extends"); } - function visitMethod(node: MethodDeclaration) { - checkParsedSignature(node) || + function checkMethod(node: MethodDeclaration) { + return checkAnyParsedSignature(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)); } @@ -4089,8 +4052,8 @@ module ts { } } - function visitModuleDeclaration(node: ModuleDeclaration): void { - checkModuleDeclarationName(node) || + function checkModuleDeclaration(node: ModuleDeclaration): boolean { + return checkModuleDeclarationName(node) || checkModuleDeclarationStatements(node); } @@ -4117,7 +4080,7 @@ module ts { } } - function visitObjectLiteral(node: ObjectLiteral): void { + function checkObjectLiteral(node: ObjectLiteral): boolean { var seen: Map = {}; var Property = 1; var GetAccessor = 2; @@ -4175,23 +4138,23 @@ module ts { seen[name.text] = currentKind | existingKind; } else { - grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } } - function visitNumericLiteral(node: LiteralExpression): void { + function checkNumericLiteral(node: LiteralExpression): boolean { if (node.flags & NodeFlags.OctalLiteral) { if (node.flags & NodeFlags.ParsedInStrictMode) { - grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); + return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } else if (languageVersion >= ScriptTarget.ES5) { - grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } } @@ -4386,33 +4349,33 @@ module ts { } } - function visitPostfixOperator(node: UnaryExpression) { + function checkPostfixOperator(node: UnaryExpression) { // The identifier eval or arguments may not appear as the LeftHandSideExpression of an // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator. if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.operand)) { - reportInvalidUseInStrictMode(node.operand); + return reportInvalidUseInStrictMode(node.operand); } } - function visitPrefixOperator(node: UnaryExpression) { + function checkPrefixOperator(node: UnaryExpression) { if (node.flags & NodeFlags.ParsedInStrictMode) { // The identifier eval or arguments may not appear as the LeftHandSideExpression of an // Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression // operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator if ((node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) && isEvalOrArgumentsIdentifier(node.operand)) { - reportInvalidUseInStrictMode(node.operand); + return reportInvalidUseInStrictMode(node.operand); } else if (node.operator === SyntaxKind.DeleteKeyword && node.operand.kind === SyntaxKind.Identifier) { // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its // UnaryExpression is a direct reference to a variable, function argument, or function name - grammarErrorOnNode(node.operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); + return grammarErrorOnNode(node.operand, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode); } } } - function visitProperty(node: PropertyDeclaration) { - (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)) || + function checkProperty(node: PropertyDeclaration) { + return (node.parent.kind === SyntaxKind.ClassDeclaration && checkForInvalidQuestionMark(node, Diagnostics.A_class_member_cannot_be_declared_optional)) || checkForInitializerInAmbientContext(node); } @@ -4422,8 +4385,8 @@ module ts { } } - function visitPropertyAssignment(node: PropertyDeclaration) { - checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); + function checkPropertyAssignment(node: PropertyDeclaration) { + return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); } function checkForInvalidQuestionMark(node: Declaration, message: DiagnosticMessage) { @@ -4433,14 +4396,14 @@ module ts { } } - function visitReturnStatement(node: ReturnStatement) { + function checkReturnStatement(node: ReturnStatement) { if (!inFunctionBlock) { - grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); + return grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); } } - function visitSetAccessor(node: MethodDeclaration) { - checkParsedSignature(node) || + function checkSetAccessor(node: MethodDeclaration) { + return checkAnyParsedSignature(node) || checkAccessor(node); } @@ -4486,11 +4449,48 @@ module ts { } } - function visitShorthandPropertyAssignment(node: ShortHandPropertyDeclaration): void { - checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); + function checkSourceFile(node: SourceFile): boolean { + return inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file); } - function visitSwitchStatement(node: SwitchStatement) { + function checkTopLevelElementsForRequiredDeclareModifier(file: SourceFile): boolean { + for (var i = 0, n = file.statements.length; i < n; i++) { + var decl = file.statements[i]; + if (isDeclaration(decl) || decl.kind === SyntaxKind.VariableStatement) { + if (checkTopLevelElementForRequiredDeclareModifier(decl)) { + return true; + } + } + } + } + + function checkTopLevelElementForRequiredDeclareModifier(node: Node): boolean { + // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: + // categories: + // + // DeclarationElement: + // ExportAssignment + // export_opt InterfaceDeclaration + // export_opt ImportDeclaration + // export_opt ExternalImportDeclaration + // export_opt AmbientDeclaration + // + if (node.kind === SyntaxKind.InterfaceDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ExportAssignment || + (node.flags & NodeFlags.Ambient)) { + + return false; + } + + return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + } + + function checkShorthandPropertyAssignment(node: ShortHandPropertyDeclaration): boolean { + return checkForInvalidQuestionMark(node, Diagnostics.An_object_member_cannot_be_declared_optional); + } + + function checkSwitchStatement(node: SwitchStatement) { var firstDefaultClause: CaseOrDefaultClause; // Error on duplicate 'default' clauses. @@ -4503,20 +4503,20 @@ module ts { else { var start = skipTrivia(file.text, clause.pos); var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end; - grammarErrorAtPos(start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); + return grammarErrorAtPos(start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement); } } } } - function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { + function checkTaggedTemplateExpression(node: TaggedTemplateExpression) { if (languageVersion < ScriptTarget.ES6) { - grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); + return grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } } - function visitTupleType(node: TupleTypeNode) { - checkForDisallowedTrailingComma(node.elementTypes) || + function checkTupleType(node: TupleTypeNode) { + return checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node); } @@ -4526,28 +4526,28 @@ module ts { } } - function visitTypeParameter(node: TypeParameterDeclaration) { + function checkTypeParameter(node: TypeParameterDeclaration) { if (node.expression) { - grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected); + return grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected); } } - function visitTypeReference(node: TypeReferenceNode) { - checkTypeArguments(node.typeArguments); + function checkTypeReference(node: TypeReferenceNode) { + return checkTypeArguments(node.typeArguments); } - function visitVariableDeclaration(node: VariableDeclaration) { + function checkVariableDeclaration(node: VariableDeclaration) { if (inAmbientContext && node.initializer) { var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end); - grammarErrorAtPos(equalsPos, "=".length, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + return grammarErrorAtPos(equalsPos, "=".length, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } if (!inAmbientContext && !node.initializer && node.flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); } if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code // and its Identifier is eval or arguments - reportInvalidUseInStrictMode(node.name); + return reportInvalidUseInStrictMode(node.name); } } @@ -4573,8 +4573,8 @@ module ts { } } - function visitVariableStatement(node: VariableStatement) { - checkVariableDeclarations(node.declarations) || + function checkVariableStatement(node: VariableStatement) { + return checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node); } @@ -4605,11 +4605,11 @@ module ts { return true; } - function visitWithStatement(node: WithStatement): void { + function checkWithStatement(node: WithStatement): boolean { if (node.flags & NodeFlags.ParsedInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such // a context is an - grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode); + return grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode); } } } diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt index 084ed1f357e..10568608a79 100644 --- a/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults.errors.txt @@ -1,14 +1,8 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(9,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(10,5): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(21,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(25,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(26,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(28,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,13): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (8 errors) ==== +==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (2 errors) ==== var x = 10; @@ -21,8 +15,6 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS111 ~~~~~~~~ !!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: // Error; third 'default' clause. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. case 3: x *= x; } @@ -40,19 +32,9 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults.ts(29,22): error TS111 case 10000: x /= x; default: // Error, third 'default' clause - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. def\u0061ult: // Error, fourth 'default' clause. - ~~~~~~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. // Errors on fifth-seventh default: return; - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: default: - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. } } \ No newline at end of file diff --git a/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt b/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt index 80b0560445a..c20bfd22af1 100644 --- a/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt +++ b/tests/baselines/reference/switchStatementsWithMultipleDefaults1.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts(8,9): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts(9,9): error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. -==== tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts (2 errors) ==== +==== tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts (1 errors) ==== var x = 10; switch (x) { @@ -14,8 +13,6 @@ tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts(9,9): error TS1113 ~~~~~~~~ !!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. default: // Error; third 'default' clause. - ~~~~~~~~ -!!! error TS1113: A 'default' clause cannot appear more than once in a 'switch' statement. case 3: x *= x; } \ No newline at end of file From 617fd2c5c9e56c59ca7b5c83178bd3264c27098a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 14:18:04 -0800 Subject: [PATCH 59/60] Remove SourceFileInternal. --- src/compiler/parser.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 88c823fa977..2f96e4f734d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -814,12 +814,6 @@ module ts { return false; } - interface SourceFileInternal extends SourceFile { - // All diagnostics for the source file. Should not be accessed directly. Lazily created - // when getSyntacticDiagnostics is called. - _syntacticDiagnostics: Diagnostic[]; - } - function modifierToFlag(token: SyntaxKind): NodeFlags { switch (token) { case SyntaxKind.StaticKeyword: return NodeFlags.Static; @@ -833,7 +827,7 @@ module ts { } export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { - var file: SourceFileInternal; + var file: SourceFile; var scanner: Scanner; var token: SyntaxKind; var parsingContext: ParsingContext; @@ -3439,22 +3433,23 @@ module ts { : undefined); } + var syntacticDiagnostics: Diagnostic[]; function getSyntacticDiagnostics() { - if (file._syntacticDiagnostics === undefined) { + if (syntacticDiagnostics === undefined) { if (file.parseDiagnostics.length > 0) { // Don't bother doing any grammar checks if there are already parser errors. // Otherwise we may end up with too many cascading errors. - file._syntacticDiagnostics = file.parseDiagnostics; + syntacticDiagnostics = file.parseDiagnostics; } else { // No parser errors were reported. Perform our stricter grammar checks. - file._syntacticDiagnostics = file.grammarDiagnostics; + syntacticDiagnostics = file.grammarDiagnostics; checkGrammar(sourceText, languageVersion, file); } } - Debug.assert(file._syntacticDiagnostics !== undefined); - return file._syntacticDiagnostics + Debug.assert(syntacticDiagnostics !== undefined); + return syntacticDiagnostics; } scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError, onComment); @@ -3462,7 +3457,7 @@ module ts { if (fileExtensionIs(filename, ".d.ts")) { rootNodeFlags = NodeFlags.DeclarationFile; } - file = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); + file = createRootNode(SyntaxKind.SourceFile, 0, sourceText.length, rootNodeFlags); file.filename = normalizePath(filename); file.text = sourceText; file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; @@ -3524,7 +3519,7 @@ module ts { return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment; } - function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFileInternal) { + function checkGrammar(sourceText: string, languageVersion: ScriptTarget, file: SourceFile) { var grammarDiagnostics = file.grammarDiagnostics; // Create a scanner so we can find the start of tokens to report errors on. From c005c33244b75911acc04d69c6fbf23269f8acea Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 20 Nov 2014 14:27:09 -0800 Subject: [PATCH 60/60] Better spans for import/export errors. --- src/compiler/parser.ts | 4 ++-- ...DeclarationInModuleDeclaration1.errors.txt | 4 ++-- .../reference/importInsideModule.errors.txt | 4 ++-- .../parserExportAssignment5.errors.txt | 2 +- .../privacyGloImportParseErrors.errors.txt | 12 +++++----- .../privacyImportParseErrors.errors.txt | 24 +++++++++---------- .../amd/intReferencingExtAndInt.errors.txt | 4 ++-- .../node/intReferencingExtAndInt.errors.txt | 4 ++-- .../nestedLocalModuleSimpleCase.errors.txt | 4 ++-- .../nestedLocalModuleSimpleCase.errors.txt | 4 ++-- ...calModuleWithRecursiveTypecheck.errors.txt | 4 ++-- ...calModuleWithRecursiveTypecheck.errors.txt | 4 ++-- ...dModuleDeclarationsInsideModule.errors.txt | 4 ++-- ...dModuleDeclarationsInsideModule.errors.txt | 4 ++-- ...arationsInsideNonExportedModule.errors.txt | 4 ++-- ...arationsInsideNonExportedModule.errors.txt | 4 ++-- ...leImportStatementInParentModule.errors.txt | 4 ++-- ...leImportStatementInParentModule.errors.txt | 4 ++-- 18 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2f96e4f734d..7173e299a39 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4066,10 +4066,10 @@ module ts { if (statement.kind === SyntaxKind.ExportAssignment) { // Export assignments are not allowed in an internal module - return grammarErrorOnFirstToken(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return grammarErrorOnNode(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } else if (statement.kind === SyntaxKind.ImportDeclaration && (statement).externalModuleName) { - return grammarErrorOnFirstToken(statement, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + return grammarErrorOnNode((statement).externalModuleName, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } } } diff --git a/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt index ba6aae1e361..e8e9de076ad 100644 --- a/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt +++ b/tests/baselines/reference/importDeclarationInModuleDeclaration1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/importDeclarationInModuleDeclaration1.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/importDeclarationInModuleDeclaration1.ts(2,25): error TS1147: Import declarations in an internal module cannot reference an external module. ==== tests/cases/compiler/importDeclarationInModuleDeclaration1.ts (1 errors) ==== module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. } \ No newline at end of file diff --git a/tests/baselines/reference/importInsideModule.errors.txt b/tests/baselines/reference/importInsideModule.errors.txt index 4a7ab9d5b78..efe9b78125f 100644 --- a/tests/baselines/reference/importInsideModule.errors.txt +++ b/tests/baselines/reference/importInsideModule.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/importInsideModule_file2.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/importInsideModule_file2.ts(2,26): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/importInsideModule_file2.ts(2,26): error TS2307: Cannot find external module 'importInsideModule_file1'. ==== tests/cases/compiler/importInsideModule_file2.ts (2 errors) ==== export module myModule { import foo = require("importInsideModule_file1"); - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'importInsideModule_file1'. diff --git a/tests/baselines/reference/parserExportAssignment5.errors.txt b/tests/baselines/reference/parserExportAssignment5.errors.txt index 16c4188bc08..b463034f621 100644 --- a/tests/baselines/reference/parserExportAssignment5.errors.txt +++ b/tests/baselines/reference/parserExportAssignment5.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignm ==== tests/cases/conformance/parser/ecmascript5/ExportAssignments/parserExportAssignment5.ts (2 errors) ==== module M { export = A; - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1063: An export assignment cannot be used in an internal module. ~~~~~~~~~~~ !!! error TS2304: Cannot find name 'A'. diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index 0e3ec1def23..14bdd82dd0c 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/privacyGloImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(121,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(121,38): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. -tests/cases/compiler/privacyGloImportParseErrors.ts(146,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyGloImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -75,7 +75,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); - ~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. @@ -143,7 +143,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import errorImport = require("glo_M2_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; @@ -178,7 +178,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambie module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index 4f54c660979..6ef7298aad2 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/privacyImportParseErrors.ts(59,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(143,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(273,9): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(302,9): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(143,37): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(273,38): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(302,38): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier. -tests/cases/compiler/privacyImportParseErrors.ts(341,5): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(350,5): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(341,25): error TS1147: Import declarations in an internal module cannot reference an external module. +tests/cases/compiler/privacyImportParseErrors.ts(350,25): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot find external module 'm1_M3_public'. @@ -102,7 +102,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m1_M3_public"); - ~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm1_M3_public'. @@ -196,7 +196,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient var m1_im2_private_v4_private = m1_im2_private.f1(); import m1_im3_private = require("m2_M3_public"); - ~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module 'm2_M3_public'. @@ -352,7 +352,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M2_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M1_public; @@ -391,7 +391,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import errorImport = require("glo_M4_private"); - ~~~~~~ + ~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. import nonerrorImport = glo_M3_private; @@ -452,7 +452,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient module m2 { import m3 = require("use_glo_M1_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; @@ -463,7 +463,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(336,12): error TS2435: Ambient export module m3 { import m3 = require("use_glo_M1_public"); - ~~~~~~ + ~~~~~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module m4 { var a = 10; diff --git a/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt b/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt index 59cbb44a3c5..fd808bc1443 100644 --- a/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt +++ b/tests/baselines/reference/project/intReferencingExtAndInt/amd/intReferencingExtAndInt.errors.txt @@ -1,10 +1,10 @@ -internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module. +internal2.ts(2,21): error TS1147: Import declarations in an internal module cannot reference an external module. ==== internal2.ts (1 errors) ==== module outer { import g = require("external2") - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var a = g.square(5); export var b = "foo"; diff --git a/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt b/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt index 59cbb44a3c5..fd808bc1443 100644 --- a/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt +++ b/tests/baselines/reference/project/intReferencingExtAndInt/node/intReferencingExtAndInt.errors.txt @@ -1,10 +1,10 @@ -internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module. +internal2.ts(2,21): error TS1147: Import declarations in an internal module cannot reference an external module. ==== internal2.ts (1 errors) ==== module outer { import g = require("external2") - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var a = g.square(5); export var b = "foo"; diff --git a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt index 43f02e4fb9d..d8a57865c22 100644 --- a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/amd/nestedLocalModuleSimpleCase.errors.txt @@ -1,10 +1,10 @@ -test1.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module. +test1.ts(2,23): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test1.ts (1 errors) ==== export module myModule { import foo = require("test2"); - ~~~~~~ + ~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); } diff --git a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt index 43f02e4fb9d..d8a57865c22 100644 --- a/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleSimpleCase/node/nestedLocalModuleSimpleCase.errors.txt @@ -1,10 +1,10 @@ -test1.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module. +test1.ts(2,23): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test1.ts (1 errors) ==== export module myModule { import foo = require("test2"); - ~~~~~~ + ~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); } diff --git a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt index 35c81a722d1..9d1540829fc 100644 --- a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/amd/nestedLocalModuleWithRecursiveTypecheck.errors.txt @@ -1,11 +1,11 @@ -test1.ts(3,2): error TS1147: Import declarations in an internal module cannot reference an external module. +test1.ts(3,23): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test1.ts (1 errors) ==== module myModule { import foo = require("test2"); - ~~~~~~ + ~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); diff --git a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt index 35c81a722d1..9d1540829fc 100644 --- a/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt +++ b/tests/baselines/reference/project/nestedLocalModuleWithRecursiveTypecheck/node/nestedLocalModuleWithRecursiveTypecheck.errors.txt @@ -1,11 +1,11 @@ -test1.ts(3,2): error TS1147: Import declarations in an internal module cannot reference an external module. +test1.ts(3,23): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test1.ts (1 errors) ==== module myModule { import foo = require("test2"); - ~~~~~~ + ~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. //console.log(foo.$); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index 09f7aed73fb..f15b4d3379b 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,10 +1,10 @@ -testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +testGlo.ts(2,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt index 09f7aed73fb..f15b4d3379b 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/privacyCheckOnImportedModuleDeclarationsInsideModule.errors.txt @@ -1,10 +1,10 @@ -testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +testGlo.ts(2,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== testGlo.ts (1 errors) ==== module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index ad44386dcd1..8589da5c54d 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/amd/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,4 +1,4 @@ -test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. +test.ts(5,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test.ts (1 errors) ==== @@ -7,7 +7,7 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot ref module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt index ad44386dcd1..8589da5c54d 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule/node/privacyCheckOnImportedModuleDeclarationsInsideNonExportedModule.errors.txt @@ -1,4 +1,4 @@ -test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module. +test.ts(5,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test.ts (1 errors) ==== @@ -7,7 +7,7 @@ test.ts(5,5): error TS1147: Import declarations in an internal module cannot ref module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. export var c1 = new mExported.me.class1; export function f1() { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index 0d281b950f4..c3c3a11c8b2 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/amd/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,10 +1,10 @@ -test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +test.ts(2,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M1 { diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt index 0d281b950f4..c3c3a11c8b2 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleImportStatementInParentModule/node/privacyCheckOnImportedModuleImportStatementInParentModule.errors.txt @@ -1,10 +1,10 @@ -test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module. +test.ts(2,39): error TS1147: Import declarations in an internal module cannot reference an external module. ==== test.ts (1 errors) ==== export module m2 { export import mExported = require("mExported"); - ~~~~~~ + ~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. module Internal_M1 {