diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e3cd0da60d5..42bcd8ac610 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -560,6 +560,23 @@ namespace ts { bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); } + // The binder visits every node in the syntax tree so it is a convenient place to perform a single localized + // check for reserved words used as identifiers in strict mode code. + function checkStrictModeIdentifier(node: Identifier) { + if (node.parserContextFlags & ParserContextFlags.StrictMode && + node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord && + node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord && + !isIdentifierName(node)) { + // Report error only if there are no parse errors in file + if (!file.parseDiagnostics.length) { + let message = getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression) ? + Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode : + Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode; + file.bindDiagnostics.push(createDiagnosticForNode(node, message, declarationNameToString(node))); + } + } + } + function getDestructuringParameterName(node: Declaration) { return "__" + indexOf((node.parent).parameters, node); } @@ -588,6 +605,8 @@ namespace ts { function bindWorker(node: Node) { switch (node.kind) { + case SyntaxKind.Identifier: + return checkStrictModeIdentifier(node); case SyntaxKind.TypeParameter: return declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); case SyntaxKind.Parameter: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bbfd36bf45..86639b9c758 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3627,7 +3627,7 @@ namespace ts { // The expression is processed as an identifier expression (section 4.3) // or property access expression(section 4.10), // the widened type(section 3.9) of which becomes the result. - links.resolvedType = getWidenedType(checkExpressionOrQualifiedName(node.exprName)); + links.resolvedType = getWidenedType(checkExpression(node.exprName)); } return links.resolvedType; } @@ -6616,7 +6616,7 @@ namespace ts { } function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { - let type = checkExpressionOrQualifiedName(left); + let type = checkExpression(left); if (isTypeAny(type)) { return type; } @@ -6657,7 +6657,7 @@ namespace ts { ? (node).expression : (node).left; - let type = checkExpressionOrQualifiedName(left); + let type = checkExpression(left); if (type !== unknownType && !isTypeAny(type)) { let prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { @@ -7732,7 +7732,7 @@ namespace ts { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); // Grammar checking - let hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node); + let hasGrammarError = checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === SyntaxKind.FunctionExpression) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } @@ -8451,11 +8451,6 @@ namespace ts { return type; } - function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { - checkGrammarIdentifierInStrictMode(node); - return checkExpressionOrQualifiedName(node, contextualMapper); - } - // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When // contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the // expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in @@ -8463,7 +8458,7 @@ namespace ts { // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. - function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { + function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { let type: Type; if (node.kind == SyntaxKind.QualifiedName) { type = checkQualifiedName(node); @@ -8567,8 +8562,6 @@ namespace ts { // DECLARATION AND STATEMENT TYPE CHECKING function checkTypeParameter(node: TypeParameterDeclaration) { - checkGrammarDeclarationNameInStrictMode(node); - // Grammar Checking if (node.expression) { grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected); @@ -8954,13 +8947,10 @@ namespace ts { } function checkTypeReferenceNode(node: TypeReferenceNode) { - checkGrammarTypeReferenceInStrictMode(node.typeName); return checkTypeReferenceOrExpressionWithTypeArguments(node); } function checkExpressionWithTypeArguments(node: ExpressionWithTypeArguments) { - checkGrammarExpressionWithTypeArgumentsInStrictMode(node.expression); - return checkTypeReferenceOrExpressionWithTypeArguments(node); } @@ -9400,7 +9390,7 @@ namespace ts { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { - checkExpressionOrQualifiedName((node).typeName); + checkExpression((node).typeName); } } } @@ -9497,7 +9487,6 @@ namespace ts { } function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { - checkGrammarDeclarationNameInStrictMode(node); checkDecorators(node); checkSignatureDeclaration(node); @@ -9783,7 +9772,6 @@ namespace 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 @@ -10568,7 +10556,6 @@ namespace ts { } function checkClassDeclaration(node: ClassDeclaration) { - checkGrammarDeclarationNameInStrictMode(node); // Grammar checking if (!node.name && !(node.flags & NodeFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); @@ -10614,7 +10601,7 @@ namespace ts { if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { // Check that base type can be evaluated as expression - checkExpressionOrQualifiedName(baseTypeNode.expression); + checkExpression(baseTypeNode.expression); } let implementedTypeNodes = getClassImplementsHeritageClauseElements(node); @@ -10793,7 +10780,7 @@ namespace ts { function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking - checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { @@ -11018,7 +11005,7 @@ namespace ts { } // Grammar checking - checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -11113,7 +11100,7 @@ namespace ts { return; } - if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -11229,7 +11216,7 @@ namespace ts { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } - if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -11256,7 +11243,7 @@ namespace ts { return; } - checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & NodeFlags.Export) { @@ -12616,153 +12603,6 @@ namespace ts { } // GRAMMAR CHECKING - function isReservedWordInStrictMode(node: Identifier): boolean { - // Check that originalKeywordKind is less than LastFutureReservedWord to see if an Identifier is a strict-mode reserved word - return (node.parserContextFlags & ParserContextFlags.StrictMode) && - (SyntaxKind.FirstFutureReservedWord <= node.originalKeywordKind && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord); - } - - 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 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 (isReservedWordInStrictMode(name)) { - 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 (isReservedWordInStrictMode(name)) { - let nameText = declarationNameToString(name); - reportError = 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 && isReservedWordInStrictMode(name)) { - 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: - return checkGrammarIdentifierInStrictMode(name); - - 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_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. - // 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 module in strict mode - return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); - } - } - return false; - } - - 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: B.private.bar) // error at private - // foo (x: public.private.package) // error at public, private, and package - else if (typeName.kind === SyntaxKind.QualifiedName) { - // 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 - checkGrammarTypeNameInStrictMode((typeName).right); - checkGrammarTypeReferenceInStrictMode((typeName).left); - } - } - - // This function will report an error for every identifier in property access expression - // whether it violates strict mode reserved words. - // Example: - // public // error at public - // public.private.package // error at public - // B.private.B // no error - function checkGrammarExpressionWithTypeArgumentsInStrictMode(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) { - // 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. - checkGrammarExpressionWithTypeArgumentsInStrictMode((expression).expression); - } - - } - - // 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); - - // 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; - } function checkGrammarDecorators(node: Node): boolean { if (!node.decorators) { @@ -13649,16 +13489,12 @@ namespace ts { if (name && name.kind === SyntaxKind.Identifier) { let identifier = name; if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { - let nameText = declarationNameToString(identifier); - // 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; + let message = getAncestor(identifier, SyntaxKind.ClassDeclaration) || getAncestor(identifier, SyntaxKind.ClassExpression) ? + Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode : + Diagnostics.Invalid_use_of_0_in_strict_mode; + return grammarErrorOnNode(identifier, message, declarationNameToString(identifier)); } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 43330935f4f..de5e0f552d5 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -171,8 +171,6 @@ namespace 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." }, - 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." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d78ea07f91a..c4a805413e7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -671,14 +671,6 @@ "category": "Error", "code": 1213 }, - "Type expected. '{0}' is a reserved word in strict mode": { - "category": "Error", - "code": 1215 - }, - "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": { - "category": "Error", - "code": 1216 - }, "Export assignment is not supported when '--module' flag is 'system'.": { "category": "Error", "code": 1218 diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1aad9d5b06b..7251867f070 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1177,6 +1177,41 @@ namespace ts { return false; } + // Return true if the given identifier is classified as an IdentifierName + export function isIdentifierName(node: Identifier): boolean { + let parent = node.parent; + switch (parent.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.EnumMember: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyAccessExpression: + // Name in member declaration or property name in property access + return (parent).name === node; + case SyntaxKind.QualifiedName: + // Name on right hand side of dot in a type query + if ((parent).right === node) { + while (parent.kind === SyntaxKind.QualifiedName) { + parent = parent.parent; + } + return parent.kind === SyntaxKind.TypeQuery; + } + return false; + case SyntaxKind.BindingElement: + case SyntaxKind.ImportSpecifier: + // Property name in binding element or import specifier + return (parent).propertyName === node; + case SyntaxKind.ExportSpecifier: + // Any name in an export specifier + return true; + } + return false; + } + // An alias symbol is created by one of the following declarations: // import = ... // import from ... diff --git a/tests/baselines/reference/parser553699.errors.txt b/tests/baselines/reference/parser553699.errors.txt index ea7e88cdf36..eb20e78814e 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 in strict mode. Class definitions are automatically in strict mode. +tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1213: Identifier 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 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 TS2304: Cannot find name 'public'. } diff --git a/tests/baselines/reference/strictModeReservedWord.errors.txt b/tests/baselines/reference/strictModeReservedWord.errors.txt index 9b7c0e03d0c..b6e9161ce7e 100644 --- a/tests/baselines/reference/strictModeReservedWord.errors.txt +++ b/tests/baselines/reference/strictModeReservedWord.errors.txt @@ -16,30 +16,32 @@ tests/cases/compiler/strictModeReservedWord.ts(12,41): error TS1212: Identifier 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 TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS9003: 'class' expressions are not currently supported. +tests/cases/compiler/strictModeReservedWord.ts(15,41): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. 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 TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS2503: Cannot find namespace '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 TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS2503: Cannot find namespace '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 TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS2503: Cannot find namespace '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(20,30): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS1212: Identifier expected. 'private' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS2503: Cannot find namespace '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(21,30): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(21,38): error TS1212: Identifier 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 TS1212: Identifier expected. 'interface' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS2503: Cannot find namespace '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(22,22): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWord.ts(22,30): error TS1212: Identifier 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) ==== +==== tests/cases/compiler/strictModeReservedWord.ts (41 errors) ==== let let = 10; function foo() { @@ -92,48 +94,52 @@ tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invok var myClass = class package extends public {} ~~~~~~~ +!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~~ !!! error TS9003: 'class' expressions are not currently supported. + ~~~~~~ +!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. var b: public.bar; ~ !!! error TS2300: Duplicate identifier 'b'. ~~~~~~ -!!! error TS1215: Type expected. 'public' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode ~~~~~~ !!! error TS2503: Cannot find namespace 'public'. function foo(x: private.x) { } ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode ~~~~~~~ !!! error TS2503: Cannot find namespace 'private'. function foo1(x: private.package.x) { } ~~~~~~~ -!!! error TS1215: Type expected. 'private' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode ~~~~~~~ !!! error TS2503: Cannot find namespace 'private'. ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode +!!! error TS1212: Identifier 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 TS1212: Identifier expected. 'private' is a reserved word in strict mode ~~~~~~~ !!! error TS2503: Cannot find namespace 'private'. ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode ~~~~~~~~~ -!!! error TS1215: Type expected. 'protected' is a reserved word in strict mode +!!! error TS1212: Identifier 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 TS1212: Identifier expected. 'interface' is a reserved word in strict mode ~~~~~~~~~ !!! error TS2503: Cannot find namespace 'interface'. ~~~~~~~ -!!! error TS1215: Type expected. 'package' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode ~~~~~~~~~~ -!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode ublic(); ~~~~~ !!! error TS2304: Cannot find name 'ublic'. diff --git a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt index 43222495b9f..138d09e9b55 100644 --- a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt @@ -4,13 +4,14 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(4,34): error TS 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(7,22): 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,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(15,26): 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. @@ -24,7 +25,7 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS2503: Cannot find namespace 'package'. -==== tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts (24 errors) ==== +==== tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts (25 errors) ==== interface public { } class Foo { @@ -45,7 +46,7 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T } public banana(x: public) { } ~~~~~~ -!!! error TS1216: Type expected. 'public' 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. } class C { @@ -66,6 +67,8 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T ~~~ !!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. var z = function let() { }; + ~~~ +!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode. } public pulbic() { } // No Error; diff --git a/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt b/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt index 0776e6b255b..3ae9ca2d09a 100644 --- a/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt +++ b/tests/baselines/reference/strictModeReservedWordInDestructuring.errors.txt @@ -3,8 +3,8 @@ tests/cases/compiler/strictModeReservedWordInDestructuring.ts(3,10): error TS121 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(6,7): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,15): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode ==== tests/cases/compiler/strictModeReservedWordInDestructuring.ts (7 errors) ==== @@ -18,13 +18,15 @@ tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,14): error TS121 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' } } }; + 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 }; - ~~~~~~ + 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 + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + var { public: a, protected: b } = { public: 1, protected: 2 }; + \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWordInDestructuring.js b/tests/baselines/reference/strictModeReservedWordInDestructuring.js index e7675e6babf..78c8ab788ca 100644 --- a/tests/baselines/reference/strictModeReservedWordInDestructuring.js +++ b/tests/baselines/reference/strictModeReservedWordInDestructuring.js @@ -3,8 +3,10 @@ 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 {public, protected} = { public: 1, protected: 2 }; +var { y: { s: static }, z: { o: { p: package } }} = { y: { s: 1 }, z: { o: { p: 'h' } } }; +var { public, protected } = { public: 1, protected: 2 }; +var { public: a, protected: b } = { public: 1, protected: 2 }; + //// [strictModeReservedWordInDestructuring.js] "use strict"; @@ -13,3 +15,4 @@ 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; +var _c = { public: 1, protected: 2 }, a = _c.public, b = _c.protected; diff --git a/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt b/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt index b5da09b4240..aed48e1d3fd 100644 --- a/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt +++ b/tests/baselines/reference/strictModeWordInImportDeclaration.errors.txt @@ -2,10 +2,11 @@ tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,13): error TS1212: I tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,26): error TS2307: Cannot find 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 module './1'. +tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,20): error TS2307: Cannot find module './1'. -==== tests/cases/compiler/strictModeWordInImportDeclaration.ts (5 errors) ==== +==== tests/cases/compiler/strictModeWordInImportDeclaration.ts (6 errors) ==== "use strict" import * as package from "./1" ~~~~~~~ @@ -18,5 +19,7 @@ tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,20): error TS2307: C ~~~~~ !!! error TS2307: Cannot find module './1'. import public from "./1" + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode ~~~~~ !!! error TS2307: Cannot find module './1'. \ No newline at end of file diff --git a/tests/cases/compiler/strictModeReservedWordInDestructuring.ts b/tests/cases/compiler/strictModeReservedWordInDestructuring.ts index 8f25ab1e6d5..2225c341f91 100644 --- a/tests/cases/compiler/strictModeReservedWordInDestructuring.ts +++ b/tests/cases/compiler/strictModeReservedWordInDestructuring.ts @@ -2,5 +2,6 @@ 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 {public, protected} = { public: 1, protected: 2 }; \ 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 }; +var { public: a, protected: b } = { public: 1, protected: 2 };