From c93fb35c53975423e8c228e61e641aa122785f99 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 17:29:32 -0700 Subject: [PATCH 01/23] Move strict mode check into TypeChecker --- src/compiler/checker.ts | 101 +++++++++++++++--- .../diagnosticInformationMap.generated.ts | 7 ++ src/compiler/diagnosticMessages.json | 30 +++++- src/compiler/parser.ts | 22 +++- src/compiler/types.ts | 1 + 5 files changed, 145 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea38a8f4b31..f415ff893f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7294,7 +7294,7 @@ module ts { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); // Grammar checking - let hasGrammarError = checkGrammarFunctionLikeDeclaration(node); + let hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === SyntaxKind.FunctionExpression) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -7954,6 +7954,7 @@ module ts { } function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { + checkGrammarExpressionInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } @@ -8069,6 +8070,8 @@ module ts { // DECLARATION AND STATEMENT TYPE CHECKING function checkTypeParameter(node: TypeParameterDeclaration) { + checkGrammarDeclarationNameInStrictMode(node); + // Grammar Checking if (node.expression) { grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected); @@ -8337,10 +8340,23 @@ module ts { } function checkTypeReferenceNode(node: TypeReferenceNode) { + // Check if the type reference is using strict mode keyword + // Example: + // class C { + // foo(x: public){} // Error. + // } + if (node.typeName.kind === SyntaxKind.Identifier && (node.typeName).strictModeKind) { + let typeName = node.typeName; + let nameText = declarationNameToString(typeName); + reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) || + reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node: HeritageClauseElement) { + checkGrammarExpressionInStrictMode(node.expression); return checkTypeReferenceOrHeritageClauseElement(node); } @@ -8871,6 +8887,7 @@ module ts { } function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); @@ -9154,6 +9171,7 @@ module ts { // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit @@ -9880,6 +9898,7 @@ module ts { } function checkClassDeclaration(node: ClassDeclaration) { + checkGrammarDeclarationNameInStrictMode(node); // Grammar checking if (node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { grammarErrorOnNode(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); @@ -10106,7 +10125,7 @@ module ts { function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { @@ -10331,7 +10350,7 @@ module ts { } // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -10401,7 +10420,7 @@ module ts { function checkModuleDeclaration(node: ModuleDeclaration) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -10567,7 +10586,7 @@ module ts { // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); - let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module); } @@ -11915,6 +11934,65 @@ module ts { // GRAMMAR CHECKING + function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { + // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) + // if so, we would like to give more explicit invalid usage error. + if (getAncestor(identifier, SyntaxKind.ClassDeclaration) || getAncestor(identifier, SyntaxKind.ClassExpression)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + + function reportStrictModeGrammarErrorInModule(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { + // We are checking if this name is inside module declaration which is automatically a strict mode code in ES6. + // If so, we would like to give more explicit invalid usage error. + if (getAncestor(identifier, SyntaxKind.ModuleDeclaration)) { + return grammarErrorOnNode(identifier, message, arg0); + } + return false; + } + + function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean { + let name = node.name; + if (name && name.kind === SyntaxKind.Identifier && (name).strictModeKind) { + let nameText = declarationNameToString(name); + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.TypeParameter: + case SyntaxKind.BindingElement: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + let reportError = reportStrictModeGrammarErrorInClassDeclaration(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) || + reportStrictModeGrammarErrorInModule(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return reportError ? reportError : false; + + case SyntaxKind.ClassDeclaration: + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText); + + case SyntaxKind.ModuleDeclaration: + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText); + + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + return grammarErrorOnNode(name, Diagnostics.ImportDecl_SlashExportDecl_SlashImportEqaul); + } + } + return false; + } + + function checkGrammarExpressionInStrictMode(node: Expression): boolean { + if (node.kind === SyntaxKind.Identifier && (node).strictModeKind) { + let nameText = declarationNameToString(node); + return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + return false; + } + function checkGrammarDecorators(node: Node): boolean { if (!node.decorators) { return false; @@ -12775,15 +12853,14 @@ module ts { if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { let nameText = declarationNameToString(identifier); - // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) - // if so, we would like to give more explicit invalid usage error. - // This will be particularly helpful in the case of "arguments" as such case is very common mistake. - if (getAncestor(name, SyntaxKind.ClassDeclaration) || getAncestor(name, SyntaxKind.ClassExpression)) { - return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); - } - else { + // We check first if the name is inside class declaration or class expression; if so give explicit message + // otherwise report generic error message. + // reportGrammarErrorInClassDeclaration only return true if grammar error is successfully reported and false otherwise + let reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText); + if (!reportErrorInClassDeclaration){ return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } + return reportErrorInClassDeclaration; } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5062be5ed46..502cd13296b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -169,6 +169,13 @@ module ts { Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, + Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Module is automatically in strict mode." }, + ImportDecl_SlashExportDecl_SlashImportEqaul: { code: 1212, category: DiagnosticCategory.Error, key: "ImportDecl/ExportDecl/ImportEqaul" }, 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 4476b0cad4a..6d822695930 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -661,12 +661,40 @@ }, "Invalid use of '{0}'. Class definitions are automatically in strict mode.": { "category": "Error", - "code": 1210 + "code": 1210 }, "A class declaration without the 'default' modifier must have a name": { "category": "Error", "code": 1211 }, + "Identifier expected. '{0}' is a reserved word in strict mode": { + "category": "Error", + "code": 1212 + }, + "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { + "category": "Error", + "code": 1212 + }, + "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode.": { + "category": "Error", + "code": 1212 + }, + "Type expected. '{0}' is a reserved word in strict mode": { + "category": "Error", + "code": 1212 + }, + "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { + "category": "Error", + "code": 1212 + }, + "Type expected. '{0}' is a reserved word. Module is automatically in strict mode.": { + "category": "Error", + "code": 1212 + }, + "ImportDecl/ExportDecl/ImportEqaul": { + "category": "Error", + "code": 1212 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bde4cec3f3f..4f3cebc1e88 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1350,7 +1350,13 @@ module ts { return speculationHelper(callback, /*isLookAhead:*/ false); } - function isIdentifier(): boolean { + // The function takes a flag "considerStrictModeContext" because in the case of parsing + // an identifier, we don't want to consider whether we are in strict mode. This is because + // if the identifier violates strict-mode reserved word, we want to report more explicit error + // in the checker. + // However, in some cases such as isLetDeclaration, we want to know at the parse time whether + // next token is really an identifier in strict mode and report an error. + function isIdentifier(considerStrictModeContext = true): boolean { if (token === SyntaxKind.Identifier) { return true; } @@ -1361,7 +1367,12 @@ module ts { return false; } - return inStrictModeContext() ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord; + if (considerStrictModeContext) { + return inStrictModeContext() ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord; + } + else { + return token > SyntaxKind.LastReservedWord; + } } function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage): boolean { @@ -1485,6 +1496,11 @@ module ts { identifierCount++; if (isIdentifier) { let node = createNode(SyntaxKind.Identifier); + + // Set strictModeKind property so that we can report appropriate error later in type checker + if (inStrictModeContext() && (token > SyntaxKind.Identifier && token <= SyntaxKind.LastFutureReservedWord)) { + node.strictModeKind = token; + } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); @@ -1494,7 +1510,7 @@ module ts { } function parseIdentifier(diagnosticMessage?: DiagnosticMessage): Identifier { - return createIdentifier(isIdentifier(), diagnosticMessage); + return createIdentifier(isIdentifier(/*considerStrictModeContext*/ false), diagnosticMessage); } function parseIdentifierName(): Identifier { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 74777057963..5b7083e164e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -387,6 +387,7 @@ module ts { export interface Identifier extends PrimaryExpression { text: string; // Text of identifier (with escapes converted to characters) + strictModeKind?: SyntaxKind; // TODO(yuisu): comment } export interface QualifiedName extends Node { From 4f0a0481f6bc13dd56c077497d62d30953fa1ef2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 17:49:14 -0700 Subject: [PATCH 02/23] Update tests --- .../constructorStaticParamName.errors.txt | 4 +- .../reference/constructorStaticParamName.js | 2 +- ...onstructorStaticParamNameErrors.errors.txt | 4 +- .../constructorStaticParamNameErrors.js | 2 +- ...torWithIncompleteTypeAnnotation.errors.txt | 93 ++------ ...constructorWithIncompleteTypeAnnotation.js | 215 +++++++++--------- .../reference/convertKeywordsYes.errors.txt | 58 ++--- .../baselines/reference/convertKeywordsYes.js | 69 +++--- .../decoratorOnClassAccessor3.errors.txt | 28 ++- .../reference/decoratorOnClassAccessor3.js | 22 +- .../decoratorOnClassAccessor6.errors.txt | 37 ++- .../reference/decoratorOnClassAccessor6.js | 20 +- ...torOnClassConstructorParameter4.errors.txt | 5 +- .../decoratorOnClassConstructorParameter4.js | 2 +- .../decoratorOnClassMethod3.errors.txt | 22 +- .../reference/decoratorOnClassMethod3.js | 15 +- .../decoratorOnClassProperty3.errors.txt | 19 +- .../reference/decoratorOnClassProperty3.js | 12 +- .../letAsIdentifierInStrictMode.errors.txt | 11 +- .../reference/letAsIdentifierInStrictMode.js | 4 +- .../reference/parser10.1.1-8gs.errors.txt | 12 +- tests/baselines/reference/parser10.1.1-8gs.js | 3 +- .../reference/parser509668.errors.txt | 5 +- tests/baselines/reference/parser509668.js | 2 +- .../reference/parser553699.errors.txt | 9 +- tests/baselines/reference/parser553699.js | 2 +- .../reference/parser642331.errors.txt | 4 +- tests/baselines/reference/parser642331.js | 2 +- .../reference/parser642331_1.errors.txt | 4 +- tests/baselines/reference/parser642331_1.js | 2 +- .../parserComputedPropertyName36.errors.txt | 16 +- .../parserComputedPropertyName38.errors.txt | 23 +- .../reference/parserComputedPropertyName38.js | 2 +- .../parserComputedPropertyName39.errors.txt | 23 +- .../reference/parserComputedPropertyName39.js | 2 +- .../reference/parserStrictMode2.errors.txt | 10 +- .../baselines/reference/parserStrictMode2.js | 2 +- .../reference/scanner10.1.1-8gs.errors.txt | 12 +- .../baselines/reference/scanner10.1.1-8gs.js | 3 +- ...arArgConstructorMemberParameter.errors.txt | 5 +- .../varArgConstructorMemberParameter.js | 2 +- 41 files changed, 354 insertions(+), 435 deletions(-) diff --git a/tests/baselines/reference/constructorStaticParamName.errors.txt b/tests/baselines/reference/constructorStaticParamName.errors.txt index ac50edd22f1..6d5c1015f48 100644 --- a/tests/baselines/reference/constructorStaticParamName.errors.txt +++ b/tests/baselines/reference/constructorStaticParamName.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1003: Identifier expected. +tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamName.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1003: Identifi class test { constructor (static) { } ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorStaticParamName.js b/tests/baselines/reference/constructorStaticParamName.js index 85b22867442..cf74aed2ebc 100644 --- a/tests/baselines/reference/constructorStaticParamName.js +++ b/tests/baselines/reference/constructorStaticParamName.js @@ -9,7 +9,7 @@ class test { //// [constructorStaticParamName.js] // static as constructor parameter name should only give error if 'use strict' var test = (function () { - function test() { + function test(static) { } return test; })(); diff --git a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt index 4739f54397c..a5f6a74b8dd 100644 --- a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt +++ b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1003: Identifier expected. +tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamNameErrors.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1003: Id class test { constructor (static) { } ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorStaticParamNameErrors.js b/tests/baselines/reference/constructorStaticParamNameErrors.js index 0bb8985545c..43e70a8c3cf 100644 --- a/tests/baselines/reference/constructorStaticParamNameErrors.js +++ b/tests/baselines/reference/constructorStaticParamNameErrors.js @@ -9,7 +9,7 @@ class test { 'use strict'; // static as constructor parameter name should give error if 'use strict' var test = (function () { - function test() { + function test(static) { } return test; })(); diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 75de7c32ebc..5d607c8f5b2 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -21,45 +21,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(49,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(65,29): 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/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(81,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,13): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(94,17): error TS1134: Variable declaration expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(95,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(105,29): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(106,13): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,24): error TS2304: Cannot find name 'any'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,30): error TS2304: Cannot find name 'bool'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,37): error TS2304: Cannot find name 'declare'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,47): error TS2304: Cannot find name 'constructor'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,61): error TS2304: Cannot find name 'get'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,67): error TS2304: Cannot find name 'implements'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(111,9): error TS1128: Declaration or statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,9): error TS2304: Cannot find name 'STATEMENTS'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,21): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,30): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(118,39): error TS1005: ';' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(108,24): error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(138,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(141,32): error TS1005: '{' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(143,13): error TS1005: 'try' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,9): error TS1128: Declaration or statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,16): error TS2304: Cannot find name 'TYPES'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,23): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(155,32): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,24): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,30): error TS1005: '(' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(159,31): error TS2304: Cannot find name 'Property'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(166,13): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,9): error TS1128: Declaration or statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,16): error TS2304: Cannot find name 'OPERATOR'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,26): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(176,35): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(180,40): error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(205,28): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(210,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(213,16): error TS2304: Cannot find name 'bool'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(218,10): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(223,23): error TS2304: Cannot find name 'bool'. @@ -69,6 +47,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,9): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,16): error TS2304: Cannot find name 'method1'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,24): error TS2304: Cannot find name 'val'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,27): error TS1005: ',' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,28): error TS2304: Cannot find name 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(235,36): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(238,16): error TS2304: Cannot find name 'method2'. @@ -83,23 +62,27 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,9): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,26): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,31): error TS1005: ',' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,9): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error TS1135: Argument expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,52): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS2304: Cannot find name 'DefaultValue'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,35): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2322: Type 'string' is not assignable to type 'boolean'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or statement expected. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (99 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (82 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -214,8 +197,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// public VARIABLES(): number { - ~~~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. var local = Number.MAX_VALUE; var min = Number.MIN_VALUE; var inf = Number.NEGATIVE_INFINITY - @@ -255,11 +236,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS var constructor = 0; var get = 0; var implements = 0; - ~~~~~~~~~~ -!!! error TS1134: Variable declaration expected. var interface = 0; - ~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. var let = 0; var module = 0; var number = 0; @@ -277,23 +254,11 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS1109: Expression expected. var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; - ~~~ -!!! error TS2304: Cannot find name 'any'. - ~~~~ -!!! error TS2304: Cannot find name 'bool'. - ~~~~~~~ -!!! error TS2304: Cannot find name 'declare'. - ~~~~~~~~~~~ -!!! error TS2304: Cannot find name 'constructor'. - ~~~ -!!! error TS2304: Cannot find name 'get'. - ~~~~~~~~~~ -!!! error TS2304: Cannot find name 'implements'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'boolean'. return 0; } - ~ -!!! error TS1128: Declaration or statement expected. /// /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally @@ -301,14 +266,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// STATEMENTS(i: number): number { - ~~~~~~~~~~ -!!! error TS2304: Cannot find name 'STATEMENTS'. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1005: ';' expected. var retVal = 0; if (i == 1) retVal = 1; @@ -352,14 +309,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS /// /// public TYPES(): number { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~ -!!! error TS2304: Cannot find name 'TYPES'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1005: ';' expected. var retVal = 0; var c = new CLASS(); var xx: IF = c; @@ -389,14 +338,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS ///// ///// public OPERATOR(): number { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'OPERATOR'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1005: ';' expected. var a: number[] = [1, 2, 3, 4, 5, ];/*[] bug*/ // YES [] var i = a[1];/*[]*/ i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/ @@ -435,8 +376,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS } } - ~ -!!! error TS1128: Declaration or statement expected. interface IF { Foo(): bool; @@ -480,6 +419,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS2304: Cannot find name 'val'. ~ !!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. ~ !!! error TS1005: ';' expected. return val; @@ -529,6 +470,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS2304: Cannot find name 'value'. ~ !!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'string'. public Overloads( while : string, ...rest: string[]) { & ~~~~~~ !!! error TS1128: Declaration or statement expected. @@ -538,14 +481,20 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS !!! error TS1135: Argument expression expected. ~ !!! error TS1005: '(' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'string'. ~~~ !!! error TS1109: Expression expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'string'. ~ !!! error TS1005: ';' expected. ~ !!! error TS1109: Expression expected. public DefaultValue(value?: string = "Hello") { } + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. ~~~~~~~~~~~~ !!! error TS1005: ';' expected. ~~~~~~~~~~~~ @@ -555,7 +504,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS ~ !!! error TS1109: Expression expected. ~~~~~~ -!!! error TS2322: Type 'string' is not assignable to type 'boolean'. +!!! error TS2304: Cannot find name 'string'. ~ !!! error TS1005: ';' expected. } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index 4fb940bc9ec..eea8367711f 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -342,7 +342,6 @@ var TypeScriptAllInOne; })(TypeScriptAllInOne || (TypeScriptAllInOne = {})); var BasicFeatures = (function () { function BasicFeatures() { - this.implements = 0; } /// /// Test various of variables. Including nullable,key world as variable,special format @@ -375,115 +374,117 @@ var BasicFeatures = (function () { var declare = 0; var constructor = 0; var get = 0; - var ; + var implements = 0; + var interface = 0; + var let = 0; + var module = 0; + var number = 0; + var package = 0; + var private = 0; + var protected = 0; + var public = 0; + var set = 0; + var static = 0; + var string = 0 / > + ; + var yield = 0; + var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; + return 0; + }; + /// + /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally + /// + /// + /// + BasicFeatures.prototype.STATEMENTS = function (i) { + var retVal = 0; + if (i == 1) + retVal = 1; + else + retVal = 0; + switch (i) { + case 2: + retVal = 1; + break; + case 3: + retVal = 1; + break; + default: + break; + } + for (var x in { x: 0, y: 1 }) { + !; + try { + throw null; + } + catch (Exception) { } + } + try { + } + finally { + try { } + catch (Exception) { } + } + return retVal; + }; + /// + /// Test types in ts language. Including class,struct,interface,delegate,anonymous type + /// + /// + BasicFeatures.prototype.TYPES = function () { + var retVal = 0; + var c = new CLASS(); + var xx = c; + retVal += ; + try { } + catch () { } + Property; + retVal += c.Member(); + retVal += xx.Foo() ? 0 : 1; + //anonymous type + var anony = { a: new CLASS() }; + retVal += anony.a.d(); + return retVal; + }; + ///// + ///// Test different operators + ///// + ///// + BasicFeatures.prototype.OPERATOR = function () { + var a = [1, 2, 3, 4, 5,]; /*[] bug*/ // YES [] + var i = a[1]; /*[]*/ + i = i + i - i * i / i % i & i | i ^ i; /*+ - * / % & | ^*/ + var b = true && false || true ^ false; /*& | ^*/ + b = !b; /*!*/ + i = ~i; /*~i*/ + b = i < (i - 1) && (i + 1) > i; /*< && >*/ + var f = true ? 1 : 0; /*? :*/ // YES : + i++; /*++*/ + i--; /*--*/ + b = true && false || true; /*&& ||*/ + i = i << 5; /*<<*/ + i = i >> 5; /*>>*/ + var j = i; + b = i == j && i != j && i <= j && i >= j; /*= == && != <= >=*/ + i += 5.0; /*+=*/ + i -= i; /*-=*/ + i *= i; /**=*/ + if (i == 0) + i++; + i /= i; /*/=*/ + i %= i; /*%=*/ + i &= i; /*&=*/ + i |= i; /*|=*/ + i ^= i; /*^=*/ + i <<= i; /*<<=*/ + i >>= i; /*>>=*/ + if (i == 0 && != b && f == 1) + return 0; + else + return 1; }; return BasicFeatures; })(); -var interface = 0; -var let = 0; -var module = 0; -var number = 0; -var package = 0; -var private = 0; -var protected = 0; -var public = 0; -var set = 0; -var static = 0; -var string = 0 / > -; -var yield = 0; -var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; -return 0; -/// -/// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally -/// -/// -/// -STATEMENTS(i, number); -number; -{ - var retVal = 0; - if (i == 1) - retVal = 1; - else - retVal = 0; - switch (i) { - case 2: - retVal = 1; - break; - case 3: - retVal = 1; - break; - default: - break; - } - for (var x in { x: 0, y: 1 }) { - !; - try { - throw null; - } - catch (Exception) { } - } - try { - } - finally { - try { } - catch (Exception) { } - } - return retVal; -} -TYPES(); -number; -{ - var retVal = 0; - var c = new CLASS(); - var xx = c; - retVal += ; - try { } - catch () { } - Property; - retVal += c.Member(); - retVal += xx.Foo() ? 0 : 1; - //anonymous type - var anony = { a: new CLASS() }; - retVal += anony.a.d(); - return retVal; -} -OPERATOR(); -number; -{ - var a = [1, 2, 3, 4, 5,]; /*[] bug*/ // YES [] - var i = a[1]; /*[]*/ - i = i + i - i * i / i % i & i | i ^ i; /*+ - * / % & | ^*/ - var b = true && false || true ^ false; /*& | ^*/ - b = !b; /*!*/ - i = ~i; /*~i*/ - b = i < (i - 1) && (i + 1) > i; /*< && >*/ - var f = true ? 1 : 0; /*? :*/ // YES : - i++; /*++*/ - i--; /*--*/ - b = true && false || true; /*&& ||*/ - i = i << 5; /*<<*/ - i = i >> 5; /*>>*/ - var j = i; - b = i == j && i != j && i <= j && i >= j; /*= == && != <= >=*/ - i += 5.0; /*+=*/ - i -= i; /*-=*/ - i *= i; /**=*/ - if (i == 0) - i++; - i /= i; /*/=*/ - i %= i; /*%=*/ - i &= i; /*&=*/ - i |= i; /*|=*/ - i ^= i; /*^=*/ - i <<= i; /*<<=*/ - i >>= i; /*>>=*/ - if (i == 0 && != b && f == 1) - return 0; - else - return 1; -} var CLASS = (function () { function CLASS() { this.d = function () { ; }; diff --git a/tests/baselines/reference/convertKeywordsYes.errors.txt b/tests/baselines/reference/convertKeywordsYes.errors.txt index 932fda09be8..b558ba0b714 100644 --- a/tests/baselines/reference/convertKeywordsYes.errors.txt +++ b/tests/baselines/reference/convertKeywordsYes.errors.txt @@ -1,21 +1,15 @@ -tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(293,21): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(296,19): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(297,19): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(298,21): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(299,18): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(301,18): error TS1005: ';' expected. -tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1005: '{' expected. -tests/cases/compiler/convertKeywordsYes.ts(303,17): error TS1005: ';' expected. +tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1212: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1212: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1212: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1212: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1212: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. -==== tests/cases/compiler/convertKeywordsYes.ts (15 errors) ==== +==== tests/cases/compiler/convertKeywordsYes.ts (9 errors) ==== // reserved ES5 future in strict mode var constructor = 0; @@ -308,46 +302,34 @@ tests/cases/compiler/convertKeywordsYes.ts(303,17): error TS1005: ';' expected. module bigModule { class constructor { } class implements { } + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. class interface { } ~~~~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. class let { } ~~~ -!!! error TS1005: '{' expected. +!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. class module { } class package { } ~~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. class private { } ~~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. class protected { } ~~~~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. class public { } ~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. class set { } class static { } ~~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. class get { } class yield { } ~~~~~ -!!! error TS1005: '{' expected. - ~ -!!! error TS1005: ';' expected. +!!! error TS1212: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. class declare { } } \ No newline at end of file diff --git a/tests/baselines/reference/convertKeywordsYes.js b/tests/baselines/reference/convertKeywordsYes.js index 2b17e744b66..a68f751f434 100644 --- a/tests/baselines/reference/convertKeywordsYes.js +++ b/tests/baselines/reference/convertKeywordsYes.js @@ -505,81 +505,66 @@ var bigModule; } return constructor; })(); - var default_1 = (function () { - function default_1() { + var implements = (function () { + function implements() { } - return default_1; + return implements; })(); - var default_2 = (function () { - function default_2() { + var interface = (function () { + function interface() { } - return default_2; + return interface; })(); - interface; - { } - var default_3 = (function () { - function default_3() { + var let = (function () { + function let() { } - return default_3; + return let; })(); - var _a = void 0; var module = (function () { function module() { } return module; })(); - var default_4 = (function () { - function default_4() { + var package = (function () { + function package() { } - return default_4; + return package; })(); - package; - { } - var default_5 = (function () { - function default_5() { + var private = (function () { + function private() { } - return default_5; + return private; })(); - private; - { } - var default_6 = (function () { - function default_6() { + var protected = (function () { + function protected() { } - return default_6; + return protected; })(); - protected; - { } - var default_7 = (function () { - function default_7() { + var public = (function () { + function public() { } - return default_7; + return public; })(); - public; - { } var set = (function () { function set() { } return set; })(); - var default_8 = (function () { - function default_8() { + var static = (function () { + function static() { } - return default_8; + return static; })(); - static; - { } var get = (function () { function get() { } return get; })(); - var default_9 = (function () { - function default_9() { + var yield = (function () { + function yield() { } - return default_9; + return yield; })(); - yield; - { } var declare = (function () { function declare() { } diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt index 1a1e6503355..b75b7e0d8b6 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -1,11 +1,35 @@ tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (1 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec get accessor() { return 1; } ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - } \ No newline at end of file + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js index 23e689f3114..f48a755953f 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.js +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -6,24 +6,14 @@ class C { } //// [decoratorOnClassAccessor3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { - switch (arguments.length) { - case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); - case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); - case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); - } -}; var C = (function () { function C() { } - Object.defineProperty(C.prototype, "accessor", { - get: function () { return 1; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "accessor", - __decorate([ - dec - ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); +public; +get; +accessor(); +{ + return 1; +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt index f43827c0e4b..ec22ae0b3e1 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -1,11 +1,44 @@ tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (1 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec set accessor(value: number) { } ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - } \ No newline at end of file + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'set'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~~~~~ +!!! error TS2304: Cannot find name 'value'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js index 465e13ebb1d..771d937634f 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.js +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -6,24 +6,12 @@ class C { } //// [decoratorOnClassAccessor6.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { - switch (arguments.length) { - case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); - case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); - case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); - } -}; var C = (function () { function C() { } - Object.defineProperty(C.prototype, "accessor", { - set: function (value) { }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "accessor", - __decorate([ - dec - ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); +public; +set; +accessor(value, number); +{ } diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt index 61ff1433662..5969cfca069 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt @@ -1,14 +1,11 @@ -tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,17): error TS1003: Identifier expected. tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,24): error TS1005: ',' expected. -==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (2 errors) ==== +==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (1 errors) ==== declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; class C { constructor(public @dec p: number) {} - ~~~~~~ -!!! error TS1003: Identifier expected. ~ !!! error TS1005: ',' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js index 638cb1cda7e..9d2b4a690ab 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -15,7 +15,7 @@ var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.deco }; var __param = this.__param || function(index, decorator) { return function (target, key) { decorator(target, key, index); } }; var C = (function () { - function C(, p) { + function C(public, p) { } C = __decorate([ __param(1, dec) diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt index 2775ab9f144..b2173dedf9e 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -1,11 +1,29 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (1 errors) ==== +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec method() {} ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - } \ No newline at end of file + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js index f93b7d7a6b2..3ac97697e80 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.js +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -6,20 +6,11 @@ class C { } //// [decoratorOnClassMethod3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { - switch (arguments.length) { - case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); - case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); - case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); - } -}; var C = (function () { function C() { } - C.prototype.method = function () { }; - Object.defineProperty(C.prototype, "method", - __decorate([ - dec - ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); return C; })(); +public; +method(); +{ } diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt index a6321c55426..29438bd67a9 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -1,11 +1,26 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (1 errors) ==== +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== declare function dec(target: any, propertyKey: string): void; class C { public @dec prop; ~~~~~~ !!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - } \ No newline at end of file + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~ +!!! error TS2304: Cannot find name 'prop'. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js index 05476c66e7d..6c9945677ca 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.js +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -6,18 +6,10 @@ class C { } //// [decoratorOnClassProperty3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { - switch (arguments.length) { - case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); - case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); - case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); - } -}; var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop"); return C; })(); +public; +prop; diff --git a/tests/baselines/reference/letAsIdentifierInStrictMode.errors.txt b/tests/baselines/reference/letAsIdentifierInStrictMode.errors.txt index 65411f23da9..b59daca008c 100644 --- a/tests/baselines/reference/letAsIdentifierInStrictMode.errors.txt +++ b/tests/baselines/reference/letAsIdentifierInStrictMode.errors.txt @@ -1,21 +1,12 @@ -tests/cases/compiler/letAsIdentifierInStrictMode.ts(2,5): error TS1134: Variable declaration expected. -tests/cases/compiler/letAsIdentifierInStrictMode.ts(2,9): error TS1134: Variable declaration expected. -tests/cases/compiler/letAsIdentifierInStrictMode.ts(2,11): error TS1134: Variable declaration expected. tests/cases/compiler/letAsIdentifierInStrictMode.ts(3,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/letAsIdentifierInStrictMode.ts(4,5): error TS1134: Variable declaration expected. tests/cases/compiler/letAsIdentifierInStrictMode.ts(4,7): error TS1134: Variable declaration expected. tests/cases/compiler/letAsIdentifierInStrictMode.ts(6,1): error TS2300: Duplicate identifier 'a'. -==== tests/cases/compiler/letAsIdentifierInStrictMode.ts (7 errors) ==== +==== tests/cases/compiler/letAsIdentifierInStrictMode.ts (4 errors) ==== "use strict"; var let = 10; - ~~~ -!!! error TS1134: Variable declaration expected. - ~ -!!! error TS1134: Variable declaration expected. - ~~ -!!! error TS1134: Variable declaration expected. var a = 10; ~ !!! error TS2300: Duplicate identifier 'a'. diff --git a/tests/baselines/reference/letAsIdentifierInStrictMode.js b/tests/baselines/reference/letAsIdentifierInStrictMode.js index ccf099bcfc4..eb840e1a641 100644 --- a/tests/baselines/reference/letAsIdentifierInStrictMode.js +++ b/tests/baselines/reference/letAsIdentifierInStrictMode.js @@ -8,9 +8,7 @@ a; //// [letAsIdentifierInStrictMode.js] "use strict"; -var ; -var ; -10; +var let = 10; var a = 10; var ; 30; diff --git a/tests/baselines/reference/parser10.1.1-8gs.errors.txt b/tests/baselines/reference/parser10.1.1-8gs.errors.txt index c396c982bb8..185665d23da 100644 --- a/tests/baselines/reference/parser10.1.1-8gs.errors.txt +++ b/tests/baselines/reference/parser10.1.1-8gs.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(16,7): error TS2304: Cannot find name 'NotEarlyError'. -tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,5): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,12): error TS1134: Variable declaration expected. -tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,14): error TS1134: Variable declaration expected. +tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,5): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -==== tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts (4 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts (2 errors) ==== /// Copyright (c) 2012 Ecma International. All rights reserved. /// Ecma International makes this code available under the terms and conditions set /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the @@ -25,9 +23,5 @@ tests/cases/conformance/parser/ecmascript5/parser10.1.1-8gs.ts(17,14): error TS1 !!! error TS2304: Cannot find name 'NotEarlyError'. var public = 1; ~~~~~~ -!!! error TS1134: Variable declaration expected. - ~ -!!! error TS1134: Variable declaration expected. - ~ -!!! error TS1134: Variable declaration expected. +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/parser10.1.1-8gs.js b/tests/baselines/reference/parser10.1.1-8gs.js index 85227fab116..e7d342cf1f1 100644 --- a/tests/baselines/reference/parser10.1.1-8gs.js +++ b/tests/baselines/reference/parser10.1.1-8gs.js @@ -33,5 +33,4 @@ var public = 1; "use strict"; "use strict"; throw NotEarlyError; -var ; -1; +var public = 1; diff --git a/tests/baselines/reference/parser509668.errors.txt b/tests/baselines/reference/parser509668.errors.txt index 588bda6d91c..5ea380592ef 100644 --- a/tests/baselines/reference/parser509668.errors.txt +++ b/tests/baselines/reference/parser509668.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,16): error TS1003: Identifier expected. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts(3,23): error TS1005: ',' expected. -==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509668.ts (1 errors) ==== class Foo3 { // Doesn't work, but should constructor (public ...args: string[]) { } - ~~~~~~ -!!! error TS1003: Identifier expected. ~~~ !!! error TS1005: ',' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/parser509668.js b/tests/baselines/reference/parser509668.js index a64c9c7b5b0..63c5d8a1a95 100644 --- a/tests/baselines/reference/parser509668.js +++ b/tests/baselines/reference/parser509668.js @@ -7,7 +7,7 @@ class Foo3 { //// [parser509668.js] var Foo3 = (function () { // Doesn't work, but should - function Foo3() { + function Foo3(public) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; diff --git a/tests/baselines/reference/parser553699.errors.txt b/tests/baselines/reference/parser553699.errors.txt index 84bc6e60707..505bc93c338 100644 --- a/tests/baselines/reference/parser553699.errors.txt +++ b/tests/baselines/reference/parser553699.errors.txt @@ -1,12 +1,15 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1110: Type expected. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS2304: Cannot find name 'public'. -==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts (2 errors) ==== class Foo { constructor() { } public banana (x: public) { } ~~~~~~ -!!! error TS1110: Type expected. +!!! error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. } class Bar { diff --git a/tests/baselines/reference/parser553699.js b/tests/baselines/reference/parser553699.js index c4cc51bf5af..8570780e74a 100644 --- a/tests/baselines/reference/parser553699.js +++ b/tests/baselines/reference/parser553699.js @@ -12,7 +12,7 @@ class Bar { var Foo = (function () { function Foo() { } - Foo.prototype.banana = function (x, ) { }; + Foo.prototype.banana = function (x) { }; return Foo; })(); var Bar = (function () { diff --git a/tests/baselines/reference/parser642331.errors.txt b/tests/baselines/reference/parser642331.errors.txt index fad38e66513..5586cf6754f 100644 --- a/tests/baselines/reference/parser642331.errors.txt +++ b/tests/baselines/reference/parser642331.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1003: Identifier expected. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts (1 errors) ==== class test { constructor (static) { } ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/parser642331.js b/tests/baselines/reference/parser642331.js index 3d88c096af3..056ea7dd384 100644 --- a/tests/baselines/reference/parser642331.js +++ b/tests/baselines/reference/parser642331.js @@ -6,7 +6,7 @@ class test { //// [parser642331.js] var test = (function () { - function test() { + function test(static) { } return test; })(); diff --git a/tests/baselines/reference/parser642331_1.errors.txt b/tests/baselines/reference/parser642331_1.errors.txt index c31cd9c5653..02674121ac9 100644 --- a/tests/baselines/reference/parser642331_1.errors.txt +++ b/tests/baselines/reference/parser642331_1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1003: Identifier expected. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,1 class test { constructor (static) { } ~~~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/parser642331_1.js b/tests/baselines/reference/parser642331_1.js index d4de3c04d1d..83833ee6612 100644 --- a/tests/baselines/reference/parser642331_1.js +++ b/tests/baselines/reference/parser642331_1.js @@ -9,7 +9,7 @@ class test { //// [parser642331_1.js] "use strict"; var test = (function () { - function test() { + function test(static) { } return test; })(); diff --git a/tests/baselines/reference/parserComputedPropertyName36.errors.txt b/tests/baselines/reference/parserComputedPropertyName36.errors.txt index 8c647be13c9..a6fa988ec32 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName36.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1109: Expression expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,14): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS2304: Cannot find name 'public'. ==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (3 errors) ==== class C { [public ]: string; + ~~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. ~~~~~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt index 28daf322748..807b91cd3e5 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName38.errors.txt @@ -1,21 +1,12 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1109: Expression expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,16): error TS1005: '=>' expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(3,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS2304: Cannot find name 'public'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (5 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (2 errors) ==== class C { [public]() { } ~~~~~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~ -!!! error TS1005: '=>' expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.js b/tests/baselines/reference/parserComputedPropertyName38.js index e47f5233a77..822695e5cfd 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.js +++ b/tests/baselines/reference/parserComputedPropertyName38.js @@ -5,5 +5,5 @@ class C { //// [parserComputedPropertyName38.js] class C { + [public]() { } } -(() => { }); diff --git a/tests/baselines/reference/parserComputedPropertyName39.errors.txt b/tests/baselines/reference/parserComputedPropertyName39.errors.txt index 32d59ad2403..766ae402491 100644 --- a/tests/baselines/reference/parserComputedPropertyName39.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName39.errors.txt @@ -1,22 +1,13 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS1109: Expression expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,16): error TS1005: '=>' expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(4,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS2304: Cannot find name 'public'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts (5 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts (2 errors) ==== "use strict"; class C { [public]() { } ~~~~~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~ -!!! error TS1005: '=>' expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName39.js b/tests/baselines/reference/parserComputedPropertyName39.js index 541d1965385..8e2c4853bd3 100644 --- a/tests/baselines/reference/parserComputedPropertyName39.js +++ b/tests/baselines/reference/parserComputedPropertyName39.js @@ -7,5 +7,5 @@ class C { //// [parserComputedPropertyName39.js] "use strict"; class C { + [public]() { } } -(() => { }); diff --git a/tests/baselines/reference/parserStrictMode2.errors.txt b/tests/baselines/reference/parserStrictMode2.errors.txt index e920c02bed1..464e8eface8 100644 --- a/tests/baselines/reference/parserStrictMode2.errors.txt +++ b/tests/baselines/reference/parserStrictMode2.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(2,1): error TS2304: Cannot find name 'foo1'. tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(3,1): error TS2304: Cannot find name 'foo1'. tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(4,1): error TS2304: Cannot find name 'foo1'. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(5,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(5,8): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(5,1): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(5,1): error TS2304: Cannot find name 'static'. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts (5 errors) ==== @@ -18,6 +18,6 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode2.ts(5,8): !!! error TS2304: Cannot find name 'foo1'. static(); ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS1109: Expression expected. \ No newline at end of file +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'static'. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode2.js b/tests/baselines/reference/parserStrictMode2.js index b8020672241..79b32ed9a58 100644 --- a/tests/baselines/reference/parserStrictMode2.js +++ b/tests/baselines/reference/parserStrictMode2.js @@ -10,4 +10,4 @@ static(); foo1(); foo1(); foo1(); -(); +static(); diff --git a/tests/baselines/reference/scanner10.1.1-8gs.errors.txt b/tests/baselines/reference/scanner10.1.1-8gs.errors.txt index 2cfe3b3080a..54cd92dc0ca 100644 --- a/tests/baselines/reference/scanner10.1.1-8gs.errors.txt +++ b/tests/baselines/reference/scanner10.1.1-8gs.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(16,7): error TS2304: Cannot find name 'NotEarlyError'. -tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(17,5): error TS1134: Variable declaration expected. -tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(17,12): error TS1134: Variable declaration expected. -tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(17,14): error TS1134: Variable declaration expected. +tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(17,5): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -==== tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts (4 errors) ==== +==== tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts (2 errors) ==== /// Copyright (c) 2012 Ecma International. All rights reserved. /// Ecma International makes this code available under the terms and conditions set /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the @@ -25,9 +23,5 @@ tests/cases/conformance/scanner/ecmascript5/scanner10.1.1-8gs.ts(17,14): error T !!! error TS2304: Cannot find name 'NotEarlyError'. var public = 1; ~~~~~~ -!!! error TS1134: Variable declaration expected. - ~ -!!! error TS1134: Variable declaration expected. - ~ -!!! error TS1134: Variable declaration expected. +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/scanner10.1.1-8gs.js b/tests/baselines/reference/scanner10.1.1-8gs.js index ed0deac165d..90a0cf8be9f 100644 --- a/tests/baselines/reference/scanner10.1.1-8gs.js +++ b/tests/baselines/reference/scanner10.1.1-8gs.js @@ -33,5 +33,4 @@ var public = 1; "use strict"; "use strict"; throw NotEarlyError; -var ; -1; +var public = 1; diff --git a/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt b/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt index 19bd0396bed..e3257b870d6 100644 --- a/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt +++ b/tests/baselines/reference/varArgConstructorMemberParameter.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/varArgConstructorMemberParameter.ts(10,18): error TS1003: Identifier expected. tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ',' expected. -==== tests/cases/compiler/varArgConstructorMemberParameter.ts (2 errors) ==== +==== tests/cases/compiler/varArgConstructorMemberParameter.ts (1 errors) ==== class Foo1 { constructor (...args: string[]) { } } @@ -13,8 +12,6 @@ tests/cases/compiler/varArgConstructorMemberParameter.ts(10,25): error TS1005: ' class Foo3 { constructor (public ...args: string[]) { } - ~~~~~~ -!!! error TS1003: Identifier expected. ~~~ !!! error TS1005: ',' expected. } diff --git a/tests/baselines/reference/varArgConstructorMemberParameter.js b/tests/baselines/reference/varArgConstructorMemberParameter.js index 100a4b07899..7f1ef8d5b3a 100644 --- a/tests/baselines/reference/varArgConstructorMemberParameter.js +++ b/tests/baselines/reference/varArgConstructorMemberParameter.js @@ -29,7 +29,7 @@ var Foo2 = (function () { return Foo2; })(); var Foo3 = (function () { - function Foo3() { + function Foo3(public) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; From 958f7b820277730e91710ed03fa6d4974a4f069b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 17:50:01 -0700 Subject: [PATCH 03/23] Add more test to cover strict mode code --- .../reference/strictModeCode1.errors.txt | 73 +++++++++++++++++ tests/baselines/reference/strictModeCode1.js | 52 +++++++++++++ .../reference/strictModeCode2.errors.txt | 78 +++++++++++++++++++ tests/baselines/reference/strictModeCode2.js | 41 ++++++++++ .../reference/strictModeCode3.errors.txt | 24 ++++++ tests/baselines/reference/strictModeCode3.js | 13 ++++ .../reference/strictModeCode4.errors.txt | 25 ++++++ tests/baselines/reference/strictModeCode4.js | 18 +++++ .../reference/strictModeCode5.errors.txt | 23 ++++++ tests/baselines/reference/strictModeCode5.js | 13 ++++ tests/cases/compiler/strictModeCode1.ts | 22 ++++++ tests/cases/compiler/strictModeCode2.ts | 17 ++++ tests/cases/compiler/strictModeCode3.ts | 6 ++ tests/cases/compiler/strictModeCode4.ts | 7 ++ tests/cases/compiler/strictModeCode5.ts | 5 ++ 15 files changed, 417 insertions(+) create mode 100644 tests/baselines/reference/strictModeCode1.errors.txt create mode 100644 tests/baselines/reference/strictModeCode1.js create mode 100644 tests/baselines/reference/strictModeCode2.errors.txt create mode 100644 tests/baselines/reference/strictModeCode2.js create mode 100644 tests/baselines/reference/strictModeCode3.errors.txt create mode 100644 tests/baselines/reference/strictModeCode3.js create mode 100644 tests/baselines/reference/strictModeCode4.errors.txt create mode 100644 tests/baselines/reference/strictModeCode4.js create mode 100644 tests/baselines/reference/strictModeCode5.errors.txt create mode 100644 tests/baselines/reference/strictModeCode5.js create mode 100644 tests/cases/compiler/strictModeCode1.ts create mode 100644 tests/cases/compiler/strictModeCode2.ts create mode 100644 tests/cases/compiler/strictModeCode3.ts create mode 100644 tests/cases/compiler/strictModeCode4.ts create mode 100644 tests/cases/compiler/strictModeCode5.ts diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt new file mode 100644 index 00000000000..a7292d6b610 --- /dev/null +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -0,0 +1,73 @@ +tests/cases/compiler/strictModeCode1.ts(4,17): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,26): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,34): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(5,9): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(5,19): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(5,28): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(7,22): error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,24): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,32): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,10): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,19): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,27): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(14,18): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,9): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,17): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeCode1.ts (16 errors) ==== + interface public { } + + class Foo { + constructor(private, public, static) { + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. + private = public = static; + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + } + public banana(x: public) { } + ~~~~~~ +!!! error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + } + + class C { + constructor(public public, let) { + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. + } + foo1(private, static, public) { + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + function let() { } + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. + var z = function let() { }; + } + + } + + class D{ } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. + + class E implements public { } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.js b/tests/baselines/reference/strictModeCode1.js new file mode 100644 index 00000000000..77d786f52d2 --- /dev/null +++ b/tests/baselines/reference/strictModeCode1.js @@ -0,0 +1,52 @@ +//// [strictModeCode1.ts] +interface public { } + +class Foo { + constructor(private, public, static) { + private = public = static; + } + public banana(x: public) { } +} + +class C { + constructor(public public, let) { + } + foo1(private, static, public) { + function let() { } + var z = function let() { }; + } + +} + +class D{ } + +class E implements public { } + +//// [strictModeCode1.js] +var Foo = (function () { + function Foo(private, public, static) { + private = public = static; + } + Foo.prototype.banana = function (x) { }; + return Foo; +})(); +var C = (function () { + function C(public, let) { + this.public = public; + } + C.prototype.foo1 = function (private, static, public) { + function let() { } + var z = function let() { }; + }; + return C; +})(); +var D = (function () { + function D() { + } + return D; +})(); +var E = (function () { + function E() { + } + return E; +})(); diff --git a/tests/baselines/reference/strictModeCode2.errors.txt b/tests/baselines/reference/strictModeCode2.errors.txt new file mode 100644 index 00000000000..072e35d19e4 --- /dev/null +++ b/tests/baselines/reference/strictModeCode2.errors.txt @@ -0,0 +1,78 @@ +tests/cases/compiler/strictModeCode2.ts(5,9): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(6,9): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(7,9): error TS1212: Identifier expected. 'let' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(8,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(8,9): error TS2300: Duplicate identifier 'package'. +tests/cases/compiler/strictModeCode2.ts(9,14): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(9,14): error TS2300: Duplicate identifier 'package'. +tests/cases/compiler/strictModeCode2.ts(10,18): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(10,27): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(10,39): error TS1212: Identifier expected. 'let' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(11,18): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(11,30): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(12,24): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(12,33): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(12,41): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(13,11): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/strictModeCode2.ts (19 errors) ==== + let let = 10; + + function foo() { + "use strict" + var public = 10; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var static = "hi"; + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + let let = "blah"; + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode + var package = "hello" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'package'. + function package() { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'package'. + function bar(private, implements, let) { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode + function baz() { } + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + function barn(cb: (private, public, package) => void) { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + barn((private, public, package) => { }); + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + + var myClass = class package extends public {} + ~~~~~~~ +!!! error TS9003: 'class' expressions are not currently supported. + } + + \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode2.js b/tests/baselines/reference/strictModeCode2.js new file mode 100644 index 00000000000..a49ca5946de --- /dev/null +++ b/tests/baselines/reference/strictModeCode2.js @@ -0,0 +1,41 @@ +//// [strictModeCode2.ts] +let let = 10; + +function foo() { + "use strict" + var public = 10; + var static = "hi"; + let let = "blah"; + var package = "hello" + function package() { } + function bar(private, implements, let) { } + function baz() { } + function barn(cb: (private, public, package) => void) { } + barn((private, public, package) => { }); + + var myClass = class package extends public {} +} + + + +//// [strictModeCode2.js] +var let = 10; +function foo() { + "use strict"; + var public = 10; + var static = "hi"; + var let = "blah"; + var package = "hello"; + function package() { } + function bar(private, implements, let) { } + function baz() { } + function barn(cb) { } + barn(function (private, public, package) { }); + var myClass = (function (_super) { + __extends(package, _super); + function package() { + _super.apply(this, arguments); + } + return package; + })(public); +} diff --git a/tests/baselines/reference/strictModeCode3.errors.txt b/tests/baselines/reference/strictModeCode3.errors.txt new file mode 100644 index 00000000000..be500ad1062 --- /dev/null +++ b/tests/baselines/reference/strictModeCode3.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/strictModeCode3.ts(2,11): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode3.ts(3,11): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeCode3.ts(4,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode3.ts(4,18): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeCode3.ts(6,6): error TS1212: Identifier expected. 'package' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeCode3.ts (5 errors) ==== + "use strict" + interface public { } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + interface implements { + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + foo(package, protected); + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + } + enum package { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode3.js b/tests/baselines/reference/strictModeCode3.js new file mode 100644 index 00000000000..596667f9925 --- /dev/null +++ b/tests/baselines/reference/strictModeCode3.js @@ -0,0 +1,13 @@ +//// [strictModeCode3.ts] +"use strict" +interface public { } +interface implements { + foo(package, protected); +} +enum package { } + +//// [strictModeCode3.js] +"use strict"; +var package; +(function (package) { +})(package || (package = {})); diff --git a/tests/baselines/reference/strictModeCode4.errors.txt b/tests/baselines/reference/strictModeCode4.errors.txt new file mode 100644 index 00000000000..b9dc2c0dce7 --- /dev/null +++ b/tests/baselines/reference/strictModeCode4.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/strictModeCode4.ts(3,17): error TS2304: Cannot find name 'foo'. +tests/cases/compiler/strictModeCode4.ts(4,13): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode4.ts(4,20): error TS1005: ',' expected. +tests/cases/compiler/strictModeCode4.ts(4,20): error TS2304: Cannot find name 'blaz'. +tests/cases/compiler/strictModeCode4.ts(4,27): error TS1005: ',' expected. + + +==== tests/cases/compiler/strictModeCode4.ts (5 errors) ==== + class C { + public bar() { + var v = foo( + ~~~ +!!! error TS2304: Cannot find name 'foo'. + public blaz() {} + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~~~~ +!!! error TS1005: ',' expected. + ~~~~ +!!! error TS2304: Cannot find name 'blaz'. + ~ +!!! error TS1005: ',' expected. + ); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode4.js b/tests/baselines/reference/strictModeCode4.js new file mode 100644 index 00000000000..cfc9f008e72 --- /dev/null +++ b/tests/baselines/reference/strictModeCode4.js @@ -0,0 +1,18 @@ +//// [strictModeCode4.ts] +class C { + public bar() { + var v = foo( + public blaz() {} + ); + } +} + +//// [strictModeCode4.js] +var C = (function () { + function C() { + } + C.prototype.bar = function () { + var v = foo(public, blaz(), {}); + }; + return C; +})(); diff --git a/tests/baselines/reference/strictModeCode5.errors.txt b/tests/baselines/reference/strictModeCode5.errors.txt new file mode 100644 index 00000000000..f4ad705cd27 --- /dev/null +++ b/tests/baselines/reference/strictModeCode5.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/strictModeCode5.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(3,10): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(4,7): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(5,15): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(5,38): error TS1212: Identifier expected. 'package' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeCode5.ts (5 errors) ==== + "use strict" + var [public] = [1]; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var { x: public } = { x: 1 }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var [[private]] = [["hello"]]; + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode5.js b/tests/baselines/reference/strictModeCode5.js new file mode 100644 index 00000000000..746d2dab580 --- /dev/null +++ b/tests/baselines/reference/strictModeCode5.js @@ -0,0 +1,13 @@ +//// [strictModeCode5.ts] +"use strict" +var [public] = [1]; +var { x: public } = { x: 1 }; +var [[private]] = [["hello"]]; +var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; + +//// [strictModeCode5.js] +"use strict"; +var public = ([1])[0]; +var public = ({ x: 1 }).x; +var private = ([["hello"]])[0][0]; +var _a = { y: { s: 1 }, z: { o: { p: 'h' } } }, static = _a.y.s, package = _a.z.o.p; diff --git a/tests/cases/compiler/strictModeCode1.ts b/tests/cases/compiler/strictModeCode1.ts new file mode 100644 index 00000000000..1c311c7cd5f --- /dev/null +++ b/tests/cases/compiler/strictModeCode1.ts @@ -0,0 +1,22 @@ +interface public { } + +class Foo { + constructor(private, public, static) { + private = public = static; + } + public banana(x: public) { } +} + +class C { + constructor(public public, let) { + } + foo1(private, static, public) { + function let() { } + var z = function let() { }; + } + +} + +class D{ } + +class E implements public { } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode2.ts b/tests/cases/compiler/strictModeCode2.ts new file mode 100644 index 00000000000..f0ba008d86d --- /dev/null +++ b/tests/cases/compiler/strictModeCode2.ts @@ -0,0 +1,17 @@ +let let = 10; + +function foo() { + "use strict" + var public = 10; + var static = "hi"; + let let = "blah"; + var package = "hello" + function package() { } + function bar(private, implements, let) { } + function baz() { } + function barn(cb: (private, public, package) => void) { } + barn((private, public, package) => { }); + + var myClass = class package extends public {} +} + diff --git a/tests/cases/compiler/strictModeCode3.ts b/tests/cases/compiler/strictModeCode3.ts new file mode 100644 index 00000000000..800f882d34d --- /dev/null +++ b/tests/cases/compiler/strictModeCode3.ts @@ -0,0 +1,6 @@ +"use strict" +interface public { } +interface implements { + foo(package, protected); +} +enum package { } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode4.ts b/tests/cases/compiler/strictModeCode4.ts new file mode 100644 index 00000000000..171c1066682 --- /dev/null +++ b/tests/cases/compiler/strictModeCode4.ts @@ -0,0 +1,7 @@ +class C { + public bar() { + var v = foo( + public blaz() {} + ); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode5.ts b/tests/cases/compiler/strictModeCode5.ts new file mode 100644 index 00000000000..4f4ff9f564f --- /dev/null +++ b/tests/cases/compiler/strictModeCode5.ts @@ -0,0 +1,5 @@ +"use strict" +var [public] = [1]; +var { x: public } = { x: 1 }; +var [[private]] = [["hello"]]; +var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; \ No newline at end of file From fb9009f741fdeca5e025ce497b1690b2298205de Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 17:51:51 -0700 Subject: [PATCH 04/23] Completely remove check strict mode from parser --- src/compiler/parser.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4f3cebc1e88..320f65ba587 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1350,13 +1350,8 @@ module ts { return speculationHelper(callback, /*isLookAhead:*/ false); } - // The function takes a flag "considerStrictModeContext" because in the case of parsing - // an identifier, we don't want to consider whether we are in strict mode. This is because - // if the identifier violates strict-mode reserved word, we want to report more explicit error - // in the checker. - // However, in some cases such as isLetDeclaration, we want to know at the parse time whether - // next token is really an identifier in strict mode and report an error. - function isIdentifier(considerStrictModeContext = true): boolean { + // Ignore strict mode flag because we will be report an error in type checker instead. + function isIdentifier(): boolean { if (token === SyntaxKind.Identifier) { return true; } @@ -1367,12 +1362,7 @@ module ts { return false; } - if (considerStrictModeContext) { - return inStrictModeContext() ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord; - } - else { - return token > SyntaxKind.LastReservedWord; - } + return token > SyntaxKind.LastReservedWord; } function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage): boolean { @@ -1510,7 +1500,7 @@ module ts { } function parseIdentifier(diagnosticMessage?: DiagnosticMessage): Identifier { - return createIdentifier(isIdentifier(/*considerStrictModeContext*/ false), diagnosticMessage); + return createIdentifier(isIdentifier(), diagnosticMessage); } function parseIdentifierName(): Identifier { From 9d296296627083f18850b71d9128968a3a8faea0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 22:02:10 -0700 Subject: [PATCH 05/23] Remove old tests --- tests/baselines/reference/strictMode1.js | 25 ------------ tests/baselines/reference/strictMode1.types | 9 ----- tests/baselines/reference/strictMode2.js | 13 ------ tests/baselines/reference/strictMode2.types | 8 ---- tests/baselines/reference/strictMode3.js | 36 ----------------- tests/baselines/reference/strictMode3.types | 20 --------- tests/baselines/reference/strictMode4.js | 14 ------- tests/baselines/reference/strictMode4.types | 7 ---- tests/baselines/reference/strictMode5.js | 45 --------------------- tests/baselines/reference/strictMode5.types | 38 ----------------- tests/cases/compiler/strictMode1.ts | 3 -- tests/cases/compiler/strictMode2.ts | 6 --- tests/cases/compiler/strictMode3.ts | 11 ----- tests/cases/compiler/strictMode4.ts | 4 -- tests/cases/compiler/strictMode5.ts | 18 --------- 15 files changed, 257 deletions(-) delete mode 100644 tests/baselines/reference/strictMode1.js delete mode 100644 tests/baselines/reference/strictMode1.types delete mode 100644 tests/baselines/reference/strictMode2.js delete mode 100644 tests/baselines/reference/strictMode2.types delete mode 100644 tests/baselines/reference/strictMode3.js delete mode 100644 tests/baselines/reference/strictMode3.types delete mode 100644 tests/baselines/reference/strictMode4.js delete mode 100644 tests/baselines/reference/strictMode4.types delete mode 100644 tests/baselines/reference/strictMode5.js delete mode 100644 tests/baselines/reference/strictMode5.types delete mode 100644 tests/cases/compiler/strictMode1.ts delete mode 100644 tests/cases/compiler/strictMode2.ts delete mode 100644 tests/cases/compiler/strictMode3.ts delete mode 100644 tests/cases/compiler/strictMode4.ts delete mode 100644 tests/cases/compiler/strictMode5.ts diff --git a/tests/baselines/reference/strictMode1.js b/tests/baselines/reference/strictMode1.js deleted file mode 100644 index f4c9db50ab7..00000000000 --- a/tests/baselines/reference/strictMode1.js +++ /dev/null @@ -1,25 +0,0 @@ -//// [strictMode1.ts] -"use strict"; -class A {} -class B extends A {} - -//// [strictMode1.js] -"use strict"; -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var A = (function () { - function A() { - } - return A; -})(); -var B = (function (_super) { - __extends(B, _super); - function B() { - _super.apply(this, arguments); - } - return B; -})(A); diff --git a/tests/baselines/reference/strictMode1.types b/tests/baselines/reference/strictMode1.types deleted file mode 100644 index c0e57de97df..00000000000 --- a/tests/baselines/reference/strictMode1.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/strictMode1.ts === -"use strict"; -class A {} ->A : A - -class B extends A {} ->B : B ->A : A - diff --git a/tests/baselines/reference/strictMode2.js b/tests/baselines/reference/strictMode2.js deleted file mode 100644 index 4331b1ef52c..00000000000 --- a/tests/baselines/reference/strictMode2.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [strictMode2.ts] -"use strict"; - -function foo() { - - return 30; -} - -//// [strictMode2.js] -"use strict"; -function foo() { - return 30; -} diff --git a/tests/baselines/reference/strictMode2.types b/tests/baselines/reference/strictMode2.types deleted file mode 100644 index 69c972355b8..00000000000 --- a/tests/baselines/reference/strictMode2.types +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/compiler/strictMode2.ts === -"use strict"; - -function foo() { ->foo : () => number - - return 30; -} diff --git a/tests/baselines/reference/strictMode3.js b/tests/baselines/reference/strictMode3.js deleted file mode 100644 index 792ab931f53..00000000000 --- a/tests/baselines/reference/strictMode3.js +++ /dev/null @@ -1,36 +0,0 @@ -//// [strictMode3.ts] -"use strict"; - -class A { -} - -class B extends A { -} - -function foo() { - return this.window; -} - -//// [strictMode3.js] -"use strict"; -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var A = (function () { - function A() { - } - return A; -})(); -var B = (function (_super) { - __extends(B, _super); - function B() { - _super.apply(this, arguments); - } - return B; -})(A); -function foo() { - return this.window; -} diff --git a/tests/baselines/reference/strictMode3.types b/tests/baselines/reference/strictMode3.types deleted file mode 100644 index 701ebc12d9a..00000000000 --- a/tests/baselines/reference/strictMode3.types +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/compiler/strictMode3.ts === -"use strict"; - -class A { ->A : A -} - -class B extends A { ->B : B ->A : A -} - -function foo() { ->foo : () => any - - return this.window; ->this.window : any ->this : any ->window : any -} diff --git a/tests/baselines/reference/strictMode4.js b/tests/baselines/reference/strictMode4.js deleted file mode 100644 index b7bf798b34f..00000000000 --- a/tests/baselines/reference/strictMode4.js +++ /dev/null @@ -1,14 +0,0 @@ -//// [strictMode4.ts] -"use strict"; - -class A { -} - - -//// [strictMode4.js] -"use strict"; -var A = (function () { - function A() { - } - return A; -})(); diff --git a/tests/baselines/reference/strictMode4.types b/tests/baselines/reference/strictMode4.types deleted file mode 100644 index 7aea014b045..00000000000 --- a/tests/baselines/reference/strictMode4.types +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/compiler/strictMode4.ts === -"use strict"; - -class A { ->A : A -} - diff --git a/tests/baselines/reference/strictMode5.js b/tests/baselines/reference/strictMode5.js deleted file mode 100644 index 8e4021820f1..00000000000 --- a/tests/baselines/reference/strictMode5.js +++ /dev/null @@ -1,45 +0,0 @@ -//// [strictMode5.ts] -function foo(...args) { - "use strict" -} - -class A { - m() { - "use strict" - - var v = () => { - return this.n(); - }; - } - n() {} -} - -function bar(x: number = 10) { - "use strict" -} - -//// [strictMode5.js] -function foo() { - "use strict"; - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; - } -} -var A = (function () { - function A() { - } - A.prototype.m = function () { - "use strict"; - var _this = this; - var v = function () { - return _this.n(); - }; - }; - A.prototype.n = function () { }; - return A; -})(); -function bar(x) { - "use strict"; - if (x === void 0) { x = 10; } -} diff --git a/tests/baselines/reference/strictMode5.types b/tests/baselines/reference/strictMode5.types deleted file mode 100644 index dd668dc24d1..00000000000 --- a/tests/baselines/reference/strictMode5.types +++ /dev/null @@ -1,38 +0,0 @@ -=== tests/cases/compiler/strictMode5.ts === -function foo(...args) { ->foo : (...args: any[]) => void ->args : any[] - - "use strict" -} - -class A { ->A : A - - m() { ->m : () => void - - "use strict" - - var v = () => { ->v : () => void ->() => { return this.n(); } : () => void - - return this.n(); ->this.n() : void ->this.n : () => void ->this : A ->n : () => void - - }; - } - n() {} ->n : () => void -} - -function bar(x: number = 10) { ->bar : (x?: number) => void ->x : number - - "use strict" -} diff --git a/tests/cases/compiler/strictMode1.ts b/tests/cases/compiler/strictMode1.ts deleted file mode 100644 index 44b495e96b4..00000000000 --- a/tests/cases/compiler/strictMode1.ts +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -class A {} -class B extends A {} \ No newline at end of file diff --git a/tests/cases/compiler/strictMode2.ts b/tests/cases/compiler/strictMode2.ts deleted file mode 100644 index 87d1430c2fa..00000000000 --- a/tests/cases/compiler/strictMode2.ts +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; - -function foo() { - - return 30; -} \ No newline at end of file diff --git a/tests/cases/compiler/strictMode3.ts b/tests/cases/compiler/strictMode3.ts deleted file mode 100644 index 3535188dbbc..00000000000 --- a/tests/cases/compiler/strictMode3.ts +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; - -class A { -} - -class B extends A { -} - -function foo() { - return this.window; -} \ No newline at end of file diff --git a/tests/cases/compiler/strictMode4.ts b/tests/cases/compiler/strictMode4.ts deleted file mode 100644 index e9c99c8bdb1..00000000000 --- a/tests/cases/compiler/strictMode4.ts +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; - -class A { -} diff --git a/tests/cases/compiler/strictMode5.ts b/tests/cases/compiler/strictMode5.ts deleted file mode 100644 index c980cf7c86d..00000000000 --- a/tests/cases/compiler/strictMode5.ts +++ /dev/null @@ -1,18 +0,0 @@ -function foo(...args) { - "use strict" -} - -class A { - m() { - "use strict" - - var v = () => { - return this.n(); - }; - } - n() {} -} - -function bar(x: number = 10) { - "use strict" -} \ No newline at end of file From 8ad9c0bee746ef223932518780ea61d43584fe0b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 22:02:33 -0700 Subject: [PATCH 06/23] Add more test for import, import equal, module --- .../reference/strictModeCode6.errors.txt | 22 +++++++++++++++++++ tests/baselines/reference/strictModeCode6.js | 8 +++++++ .../reference/strictModeCode7.errors.txt | 12 ++++++++++ tests/baselines/reference/strictModeCode7.js | 7 ++++++ .../reference/strictModeCode8.errors.txt | 12 ++++++++++ tests/baselines/reference/strictModeCode8.js | 7 ++++++ tests/cases/compiler/strictModeCode6.ts | 5 +++++ tests/cases/compiler/strictModeCode7.ts | 4 ++++ tests/cases/compiler/strictModeCode8.ts | 3 +++ 9 files changed, 80 insertions(+) create mode 100644 tests/baselines/reference/strictModeCode6.errors.txt create mode 100644 tests/baselines/reference/strictModeCode6.js create mode 100644 tests/baselines/reference/strictModeCode7.errors.txt create mode 100644 tests/baselines/reference/strictModeCode7.js create mode 100644 tests/baselines/reference/strictModeCode8.errors.txt create mode 100644 tests/baselines/reference/strictModeCode8.js create mode 100644 tests/cases/compiler/strictModeCode6.ts create mode 100644 tests/cases/compiler/strictModeCode7.ts create mode 100644 tests/cases/compiler/strictModeCode8.ts diff --git a/tests/baselines/reference/strictModeCode6.errors.txt b/tests/baselines/reference/strictModeCode6.errors.txt new file mode 100644 index 00000000000..dd1cb2dc433 --- /dev/null +++ b/tests/baselines/reference/strictModeCode6.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/strictModeCode6.ts(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode6.ts(2,26): error TS2307: Cannot find external module './1'. +tests/cases/compiler/strictModeCode6.ts(3,16): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode6.ts(3,30): error TS2307: Cannot find external module './1'. +tests/cases/compiler/strictModeCode6.ts(4,20): error TS2307: Cannot find external module './1'. + + +==== tests/cases/compiler/strictModeCode6.ts (5 errors) ==== + "use strict" + import * as package from "./1" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~ +!!! error TS2307: Cannot find external module './1'. + import {foo as private} from "./1" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~ +!!! error TS2307: Cannot find external module './1'. + import public from "./1" + ~~~~~ +!!! error TS2307: Cannot find external module './1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode6.js b/tests/baselines/reference/strictModeCode6.js new file mode 100644 index 00000000000..e8fd529d1aa --- /dev/null +++ b/tests/baselines/reference/strictModeCode6.js @@ -0,0 +1,8 @@ +//// [strictModeCode6.ts] +"use strict" +import * as package from "./1" +import {foo as private} from "./1" +import public from "./1" + +//// [strictModeCode6.js] +"use strict"; diff --git a/tests/baselines/reference/strictModeCode7.errors.txt b/tests/baselines/reference/strictModeCode7.errors.txt new file mode 100644 index 00000000000..066fd01b897 --- /dev/null +++ b/tests/baselines/reference/strictModeCode7.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/strictModeCode7.ts(3,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode7.ts(3,25): error TS2307: Cannot find external module '1'. + + +==== tests/cases/compiler/strictModeCode7.ts (2 errors) ==== + + "use strict" + import public = require("1"); + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~ +!!! error TS2307: Cannot find external module '1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode7.js b/tests/baselines/reference/strictModeCode7.js new file mode 100644 index 00000000000..eee01c59a27 --- /dev/null +++ b/tests/baselines/reference/strictModeCode7.js @@ -0,0 +1,7 @@ +//// [strictModeCode7.ts] + +"use strict" +import public = require("1"); + +//// [strictModeCode7.js] +"use strict"; diff --git a/tests/baselines/reference/strictModeCode8.errors.txt b/tests/baselines/reference/strictModeCode8.errors.txt new file mode 100644 index 00000000000..faf13a186e5 --- /dev/null +++ b/tests/baselines/reference/strictModeCode8.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/strictModeCode8.ts(2,8): error TS1212: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. +tests/cases/compiler/strictModeCode8.ts(3,8): error TS1212: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. + + +==== tests/cases/compiler/strictModeCode8.ts (2 errors) ==== + "use strict" + module public { } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. + module private { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode8.js b/tests/baselines/reference/strictModeCode8.js new file mode 100644 index 00000000000..39d7cfff9ca --- /dev/null +++ b/tests/baselines/reference/strictModeCode8.js @@ -0,0 +1,7 @@ +//// [strictModeCode8.ts] +"use strict" +module public { } +module private { } + +//// [strictModeCode8.js] +"use strict"; diff --git a/tests/cases/compiler/strictModeCode6.ts b/tests/cases/compiler/strictModeCode6.ts new file mode 100644 index 00000000000..36b8b7ef05e --- /dev/null +++ b/tests/cases/compiler/strictModeCode6.ts @@ -0,0 +1,5 @@ +// @target: ES6 +"use strict" +import * as package from "./1" +import {foo as private} from "./1" +import public from "./1" \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode7.ts b/tests/cases/compiler/strictModeCode7.ts new file mode 100644 index 00000000000..a17dcfed181 --- /dev/null +++ b/tests/cases/compiler/strictModeCode7.ts @@ -0,0 +1,4 @@ +// @module: commonjs + +"use strict" +import public = require("1"); \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode8.ts b/tests/cases/compiler/strictModeCode8.ts new file mode 100644 index 00000000000..88a409ebb7b --- /dev/null +++ b/tests/cases/compiler/strictModeCode8.ts @@ -0,0 +1,3 @@ +"use strict" +module public { } +module private { } \ No newline at end of file From 111a297584a4be1c4162cdbaa95660dbfe93cd4e Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 22:02:50 -0700 Subject: [PATCH 07/23] Check for import, import equal, module --- src/compiler/checker.ts | 41 +++++++++++++++++++++++++++++++++++++---- src/compiler/parser.ts | 2 +- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f415ff893f7..edfdb6d9484 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10524,6 +10524,8 @@ module ts { } function checkImportDeclaration(node: ImportDeclaration) { + checkGrammarImportDeclarationNameInStrictMode(node); + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } @@ -10546,6 +10548,8 @@ module ts { } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { + checkGrammarDeclarationNameInStrictMode(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); @@ -11952,6 +11956,35 @@ module ts { return false; } + function checkGrammarImportDeclarationNameInStrictMode(node: ImportDeclaration): boolean { + // Check if the import declaration used strict-mode reserved word in its names bindings + if (node.importClause) { + let impotClause = node.importClause; + if (impotClause.namedBindings) { + let nameBindings = impotClause.namedBindings; + if (nameBindings.kind === SyntaxKind.NamespaceImport) { + let name = (nameBindings).name; + if (name.strictModeKind) { + let nameText = declarationNameToString(name); + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + else if (nameBindings.kind === SyntaxKind.NamedImports) { + let reportError = false; + for (let element of (nameBindings).elements) { + let name = element.name; + if (name.strictModeKind) { + let nameText = declarationNameToString(name); + reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } + } + return reportError; + } + } + } + return false; + } + function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean { let name = node.name; if (name && name.kind === SyntaxKind.Identifier && (name).strictModeKind) { @@ -11971,15 +12004,15 @@ module ts { return reportError ? reportError : false; case SyntaxKind.ClassDeclaration: + // Report an error if the class declaration uses strict-mode reserved word. return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText); case SyntaxKind.ModuleDeclaration: - return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText); + // Report an error if the module declaration uses strict-mode reserved word. + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText); - case SyntaxKind.ImportDeclaration: - case SyntaxKind.ExportDeclaration: case SyntaxKind.ImportEqualsDeclaration: - return grammarErrorOnNode(name, Diagnostics.ImportDecl_SlashExportDecl_SlashImportEqaul); + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return false; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 320f65ba587..e70090abd80 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1350,7 +1350,7 @@ module ts { return speculationHelper(callback, /*isLookAhead:*/ false); } - // Ignore strict mode flag because we will be report an error in type checker instead. + // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier(): boolean { if (token === SyntaxKind.Identifier) { return true; From 3a7384a95e7d7f104af7a9495aab7fb9bc478fe3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 23:39:54 -0700 Subject: [PATCH 08/23] Update error code --- src/compiler/checker.ts | 8 +--- .../diagnosticInformationMap.generated.ts | 11 ++--- src/compiler/diagnosticMessages.json | 14 ++---- .../constructorStaticParamName.errors.txt | 4 +- ...onstructorStaticParamNameErrors.errors.txt | 4 +- .../reference/convertKeywordsYes.errors.txt | 36 +++++++------- .../reference/decoratorOnClassMethod11.js | 14 +++--- .../reference/parser553699.errors.txt | 4 +- .../reference/parser642331.errors.txt | 4 +- .../reference/parser642331_1.errors.txt | 4 +- .../reference/strictModeCode1.errors.txt | 48 +++++++++---------- .../reference/strictModeCode8.errors.txt | 8 ++-- 12 files changed, 75 insertions(+), 84 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index edfdb6d9484..0d2575401c7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10524,9 +10524,7 @@ module ts { } function checkImportDeclaration(node: ImportDeclaration) { - checkGrammarImportDeclarationNameInStrictMode(node); - - if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -10548,9 +10546,7 @@ module ts { } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { - checkGrammarDeclarationNameInStrictMode(node); - - checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & NodeFlags.Export) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 502cd13296b..5f36f90d60a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -170,12 +170,11 @@ module ts { Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, - Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, - Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode." }, - Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, - Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, - Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Module is automatically in strict mode." }, - ImportDecl_SlashExportDecl_SlashImportEqaul: { code: 1212, category: DiagnosticCategory.Error, key: "ImportDecl/ExportDecl/ImportEqaul" }, + Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, + Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Module is automatically in strict mode." }, 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 6d822695930..61726910846 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -673,27 +673,23 @@ }, "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { "category": "Error", - "code": 1212 + "code": 1213 }, "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode.": { "category": "Error", - "code": 1212 + "code": 1214 }, "Type expected. '{0}' is a reserved word in strict mode": { "category": "Error", - "code": 1212 + "code": 1215 }, "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { "category": "Error", - "code": 1212 + "code": 1216 }, "Type expected. '{0}' is a reserved word. Module is automatically in strict mode.": { "category": "Error", - "code": 1212 - }, - "ImportDecl/ExportDecl/ImportEqaul": { - "category": "Error", - "code": 1212 + "code": 1217 }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/constructorStaticParamName.errors.txt b/tests/baselines/reference/constructorStaticParamName.errors.txt index 6d5c1015f48..36ee447e4e8 100644 --- a/tests/baselines/reference/constructorStaticParamName.errors.txt +++ b/tests/baselines/reference/constructorStaticParamName.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamName.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1212: Identifi class test { constructor (static) { } ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt index a5f6a74b8dd..cd49422e7d5 100644 --- a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt +++ b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamNameErrors.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1212: Id class test { constructor (static) { } ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/convertKeywordsYes.errors.txt b/tests/baselines/reference/convertKeywordsYes.errors.txt index b558ba0b714..dcecdacd776 100644 --- a/tests/baselines/reference/convertKeywordsYes.errors.txt +++ b/tests/baselines/reference/convertKeywordsYes.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1212: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1212: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1212: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1212: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1212: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1213: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1213: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1213: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1213: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1213: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/compiler/convertKeywordsYes.ts (9 errors) ==== @@ -303,33 +303,33 @@ tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1212: Identifier exp class constructor { } class implements { } ~~~~~~~~~~ -!!! error TS1212: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. class interface { } ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. class let { } ~~~ -!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. class module { } class package { } ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. class private { } ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. class protected { } ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. class public { } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. class set { } class static { } ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. class get { } class yield { } ~~~~~ -!!! error TS1212: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. class declare { } } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index 71d4298f02c..f8276de2fe3 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -1,11 +1,11 @@ //// [decoratorOnClassMethod11.ts] -module M { - class C { - decorator(target: Object, key: string): void { } - - @this.decorator - method() { } - } +module M { + class C { + decorator(target: Object, key: string): void { } + + @this.decorator + method() { } + } } //// [decoratorOnClassMethod11.js] diff --git a/tests/baselines/reference/parser553699.errors.txt b/tests/baselines/reference/parser553699.errors.txt index 505bc93c338..f526629b7b6 100644 --- a/tests/baselines/reference/parser553699.errors.txt +++ b/tests/baselines/reference/parser553699.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS2304: Cannot find name 'public'. @@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21) constructor() { } public banana (x: public) { } ~~~~~~ -!!! error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~ !!! error TS2304: Cannot find name 'public'. } diff --git a/tests/baselines/reference/parser642331.errors.txt b/tests/baselines/reference/parser642331.errors.txt index 5586cf6754f..5d7db637653 100644 --- a/tests/baselines/reference/parser642331.errors.txt +++ b/tests/baselines/reference/parser642331.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts (1 errors) ==== class test { constructor (static) { } ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/parser642331_1.errors.txt b/tests/baselines/reference/parser642331_1.errors.txt index 02674121ac9..be6fa63ee7c 100644 --- a/tests/baselines/reference/parser642331_1.errors.txt +++ b/tests/baselines/reference/parser642331_1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,1 class test { constructor (static) { } ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index a7292d6b610..8cc66072c4b 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/strictModeCode1.ts(4,17): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,26): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,34): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(5,9): error TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode1.ts(5,19): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeCode1.ts(5,28): error TS1212: Identifier expected. 'static' is a reserved word in strict mode -tests/cases/compiler/strictModeCode1.ts(7,22): error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,24): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,32): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,10): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,19): error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,27): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(14,18): error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,9): error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,17): error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(7,22): error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,9): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,17): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode @@ -22,11 +22,11 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte class Foo { constructor(private, public, static) { ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. private = public = static; ~~~~~~~ !!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode @@ -37,26 +37,26 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte } public banana(x: public) { } ~~~~~~ -!!! error TS1212: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. } class C { constructor(public public, let) { ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. ~~~ -!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. } foo1(private, static, public) { ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. function let() { } ~~~ -!!! error TS1212: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. var z = function let() { }; } @@ -64,9 +64,9 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte class D{ } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. class E implements public { } ~~~~~~ diff --git a/tests/baselines/reference/strictModeCode8.errors.txt b/tests/baselines/reference/strictModeCode8.errors.txt index faf13a186e5..b0134007e0d 100644 --- a/tests/baselines/reference/strictModeCode8.errors.txt +++ b/tests/baselines/reference/strictModeCode8.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/strictModeCode8.ts(2,8): error TS1212: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. -tests/cases/compiler/strictModeCode8.ts(3,8): error TS1212: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. +tests/cases/compiler/strictModeCode8.ts(2,8): error TS1214: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. +tests/cases/compiler/strictModeCode8.ts(3,8): error TS1214: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. ==== tests/cases/compiler/strictModeCode8.ts (2 errors) ==== "use strict" module public { } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. +!!! error TS1214: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. module private { } ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. \ No newline at end of file +!!! error TS1214: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. \ No newline at end of file From 1246dca703bc2d563efa2318c189f8a4051a2645 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Apr 2015 23:54:42 -0700 Subject: [PATCH 09/23] Add comment --- src/compiler/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5b7083e164e..01b4003c0e1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -387,7 +387,7 @@ module ts { export interface Identifier extends PrimaryExpression { text: string; // Text of identifier (with escapes converted to characters) - strictModeKind?: SyntaxKind; // TODO(yuisu): comment + strictModeKind?: SyntaxKind; // SyntaxKind set when violating strict mode reserved word } export interface QualifiedName extends Node { From 4b7d2f2411e8e1cdbacf0ffdfca18904d6bb486e Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 14:46:02 -0700 Subject: [PATCH 10/23] Address code review --- src/compiler/checker.ts | 24 +++++----- .../diagnosticInformationMap.generated.ts | 8 ++-- src/compiler/diagnosticMessages.json | 8 ++-- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 2 +- .../constructorStaticParamName.errors.txt | 4 +- ...onstructorStaticParamNameErrors.errors.txt | 4 +- .../reference/convertKeywordsYes.errors.txt | 36 +++++++------- .../reference/parser553699.errors.txt | 4 +- .../reference/parser642331.errors.txt | 4 +- .../reference/parser642331_1.errors.txt | 4 +- .../reference/strictModeCode1.errors.txt | 48 +++++++++---------- .../reference/strictModeCode5.errors.txt | 11 ++++- tests/baselines/reference/strictModeCode5.js | 4 +- .../reference/strictModeCode8.errors.txt | 22 +++++++-- tests/baselines/reference/strictModeCode8.js | 5 +- tests/cases/compiler/strictModeCode5.ts | 3 +- tests/cases/compiler/strictModeCode8.ts | 5 +- 18 files changed, 113 insertions(+), 85 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d2575401c7..cd9db15c7fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8345,12 +8345,12 @@ module ts { // class C { // foo(x: public){} // Error. // } - if (node.typeName.kind === SyntaxKind.Identifier && (node.typeName).strictModeKind) { + if (node.typeName.kind === SyntaxKind.Identifier && (node.typeName).isKeywordInStrictMode) { let typeName = node.typeName; let nameText = declarationNameToString(typeName); - reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) || - reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) || - grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); } return checkTypeReferenceOrHeritageClauseElement(node); } @@ -11960,7 +11960,7 @@ module ts { let nameBindings = impotClause.namedBindings; if (nameBindings.kind === SyntaxKind.NamespaceImport) { let name = (nameBindings).name; - if (name.strictModeKind) { + if (name.isKeywordInStrictMode) { let nameText = declarationNameToString(name); return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11969,7 +11969,7 @@ module ts { let reportError = false; for (let element of (nameBindings).elements) { let name = element.name; - if (name.strictModeKind) { + if (name.isKeywordInStrictMode) { let nameText = declarationNameToString(name); reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11983,7 +11983,7 @@ module ts { function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean { let name = node.name; - if (name && name.kind === SyntaxKind.Identifier && (name).strictModeKind) { + if (name && name.kind === SyntaxKind.Identifier && (name).isKeywordInStrictMode) { let nameText = declarationNameToString(name); switch (node.kind) { case SyntaxKind.Parameter: @@ -11994,18 +11994,18 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: - let reportError = reportStrictModeGrammarErrorInClassDeclaration(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) || - reportStrictModeGrammarErrorInModule(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) || + let reportError = reportStrictModeGrammarErrorInClassDeclaration(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + reportStrictModeGrammarErrorInModule(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) || grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); return reportError ? reportError : false; case SyntaxKind.ClassDeclaration: // Report an error if the class declaration uses strict-mode reserved word. - return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText); + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText); case SyntaxKind.ModuleDeclaration: // Report an error if the module declaration uses strict-mode reserved word. - return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText); + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText); case SyntaxKind.ImportEqualsDeclaration: return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); @@ -12015,7 +12015,7 @@ module ts { } function checkGrammarExpressionInStrictMode(node: Expression): boolean { - if (node.kind === SyntaxKind.Identifier && (node).strictModeKind) { + if (node.kind === SyntaxKind.Identifier && (node).isKeywordInStrictMode) { let nameText = declarationNameToString(node); return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5f36f90d60a..171413a19df 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -170,11 +170,11 @@ module ts { Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, - Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, - Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, - Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." }, - Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Module is automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, + Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, 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 61726910846..32c289a6d23 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -671,11 +671,11 @@ "category": "Error", "code": 1212 }, - "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { + "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": { "category": "Error", "code": 1213 }, - "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode.": { + "Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": { "category": "Error", "code": 1214 }, @@ -683,11 +683,11 @@ "category": "Error", "code": 1215 }, - "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": { + "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": { "category": "Error", "code": 1216 }, - "Type expected. '{0}' is a reserved word. Module is automatically in strict mode.": { + "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": { "category": "Error", "code": 1217 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e70090abd80..0edb44dc26a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1489,7 +1489,7 @@ module ts { // Set strictModeKind property so that we can report appropriate error later in type checker if (inStrictModeContext() && (token > SyntaxKind.Identifier && token <= SyntaxKind.LastFutureReservedWord)) { - node.strictModeKind = token; + node.isKeywordInStrictMode = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 01b4003c0e1..a3e6afbeb17 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -387,7 +387,7 @@ module ts { export interface Identifier extends PrimaryExpression { text: string; // Text of identifier (with escapes converted to characters) - strictModeKind?: SyntaxKind; // SyntaxKind set when violating strict mode reserved word + isKeywordInStrictMode?: SyntaxKind; // SyntaxKind which get set when violating strict mode reserved word } export interface QualifiedName extends Node { diff --git a/tests/baselines/reference/constructorStaticParamName.errors.txt b/tests/baselines/reference/constructorStaticParamName.errors.txt index 36ee447e4e8..bd5012d00c1 100644 --- a/tests/baselines/reference/constructorStaticParamName.errors.txt +++ b/tests/baselines/reference/constructorStaticParamName.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamName.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifi class test { constructor (static) { } ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt index cd49422e7d5..847bb575a98 100644 --- a/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt +++ b/tests/baselines/reference/constructorStaticParamNameErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. ==== tests/cases/compiler/constructorStaticParamNameErrors.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Id class test { constructor (static) { } ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/convertKeywordsYes.errors.txt b/tests/baselines/reference/convertKeywordsYes.errors.txt index dcecdacd776..7218e1fd12c 100644 --- a/tests/baselines/reference/convertKeywordsYes.errors.txt +++ b/tests/baselines/reference/convertKeywordsYes.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1213: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1213: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1213: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1213: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1213: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(292,11): error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(293,11): error TS1213: Identifier expected. 'interface' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(294,11): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(296,11): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(297,11): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(298,11): error TS1213: Identifier expected. 'protected' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(299,11): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(301,11): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1213: Identifier expected. 'yield' is a reserved word in strict mode. Class definitions are automatically in strict mode. ==== tests/cases/compiler/convertKeywordsYes.ts (9 errors) ==== @@ -303,33 +303,33 @@ tests/cases/compiler/convertKeywordsYes.ts(303,11): error TS1213: Identifier exp class constructor { } class implements { } ~~~~~~~~~~ -!!! error TS1213: Identifier expected. 'implements' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. class interface { } ~~~~~~~~~ -!!! error TS1213: Identifier expected. 'interface' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'interface' is a reserved word in strict mode. Class definitions are automatically in strict mode. class let { } ~~~ -!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. class module { } class package { } ~~~~~~~ -!!! error TS1213: Identifier expected. 'package' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. class private { } ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. class protected { } ~~~~~~~~~ -!!! error TS1213: Identifier expected. 'protected' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'protected' is a reserved word in strict mode. Class definitions are automatically in strict mode. class public { } ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. class set { } class static { } ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. class get { } class yield { } ~~~~~ -!!! error TS1213: Identifier expected. 'yield' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'yield' is a reserved word in strict mode. Class definitions are automatically in strict mode. class declare { } } \ No newline at end of file diff --git a/tests/baselines/reference/parser553699.errors.txt b/tests/baselines/reference/parser553699.errors.txt index f526629b7b6..ea7e88cdf36 100644 --- a/tests/baselines/reference/parser553699.errors.txt +++ b/tests/baselines/reference/parser553699.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS2304: Cannot find name 'public'. @@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21) constructor() { } public banana (x: public) { } ~~~~~~ -!!! error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ !!! error TS2304: Cannot find name 'public'. } diff --git a/tests/baselines/reference/parser642331.errors.txt b/tests/baselines/reference/parser642331.errors.txt index 5d7db637653..acff017d0ba 100644 --- a/tests/baselines/reference/parser642331.errors.txt +++ b/tests/baselines/reference/parser642331.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts(2,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331.ts (1 errors) ==== class test { constructor (static) { } ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/parser642331_1.errors.txt b/tests/baselines/reference/parser642331_1.errors.txt index be6fa63ee7c..fe01123f865 100644 --- a/tests/baselines/reference/parser642331_1.errors.txt +++ b/tests/baselines/reference/parser642331_1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser642331_1.ts(4,1 class test { constructor (static) { } ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index 8cc66072c4b..13b9d87854f 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/strictModeCode1.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(5,9): error TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode1.ts(5,19): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeCode1.ts(5,28): error TS1212: Identifier expected. 'static' is a reserved word in strict mode -tests/cases/compiler/strictModeCode1.ts(7,22): error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,9): error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,17): error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(7,22): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(20,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode @@ -22,11 +22,11 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte class Foo { constructor(private, public, static) { ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. private = public = static; ~~~~~~~ !!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode @@ -37,26 +37,26 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte } public banana(x: public) { } ~~~~~~ -!!! error TS1216: Type expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. } class C { constructor(public public, let) { ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~ -!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. } foo1(private, static, public) { ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. function let() { } ~~~ -!!! error TS1213: Identifier expected. 'let' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. var z = function let() { }; } @@ -64,9 +64,9 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte class D{ } ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word. Class definitions are automatically in strict mode. +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. class E implements public { } ~~~~~~ diff --git a/tests/baselines/reference/strictModeCode5.errors.txt b/tests/baselines/reference/strictModeCode5.errors.txt index f4ad705cd27..ac6d17e1bb9 100644 --- a/tests/baselines/reference/strictModeCode5.errors.txt +++ b/tests/baselines/reference/strictModeCode5.errors.txt @@ -3,9 +3,11 @@ tests/cases/compiler/strictModeCode5.ts(3,10): error TS1212: Identifier expected tests/cases/compiler/strictModeCode5.ts(4,7): error TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode5.ts(5,15): error TS1212: Identifier expected. 'static' is a reserved word in strict mode tests/cases/compiler/strictModeCode5.ts(5,38): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(6,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode5.ts(6,14): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode -==== tests/cases/compiler/strictModeCode5.ts (5 errors) ==== +==== tests/cases/compiler/strictModeCode5.ts (7 errors) ==== "use strict" var [public] = [1]; ~~~~~~ @@ -20,4 +22,9 @@ tests/cases/compiler/strictModeCode5.ts(5,38): error TS1212: Identifier expected ~~~~~~ !!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode \ No newline at end of file +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + var {public, protected} = { public: 1, protected: 2 }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode5.js b/tests/baselines/reference/strictModeCode5.js index 746d2dab580..8a480b0fe70 100644 --- a/tests/baselines/reference/strictModeCode5.js +++ b/tests/baselines/reference/strictModeCode5.js @@ -3,7 +3,8 @@ var [public] = [1]; var { x: public } = { x: 1 }; var [[private]] = [["hello"]]; -var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; +var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; +var {public, protected} = { public: 1, protected: 2 }; //// [strictModeCode5.js] "use strict"; @@ -11,3 +12,4 @@ var public = ([1])[0]; var public = ({ x: 1 }).x; var private = ([["hello"]])[0][0]; var _a = { y: { s: 1 }, z: { o: { p: 'h' } } }, static = _a.y.s, package = _a.z.o.p; +var _b = { public: 1, protected: 2 }, public = _b.public, protected = _b.protected; diff --git a/tests/baselines/reference/strictModeCode8.errors.txt b/tests/baselines/reference/strictModeCode8.errors.txt index b0134007e0d..25b087e9016 100644 --- a/tests/baselines/reference/strictModeCode8.errors.txt +++ b/tests/baselines/reference/strictModeCode8.errors.txt @@ -1,12 +1,24 @@ -tests/cases/compiler/strictModeCode8.ts(2,8): error TS1214: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. -tests/cases/compiler/strictModeCode8.ts(3,8): error TS1214: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. +tests/cases/compiler/strictModeCode8.ts(2,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode8.ts(3,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode8.ts(4,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode8.ts(6,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode8.ts(6,16): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -==== tests/cases/compiler/strictModeCode8.ts (2 errors) ==== +==== tests/cases/compiler/strictModeCode8.ts (5 errors) ==== "use strict" module public { } ~~~~~~ -!!! error TS1214: Identifier expected. 'public' is a reserved word. Module is automatically in strict mode. +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode module private { } ~~~~~~~ -!!! error TS1214: Identifier expected. 'private' is a reserved word. Module is automatically in strict mode. \ No newline at end of file +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + module public.whatever { + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + } + module private.public.foo { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode8.js b/tests/baselines/reference/strictModeCode8.js index 39d7cfff9ca..e2c541217f4 100644 --- a/tests/baselines/reference/strictModeCode8.js +++ b/tests/baselines/reference/strictModeCode8.js @@ -1,7 +1,10 @@ //// [strictModeCode8.ts] "use strict" module public { } -module private { } +module private { } +module public.whatever { +} +module private.public.foo { } //// [strictModeCode8.js] "use strict"; diff --git a/tests/cases/compiler/strictModeCode5.ts b/tests/cases/compiler/strictModeCode5.ts index 4f4ff9f564f..8f25ab1e6d5 100644 --- a/tests/cases/compiler/strictModeCode5.ts +++ b/tests/cases/compiler/strictModeCode5.ts @@ -2,4 +2,5 @@ var [public] = [1]; var { x: public } = { x: 1 }; var [[private]] = [["hello"]]; -var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; \ No newline at end of file +var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; +var {public, protected} = { public: 1, protected: 2 }; \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode8.ts b/tests/cases/compiler/strictModeCode8.ts index 88a409ebb7b..24c4b7d6177 100644 --- a/tests/cases/compiler/strictModeCode8.ts +++ b/tests/cases/compiler/strictModeCode8.ts @@ -1,3 +1,6 @@ "use strict" module public { } -module private { } \ No newline at end of file +module private { } +module public.whatever { +} +module private.public.foo { } \ No newline at end of file From e91ef844edee6938ab688dda76b148a06318d98b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 14:49:47 -0700 Subject: [PATCH 11/23] Address code review; better error recovering --- src/compiler/parser.ts | 5 ++- .../decoratorOnClassAccessor3.errors.txt | 28 +------------- .../reference/decoratorOnClassAccessor3.js | 22 ++++++++--- .../decoratorOnClassAccessor6.errors.txt | 37 +------------------ .../reference/decoratorOnClassAccessor6.js | 20 ++++++++-- .../decoratorOnClassMethod3.errors.txt | 22 +---------- .../reference/decoratorOnClassMethod3.js | 15 ++++++-- .../decoratorOnClassProperty3.errors.txt | 19 +--------- .../reference/decoratorOnClassProperty3.js | 12 +++++- 9 files changed, 65 insertions(+), 115 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0edb44dc26a..95f9955733b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1487,8 +1487,8 @@ module ts { if (isIdentifier) { let node = createNode(SyntaxKind.Identifier); - // Set strictModeKind property so that we can report appropriate error later in type checker - if (inStrictModeContext() && (token > SyntaxKind.Identifier && token <= SyntaxKind.LastFutureReservedWord)) { + // Store original token kind so we can report appropriate error later in type checker + if (token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastFutureReservedWord) { node.isKeywordInStrictMode = token; } node.text = internIdentifier(scanner.getTokenValue()); @@ -4640,6 +4640,7 @@ module ts { case SyntaxKind.ColonToken: // Type Annotation for declaration case SyntaxKind.EqualsToken: // Initializer for declaration case SyntaxKind.QuestionToken: // Not valid, but permitted so that it gets caught later on. + case SyntaxKind.AtToken: return true; default: // Covers diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt index b75b7e0d8b6..98b96b9b1c4 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -1,35 +1,11 @@ -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec get accessor() { return 1; } - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. ~ !!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'get'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~ -!!! error TS1005: ';' expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js index f48a755953f..23e689f3114 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.js +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -6,14 +6,24 @@ class C { } //// [decoratorOnClassAccessor3.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; var C = (function () { function C() { } + Object.defineProperty(C.prototype, "accessor", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", + __decorate([ + dec + ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); -public; -get; -accessor(); -{ - return 1; -} diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt index ec22ae0b3e1..e430b4cf1ee 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -1,44 +1,11 @@ -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec set accessor(value: number) { } - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. ~ !!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'set'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~~~~~ -!!! error TS2304: Cannot find name 'value'. - ~ -!!! error TS1005: ',' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'number'. - ~ -!!! error TS1005: ';' expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js index 771d937634f..465e13ebb1d 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.js +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -6,12 +6,24 @@ class C { } //// [decoratorOnClassAccessor6.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; var C = (function () { function C() { } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", + __decorate([ + dec + ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); return C; })(); -public; -set; -accessor(value, number); -{ } diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt index b2173dedf9e..4881502a02e 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -1,29 +1,11 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { public @dec method() {} - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. ~ !!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js index 3ac97697e80..f93b7d7a6b2 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.js +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -6,11 +6,20 @@ class C { } //// [decoratorOnClassMethod3.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; var C = (function () { function C() { } + C.prototype.method = function () { }; + Object.defineProperty(C.prototype, "method", + __decorate([ + dec + ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); return C; })(); -public; -method(); -{ } diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt index 29438bd67a9..12d0efb78d7 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -1,26 +1,11 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (1 errors) ==== declare function dec(target: any, propertyKey: string): void; class C { public @dec prop; - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. ~ !!! error TS1005: ';' expected. - -!!! error TS1146: Declaration expected. - ~~~~ -!!! error TS2304: Cannot find name 'prop'. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js index 6c9945677ca..05476c66e7d 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.js +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -6,10 +6,18 @@ class C { } //// [decoratorOnClassProperty3.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; var C = (function () { function C() { } + __decorate([ + dec + ], C.prototype, "prop"); return C; })(); -public; -prop; From 8771212d5850d97d5518c353bba8329a1df93121 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 15:58:56 -0700 Subject: [PATCH 12/23] Remove incorrect check of module declartion --- src/compiler/checker.ts | 39 ++++++++++--------- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cd9db15c7fa..2133915ba46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8345,12 +8345,14 @@ module ts { // class C { // foo(x: public){} // Error. // } - if (node.typeName.kind === SyntaxKind.Identifier && (node.typeName).isKeywordInStrictMode) { + if (node.typeName.kind === SyntaxKind.Identifier) { let typeName = node.typeName; - let nameText = declarationNameToString(typeName); - reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || - reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) || - grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + if (isReservedwordInStrictMode(typeName)) { + let nameText = declarationNameToString(typeName); + // TODO(yuisu): Fix this when external module becomes strict mode code; + reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + } } return checkTypeReferenceOrHeritageClauseElement(node); } @@ -11932,8 +11934,14 @@ module ts { anyArrayType = createArrayType(anyType); } - // GRAMMAR CHECKING + function isReservedwordInStrictMode(node: Identifier): boolean { + if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.isKeywordInStrictMode) { + return true; + } + return false + } + function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { // We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.) // if so, we would like to give more explicit invalid usage error. @@ -11943,15 +11951,6 @@ module ts { return false; } - function reportStrictModeGrammarErrorInModule(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { - // We are checking if this name is inside module declaration which is automatically a strict mode code in ES6. - // If so, we would like to give more explicit invalid usage error. - if (getAncestor(identifier, SyntaxKind.ModuleDeclaration)) { - return grammarErrorOnNode(identifier, message, arg0); - } - return false; - } - function checkGrammarImportDeclarationNameInStrictMode(node: ImportDeclaration): boolean { // Check if the import declaration used strict-mode reserved word in its names bindings if (node.importClause) { @@ -11983,7 +11982,7 @@ module ts { function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean { let name = node.name; - if (name && name.kind === SyntaxKind.Identifier && (name).isKeywordInStrictMode) { + if (name && name.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(name)) { let nameText = declarationNameToString(name); switch (node.kind) { case SyntaxKind.Parameter: @@ -11994,8 +11993,8 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: + // TODO(yuisu): fix this when having external moduel in strict mode let reportError = reportStrictModeGrammarErrorInClassDeclaration(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || - reportStrictModeGrammarErrorInModule(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) || grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); return reportError ? reportError : false; @@ -12005,9 +12004,11 @@ module ts { case SyntaxKind.ModuleDeclaration: // Report an error if the module declaration uses strict-mode reserved word. - return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText); + // TODO(yuisu): fix this when having external module in strict mode + return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); case SyntaxKind.ImportEqualsDeclaration: + // TODO(yuisu): fix this when having external moduel in strict mode return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } @@ -12015,7 +12016,7 @@ module ts { } function checkGrammarExpressionInStrictMode(node: Expression): boolean { - if (node.kind === SyntaxKind.Identifier && (node).isKeywordInStrictMode) { + if (node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(node)) { let nameText = declarationNameToString(node); return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 171413a19df..2b3c022d45a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -171,7 +171,7 @@ module ts { A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, - Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, + Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." }, Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 32c289a6d23..07f6c1f526c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -675,7 +675,7 @@ "category": "Error", "code": 1213 }, - "Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": { + "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode.": { "category": "Error", "code": 1214 }, From 8adac948967213ba6af93e53370a3303f396ff9a Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 15:59:37 -0700 Subject: [PATCH 13/23] Better recovery when running into modifier --- src/compiler/parser.ts | 23 ++++++++++++++++++- .../reference/classUpdateTests.errors.txt | 22 +++++++++++------- .../reference/strictModeCode1.errors.txt | 7 +++--- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 95f9955733b..59a1e12fe6b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4596,6 +4596,18 @@ module ts { return finishNode(node); } + function isClassMemberModifier(idToken: SyntaxKind) { + switch (idToken) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.StaticKeyword: + return true; + default: + return false; + } + } + function isClassMemberStart(): boolean { let idToken: SyntaxKind; @@ -4606,6 +4618,16 @@ module ts { // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (isModifier(token)) { idToken = token; + // If the idToken is a class modifier (protected, private, public, and static), it is + // certain that we are starting to parse class member. This allows better error recovery + // Example: + // public foo() ... // true + // public @dec blah ... // true; we will then report an error later + // export public ... // true; we will then report an error later + if (isClassMemberModifier(idToken)) { + return true; + } + nextToken(); } @@ -4640,7 +4662,6 @@ module ts { case SyntaxKind.ColonToken: // Type Annotation for declaration case SyntaxKind.EqualsToken: // Initializer for declaration case SyntaxKind.QuestionToken: // Not valid, but permitted so that it gets caught later on. - case SyntaxKind.AtToken: return true; default: // Covers diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 5d5c4a36ab3..e7f34fec546 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -13,12 +13,14 @@ tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or sta tests/cases/compiler/classUpdateTests.ts(99,3): error TS1129: Statement expected. tests/cases/compiler/classUpdateTests.ts(101,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(105,3): error TS1129: Statement expected. -tests/cases/compiler/classUpdateTests.ts(105,15): error TS2339: Property 'p1' does not exist on type 'Q'. +tests/cases/compiler/classUpdateTests.ts(105,14): error TS1005: ';' expected. +tests/cases/compiler/classUpdateTests.ts(107,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(111,3): error TS1129: Statement expected. -tests/cases/compiler/classUpdateTests.ts(111,16): error TS2339: Property 'p1' does not exist on type 'R'. +tests/cases/compiler/classUpdateTests.ts(111,15): error TS1005: ';' expected. +tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected. -==== tests/cases/compiler/classUpdateTests.ts (16 errors) ==== +==== tests/cases/compiler/classUpdateTests.ts (18 errors) ==== // // test codegen for instance properties // @@ -158,17 +160,21 @@ tests/cases/compiler/classUpdateTests.ts(111,16): error TS2339: Property 'p1' do public this.p1 = 0; // ERROR ~~~~~~ !!! error TS1129: Statement expected. - ~~ -!!! error TS2339: Property 'p1' does not exist on type 'Q'. + ~ +!!! error TS1005: ';' expected. } } + ~ +!!! error TS1128: Declaration or statement expected. class R { constructor() { private this.p1 = 0; // ERROR ~~~~~~~ !!! error TS1129: Statement expected. - ~~ -!!! error TS2339: Property 'p1' does not exist on type 'R'. + ~ +!!! error TS1005: ';' expected. } - } \ No newline at end of file + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index 13b9d87854f..7c80a4a71d5 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -11,9 +11,9 @@ tests/cases/compiler/strictModeCode1.ts(13,10): error TS1213: Identifier expecte tests/cases/compiler/strictModeCode1.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(20,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(23,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode ==== tests/cases/compiler/strictModeCode1.ts (16 errors) ==== @@ -60,6 +60,7 @@ tests/cases/compiler/strictModeCode1.ts(22,20): error TS1212: Identifier expecte var z = function let() { }; } + public pulbic() { } // No Error; } class D{ } From 39f7247004f81ad95aa026f14c199270b654b4d5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 15:59:49 -0700 Subject: [PATCH 14/23] Add more tests --- tests/baselines/reference/strictModeCode1.js | 2 ++ tests/cases/compiler/strictModeCode1.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/baselines/reference/strictModeCode1.js b/tests/baselines/reference/strictModeCode1.js index 77d786f52d2..32d3eb93242 100644 --- a/tests/baselines/reference/strictModeCode1.js +++ b/tests/baselines/reference/strictModeCode1.js @@ -16,6 +16,7 @@ class C { var z = function let() { }; } + public pulbic() { } // No Error; } class D{ } @@ -38,6 +39,7 @@ var C = (function () { function let() { } var z = function let() { }; }; + C.prototype.pulbic = function () { }; // No Error; return C; })(); var D = (function () { diff --git a/tests/cases/compiler/strictModeCode1.ts b/tests/cases/compiler/strictModeCode1.ts index 1c311c7cd5f..e67a27dca77 100644 --- a/tests/cases/compiler/strictModeCode1.ts +++ b/tests/cases/compiler/strictModeCode1.ts @@ -15,6 +15,7 @@ class C { var z = function let() { }; } + public pulbic() { } // No Error; } class D{ } From 33d6a81a3598ac5a7217975942894269b398c005 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Apr 2015 16:50:43 -0700 Subject: [PATCH 15/23] update property in Identifier --- src/compiler/checker.ts | 6 +++--- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2133915ba46..e103fbb8dbc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11936,7 +11936,7 @@ module ts { // GRAMMAR CHECKING function isReservedwordInStrictMode(node: Identifier): boolean { - if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.isKeywordInStrictMode) { + if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalSyntaxKind) { return true; } return false @@ -11959,7 +11959,7 @@ module ts { let nameBindings = impotClause.namedBindings; if (nameBindings.kind === SyntaxKind.NamespaceImport) { let name = (nameBindings).name; - if (name.isKeywordInStrictMode) { + if (name.originalSyntaxKind) { let nameText = declarationNameToString(name); return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11968,7 +11968,7 @@ module ts { let reportError = false; for (let element of (nameBindings).elements) { let name = element.name; - if (name.isKeywordInStrictMode) { + if (name.originalSyntaxKind) { let nameText = declarationNameToString(name); reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 59a1e12fe6b..200c36bea51 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1489,7 +1489,7 @@ module ts { // Store original token kind so we can report appropriate error later in type checker if (token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastFutureReservedWord) { - node.isKeywordInStrictMode = token; + node.originalSyntaxKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a3e6afbeb17..27e38ff7178 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -386,8 +386,8 @@ module ts { } export interface Identifier extends PrimaryExpression { - text: string; // Text of identifier (with escapes converted to characters) - isKeywordInStrictMode?: SyntaxKind; // SyntaxKind which get set when violating strict mode reserved word + text: string; // Text of identifier (with escapes converted to characters) + originalSyntaxKind?: SyntaxKind; // original syntaxKind which get set so that we can report an error later } export interface QualifiedName extends Node { From 5bab826c6b41af84d7f4a0ce7dbbef0a07159fee Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Apr 2015 14:23:54 -0700 Subject: [PATCH 16/23] Address issue with propertyAccessExpression and QualifiedName in TypeReference --- src/compiler/checker.ts | 130 +++++++++++++++++++++++++++++++--------- src/compiler/parser.ts | 6 +- src/compiler/types.ts | 4 +- 3 files changed, 107 insertions(+), 33 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e103fbb8dbc..e75515cbb56 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7954,7 +7954,7 @@ module ts { } function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { - checkGrammarExpressionInStrictMode(node); + checkGrammarIdentifierInStrictMode(node); return checkExpressionOrQualifiedName(node, contextualMapper); } @@ -8340,25 +8340,13 @@ module ts { } function checkTypeReferenceNode(node: TypeReferenceNode) { - // Check if the type reference is using strict mode keyword - // Example: - // class C { - // foo(x: public){} // Error. - // } - if (node.typeName.kind === SyntaxKind.Identifier) { - let typeName = node.typeName; - if (isReservedwordInStrictMode(typeName)) { - let nameText = declarationNameToString(typeName); - // TODO(yuisu): Fix this when external module becomes strict mode code; - reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || - grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); - } - } + checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrHeritageClauseElement(node); } function checkHeritageClauseElement(node: HeritageClauseElement) { - checkGrammarExpressionInStrictMode(node.expression); + checkGrammarHeritageClauseElementInStrictMode(node.expression); + return checkTypeReferenceOrHeritageClauseElement(node); } @@ -10588,7 +10576,7 @@ module ts { // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); - let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module); } @@ -11936,7 +11924,8 @@ module ts { // GRAMMAR CHECKING function isReservedwordInStrictMode(node: Identifier): boolean { - if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalSyntaxKind) { + // Check that originalStrictModeSyntaxKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word + if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalStrictModeSyntaxKind <= SyntaxKind.LastFutureReservedWord) { return true; } return false @@ -11959,7 +11948,7 @@ module ts { let nameBindings = impotClause.namedBindings; if (nameBindings.kind === SyntaxKind.NamespaceImport) { let name = (nameBindings).name; - if (name.originalSyntaxKind) { + if (name.originalStrictModeSyntaxKind) { let nameText = declarationNameToString(name); return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11968,7 +11957,7 @@ module ts { let reportError = false; for (let element of (nameBindings).elements) { let name = element.name; - if (name.originalSyntaxKind) { + if (name.originalStrictModeSyntaxKind) { let nameText = declarationNameToString(name); reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11993,10 +11982,7 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: - // TODO(yuisu): fix this when having external moduel in strict mode - let reportError = reportStrictModeGrammarErrorInClassDeclaration(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || - grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); - return reportError ? reportError : false; + return checkGrammarIdentifierInStrictMode(name); case SyntaxKind.ClassDeclaration: // Report an error if the class declaration uses strict-mode reserved word. @@ -12008,17 +11994,105 @@ module ts { return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); case SyntaxKind.ImportEqualsDeclaration: - // TODO(yuisu): fix this when having external moduel in strict mode + // TODO(yuisu): fix this when having external module in strict mode return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return false; } - function checkGrammarExpressionInStrictMode(node: Expression): boolean { - if (node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(node)) { + function checkGrammarTypeReferenceInStrictMode(typeName: Identifier | QualifiedName) { + // Check if the type reference is using strict mode keyword + // Example: + // class C { + // foo(x: public){} // Error. + // } + if (typeName.kind === SyntaxKind.Identifier) { + checkGrammarTypeNameInStrictMode(typeName); + } + // Report an error for each identifier in QualifiedName + // Example: + // foo (x: public.private.bar) // Error at public, private + // foo (x: public.private.package) // Error at public, private, package + else if (typeName.kind === SyntaxKind.QualifiedName) { + let partOfTypeName = typeName; + + // Keep traverse from right to left in QualifiedName and report an error at each one + // Stop when the next left is not longer a QualifiedName, then it must be the first component + // in QualifiedName and must be an Identifier. + // Example: + // x1: public.private.package // Error at public, private + while (partOfTypeName && partOfTypeName.kind === SyntaxKind.QualifiedName) { + let name = (partOfTypeName).right; + checkGrammarTypeNameInStrictMode(name); + partOfTypeName = (partOfTypeName).left; + } + + // Report and error at the component in QualifiedName which must be an identifier. + // Example: + // x1: public.private.package // Error at package + checkGrammarTypeNameInStrictMode(partOfTypeName); + } + } + + // This function will report an error for every identifier in property access expression + // whether it violates strict mode reserved words. + // Example: + // public.B // error at public + // public.private.A // error at public and private + // public.private.package // error at public and private and package + function checkGrammarHeritageClauseElementInStrictMode(expression: Expression) { + // Example: + // class C extends public // error at public + if (expression && expression.kind === SyntaxKind.Identifier) { + return checkGrammarIdentifierInStrictMode(expression); + } + else if (expression && expression.kind === SyntaxKind.PropertyAccessExpression) { + let propertyAccessExp = expression; + + // Keep traverse from right to left in propertyAccessExpression and report an error at each name + // in the PropertyAccessExpression. + // Stop when expression is no longer a propertyAccessExpression, then it must be the first + // expression in PropertyAccessExpression and must be an Identifier. + // Example: + // public.private.package // error at package, private + while (propertyAccessExp && propertyAccessExp.kind === SyntaxKind.PropertyAccessExpression) { + checkGrammarIdentifierInStrictMode(propertyAccessExp.name); + propertyAccessExp = propertyAccessExp.expression; + } + + // Report an error at the first expression in PropertyAccessExpression + // Example: + // public.private.package // error at public + checkGrammarIdentifierInStrictMode(propertyAccessExp); + } + + } + + // The function takes an identifier itself or an expression which has SyntaxKind.Identifier. + function checkGrammarIdentifierInStrictMode(node: Expression | Identifier, nameText?: string): boolean { + if (node && node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(node)) { + if (!nameText) { + nameText = declarationNameToString(node); + } + + // TODO (yuisu): Fix when module is a strict mode + let errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText)|| + grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; + } + return false; + } + + // The function takes an identifier when uses as a typeName in TypeReferenceNode + function checkGrammarTypeNameInStrictMode(node: Identifier): boolean { + if (node && node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(node)) { let nameText = declarationNameToString(node); - return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + + // TODO (yuisu): Fix when module is a strict mode + let errorReport = reportStrictModeGrammarErrorInClassDeclaration(node, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || + grammarErrorOnNode(node, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText); + return errorReport; } return false; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 200c36bea51..a8a3dfbe8d9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1487,9 +1487,9 @@ module ts { if (isIdentifier) { let node = createNode(SyntaxKind.Identifier); - // Store original token kind so we can report appropriate error later in type checker - if (token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastFutureReservedWord) { - node.originalSyntaxKind = token; + // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker + if (token !== SyntaxKind.Identifier) { + node.originalStrictModeSyntaxKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 27e38ff7178..b436ad115f6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -386,8 +386,8 @@ module ts { } export interface Identifier extends PrimaryExpression { - text: string; // Text of identifier (with escapes converted to characters) - originalSyntaxKind?: SyntaxKind; // original syntaxKind which get set so that we can report an error later + text: string; // Text of identifier (with escapes converted to characters) + originalStrictModeSyntaxKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later } export interface QualifiedName extends Node { From bf60eabdbbd525c4adcb63bdfabac09df66166b1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Apr 2015 14:24:10 -0700 Subject: [PATCH 17/23] Update tests cases --- .../parserComputedPropertyName36.errors.txt | 4 +- .../parserComputedPropertyName38.errors.txt | 4 +- .../parserComputedPropertyName39.errors.txt | 4 +- .../reference/strictModeCode1.errors.txt | 43 ++++++++++--- tests/baselines/reference/strictModeCode1.js | 31 +++++++++- .../reference/strictModeCode2.errors.txt | 60 ++++++++++++++++++- tests/baselines/reference/strictModeCode2.js | 12 ++++ tests/cases/compiler/strictModeCode1.ts | 6 +- tests/cases/compiler/strictModeCode2.ts | 7 +++ 9 files changed, 153 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/parserComputedPropertyName36.errors.txt b/tests/baselines/reference/parserComputedPropertyName36.errors.txt index a6fa988ec32..6bcb5b52789 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName36.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS2304: Cannot find name 'public'. @@ -9,7 +9,7 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedP ~~~~~~~~~ !!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ !!! error TS2304: Cannot find name 'public'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt index 807b91cd3e5..80589f1fde3 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName38.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS2304: Cannot find name 'public'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedP class C { [public]() { } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ !!! error TS2304: Cannot find name 'public'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName39.errors.txt b/tests/baselines/reference/parserComputedPropertyName39.errors.txt index 766ae402491..0213127f6d9 100644 --- a/tests/baselines/reference/parserComputedPropertyName39.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName39.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts(3,6): error TS2304: Cannot find name 'public'. @@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedP class C { [public]() { } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ !!! error TS2304: Cannot find name 'public'. } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index 7c80a4a71d5..f33163a7f03 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -1,9 +1,9 @@ tests/cases/compiler/strictModeCode1.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(5,9): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode1.ts(5,19): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode1.ts(5,28): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(5,9): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(5,19): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(5,28): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(7,22): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -13,10 +13,17 @@ tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expecte tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(23,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode1.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(25,20): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode1.ts(25,27): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(26,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(26,17): error TS2304: Cannot find name 'package'. +tests/cases/compiler/strictModeCode1.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name 'package'. -==== tests/cases/compiler/strictModeCode1.ts (16 errors) ==== +==== tests/cases/compiler/strictModeCode1.ts (23 errors) ==== interface public { } class Foo { @@ -29,11 +36,11 @@ tests/cases/compiler/strictModeCode1.ts(23,20): error TS1212: Identifier expecte !!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. private = public = static; ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. } public banana(x: public) { } ~~~~~~ @@ -71,4 +78,22 @@ tests/cases/compiler/strictModeCode1.ts(23,20): error TS1212: Identifier expecte class E implements public { } ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + + class F implements public.private.B { } + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~~~~~~~ +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + class G extends package { } + ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS2304: Cannot find name 'package'. + class H extends package.A { } + ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS2304: Cannot find name 'package'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.js b/tests/baselines/reference/strictModeCode1.js index 32d3eb93242..88ff24d1b36 100644 --- a/tests/baselines/reference/strictModeCode1.js +++ b/tests/baselines/reference/strictModeCode1.js @@ -21,9 +21,19 @@ class C { class D{ } -class E implements public { } +class E implements public { } + +class F implements public.private.B { } +class G extends package { } +class H extends package.A { } //// [strictModeCode1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; var Foo = (function () { function Foo(private, public, static) { private = public = static; @@ -52,3 +62,22 @@ var E = (function () { } return E; })(); +var F = (function () { + function F() { + } + return F; +})(); +var G = (function (_super) { + __extends(G, _super); + function G() { + _super.apply(this, arguments); + } + return G; +})(package); +var H = (function (_super) { + __extends(H, _super); + function H() { + _super.apply(this, arguments); + } + return H; +})(package.A); diff --git a/tests/baselines/reference/strictModeCode2.errors.txt b/tests/baselines/reference/strictModeCode2.errors.txt index 072e35d19e4..3016f02af7a 100644 --- a/tests/baselines/reference/strictModeCode2.errors.txt +++ b/tests/baselines/reference/strictModeCode2.errors.txt @@ -17,9 +17,26 @@ tests/cases/compiler/strictModeCode2.ts(13,11): error TS1212: Identifier expecte tests/cases/compiler/strictModeCode2.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expressions are not currently supported. +tests/cases/compiler/strictModeCode2.ts(17,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeCode2.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(17,12): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode2.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(19,21): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(20,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(21,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(22,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeCode2.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(22,12): error TS2304: Cannot find name 'interface'. +tests/cases/compiler/strictModeCode2.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode -==== tests/cases/compiler/strictModeCode2.ts (19 errors) ==== +==== tests/cases/compiler/strictModeCode2.ts (36 errors) ==== let let = 10; function foo() { @@ -73,6 +90,47 @@ tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expression var myClass = class package extends public {} ~~~~~~~ !!! error TS9003: 'class' expressions are not currently supported. + + var b: public.bar; + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~~~~~~ +!!! error TS1215: Type expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + + function foo(x: private.x) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + function foo1(x: private.package.x) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + function foo2(x: private.package.protected) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1215: Type expected. 'protected' is a reserved word in strict mode + let b: interface.package.implements.B; + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~~~~~~~~~ +!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'interface'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + ~~~~~~~~~~ +!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode2.js b/tests/baselines/reference/strictModeCode2.js index a49ca5946de..e3f7bc83369 100644 --- a/tests/baselines/reference/strictModeCode2.js +++ b/tests/baselines/reference/strictModeCode2.js @@ -14,6 +14,13 @@ function foo() { barn((private, public, package) => { }); var myClass = class package extends public {} + + var b: public.bar; + + function foo(x: private.x) { } + function foo1(x: private.package.x) { } + function foo2(x: private.package.protected) { } + let b: interface.package.implements.B; } @@ -38,4 +45,9 @@ function foo() { } return package; })(public); + var b; + function foo(x) { } + function foo1(x) { } + function foo2(x) { } + var b; } diff --git a/tests/cases/compiler/strictModeCode1.ts b/tests/cases/compiler/strictModeCode1.ts index e67a27dca77..0a7426d35c5 100644 --- a/tests/cases/compiler/strictModeCode1.ts +++ b/tests/cases/compiler/strictModeCode1.ts @@ -20,4 +20,8 @@ class C { class D{ } -class E implements public { } \ No newline at end of file +class E implements public { } + +class F implements public.private.B { } +class G extends package { } +class H extends package.A { } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode2.ts b/tests/cases/compiler/strictModeCode2.ts index f0ba008d86d..6336329ae71 100644 --- a/tests/cases/compiler/strictModeCode2.ts +++ b/tests/cases/compiler/strictModeCode2.ts @@ -13,5 +13,12 @@ function foo() { barn((private, public, package) => { }); var myClass = class package extends public {} + + var b: public.bar; + + function foo(x: private.x) { } + function foo1(x: private.package.x) { } + function foo2(x: private.package.protected) { } + let b: interface.package.implements.B; } From 8448ba7b13f87242ec5631b9786474c51b06ffcf Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Apr 2015 16:22:09 -0700 Subject: [PATCH 18/23] Allow IdentifierName in memberExpression --- src/compiler/checker.ts | 46 +++++-------------- .../reference/strictModeCode1.errors.txt | 20 ++++---- tests/baselines/reference/strictModeCode1.js | 6 +++ .../reference/strictModeCode2.errors.txt | 29 +----------- tests/cases/compiler/strictModeCode1.ts | 1 + 5 files changed, 28 insertions(+), 74 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e75515cbb56..48b66562fa6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12012,35 +12012,22 @@ module ts { } // Report an error for each identifier in QualifiedName // Example: - // foo (x: public.private.bar) // Error at public, private - // foo (x: public.private.package) // Error at public, private, package + // foo (x: public.private.bar) // no Error + // foo (x: public.private.package) // error at package else if (typeName.kind === SyntaxKind.QualifiedName) { - let partOfTypeName = typeName; - - // Keep traverse from right to left in QualifiedName and report an error at each one - // Stop when the next left is not longer a QualifiedName, then it must be the first component - // in QualifiedName and must be an Identifier. + // Report strict mode at the property of memberExpression // Example: - // x1: public.private.package // Error at public, private - while (partOfTypeName && partOfTypeName.kind === SyntaxKind.QualifiedName) { - let name = (partOfTypeName).right; - checkGrammarTypeNameInStrictMode(name); - partOfTypeName = (partOfTypeName).left; - } - - // Report and error at the component in QualifiedName which must be an identifier. - // Example: - // x1: public.private.package // Error at package - checkGrammarTypeNameInStrictMode(partOfTypeName); + // x1: public.private.package // error at package as memberExpression can be IdentifierName + checkGrammarTypeNameInStrictMode((typeName).right); } } // This function will report an error for every identifier in property access expression // whether it violates strict mode reserved words. // Example: - // public.B // error at public - // public.private.A // error at public and private - // public.private.package // error at public and private and package + // public // error at public + // public.private.package // error at package + // public.private.B // no error function checkGrammarHeritageClauseElementInStrictMode(expression: Expression) { // Example: // class C extends public // error at public @@ -12050,21 +12037,10 @@ module ts { else if (expression && expression.kind === SyntaxKind.PropertyAccessExpression) { let propertyAccessExp = expression; - // Keep traverse from right to left in propertyAccessExpression and report an error at each name - // in the PropertyAccessExpression. - // Stop when expression is no longer a propertyAccessExpression, then it must be the first - // expression in PropertyAccessExpression and must be an Identifier. + // Report strict mode at the property of memberExpression // Example: - // public.private.package // error at package, private - while (propertyAccessExp && propertyAccessExp.kind === SyntaxKind.PropertyAccessExpression) { - checkGrammarIdentifierInStrictMode(propertyAccessExp.name); - propertyAccessExp = propertyAccessExp.expression; - } - - // Report an error at the first expression in PropertyAccessExpression - // Example: - // public.private.package // error at public - checkGrammarIdentifierInStrictMode(propertyAccessExp); + // public.private.package // error at package as memberExpression can be IdentifierName + checkGrammarIdentifierInStrictMode((expression).name); } } diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index f33163a7f03..c32fca7997d 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -14,16 +14,15 @@ tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expecte tests/cases/compiler/strictModeCode1.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(25,20): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode1.ts(25,27): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(26,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(26,17): error TS2304: Cannot find name 'package'. +tests/cases/compiler/strictModeCode1.ts(26,21): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode1.ts(26,36): error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name 'package'. +tests/cases/compiler/strictModeCode1.ts(28,17): error TS2304: Cannot find name 'package'. -==== tests/cases/compiler/strictModeCode1.ts (23 errors) ==== +==== tests/cases/compiler/strictModeCode1.ts (22 errors) ==== interface public { } class Foo { @@ -82,11 +81,12 @@ tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name ' class F implements public.private.B { } ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ !!! error TS2304: Cannot find name 'public'. - ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + class F1 implements public.private.implements { } + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~~~~~~~~~~ +!!! error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. class G extends package { } ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -94,6 +94,4 @@ tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name ' !!! error TS2304: Cannot find name 'package'. class H extends package.A { } ~~~~~~~ -!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~~ !!! error TS2304: Cannot find name 'package'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.js b/tests/baselines/reference/strictModeCode1.js index 88ff24d1b36..1a7b93417c6 100644 --- a/tests/baselines/reference/strictModeCode1.js +++ b/tests/baselines/reference/strictModeCode1.js @@ -24,6 +24,7 @@ class D{ } class E implements public { } class F implements public.private.B { } +class F1 implements public.private.implements { } class G extends package { } class H extends package.A { } @@ -67,6 +68,11 @@ var F = (function () { } return F; })(); +var F1 = (function () { + function F1() { + } + return F1; +})(); var G = (function (_super) { __extends(G, _super); function G() { diff --git a/tests/baselines/reference/strictModeCode2.errors.txt b/tests/baselines/reference/strictModeCode2.errors.txt index 3016f02af7a..e6c338a2def 100644 --- a/tests/baselines/reference/strictModeCode2.errors.txt +++ b/tests/baselines/reference/strictModeCode2.errors.txt @@ -18,25 +18,16 @@ tests/cases/compiler/strictModeCode2.ts(13,20): error TS1212: Identifier expecte tests/cases/compiler/strictModeCode2.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expressions are not currently supported. tests/cases/compiler/strictModeCode2.ts(17,9): error TS2300: Duplicate identifier 'b'. -tests/cases/compiler/strictModeCode2.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(17,12): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode2.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(19,21): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(20,22): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(21,22): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(22,9): error TS2300: Duplicate identifier 'b'. -tests/cases/compiler/strictModeCode2.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(22,12): error TS2304: Cannot find name 'interface'. -tests/cases/compiler/strictModeCode2.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode -==== tests/cases/compiler/strictModeCode2.ts (36 errors) ==== +==== tests/cases/compiler/strictModeCode2.ts (27 errors) ==== let let = 10; function foo() { @@ -95,42 +86,24 @@ tests/cases/compiler/strictModeCode2.ts(22,30): error TS1215: Type expected. 'im ~ !!! error TS2300: Duplicate identifier 'b'. ~~~~~~ -!!! error TS1215: Type expected. 'public' is a reserved word in strict mode - ~~~~~~ !!! error TS2304: Cannot find name 'public'. function foo(x: private.x) { } ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ !!! error TS2304: Cannot find name 'private'. function foo1(x: private.package.x) { } ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ !!! error TS2304: Cannot find name 'private'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode function foo2(x: private.package.protected) { } ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ !!! error TS2304: Cannot find name 'private'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode ~~~~~~~~~ !!! error TS1215: Type expected. 'protected' is a reserved word in strict mode let b: interface.package.implements.B; ~ !!! error TS2300: Duplicate identifier 'b'. ~~~~~~~~~ -!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode - ~~~~~~~~~ !!! error TS2304: Cannot find name 'interface'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode - ~~~~~~~~~~ -!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode1.ts b/tests/cases/compiler/strictModeCode1.ts index 0a7426d35c5..9035ca2f4ff 100644 --- a/tests/cases/compiler/strictModeCode1.ts +++ b/tests/cases/compiler/strictModeCode1.ts @@ -23,5 +23,6 @@ class D{ } class E implements public { } class F implements public.private.B { } +class F1 implements public.private.implements { } class G extends package { } class H extends package.A { } \ No newline at end of file From fe7a3a5d02b017ec3d898b5ddf2920f05ee4e7a5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Apr 2015 18:52:37 -0700 Subject: [PATCH 19/23] Address CR --- src/compiler/checker.ts | 42 ++++++++++++------- .../reference/strictModeCode1.errors.txt | 14 +++++-- .../reference/strictModeCode2.errors.txt | 33 +++++++++++++-- 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 48b66562fa6..4d7cb4c472a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11925,10 +11925,7 @@ module ts { // GRAMMAR CHECKING function isReservedwordInStrictMode(node: Identifier): boolean { // Check that originalStrictModeSyntaxKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word - if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalStrictModeSyntaxKind <= SyntaxKind.LastFutureReservedWord) { - return true; - } - return false + return (node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalStrictModeSyntaxKind <= SyntaxKind.LastFutureReservedWord; } function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { @@ -11959,7 +11956,7 @@ module ts { let name = element.name; if (name.originalStrictModeSyntaxKind) { let nameText = declarationNameToString(name); - reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + reportError = reportError || grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -12012,13 +12009,22 @@ module ts { } // Report an error for each identifier in QualifiedName // Example: - // foo (x: public.private.bar) // no Error - // foo (x: public.private.package) // error at package + // foo (x: B.private.bar) // error at private + // foo (x: public.private.package) // error at public, private, and package else if (typeName.kind === SyntaxKind.QualifiedName) { - // Report strict mode at the property of memberExpression + // Walk from right to left and report a possible error at each Identifier in QualifiedName // Example: - // x1: public.private.package // error at package as memberExpression can be IdentifierName - checkGrammarTypeNameInStrictMode((typeName).right); + // x1: public.private.package // error at public and private + let qualifiedName = typeName; + while (qualifiedName && qualifiedName.kind === SyntaxKind.QualifiedName) { + checkGrammarTypeNameInStrictMode((qualifiedName).right); + qualifiedName = (qualifiedName).left; + } + + // Report an error at the last Identifier in QualifiedName + // Example: + // x1: public.private.package // error at package + checkGrammarTypeNameInStrictMode(qualifiedName); } } @@ -12026,8 +12032,8 @@ module ts { // whether it violates strict mode reserved words. // Example: // public // error at public - // public.private.package // error at package - // public.private.B // no error + // public.private.package // error at public + // B.private.B // no error function checkGrammarHeritageClauseElementInStrictMode(expression: Expression) { // Example: // class C extends public // error at public @@ -12037,10 +12043,18 @@ module ts { else if (expression && expression.kind === SyntaxKind.PropertyAccessExpression) { let propertyAccessExp = expression; + // Walk from left to right in PropertyAccessExpression until we are at the left most expression + // in PropertyAccessExpression. According to grammar production of MemberExpression, + // the left component expression is a PrimaryExpression (i.e. Identifier) while the other + // component after dots can be IdentifierName. + while (propertyAccessExp && propertyAccessExp.kind === SyntaxKind.PropertyAccessExpression) { + propertyAccessExp = propertyAccessExp.expression; + } + // Report strict mode at the property of memberExpression // Example: - // public.private.package // error at package as memberExpression can be IdentifierName - checkGrammarIdentifierInStrictMode((expression).name); + // public.private.package // error at public as it is parsed as an Identifier in the PropertyAccessExpression + checkGrammarIdentifierInStrictMode(propertyAccessExp); } } diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt index c32fca7997d..a9a2c50a6ca 100644 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ b/tests/baselines/reference/strictModeCode1.errors.txt @@ -14,15 +14,17 @@ tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expecte tests/cases/compiler/strictModeCode1.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeCode1.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(25,20): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode1.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(26,21): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode1.ts(26,36): error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name 'package'. +tests/cases/compiler/strictModeCode1.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeCode1.ts(28,17): error TS2304: Cannot find name 'package'. -==== tests/cases/compiler/strictModeCode1.ts (22 errors) ==== +==== tests/cases/compiler/strictModeCode1.ts (24 errors) ==== interface public { } class Foo { @@ -81,12 +83,14 @@ tests/cases/compiler/strictModeCode1.ts(28,17): error TS2304: Cannot find name ' class F implements public.private.B { } ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ !!! error TS2304: Cannot find name 'public'. class F1 implements public.private.implements { } ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ !!! error TS2304: Cannot find name 'public'. - ~~~~~~~~~~ -!!! error TS1213: Identifier expected. 'implements' is a reserved word in strict mode. Class definitions are automatically in strict mode. class G extends package { } ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -94,4 +98,6 @@ tests/cases/compiler/strictModeCode1.ts(28,17): error TS2304: Cannot find name ' !!! error TS2304: Cannot find name 'package'. class H extends package.A { } ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ !!! error TS2304: Cannot find name 'package'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode2.errors.txt b/tests/baselines/reference/strictModeCode2.errors.txt index e6c338a2def..3016f02af7a 100644 --- a/tests/baselines/reference/strictModeCode2.errors.txt +++ b/tests/baselines/reference/strictModeCode2.errors.txt @@ -18,16 +18,25 @@ tests/cases/compiler/strictModeCode2.ts(13,20): error TS1212: Identifier expecte tests/cases/compiler/strictModeCode2.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expressions are not currently supported. tests/cases/compiler/strictModeCode2.ts(17,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeCode2.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(17,12): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeCode2.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(19,21): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(20,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(21,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeCode2.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(22,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeCode2.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode tests/cases/compiler/strictModeCode2.ts(22,12): error TS2304: Cannot find name 'interface'. +tests/cases/compiler/strictModeCode2.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeCode2.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode -==== tests/cases/compiler/strictModeCode2.ts (27 errors) ==== +==== tests/cases/compiler/strictModeCode2.ts (36 errors) ==== let let = 10; function foo() { @@ -86,24 +95,42 @@ tests/cases/compiler/strictModeCode2.ts(22,12): error TS2304: Cannot find name ' ~ !!! error TS2300: Duplicate identifier 'b'. ~~~~~~ +!!! error TS1215: Type expected. 'public' is a reserved word in strict mode + ~~~~~~ !!! error TS2304: Cannot find name 'public'. function foo(x: private.x) { } ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ !!! error TS2304: Cannot find name 'private'. function foo1(x: private.package.x) { } ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. - function foo2(x: private.package.protected) { } +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode ~~~~~~~ !!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + function foo2(x: private.package.protected) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode ~~~~~~~~~ !!! error TS1215: Type expected. 'protected' is a reserved word in strict mode let b: interface.package.implements.B; ~ !!! error TS2300: Duplicate identifier 'b'. ~~~~~~~~~ +!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode + ~~~~~~~~~ !!! error TS2304: Cannot find name 'interface'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + ~~~~~~~~~~ +!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode } \ No newline at end of file From a60cf0271595599d8efd9a80b5e5ec110073a9a1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Apr 2015 19:00:31 -0700 Subject: [PATCH 20/23] Address CR --- src/compiler/checker.ts | 8 ++++---- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4d7cb4c472a..59400b959b3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11924,8 +11924,8 @@ module ts { // GRAMMAR CHECKING function isReservedwordInStrictMode(node: Identifier): boolean { - // Check that originalStrictModeSyntaxKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word - return (node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalStrictModeSyntaxKind <= SyntaxKind.LastFutureReservedWord; + // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word + return (node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord; } function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { @@ -11945,7 +11945,7 @@ module ts { let nameBindings = impotClause.namedBindings; if (nameBindings.kind === SyntaxKind.NamespaceImport) { let name = (nameBindings).name; - if (name.originalStrictModeSyntaxKind) { + if (name.originalKeywordKind) { let nameText = declarationNameToString(name); return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } @@ -11954,7 +11954,7 @@ module ts { let reportError = false; for (let element of (nameBindings).elements) { let name = element.name; - if (name.originalStrictModeSyntaxKind) { + if (name.originalKeywordKind) { let nameText = declarationNameToString(name); reportError = reportError || grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a8a3dfbe8d9..56eb6d9aa3c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1489,7 +1489,7 @@ module ts { // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker if (token !== SyntaxKind.Identifier) { - node.originalStrictModeSyntaxKind = token; + node.originalKeywordKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b436ad115f6..bac41694a88 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -387,7 +387,7 @@ module ts { export interface Identifier extends PrimaryExpression { text: string; // Text of identifier (with escapes converted to characters) - originalStrictModeSyntaxKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later + originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later } export interface QualifiedName extends Node { From 3c2196bf54e7dfc21ba6d58d9ec630e3848b2123 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 11 Apr 2015 12:15:22 -0700 Subject: [PATCH 21/23] Address code review --- src/compiler/checker.ts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 59400b959b3..123346aa210 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11925,7 +11925,8 @@ module ts { // GRAMMAR CHECKING function isReservedwordInStrictMode(node: Identifier): boolean { // Check that originalKeywordKind is less than LastFurtureReservedWord to see if an Identifier is a strict-mode reserved word - return (node.parserContextFlags & ParserContextFlags.StrictMode) && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord; + return (node.parserContextFlags & ParserContextFlags.StrictMode) && + (node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord); } function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean { @@ -12015,16 +12016,8 @@ module ts { // Walk from right to left and report a possible error at each Identifier in QualifiedName // Example: // x1: public.private.package // error at public and private - let qualifiedName = typeName; - while (qualifiedName && qualifiedName.kind === SyntaxKind.QualifiedName) { - checkGrammarTypeNameInStrictMode((qualifiedName).right); - qualifiedName = (qualifiedName).left; - } - - // Report an error at the last Identifier in QualifiedName - // Example: - // x1: public.private.package // error at package - checkGrammarTypeNameInStrictMode(qualifiedName); + checkGrammarTypeNameInStrictMode((typeName).right); + checkGrammarTypeReferenceInStrictMode((typeName).left); } } @@ -12034,27 +12027,18 @@ module ts { // public // error at public // public.private.package // error at public // B.private.B // no error - function checkGrammarHeritageClauseElementInStrictMode(expression: Expression) { + function checkGrammarHeritageClauseElementInStrictMode(expression: PropertyAccessExpression) { // Example: // class C extends public // error at public if (expression && expression.kind === SyntaxKind.Identifier) { return checkGrammarIdentifierInStrictMode(expression); } else if (expression && expression.kind === SyntaxKind.PropertyAccessExpression) { - let propertyAccessExp = expression; - // Walk from left to right in PropertyAccessExpression until we are at the left most expression // in PropertyAccessExpression. According to grammar production of MemberExpression, // the left component expression is a PrimaryExpression (i.e. Identifier) while the other // component after dots can be IdentifierName. - while (propertyAccessExp && propertyAccessExp.kind === SyntaxKind.PropertyAccessExpression) { - propertyAccessExp = propertyAccessExp.expression; - } - - // Report strict mode at the property of memberExpression - // Example: - // public.private.package // error at public as it is parsed as an Identifier in the PropertyAccessExpression - checkGrammarIdentifierInStrictMode(propertyAccessExp); + checkGrammarHeritageClauseElementInStrictMode(expression.expression); } } From 65b8792be787da8e34b7b795c5c42dc8a9abe500 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 11 Apr 2015 12:15:47 -0700 Subject: [PATCH 22/23] Organize test cases for strict mode --- ...errorRecoveryInClassDeclaration.errors.txt | 25 +++ ....js => errorRecoveryInClassDeclaration.js} | 4 +- .../reference/reservedWords2.errors.txt | 85 ++++++++++ tests/baselines/reference/reservedWords2.js | 37 +++++ .../reference/strictModeCode1.errors.txt | 103 ------------ .../reference/strictModeCode2.errors.txt | 136 ---------------- .../reference/strictModeCode3.errors.txt | 24 --- tests/baselines/reference/strictModeCode3.js | 13 -- .../reference/strictModeCode4.errors.txt | 25 --- .../reference/strictModeCode5.errors.txt | 30 ---- .../reference/strictModeCode6.errors.txt | 22 --- .../reference/strictModeCode7.errors.txt | 12 -- tests/baselines/reference/strictModeCode7.js | 7 - .../reference/strictModeCode8.errors.txt | 24 --- .../strictModeReservedWord.errors.txt | 147 ++++++++++++++++++ ...ModeCode2.js => strictModeReservedWord.js} | 8 +- .../strictModeReservedWord2.errors.txt | 45 ++++++ .../reference/strictModeReservedWord2.js | 37 +++++ ...eReservedWordInClassDeclaration.errors.txt | 103 ++++++++++++ ...rictModeReservedWordInClassDeclaration.js} | 4 +- ...ModeReservedWordInDestructuring.errors.txt | 30 ++++ ... strictModeReservedWordInDestructuring.js} | 4 +- ...vedWordInImportEqualDeclaration.errors.txt | 12 ++ ...odeReservedWordInImportEqualDeclaration.js | 7 + ...ReservedWordInModuleDeclaration.errors.txt | 24 +++ ...ictModeReservedWordInModuleDeclaration.js} | 4 +- .../strictModeWordInExportDeclaration.js | 13 ++ .../strictModeWordInExportDeclaration.types | 17 ++ ...rictModeWordInImportDeclaration.errors.txt | 22 +++ ...s => strictModeWordInImportDeclaration.js} | 4 +- ....ts => errorRecoveryInClassDeclaration.ts} | 0 tests/cases/compiler/reservedWords2.ts | 12 ++ tests/cases/compiler/strictModeCode3.ts | 6 - ...ModeCode2.ts => strictModeReservedWord.ts} | 2 + .../cases/compiler/strictModeReservedWord2.ts | 23 +++ ...rictModeReservedWordInClassDeclaration.ts} | 0 ... strictModeReservedWordInDestructuring.ts} | 0 ...deReservedWordInImportEqualDeclaration.ts} | 0 ...ictModeReservedWordInModuleDeclaration.ts} | 0 .../strictModeWordInExportDeclaration.ts | 6 + ...s => strictModeWordInImportDeclaration.ts} | 0 41 files changed, 663 insertions(+), 414 deletions(-) create mode 100644 tests/baselines/reference/errorRecoveryInClassDeclaration.errors.txt rename tests/baselines/reference/{strictModeCode4.js => errorRecoveryInClassDeclaration.js} (72%) create mode 100644 tests/baselines/reference/reservedWords2.errors.txt create mode 100644 tests/baselines/reference/reservedWords2.js delete mode 100644 tests/baselines/reference/strictModeCode1.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode2.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode3.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode3.js delete mode 100644 tests/baselines/reference/strictModeCode4.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode5.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode6.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode7.errors.txt delete mode 100644 tests/baselines/reference/strictModeCode7.js delete mode 100644 tests/baselines/reference/strictModeCode8.errors.txt create mode 100644 tests/baselines/reference/strictModeReservedWord.errors.txt rename tests/baselines/reference/{strictModeCode2.js => strictModeReservedWord.js} (89%) create mode 100644 tests/baselines/reference/strictModeReservedWord2.errors.txt create mode 100644 tests/baselines/reference/strictModeReservedWord2.js create mode 100644 tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt rename tests/baselines/reference/{strictModeCode1.js => strictModeReservedWordInClassDeclaration.js} (91%) create mode 100644 tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt rename tests/baselines/reference/{strictModeCode5.js => strictModeReservedWordInDestructuring.js} (82%) create mode 100644 tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.errors.txt create mode 100644 tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.js create mode 100644 tests/baselines/reference/strictModeReservedWordInModuleDeclaration.errors.txt rename tests/baselines/reference/{strictModeCode8.js => strictModeReservedWordInModuleDeclaration.js} (52%) create mode 100644 tests/baselines/reference/strictModeWordInExportDeclaration.js create mode 100644 tests/baselines/reference/strictModeWordInExportDeclaration.types create mode 100644 tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt rename tests/baselines/reference/{strictModeCode6.js => strictModeWordInImportDeclaration.js} (56%) rename tests/cases/compiler/{strictModeCode4.ts => errorRecoveryInClassDeclaration.ts} (100%) create mode 100644 tests/cases/compiler/reservedWords2.ts delete mode 100644 tests/cases/compiler/strictModeCode3.ts rename tests/cases/compiler/{strictModeCode2.ts => strictModeReservedWord.ts} (92%) create mode 100644 tests/cases/compiler/strictModeReservedWord2.ts rename tests/cases/compiler/{strictModeCode1.ts => strictModeReservedWordInClassDeclaration.ts} (100%) rename tests/cases/compiler/{strictModeCode5.ts => strictModeReservedWordInDestructuring.ts} (100%) rename tests/cases/compiler/{strictModeCode7.ts => strictModeReservedWordInImportEqualDeclaration.ts} (100%) rename tests/cases/compiler/{strictModeCode8.ts => strictModeReservedWordInModuleDeclaration.ts} (100%) create mode 100644 tests/cases/compiler/strictModeWordInExportDeclaration.ts rename tests/cases/compiler/{strictModeCode6.ts => strictModeWordInImportDeclaration.ts} (100%) diff --git a/tests/baselines/reference/errorRecoveryInClassDeclaration.errors.txt b/tests/baselines/reference/errorRecoveryInClassDeclaration.errors.txt new file mode 100644 index 00000000000..0835a7f256d --- /dev/null +++ b/tests/baselines/reference/errorRecoveryInClassDeclaration.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/errorRecoveryInClassDeclaration.ts(3,17): error TS2304: Cannot find name 'foo'. +tests/cases/compiler/errorRecoveryInClassDeclaration.ts(4,13): error TS2304: Cannot find name 'public'. +tests/cases/compiler/errorRecoveryInClassDeclaration.ts(4,20): error TS1005: ',' expected. +tests/cases/compiler/errorRecoveryInClassDeclaration.ts(4,20): error TS2304: Cannot find name 'blaz'. +tests/cases/compiler/errorRecoveryInClassDeclaration.ts(4,27): error TS1005: ',' expected. + + +==== tests/cases/compiler/errorRecoveryInClassDeclaration.ts (5 errors) ==== + class C { + public bar() { + var v = foo( + ~~~ +!!! error TS2304: Cannot find name 'foo'. + public blaz() {} + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~~~~ +!!! error TS1005: ',' expected. + ~~~~ +!!! error TS2304: Cannot find name 'blaz'. + ~ +!!! error TS1005: ',' expected. + ); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode4.js b/tests/baselines/reference/errorRecoveryInClassDeclaration.js similarity index 72% rename from tests/baselines/reference/strictModeCode4.js rename to tests/baselines/reference/errorRecoveryInClassDeclaration.js index cfc9f008e72..7f95bed19f9 100644 --- a/tests/baselines/reference/strictModeCode4.js +++ b/tests/baselines/reference/errorRecoveryInClassDeclaration.js @@ -1,4 +1,4 @@ -//// [strictModeCode4.ts] +//// [errorRecoveryInClassDeclaration.ts] class C { public bar() { var v = foo( @@ -7,7 +7,7 @@ class C { } } -//// [strictModeCode4.js] +//// [errorRecoveryInClassDeclaration.js] var C = (function () { function C() { } diff --git a/tests/baselines/reference/reservedWords2.errors.txt b/tests/baselines/reference/reservedWords2.errors.txt new file mode 100644 index 00000000000..ec4b7b09887 --- /dev/null +++ b/tests/baselines/reference/reservedWords2.errors.txt @@ -0,0 +1,85 @@ +tests/cases/compiler/reservedWords2.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/compiler/reservedWords2.ts(1,8): error TS1109: Expression expected. +tests/cases/compiler/reservedWords2.ts(1,14): error TS1005: '(' expected. +tests/cases/compiler/reservedWords2.ts(1,16): error TS2304: Cannot find name 'require'. +tests/cases/compiler/reservedWords2.ts(1,31): error TS1005: ')' expected. +tests/cases/compiler/reservedWords2.ts(2,12): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/reservedWords2.ts(2,14): error TS1003: Identifier expected. +tests/cases/compiler/reservedWords2.ts(2,20): error TS1005: '(' expected. +tests/cases/compiler/reservedWords2.ts(2,20): error TS2304: Cannot find name 'from'. +tests/cases/compiler/reservedWords2.ts(2,25): error TS1005: ')' expected. +tests/cases/compiler/reservedWords2.ts(4,5): error TS1134: Variable declaration expected. +tests/cases/compiler/reservedWords2.ts(4,12): error TS1109: Expression expected. +tests/cases/compiler/reservedWords2.ts(5,9): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/reservedWords2.ts(5,10): error TS1003: Identifier expected. +tests/cases/compiler/reservedWords2.ts(5,18): error TS1005: '=>' expected. +tests/cases/compiler/reservedWords2.ts(6,7): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/reservedWords2.ts(6,8): error TS1003: Identifier expected. +tests/cases/compiler/reservedWords2.ts(9,6): error TS1181: Array element destructuring pattern expected. +tests/cases/compiler/reservedWords2.ts(9,14): error TS1005: ';' expected. +tests/cases/compiler/reservedWords2.ts(9,18): error TS1005: '(' expected. +tests/cases/compiler/reservedWords2.ts(9,20): error TS1128: Declaration or statement expected. +tests/cases/compiler/reservedWords2.ts(10,5): error TS2300: Duplicate identifier '(Missing)'. +tests/cases/compiler/reservedWords2.ts(10,6): error TS1003: Identifier expected. + + +==== tests/cases/compiler/reservedWords2.ts (23 errors) ==== + import while = require("dfdf"); + ~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + ~~~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'require'. + ~ +!!! error TS1005: ')' expected. + import * as while from "foo" + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~ +!!! error TS1003: Identifier expected. + ~~~~ +!!! error TS1005: '(' expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~ +!!! error TS1005: ')' expected. + + var typeof = 10; + ~~~~~~ +!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1109: Expression expected. + function throw() {} + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '=>' expected. + module void {} + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~ +!!! error TS1003: Identifier expected. + var {while, return} = { while: 1, return: 2 }; + var {this, switch: { continue} } = { this: 1, switch: { continue: 2 }}; + var [debugger, if] = [1, 2]; + ~~~~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1005: '(' expected. + ~ +!!! error TS1128: Declaration or statement expected. + enum void {} + +!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~ +!!! error TS1003: Identifier expected. + + + \ No newline at end of file diff --git a/tests/baselines/reference/reservedWords2.js b/tests/baselines/reference/reservedWords2.js new file mode 100644 index 00000000000..4bda38842a3 --- /dev/null +++ b/tests/baselines/reference/reservedWords2.js @@ -0,0 +1,37 @@ +//// [reservedWords2.ts] +import while = require("dfdf"); +import * as while from "foo" + +var typeof = 10; +function throw() {} +module void {} +var {while, return} = { while: 1, return: 2 }; +var {this, switch: { continue} } = { this: 1, switch: { continue: 2 }}; +var [debugger, if] = [1, 2]; +enum void {} + + + + +//// [reservedWords2.js] +require(); +while ( = require("dfdf")) + ; +while (from) + "foo"; +var ; +typeof ; +10; +throw function () { }; +void {}; +var _a = { while: 1, return: 2 }, while = _a.while, return = _a.return; +var _b = { this: 1, switch: { continue: 2 } }, this = _b.this, continue = _b.switch.continue; +var _c = void 0; +debugger; +if () + ; +[1, 2]; +var ; +(function () { +})( || ( = {})); +void {}; diff --git a/tests/baselines/reference/strictModeCode1.errors.txt b/tests/baselines/reference/strictModeCode1.errors.txt deleted file mode 100644 index a9a2c50a6ca..00000000000 --- a/tests/baselines/reference/strictModeCode1.errors.txt +++ /dev/null @@ -1,103 +0,0 @@ -tests/cases/compiler/strictModeCode1.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(5,9): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(5,19): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(5,28): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(7,22): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(25,20): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode1.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(26,21): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode1.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(27,17): error TS2304: Cannot find name 'package'. -tests/cases/compiler/strictModeCode1.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeCode1.ts(28,17): error TS2304: Cannot find name 'package'. - - -==== tests/cases/compiler/strictModeCode1.ts (24 errors) ==== - interface public { } - - class Foo { - constructor(private, public, static) { - ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. - private = public = static; - ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. - } - public banana(x: public) { } - ~~~~~~ -!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - } - - class C { - constructor(public public, let) { - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~ -!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. - } - foo1(private, static, public) { - ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - function let() { } - ~~~ -!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. - var z = function let() { }; - } - - public pulbic() { } // No Error; - } - - class D{ } - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~~ -!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. - - class E implements public { } - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - - class F implements public.private.B { } - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - class F1 implements public.private.implements { } - ~~~~~~ -!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - class G extends package { } - ~~~~~~~ -!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~~ -!!! error TS2304: Cannot find name 'package'. - class H extends package.A { } - ~~~~~~~ -!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~~ -!!! error TS2304: Cannot find name 'package'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode2.errors.txt b/tests/baselines/reference/strictModeCode2.errors.txt deleted file mode 100644 index 3016f02af7a..00000000000 --- a/tests/baselines/reference/strictModeCode2.errors.txt +++ /dev/null @@ -1,136 +0,0 @@ -tests/cases/compiler/strictModeCode2.ts(5,9): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(6,9): error TS1212: Identifier expected. 'static' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(7,9): error TS1212: Identifier expected. 'let' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(8,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(8,9): error TS2300: Duplicate identifier 'package'. -tests/cases/compiler/strictModeCode2.ts(9,14): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(9,14): error TS2300: Duplicate identifier 'package'. -tests/cases/compiler/strictModeCode2.ts(10,18): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(10,27): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(10,39): error TS1212: Identifier expected. 'let' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(11,18): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(11,30): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(12,24): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(12,33): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(12,41): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(13,11): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(15,25): error TS9003: 'class' expressions are not currently supported. -tests/cases/compiler/strictModeCode2.ts(17,9): error TS2300: Duplicate identifier 'b'. -tests/cases/compiler/strictModeCode2.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(17,12): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode2.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(19,21): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(20,22): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(21,22): error TS2304: Cannot find name 'private'. -tests/cases/compiler/strictModeCode2.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(22,9): error TS2300: Duplicate identifier 'b'. -tests/cases/compiler/strictModeCode2.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(22,12): error TS2304: Cannot find name 'interface'. -tests/cases/compiler/strictModeCode2.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode2.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode - - -==== tests/cases/compiler/strictModeCode2.ts (36 errors) ==== - let let = 10; - - function foo() { - "use strict" - var public = 10; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - var static = "hi"; - ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode - let let = "blah"; - ~~~ -!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode - var package = "hello" - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - ~~~~~~~ -!!! error TS2300: Duplicate identifier 'package'. - function package() { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - ~~~~~~~ -!!! error TS2300: Duplicate identifier 'package'. - function bar(private, implements, let) { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - ~~~~~~~~~~ -!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode - ~~~ -!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode - function baz() { } - ~~~~~~~~~~ -!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode - ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode - function barn(cb: (private, public, package) => void) { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - barn((private, public, package) => { }); - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - - var myClass = class package extends public {} - ~~~~~~~ -!!! error TS9003: 'class' expressions are not currently supported. - - var b: public.bar; - ~ -!!! error TS2300: Duplicate identifier 'b'. - ~~~~~~ -!!! error TS1215: Type expected. 'public' is a reserved word in strict mode - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - - function foo(x: private.x) { } - ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. - function foo1(x: private.package.x) { } - ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode - function foo2(x: private.package.protected) { } - ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode - ~~~~~~~~~ -!!! error TS1215: Type expected. 'protected' is a reserved word in strict mode - let b: interface.package.implements.B; - ~ -!!! error TS2300: Duplicate identifier 'b'. - ~~~~~~~~~ -!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode - ~~~~~~~~~ -!!! error TS2304: Cannot find name 'interface'. - ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode - ~~~~~~~~~~ -!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode - } - - \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode3.errors.txt b/tests/baselines/reference/strictModeCode3.errors.txt deleted file mode 100644 index be500ad1062..00000000000 --- a/tests/baselines/reference/strictModeCode3.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/strictModeCode3.ts(2,11): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode3.ts(3,11): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode -tests/cases/compiler/strictModeCode3.ts(4,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode3.ts(4,18): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode -tests/cases/compiler/strictModeCode3.ts(6,6): error TS1212: Identifier expected. 'package' is a reserved word in strict mode - - -==== tests/cases/compiler/strictModeCode3.ts (5 errors) ==== - "use strict" - interface public { } - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - interface implements { - ~~~~~~~~~~ -!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode - foo(package, protected); - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode - } - enum package { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode3.js b/tests/baselines/reference/strictModeCode3.js deleted file mode 100644 index 596667f9925..00000000000 --- a/tests/baselines/reference/strictModeCode3.js +++ /dev/null @@ -1,13 +0,0 @@ -//// [strictModeCode3.ts] -"use strict" -interface public { } -interface implements { - foo(package, protected); -} -enum package { } - -//// [strictModeCode3.js] -"use strict"; -var package; -(function (package) { -})(package || (package = {})); diff --git a/tests/baselines/reference/strictModeCode4.errors.txt b/tests/baselines/reference/strictModeCode4.errors.txt deleted file mode 100644 index b9dc2c0dce7..00000000000 --- a/tests/baselines/reference/strictModeCode4.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/compiler/strictModeCode4.ts(3,17): error TS2304: Cannot find name 'foo'. -tests/cases/compiler/strictModeCode4.ts(4,13): error TS2304: Cannot find name 'public'. -tests/cases/compiler/strictModeCode4.ts(4,20): error TS1005: ',' expected. -tests/cases/compiler/strictModeCode4.ts(4,20): error TS2304: Cannot find name 'blaz'. -tests/cases/compiler/strictModeCode4.ts(4,27): error TS1005: ',' expected. - - -==== tests/cases/compiler/strictModeCode4.ts (5 errors) ==== - class C { - public bar() { - var v = foo( - ~~~ -!!! error TS2304: Cannot find name 'foo'. - public blaz() {} - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~~~~ -!!! error TS1005: ',' expected. - ~~~~ -!!! error TS2304: Cannot find name 'blaz'. - ~ -!!! error TS1005: ',' expected. - ); - } - } \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode5.errors.txt b/tests/baselines/reference/strictModeCode5.errors.txt deleted file mode 100644 index ac6d17e1bb9..00000000000 --- a/tests/baselines/reference/strictModeCode5.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/compiler/strictModeCode5.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(3,10): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(4,7): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(5,15): error TS1212: Identifier expected. 'static' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(5,38): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(6,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode5.ts(6,14): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode - - -==== tests/cases/compiler/strictModeCode5.ts (7 errors) ==== - "use strict" - var [public] = [1]; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - var { x: public } = { x: 1 }; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - var [[private]] = [["hello"]]; - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; - ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - var {public, protected} = { public: 1, protected: 2 }; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode6.errors.txt b/tests/baselines/reference/strictModeCode6.errors.txt deleted file mode 100644 index dd1cb2dc433..00000000000 --- a/tests/baselines/reference/strictModeCode6.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/strictModeCode6.ts(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/compiler/strictModeCode6.ts(2,26): error TS2307: Cannot find external module './1'. -tests/cases/compiler/strictModeCode6.ts(3,16): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode6.ts(3,30): error TS2307: Cannot find external module './1'. -tests/cases/compiler/strictModeCode6.ts(4,20): error TS2307: Cannot find external module './1'. - - -==== tests/cases/compiler/strictModeCode6.ts (5 errors) ==== - "use strict" - import * as package from "./1" - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - ~~~~~ -!!! error TS2307: Cannot find external module './1'. - import {foo as private} from "./1" - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - ~~~~~ -!!! error TS2307: Cannot find external module './1'. - import public from "./1" - ~~~~~ -!!! error TS2307: Cannot find external module './1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode7.errors.txt b/tests/baselines/reference/strictModeCode7.errors.txt deleted file mode 100644 index 066fd01b897..00000000000 --- a/tests/baselines/reference/strictModeCode7.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/compiler/strictModeCode7.ts(3,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode7.ts(3,25): error TS2307: Cannot find external module '1'. - - -==== tests/cases/compiler/strictModeCode7.ts (2 errors) ==== - - "use strict" - import public = require("1"); - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~ -!!! error TS2307: Cannot find external module '1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode7.js b/tests/baselines/reference/strictModeCode7.js deleted file mode 100644 index eee01c59a27..00000000000 --- a/tests/baselines/reference/strictModeCode7.js +++ /dev/null @@ -1,7 +0,0 @@ -//// [strictModeCode7.ts] - -"use strict" -import public = require("1"); - -//// [strictModeCode7.js] -"use strict"; diff --git a/tests/baselines/reference/strictModeCode8.errors.txt b/tests/baselines/reference/strictModeCode8.errors.txt deleted file mode 100644 index 25b087e9016..00000000000 --- a/tests/baselines/reference/strictModeCode8.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/strictModeCode8.ts(2,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode8.ts(3,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode8.ts(4,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/compiler/strictModeCode8.ts(6,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode -tests/cases/compiler/strictModeCode8.ts(6,16): error TS1212: Identifier expected. 'public' is a reserved word in strict mode - - -==== tests/cases/compiler/strictModeCode8.ts (5 errors) ==== - "use strict" - module public { } - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - module private { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - module public.whatever { - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - } - module private.public.foo { } - ~~~~~~~ -!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWord.errors.txt b/tests/baselines/reference/strictModeReservedWord.errors.txt new file mode 100644 index 00000000000..9e76e36551d --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWord.errors.txt @@ -0,0 +1,147 @@ +tests/cases/compiler/strictModeReservedWord.ts(5,9): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(6,9): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(7,9): error TS1212: Identifier expected. 'let' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(8,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(8,9): error TS2300: Duplicate identifier 'package'. +tests/cases/compiler/strictModeReservedWord.ts(9,14): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(9,14): error TS2300: Duplicate identifier 'package'. +tests/cases/compiler/strictModeReservedWord.ts(10,18): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(10,27): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(10,39): error TS1212: Identifier expected. 'let' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(11,18): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(11,30): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(12,24): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(12,33): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(12,41): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(13,11): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS9003: 'class' expressions are not currently supported. +tests/cases/compiler/strictModeReservedWord.ts(17,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeReservedWord.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS2304: Cannot find name 'private'. +tests/cases/compiler/strictModeReservedWord.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(22,9): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS2304: Cannot find name 'interface'. +tests/cases/compiler/strictModeReservedWord.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(23,5): error TS2304: Cannot find name 'ublic'. +tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/compiler/strictModeReservedWord.ts (39 errors) ==== + let let = 10; + + function foo() { + "use strict" + var public = 10; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var static = "hi"; + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + let let = "blah"; + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode + var package = "hello" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'package'. + function package() { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'package'. + function bar(private, implements, let) { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + ~~~ +!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode + function baz() { } + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + function barn(cb: (private, public, package) => void) { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + barn((private, public, package) => { }); + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + + var myClass = class package extends public {} + ~~~~~~~ +!!! error TS9003: 'class' expressions are not currently supported. + + var b: public.bar; + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~~~~~~ +!!! error TS1215: Type expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + + function foo(x: private.x) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + function foo1(x: private.package.x) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + function foo2(x: private.package.protected) { } + ~~~~~~~ +!!! error TS1215: Type expected. 'private' is a reserved word in strict mode + ~~~~~~~ +!!! error TS2304: Cannot find name 'private'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1215: Type expected. 'protected' is a reserved word in strict mode + let b: interface.package.implements.B; + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~~~~~~~~~ +!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'interface'. + ~~~~~~~ +!!! error TS1215: Type expected. 'package' is a reserved word in strict mode + ~~~~~~~~~~ +!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode + ublic(); + ~~~~~ +!!! error TS2304: Cannot find name 'ublic'. + static(); + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + ~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + } + + \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode2.js b/tests/baselines/reference/strictModeReservedWord.js similarity index 89% rename from tests/baselines/reference/strictModeCode2.js rename to tests/baselines/reference/strictModeReservedWord.js index e3f7bc83369..9be21b20ae6 100644 --- a/tests/baselines/reference/strictModeCode2.js +++ b/tests/baselines/reference/strictModeReservedWord.js @@ -1,4 +1,4 @@ -//// [strictModeCode2.ts] +//// [strictModeReservedWord.ts] let let = 10; function foo() { @@ -21,11 +21,13 @@ function foo() { function foo1(x: private.package.x) { } function foo2(x: private.package.protected) { } let b: interface.package.implements.B; + ublic(); + static(); } -//// [strictModeCode2.js] +//// [strictModeReservedWord.js] var let = 10; function foo() { "use strict"; @@ -50,4 +52,6 @@ function foo() { function foo1(x) { } function foo2(x) { } var b; + ublic(); + static(); } diff --git a/tests/baselines/reference/strictModeReservedWord2.errors.txt b/tests/baselines/reference/strictModeReservedWord2.errors.txt new file mode 100644 index 00000000000..8fbc79bbce0 --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWord2.errors.txt @@ -0,0 +1,45 @@ +tests/cases/compiler/strictModeReservedWord2.ts(2,11): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord2.ts(3,11): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord2.ts(4,9): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord2.ts(4,18): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord2.ts(6,6): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord2.ts(13,12): error TS1212: Identifier expected. 'private' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeReservedWord2.ts (6 errors) ==== + "use strict" + interface public { } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + interface implements { + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + foo(package, protected); + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + } + enum package { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + enum foo { + public, + private, + pacakge + } + + const enum private { + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + public, + private, + pacakge + } + + const enum bar { + public, + private, + pacakge + } + \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWord2.js b/tests/baselines/reference/strictModeReservedWord2.js new file mode 100644 index 00000000000..f6adc2389cd --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWord2.js @@ -0,0 +1,37 @@ +//// [strictModeReservedWord2.ts] +"use strict" +interface public { } +interface implements { + foo(package, protected); +} +enum package { } +enum foo { + public, + private, + pacakge +} + +const enum private { + public, + private, + pacakge +} + +const enum bar { + public, + private, + pacakge +} + + +//// [strictModeReservedWord2.js] +"use strict"; +var package; +(function (package) { +})(package || (package = {})); +var foo; +(function (foo) { + foo[foo["public"] = 0] = "public"; + foo[foo["private"] = 1] = "private"; + foo[foo["pacakge"] = 2] = "pacakge"; +})(foo || (foo = {})); diff --git a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt new file mode 100644 index 00000000000..b7876b1b849 --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt @@ -0,0 +1,103 @@ +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(4,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(4,26): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(4,34): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,9): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,19): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,28): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(7,22): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2304: Cannot find name 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS2304: Cannot find name 'package'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS2304: Cannot find name 'package'. + + +==== tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts (24 errors) ==== + interface public { } + + class Foo { + constructor(private, public, static) { + ~~~~~~~ +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. + private = public = static; + ~~~~~~~ +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. + } + public banana(x: public) { } + ~~~~~~ +!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + } + + class C { + constructor(public public, let) { + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~ +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. + } + foo1(private, static, public) { + ~~~~~~~ +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + function let() { } + ~~~ +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. + var z = function let() { }; + } + + public pulbic() { } // No Error; + } + + class D{ } + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. + + class E implements public { } + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + + class F implements public.private.B { } + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + class F1 implements public.private.implements { } + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + class G extends package { } + ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS2304: Cannot find name 'package'. + class H extends package.A { } + ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ +!!! error TS2304: Cannot find name 'package'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode1.js b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.js similarity index 91% rename from tests/baselines/reference/strictModeCode1.js rename to tests/baselines/reference/strictModeReservedWordInClassDeclaration.js index 1a7b93417c6..98b38532aa6 100644 --- a/tests/baselines/reference/strictModeCode1.js +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.js @@ -1,4 +1,4 @@ -//// [strictModeCode1.ts] +//// [strictModeReservedWordInClassDeclaration.ts] interface public { } class Foo { @@ -28,7 +28,7 @@ class F1 implements public.private.implements { } class G extends package { } class H extends package.A { } -//// [strictModeCode1.js] +//// [strictModeReservedWordInClassDeclaration.js] var __extends = this.__extends || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } diff --git a/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt b/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt new file mode 100644 index 00000000000..0776e6b255b --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(3,10): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(4,7): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(5,15): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(5,38): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,14): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeReservedWordInDestructuring.ts (7 errors) ==== + "use strict" + var [public] = [1]; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var { x: public } = { x: 1 }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + var [[private]] = [["hello"]]; + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + var {public, protected} = { public: 1, protected: 2 }; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode5.js b/tests/baselines/reference/strictModeReservedWordInDestructuring.js similarity index 82% rename from tests/baselines/reference/strictModeCode5.js rename to tests/baselines/reference/strictModeReservedWordInDestructuring.js index 8a480b0fe70..1fe5a9f71d6 100644 --- a/tests/baselines/reference/strictModeCode5.js +++ b/tests/baselines/reference/strictModeReservedWordInDestructuring.js @@ -1,4 +1,4 @@ -//// [strictModeCode5.ts] +//// [strictModeReservedWordInDestructuring.ts] "use strict" var [public] = [1]; var { x: public } = { x: 1 }; @@ -6,7 +6,7 @@ var [[private]] = [["hello"]]; var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; var {public, protected} = { public: 1, protected: 2 }; -//// [strictModeCode5.js] +//// [strictModeReservedWordInDestructuring.js] "use strict"; var public = ([1])[0]; var public = ({ x: 1 }).x; diff --git a/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.errors.txt new file mode 100644 index 00000000000..408cf161f3c --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,25): error TS2307: Cannot find external module '1'. + + +==== tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts (2 errors) ==== + + "use strict" + import public = require("1"); + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~ +!!! error TS2307: Cannot find external module '1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.js b/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.js new file mode 100644 index 00000000000..50ed1b4d755 --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWordInImportEqualDeclaration.js @@ -0,0 +1,7 @@ +//// [strictModeReservedWordInImportEqualDeclaration.ts] + +"use strict" +import public = require("1"); + +//// [strictModeReservedWordInImportEqualDeclaration.js] +"use strict"; diff --git a/tests/baselines/reference/strictModeReservedWordInModuleDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInModuleDeclaration.errors.txt new file mode 100644 index 00000000000..f745f93f79e --- /dev/null +++ b/tests/baselines/reference/strictModeReservedWordInModuleDeclaration.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts(2,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts(3,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts(4,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts(6,8): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts(6,16): error TS1212: Identifier expected. 'public' is a reserved word in strict mode + + +==== tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts (5 errors) ==== + "use strict" + module public { } + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + module private { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + module public.whatever { + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + } + module private.public.foo { } + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode8.js b/tests/baselines/reference/strictModeReservedWordInModuleDeclaration.js similarity index 52% rename from tests/baselines/reference/strictModeCode8.js rename to tests/baselines/reference/strictModeReservedWordInModuleDeclaration.js index e2c541217f4..b7e7d0df341 100644 --- a/tests/baselines/reference/strictModeCode8.js +++ b/tests/baselines/reference/strictModeReservedWordInModuleDeclaration.js @@ -1,4 +1,4 @@ -//// [strictModeCode8.ts] +//// [strictModeReservedWordInModuleDeclaration.ts] "use strict" module public { } module private { } @@ -6,5 +6,5 @@ module public.whatever { } module private.public.foo { } -//// [strictModeCode8.js] +//// [strictModeReservedWordInModuleDeclaration.js] "use strict"; diff --git a/tests/baselines/reference/strictModeWordInExportDeclaration.js b/tests/baselines/reference/strictModeWordInExportDeclaration.js new file mode 100644 index 00000000000..e884f49e1b8 --- /dev/null +++ b/tests/baselines/reference/strictModeWordInExportDeclaration.js @@ -0,0 +1,13 @@ +//// [strictModeWordInExportDeclaration.ts] +"use strict" +var x = 1; +export { x as foo } +export { x as implements } +export { x as while } + +//// [strictModeWordInExportDeclaration.js] +"use strict"; +var x = 1; +export { x as foo }; +export { x as implements }; +export { x as while }; diff --git a/tests/baselines/reference/strictModeWordInExportDeclaration.types b/tests/baselines/reference/strictModeWordInExportDeclaration.types new file mode 100644 index 00000000000..8a54d7275d2 --- /dev/null +++ b/tests/baselines/reference/strictModeWordInExportDeclaration.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/strictModeWordInExportDeclaration.ts === +"use strict" +var x = 1; +>x : number + +export { x as foo } +>x : number +>foo : number + +export { x as implements } +>x : number +>implements : number + +export { x as while } +>x : number +>while : number + diff --git a/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt b/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt new file mode 100644 index 00000000000..83e44ab50b9 --- /dev/null +++ b/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,26): error TS2307: Cannot find external module './1'. +tests/cases/compiler/strictModeWordInImportDeclaration.ts(3,16): error TS1212: Identifier expected. 'private' is a reserved word in strict mode +tests/cases/compiler/strictModeWordInImportDeclaration.ts(3,30): error TS2307: Cannot find external module './1'. +tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,20): error TS2307: Cannot find external module './1'. + + +==== tests/cases/compiler/strictModeWordInImportDeclaration.ts (5 errors) ==== + "use strict" + import * as package from "./1" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + ~~~~~ +!!! error TS2307: Cannot find external module './1'. + import {foo as private} from "./1" + ~~~~~~~ +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode + ~~~~~ +!!! error TS2307: Cannot find external module './1'. + import public from "./1" + ~~~~~ +!!! error TS2307: Cannot find external module './1'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeCode6.js b/tests/baselines/reference/strictModeWordInImportDeclaration.js similarity index 56% rename from tests/baselines/reference/strictModeCode6.js rename to tests/baselines/reference/strictModeWordInImportDeclaration.js index e8fd529d1aa..4a335d8a744 100644 --- a/tests/baselines/reference/strictModeCode6.js +++ b/tests/baselines/reference/strictModeWordInImportDeclaration.js @@ -1,8 +1,8 @@ -//// [strictModeCode6.ts] +//// [strictModeWordInImportDeclaration.ts] "use strict" import * as package from "./1" import {foo as private} from "./1" import public from "./1" -//// [strictModeCode6.js] +//// [strictModeWordInImportDeclaration.js] "use strict"; diff --git a/tests/cases/compiler/strictModeCode4.ts b/tests/cases/compiler/errorRecoveryInClassDeclaration.ts similarity index 100% rename from tests/cases/compiler/strictModeCode4.ts rename to tests/cases/compiler/errorRecoveryInClassDeclaration.ts diff --git a/tests/cases/compiler/reservedWords2.ts b/tests/cases/compiler/reservedWords2.ts new file mode 100644 index 00000000000..54482264d0e --- /dev/null +++ b/tests/cases/compiler/reservedWords2.ts @@ -0,0 +1,12 @@ +import while = require("dfdf"); +import * as while from "foo" + +var typeof = 10; +function throw() {} +module void {} +var {while, return} = { while: 1, return: 2 }; +var {this, switch: { continue} } = { this: 1, switch: { continue: 2 }}; +var [debugger, if] = [1, 2]; +enum void {} + + diff --git a/tests/cases/compiler/strictModeCode3.ts b/tests/cases/compiler/strictModeCode3.ts deleted file mode 100644 index 800f882d34d..00000000000 --- a/tests/cases/compiler/strictModeCode3.ts +++ /dev/null @@ -1,6 +0,0 @@ -"use strict" -interface public { } -interface implements { - foo(package, protected); -} -enum package { } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode2.ts b/tests/cases/compiler/strictModeReservedWord.ts similarity index 92% rename from tests/cases/compiler/strictModeCode2.ts rename to tests/cases/compiler/strictModeReservedWord.ts index 6336329ae71..e26e04f23e4 100644 --- a/tests/cases/compiler/strictModeCode2.ts +++ b/tests/cases/compiler/strictModeReservedWord.ts @@ -20,5 +20,7 @@ function foo() { function foo1(x: private.package.x) { } function foo2(x: private.package.protected) { } let b: interface.package.implements.B; + ublic(); + static(); } diff --git a/tests/cases/compiler/strictModeReservedWord2.ts b/tests/cases/compiler/strictModeReservedWord2.ts new file mode 100644 index 00000000000..07ca04b849b --- /dev/null +++ b/tests/cases/compiler/strictModeReservedWord2.ts @@ -0,0 +1,23 @@ +"use strict" +interface public { } +interface implements { + foo(package, protected); +} +enum package { } +enum foo { + public, + private, + pacakge +} + +const enum private { + public, + private, + pacakge +} + +const enum bar { + public, + private, + pacakge +} diff --git a/tests/cases/compiler/strictModeCode1.ts b/tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts similarity index 100% rename from tests/cases/compiler/strictModeCode1.ts rename to tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts diff --git a/tests/cases/compiler/strictModeCode5.ts b/tests/cases/compiler/strictModeReservedWordInDestructuring.ts similarity index 100% rename from tests/cases/compiler/strictModeCode5.ts rename to tests/cases/compiler/strictModeReservedWordInDestructuring.ts diff --git a/tests/cases/compiler/strictModeCode7.ts b/tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts similarity index 100% rename from tests/cases/compiler/strictModeCode7.ts rename to tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts diff --git a/tests/cases/compiler/strictModeCode8.ts b/tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts similarity index 100% rename from tests/cases/compiler/strictModeCode8.ts rename to tests/cases/compiler/strictModeReservedWordInModuleDeclaration.ts diff --git a/tests/cases/compiler/strictModeWordInExportDeclaration.ts b/tests/cases/compiler/strictModeWordInExportDeclaration.ts new file mode 100644 index 00000000000..fe6a0d6691a --- /dev/null +++ b/tests/cases/compiler/strictModeWordInExportDeclaration.ts @@ -0,0 +1,6 @@ +// @target: ES6 +"use strict" +var x = 1; +export { x as foo } +export { x as implements } +export { x as while } \ No newline at end of file diff --git a/tests/cases/compiler/strictModeCode6.ts b/tests/cases/compiler/strictModeWordInImportDeclaration.ts similarity index 100% rename from tests/cases/compiler/strictModeCode6.ts rename to tests/cases/compiler/strictModeWordInImportDeclaration.ts From a01bdcfab3424bfb6c057a11a2fdba14f81385ef Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 11 Apr 2015 20:58:42 -0700 Subject: [PATCH 23/23] Address code review --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 123346aa210..14de22bbe70 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12027,7 +12027,7 @@ module ts { // public // error at public // public.private.package // error at public // B.private.B // no error - function checkGrammarHeritageClauseElementInStrictMode(expression: PropertyAccessExpression) { + function checkGrammarHeritageClauseElementInStrictMode(expression: Expression) { // Example: // class C extends public // error at public if (expression && expression.kind === SyntaxKind.Identifier) { @@ -12038,7 +12038,7 @@ module ts { // in PropertyAccessExpression. According to grammar production of MemberExpression, // the left component expression is a PrimaryExpression (i.e. Identifier) while the other // component after dots can be IdentifierName. - checkGrammarHeritageClauseElementInStrictMode(expression.expression); + checkGrammarHeritageClauseElementInStrictMode((expression).expression); } }