Address CR

This commit is contained in:
Yui T 2015-04-10 18:52:37 -07:00
parent 8448ba7b13
commit fe7a3a5d02
3 changed files with 68 additions and 21 deletions

View File

@ -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((<QualifiedName>typeName).right);
// x1: public.private.package // error at public and private
let qualifiedName = typeName;
while (qualifiedName && qualifiedName.kind === SyntaxKind.QualifiedName) {
checkGrammarTypeNameInStrictMode((<QualifiedName>qualifiedName).right);
qualifiedName = (<QualifiedName>qualifiedName).left;
}
// Report an error at the last Identifier in QualifiedName
// Example:
// x1: public.private.package // error at package
checkGrammarTypeNameInStrictMode(<Identifier>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 = <PropertyAccessExpression>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 = <PropertyAccessExpression>propertyAccessExp.expression;
}
// Report strict mode at the property of memberExpression
// Example:
// public.private.package // error at package as memberExpression can be IdentifierName
checkGrammarIdentifierInStrictMode((<PropertyAccessExpression>expression).name);
// public.private.package // error at public as it is parsed as an Identifier in the PropertyAccessExpression
checkGrammarIdentifierInStrictMode(propertyAccessExp);
}
}

View File

@ -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'.

View File

@ -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
}