File tree 3 files changed +61
-5
lines changed
3 files changed +61
-5
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ var canReflect = require("can-reflect");
18
18
var canLog = require ( 'can-log/dev/dev' ) ;
19
19
var defineLazyValue = require ( 'can-define-lazy-value' ) ;
20
20
var stacheHelpers = require ( 'can-stache-helpers' ) ;
21
- var SimpleMap = require ( 'can-simple-map ' ) ;
21
+ var LetContext = require ( './let-context ' ) ;
22
22
23
23
24
24
// ## Helpers
@@ -30,10 +30,6 @@ function returnFalse(){
30
30
return false ;
31
31
}
32
32
33
- // ### LetContext
34
- // Instances of this are used to create a `let` variable context.
35
- var LetContext = SimpleMap . extend ( "LetContext" , { } ) ;
36
-
37
33
// ## Scope
38
34
// Represents a node in the scope tree.
39
35
function Scope ( context , parent , meta ) {
Original file line number Diff line number Diff line change
1
+ var SimpleMap = require ( 'can-simple-map' ) ;
2
+
3
+ // ### LetContext
4
+ // Instances of this are used to create a `let` variable context.
5
+
6
+ // Like Object.create, but only keeps Symbols and properties in `propertiesToKeep`
7
+ function objectCreateWithSymbolsAndSpecificProperties ( obj , propertiesToKeep ) {
8
+ var newObj = { } ;
9
+
10
+ // copy over all Symbols from obj
11
+ if ( "getOwnPropertySymbols" in Object ) {
12
+ Object . getOwnPropertySymbols ( obj ) . forEach ( function ( key ) {
13
+ newObj [ key ] = obj [ key ] ;
14
+ } ) ;
15
+ }
16
+
17
+ // copy over specific properties from obj (also fake Symbols properties for IE support);
18
+ Object . getOwnPropertyNames ( obj ) . forEach ( function ( key ) {
19
+ if ( propertiesToKeep . indexOf ( key ) >= 0 || key . indexOf ( "@@symbol" ) === 0 ) {
20
+ newObj [ key ] = obj [ key ] ;
21
+ }
22
+ } ) ;
23
+
24
+ return Object . create ( newObj ) ;
25
+ }
26
+
27
+ var LetContext = SimpleMap . extend ( "LetContext" , { } ) ;
28
+ LetContext . prototype = objectCreateWithSymbolsAndSpecificProperties ( SimpleMap . prototype , [
29
+ // SimpleMap properties
30
+ "setup" ,
31
+ "attr" ,
32
+ "serialize" ,
33
+ "get" ,
34
+ "set" ,
35
+ "log" ,
36
+ // required by SimpleMap properties
37
+ "dispatch" ,
38
+ // Construct properties (not added by can-event-queue)
39
+ "constructorExtends" ,
40
+ "newInstance" ,
41
+ "_inherit" ,
42
+ "_defineProperty" ,
43
+ "_overwrite" ,
44
+ "instance" ,
45
+ "extend" ,
46
+ "ReturnValue" ,
47
+ "setup" ,
48
+ "init"
49
+ ] ) ;
50
+ LetContext . prototype . constructor = LetContext ;
51
+
52
+ module . exports = LetContext ;
Original file line number Diff line number Diff line change @@ -1379,7 +1379,15 @@ QUnit.test("able to read partials", function(assert) {
1379
1379
var result = scope . get ( "myPartial" ) ;
1380
1380
1381
1381
assert . equal ( result , myPartial , "read the value" ) ;
1382
+ } ) ;
1383
+
1384
+ QUnit . test ( "properties can shadow functions on can-event-queue/map when there is a LetContext" , function ( assert ) {
1385
+ var scope = new Scope ( {
1386
+ one : "the one property"
1387
+ } )
1388
+ . addLetContext ( ) ;
1382
1389
1390
+ assert . equal ( scope . get ( "one" ) , "the one property" , "read the value" ) ;
1383
1391
} ) ;
1384
1392
1385
1393
require ( "./variable-scope-test" ) ;
You can’t perform that action at this time.
0 commit comments