Allow IdentifierName in memberExpression

This commit is contained in:
Yui T
2015-04-10 16:22:09 -07:00
parent bf60eabdbb
commit 8448ba7b13
5 changed files with 28 additions and 74 deletions
+11 -35
View File
@@ -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 = (<QualifiedName>partOfTypeName).right;
checkGrammarTypeNameInStrictMode(name);
partOfTypeName = (<QualifiedName>partOfTypeName).left;
}
// Report and error at the component in QualifiedName which must be an identifier.
// Example:
// x1: public.private.package // Error at package
checkGrammarTypeNameInStrictMode(<Identifier>partOfTypeName);
// x1: public.private.package // error at package as memberExpression can be IdentifierName
checkGrammarTypeNameInStrictMode((<QualifiedName>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 = <PropertyAccessExpression>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 = <PropertyAccessExpression>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((<PropertyAccessExpression>expression).name);
}
}
@@ -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'.
@@ -24,6 +24,7 @@ class D<public, private>{ }
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() {
@@ -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
}
+1
View File
@@ -23,5 +23,6 @@ class D<public, private>{ }
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 { }