From 7ddb79bc52976713d6b42e00dfb1942bb87b4ad8 Mon Sep 17 00:00:00 2001 From: york yao Date: Thu, 15 Sep 2016 11:00:21 +0800 Subject: [PATCH] fix error --- src/compiler/checker.ts | 11 ++-- ...heckGrammarStaticMemberName_es5.errors.txt | 60 ----------------- .../checkGrammarStaticMemberName_es5.js | 23 ++++--- .../checkGrammarStaticMemberName_es5.symbols | 51 +++++++++++++++ .../checkGrammarStaticMemberName_es5.types | 64 +++++++++++++++++++ ...heckGrammarStaticMemberName_es6.errors.txt | 48 -------------- .../checkGrammarStaticMemberName_es6.symbols | 51 +++++++++++++++ .../checkGrammarStaticMemberName_es6.types | 64 +++++++++++++++++++ ...cMemberOfAnotherClassAssignment.errors.txt | 5 +- 9 files changed, 248 insertions(+), 129 deletions(-) delete mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es5.errors.txt create mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es5.symbols create mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es5.types delete mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es6.errors.txt create mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es6.symbols create mode 100644 tests/baselines/reference/checkGrammarStaticMemberName_es6.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f0382b0a6ee3a..27d75eb2797cc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14237,7 +14237,7 @@ namespace ts { } function checkGrammarStaticPropertyOrMethodName(node: ClassElement) { - if (node.flags & NodeFlags.Static) { + if (node.flags & ModifierFlags.Static) { if (node.kind === SyntaxKind.PropertyDeclaration) { return checkGrammarStaticMemberName(node, ((node as ClassElement).name as Identifier).text); } @@ -14256,9 +14256,10 @@ namespace ts { const forbiddenNames = ["length", "name", "arguments", "caller"]; if (forbiddenNames.indexOf(name) !== -1) { if (languageVersion < ScriptTarget.ES6) { - return grammarErrorOnNode(node, Diagnostics._0_is_not_allowed_to_be_used_as_a_name_of_a_static_property_or_method_in_a_class_for_target_es5_2696, name); - } else { - return grammarErrorOnNode(node, Diagnostics._0_is_not_allowed_to_be_used_as_a_name_of_a_static_property_in_a_class_for_target_es6_and_higher_2697, name); + return grammarErrorOnNode(node, Diagnostics._0_is_not_allowed_to_be_used_as_a_name_of_a_static_property_or_method_in_a_class_for_target_ES5, name); + } + else { + return grammarErrorOnNode(node, Diagnostics._0_is_not_allowed_to_be_used_as_a_name_of_a_static_property_in_a_class_for_target_ES6_and_higher, name); } } @@ -19746,7 +19747,7 @@ namespace ts { if (computedPropertyName.expression.kind === SyntaxKind.StringLiteral) { const member = computedPropertyName.parent.parent.parent; - if (member.flags & NodeFlags.Static && member.kind === SyntaxKind.PropertyDeclaration) { + if (member.flags & ModifierFlags.Static && member.kind === SyntaxKind.PropertyDeclaration) { return checkGrammarStaticMemberName(computedPropertyName, (computedPropertyName.expression as StringLiteral).text); } } diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es5.errors.txt b/tests/baselines/reference/checkGrammarStaticMemberName_es5.errors.txt deleted file mode 100644 index ec2d9292600c5..0000000000000 --- a/tests/baselines/reference/checkGrammarStaticMemberName_es5.errors.txt +++ /dev/null @@ -1,60 +0,0 @@ -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(3,5): error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(4,5): error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(5,5): error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(6,5): error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(8,9): error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(9,9): error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(10,9): error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(11,9): error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(16,12): error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(17,12): error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(18,12): error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. -tests/cases/compiler/checkGrammarStaticMemberName_es5.ts(19,12): error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. - - -==== tests/cases/compiler/checkGrammarStaticMemberName_es5.ts (12 errors) ==== - - class static_property { - static length = 1; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. - static name = 1; - ~~~~~~~~~~~~~~~~ -!!! error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. - static arguments = 1; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. - static caller = 1; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. - static foo = { - ["length"]: 1, - ~~~~~~~~~~ -!!! error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. - ["name"]: 1, - ~~~~~~~~ -!!! error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. - ["arguments"]: 1, - ~~~~~~~~~~~~~ -!!! error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. - ["caller"]: 1, - ~~~~~~~~~~ -!!! error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. - }; - } - - class static_method { - static length() { return 1; } - ~~~~~~ -!!! error TS2696: 'length' is not allowed to be used as a name of a static property or method in a class for target ES5. - static name() { return 1; } - ~~~~ -!!! error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. - static arguments() { return 1; } - ~~~~~~~~~ -!!! error TS2696: 'arguments' is not allowed to be used as a name of a static property or method in a class for target ES5. - static caller() { return 1; } - ~~~~~~ -!!! error TS2696: 'caller' is not allowed to be used as a name of a static property or method in a class for target ES5. - } - \ No newline at end of file diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es5.js b/tests/baselines/reference/checkGrammarStaticMemberName_es5.js index 5735f94995869..5469d2e6ed035 100644 --- a/tests/baselines/reference/checkGrammarStaticMemberName_es5.js +++ b/tests/baselines/reference/checkGrammarStaticMemberName_es5.js @@ -25,20 +25,18 @@ class static_method { var static_property = (function () { function static_property() { } - static_property.length = 1; - static_property.name = 1; - static_property.arguments = 1; - static_property.caller = 1; - static_property.foo = (_a = {}, - _a["length"] = 1, - _a["name"] = 1, - _a["arguments"] = 1, - _a["caller"] = 1, - _a - ); return static_property; - var _a; }()); +static_property.length = 1; +static_property.name = 1; +static_property.arguments = 1; +static_property.caller = 1; +static_property.foo = (_a = {}, + _a["length"] = 1, + _a["name"] = 1, + _a["arguments"] = 1, + _a["caller"] = 1, + _a); var static_method = (function () { function static_method() { } @@ -48,3 +46,4 @@ var static_method = (function () { static_method.caller = function () { return 1; }; return static_method; }()); +var _a; diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es5.symbols b/tests/baselines/reference/checkGrammarStaticMemberName_es5.symbols new file mode 100644 index 0000000000000..33574365958de --- /dev/null +++ b/tests/baselines/reference/checkGrammarStaticMemberName_es5.symbols @@ -0,0 +1,51 @@ +=== tests/cases/compiler/checkGrammarStaticMemberName_es5.ts === + +class static_property { +>static_property : Symbol(static_property, Decl(checkGrammarStaticMemberName_es5.ts, 0, 0)) + + static length = 1; +>length : Symbol(static_property.length, Decl(checkGrammarStaticMemberName_es5.ts, 1, 23)) + + static name = 1; +>name : Symbol(static_property.name, Decl(checkGrammarStaticMemberName_es5.ts, 2, 22)) + + static arguments = 1; +>arguments : Symbol(static_property.arguments, Decl(checkGrammarStaticMemberName_es5.ts, 3, 20)) + + static caller = 1; +>caller : Symbol(static_property.caller, Decl(checkGrammarStaticMemberName_es5.ts, 4, 25)) + + static foo = { +>foo : Symbol(static_property.foo, Decl(checkGrammarStaticMemberName_es5.ts, 5, 22)) + + ["length"]: 1, +>"length" : Symbol(["length"], Decl(checkGrammarStaticMemberName_es5.ts, 6, 18)) + + ["name"]: 1, +>"name" : Symbol(["name"], Decl(checkGrammarStaticMemberName_es5.ts, 7, 22)) + + ["arguments"]: 1, +>"arguments" : Symbol(["arguments"], Decl(checkGrammarStaticMemberName_es5.ts, 8, 20)) + + ["caller"]: 1, +>"caller" : Symbol(["caller"], Decl(checkGrammarStaticMemberName_es5.ts, 9, 25)) + + }; +} + +class static_method { +>static_method : Symbol(static_method, Decl(checkGrammarStaticMemberName_es5.ts, 12, 1)) + + static length() { return 1; } +>length : Symbol(static_method.length, Decl(checkGrammarStaticMemberName_es5.ts, 14, 21)) + + static name() { return 1; } +>name : Symbol(static_method.name, Decl(checkGrammarStaticMemberName_es5.ts, 15, 33)) + + static arguments() { return 1; } +>arguments : Symbol(static_method.arguments, Decl(checkGrammarStaticMemberName_es5.ts, 16, 31)) + + static caller() { return 1; } +>caller : Symbol(static_method.caller, Decl(checkGrammarStaticMemberName_es5.ts, 17, 36)) +} + diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es5.types b/tests/baselines/reference/checkGrammarStaticMemberName_es5.types new file mode 100644 index 0000000000000..c8478a5467753 --- /dev/null +++ b/tests/baselines/reference/checkGrammarStaticMemberName_es5.types @@ -0,0 +1,64 @@ +=== tests/cases/compiler/checkGrammarStaticMemberName_es5.ts === + +class static_property { +>static_property : static_property + + static length = 1; +>length : number +>1 : 1 + + static name = 1; +>name : number +>1 : 1 + + static arguments = 1; +>arguments : number +>1 : 1 + + static caller = 1; +>caller : number +>1 : 1 + + static foo = { +>foo : { ["length"]: number; ["name"]: number; ["arguments"]: number; ["caller"]: number; } +>{ ["length"]: 1, ["name"]: 1, ["arguments"]: 1, ["caller"]: 1, } : { ["length"]: number; ["name"]: number; ["arguments"]: number; ["caller"]: number; } + + ["length"]: 1, +>"length" : "length" +>1 : 1 + + ["name"]: 1, +>"name" : "name" +>1 : 1 + + ["arguments"]: 1, +>"arguments" : "arguments" +>1 : 1 + + ["caller"]: 1, +>"caller" : "caller" +>1 : 1 + + }; +} + +class static_method { +>static_method : static_method + + static length() { return 1; } +>length : () => number +>1 : 1 + + static name() { return 1; } +>name : () => number +>1 : 1 + + static arguments() { return 1; } +>arguments : () => number +>1 : 1 + + static caller() { return 1; } +>caller : () => number +>1 : 1 +} + diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es6.errors.txt b/tests/baselines/reference/checkGrammarStaticMemberName_es6.errors.txt deleted file mode 100644 index 0b07dbecee7db..0000000000000 --- a/tests/baselines/reference/checkGrammarStaticMemberName_es6.errors.txt +++ /dev/null @@ -1,48 +0,0 @@ -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(3,5): error TS2697: 'length' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(4,5): error TS2697: 'name' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(5,5): error TS2697: 'arguments' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(6,5): error TS2697: 'caller' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(8,9): error TS2697: 'length' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(9,9): error TS2697: 'name' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(10,9): error TS2697: 'arguments' is not allowed to be used as a name of a static property in a class for target ES6 and higher. -tests/cases/compiler/checkGrammarStaticMemberName_es6.ts(11,9): error TS2697: 'caller' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - - -==== tests/cases/compiler/checkGrammarStaticMemberName_es6.ts (8 errors) ==== - - class static_property { - static length = 1; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2697: 'length' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - static name = 1; - ~~~~~~~~~~~~~~~~ -!!! error TS2697: 'name' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - static arguments = 1; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2697: 'arguments' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - static caller = 1; - ~~~~~~~~~~~~~~~~~~ -!!! error TS2697: 'caller' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - static foo = { - ["length"]: 1, - ~~~~~~~~~~ -!!! error TS2697: 'length' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - ["name"]: 1, - ~~~~~~~~ -!!! error TS2697: 'name' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - ["arguments"]: 1, - ~~~~~~~~~~~~~ -!!! error TS2697: 'arguments' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - ["caller"]: 1, - ~~~~~~~~~~ -!!! error TS2697: 'caller' is not allowed to be used as a name of a static property in a class for target ES6 and higher. - }; - } - - class static_method { - static length() { return 1; } - static name() { return 1; } - static arguments() { return 1; } - static caller() { return 1; } - } - \ No newline at end of file diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es6.symbols b/tests/baselines/reference/checkGrammarStaticMemberName_es6.symbols new file mode 100644 index 0000000000000..5f877e054ee7a --- /dev/null +++ b/tests/baselines/reference/checkGrammarStaticMemberName_es6.symbols @@ -0,0 +1,51 @@ +=== tests/cases/compiler/checkGrammarStaticMemberName_es6.ts === + +class static_property { +>static_property : Symbol(static_property, Decl(checkGrammarStaticMemberName_es6.ts, 0, 0)) + + static length = 1; +>length : Symbol(static_property.length, Decl(checkGrammarStaticMemberName_es6.ts, 1, 23)) + + static name = 1; +>name : Symbol(static_property.name, Decl(checkGrammarStaticMemberName_es6.ts, 2, 22)) + + static arguments = 1; +>arguments : Symbol(static_property.arguments, Decl(checkGrammarStaticMemberName_es6.ts, 3, 20)) + + static caller = 1; +>caller : Symbol(static_property.caller, Decl(checkGrammarStaticMemberName_es6.ts, 4, 25)) + + static foo = { +>foo : Symbol(static_property.foo, Decl(checkGrammarStaticMemberName_es6.ts, 5, 22)) + + ["length"]: 1, +>"length" : Symbol(["length"], Decl(checkGrammarStaticMemberName_es6.ts, 6, 18)) + + ["name"]: 1, +>"name" : Symbol(["name"], Decl(checkGrammarStaticMemberName_es6.ts, 7, 22)) + + ["arguments"]: 1, +>"arguments" : Symbol(["arguments"], Decl(checkGrammarStaticMemberName_es6.ts, 8, 20)) + + ["caller"]: 1, +>"caller" : Symbol(["caller"], Decl(checkGrammarStaticMemberName_es6.ts, 9, 25)) + + }; +} + +class static_method { +>static_method : Symbol(static_method, Decl(checkGrammarStaticMemberName_es6.ts, 12, 1)) + + static length() { return 1; } +>length : Symbol(static_method.length, Decl(checkGrammarStaticMemberName_es6.ts, 14, 21)) + + static name() { return 1; } +>name : Symbol(static_method.name, Decl(checkGrammarStaticMemberName_es6.ts, 15, 33)) + + static arguments() { return 1; } +>arguments : Symbol(static_method.arguments, Decl(checkGrammarStaticMemberName_es6.ts, 16, 31)) + + static caller() { return 1; } +>caller : Symbol(static_method.caller, Decl(checkGrammarStaticMemberName_es6.ts, 17, 36)) +} + diff --git a/tests/baselines/reference/checkGrammarStaticMemberName_es6.types b/tests/baselines/reference/checkGrammarStaticMemberName_es6.types new file mode 100644 index 0000000000000..b78ca9c96578f --- /dev/null +++ b/tests/baselines/reference/checkGrammarStaticMemberName_es6.types @@ -0,0 +1,64 @@ +=== tests/cases/compiler/checkGrammarStaticMemberName_es6.ts === + +class static_property { +>static_property : static_property + + static length = 1; +>length : number +>1 : 1 + + static name = 1; +>name : number +>1 : 1 + + static arguments = 1; +>arguments : number +>1 : 1 + + static caller = 1; +>caller : number +>1 : 1 + + static foo = { +>foo : { ["length"]: number; ["name"]: number; ["arguments"]: number; ["caller"]: number; } +>{ ["length"]: 1, ["name"]: 1, ["arguments"]: 1, ["caller"]: 1, } : { ["length"]: number; ["name"]: number; ["arguments"]: number; ["caller"]: number; } + + ["length"]: 1, +>"length" : "length" +>1 : 1 + + ["name"]: 1, +>"name" : "name" +>1 : 1 + + ["arguments"]: 1, +>"arguments" : "arguments" +>1 : 1 + + ["caller"]: 1, +>"caller" : "caller" +>1 : 1 + + }; +} + +class static_method { +>static_method : static_method + + static length() { return 1; } +>length : () => number +>1 : 1 + + static name() { return 1; } +>name : () => number +>1 : 1 + + static arguments() { return 1; } +>arguments : () => number +>1 : 1 + + static caller() { return 1; } +>caller : () => number +>1 : 1 +} + diff --git a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt index 494eaef6f0820..5962654080621 100644 --- a/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt +++ b/tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(8,19): error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(12,1): error TS2322: Type 'C' is not assignable to type 'A'. Property 'name' is missing in type 'C'. tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(13,1): error TS2322: Type 'typeof B' is not assignable to type 'A'. @@ -9,7 +8,7 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment. Property 'name' is missing in type 'typeof B'. -==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (5 errors) ==== +==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (4 errors) ==== interface A { name(); } @@ -18,8 +17,6 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment. } class C { public static name() { } - ~~~~ -!!! error TS2696: 'name' is not allowed to be used as a name of a static property or method in a class for target ES5. } var a: A = new B();