privatename-valid-no-earlyerr.js (1588B)
1 // |reftest| module 2 // Copyright (C) 2017 Valerie Young. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: sec-module-semantics-static-semantics-early-errors 6 description: Referencing privatename in class within class does not error. 7 info: | 8 Static Semantics: Early Errors 9 Module : ModuleBody 10 It is a Syntax Error if AllPrivateNamesValid of ModuleBody with an empty List as an argument is false. 11 12 Static Semantics: AllPrivateNamesValid 13 AllPrivateNamesValid is an abstract operation which takes names as an argument. 14 15 MemberExpression : MemberExpression . PrivateName 16 1. If StringValue of PrivateName is in names, return true. 17 2. Return false. 18 19 CallExpression : CallExpression . PrivateName 20 1. If StringValue of PrivateName is in names, return true. 21 2. Return false. 22 23 ClassBody:ClassElementList 24 1. Let newNames be the concatenation of names with PrivateBoundNames of ClassBody. 25 2.Return AllPrivateNamesValid of ClassElementList with the argument newNames. 26 27 For all other grammatical productions, recurse on subexpressions/substatements, passing in the names of the caller. If all pieces return true, then return true. If any returns false, return false. 28 flags: [module] 29 features: [class, class-fields-private] 30 ---*/ 31 32 class outer { 33 #x = 42; 34 35 f() { 36 var self = this; 37 return class inner { 38 g() { 39 return self.#x; 40 } 41 } 42 } 43 } 44 45 var innerclass = new outer().f(); 46 var test = new innerclass().g(); 47 48 assert.sameValue(test, 42); 49 50 reportCompare(0, 0);