File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -651,10 +651,14 @@ helpers.superPropBase = helper("7.0.0-beta.0")`
651651 }
652652` ;
653653
654+ // https://tc39.es/ecma262/multipage/reflection.html#sec-reflect.get
655+ //
656+ // 28.1.5 Reflect.get ( target, propertyKey [ , receiver ] )
657+ //
654658helpers . get = helper ( "7.0.0-beta.0" ) `
655659 import superPropBase from "superPropBase";
656660
657- export default function _get(target, property, receiver ) {
661+ export default function _get() {
658662 if (typeof Reflect !== "undefined" && Reflect.get) {
659663 _get = Reflect.get;
660664 } else {
@@ -665,13 +669,14 @@ helpers.get = helper("7.0.0-beta.0")`
665669
666670 var desc = Object.getOwnPropertyDescriptor(base, property);
667671 if (desc.get) {
668- return desc.get.call(receiver);
672+ // STEP 3. If receiver is not present, then set receiver to target.
673+ return desc.get.call(arguments.length < 3 ? target : receiver);
669674 }
670675
671676 return desc.value;
672677 };
673678 }
674- return _get(target, property, receiver || target );
679+ return _get.apply(this, arguments );
675680 }
676681` ;
677682
Original file line number Diff line number Diff line change 1+ // ensure we test the helper implementation,
2+ // not built-in Reflect.get to which it defers
3+ delete Reflect ;
4+
5+ class Target {
6+ get typeOf ( ) {
7+ return this === null ? "null" : typeof this ;
8+ }
9+ } ;
10+
11+ // check that the 1st argument (target) *is not* used
12+ // in place of present but undefined 3rd argument (receiver)
13+ expect ( HELPER_GET ( new Target , "typeOf" , undefined ) ) . toBe ( "undefined" ) ;
14+
15+ // because the helper replaces itself upon invocation,
16+ // check it again with nullish arguments
17+ expect ( HELPER_GET ( new Target , "typeOf" , undefined ) ) . toBe ( "undefined" ) ;
18+ expect ( HELPER_GET ( new Target , "typeOf" , null ) ) . toBe ( "null" ) ;
19+
20+ // check other falsy types
21+ expect ( HELPER_GET ( new Target , "typeOf" , false ) ) . toBe ( "boolean" ) ;
22+ expect ( HELPER_GET ( new Target , "typeOf" , 0 ) ) . toBe ( "number" ) ;
23+ expect ( HELPER_GET ( new Target , "typeOf" , "" ) ) . toBe ( "string" ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "plugins" : [" ./plugin" ]
3+ }
Original file line number Diff line number Diff line change 1+ module . exports = function ( ) {
2+ return {
3+ visitor : {
4+ Identifier ( path ) {
5+ if ( path . node . name === "HELPER_GET" ) {
6+ const helper = this . addHelper ( "get" ) ;
7+ path . replaceWith ( helper ) ;
8+ }
9+ } ,
10+ } ,
11+ } ;
12+ } ;
Original file line number Diff line number Diff line change 1+ // ensure we test the helper implementation,
2+ // not built-in Reflect.get to which it defers
3+ delete Reflect ;
4+
5+ class Target {
6+ get receiver ( ) {
7+ return this ;
8+ }
9+ } ;
10+
11+ // check that the 1st argument (target) *is* used
12+ // in place of missing 3rd argument (receiver)
13+ expect ( HELPER_GET ( new Target , "receiver" ) ) . toBeInstanceOf ( Target ) ;
14+
15+ // because the helper replaces itself upon invocation,
16+ // check it again with the same arguments
17+ expect ( HELPER_GET ( new Target , "receiver" ) ) . toBeInstanceOf ( Target ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "plugins" : [" ./plugin" ]
3+ }
Original file line number Diff line number Diff line change 1+ module . exports = function ( ) {
2+ return {
3+ visitor : {
4+ Identifier ( path ) {
5+ if ( path . node . name === "HELPER_GET" ) {
6+ const helper = this . addHelper ( "get" ) ;
7+ path . replaceWith ( helper ) ;
8+ }
9+ } ,
10+ } ,
11+ } ;
12+ } ;
You can’t perform that action at this time.
0 commit comments