Skip to content

Commit 649b892

Browse files
committed
feat(Scope): expose transcluded and isolate scope info for batarang
test($compile): add test for exposing transclude and isolate scope info to batarang
1 parent e0295cf commit 649b892

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/ng/compile.js

+3
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ function $CompileProvider($provide) {
420420
(function(transcludeFn) {
421421
return function(cloneFn) {
422422
var transcludeScope = scope.$new();
423+
transcludeScope.$$transcluded = true;
423424

424425
return transcludeFn(transcludeScope, cloneFn).
425426
bind('$destroy', bind(transcludeScope, transcludeScope.$destroy));
@@ -725,6 +726,8 @@ function $CompileProvider($provide) {
725726
lastValue,
726727
parentGet, parentSet;
727728

729+
scope.$$isolateBindings[scopeName] = mode + attrName;
730+
728731
switch (mode) {
729732

730733
case '@': {

src/ng/rootScope.js

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function $RootScopeProvider(){
137137
this.$$destroyed = false;
138138
this.$$asyncQueue = [];
139139
this.$$listeners = {};
140+
this.$$isolateBindings = {};
140141
}
141142

142143
/**

test/ng/compileSpec.js

+38
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,21 @@ describe('$compile', function() {
19381938
compile('<div><span bad-declaration>');
19391939
}).toThrow('Invalid isolate scope definition for directive badDeclaration: xxx');
19401940
}));
1941+
1942+
it('should expose a $$isolateBindings property onto the scope', inject(function() {
1943+
compile('<div><span my-component>');
1944+
1945+
expect(typeof componentScope.$$isolateBindings).toBe('object');
1946+
1947+
expect(componentScope.$$isolateBindings.attr).toBe('@attr');
1948+
expect(componentScope.$$isolateBindings.attrAlias).toBe('@attr');
1949+
expect(componentScope.$$isolateBindings.ref).toBe('=ref');
1950+
expect(componentScope.$$isolateBindings.refAlias).toBe('=ref');
1951+
expect(componentScope.$$isolateBindings.reference).toBe('=reference');
1952+
expect(componentScope.$$isolateBindings.expr).toBe('&expr');
1953+
expect(componentScope.$$isolateBindings.exprAlias).toBe('&expr');
1954+
1955+
}));
19411956
});
19421957

19431958

@@ -2264,5 +2279,28 @@ describe('$compile', function() {
22642279

22652280
expect(element.text()).toBe('-->|x|');
22662281
}));
2282+
2283+
2284+
it('should add a $$transcluded property onto the transcluded scope', function() {
2285+
module(function() {
2286+
directive('trans', function() {
2287+
return {
2288+
transclude: true,
2289+
replace: true,
2290+
scope: true,
2291+
template: '<div><span>I:{{$$transcluded}}</span><div ng-transclude></div></div>'
2292+
};
2293+
});
2294+
});
2295+
inject(function(log, $rootScope, $compile) {
2296+
element = $compile('<div><div trans>T:{{$$transcluded}}</div></div>')
2297+
($rootScope);
2298+
$rootScope.$apply();
2299+
expect(jqLite(element.find('span')[0]).text()).toEqual('I:');
2300+
expect(jqLite(element.find('span')[1]).text()).toEqual('T:true');
2301+
});
2302+
});
2303+
2304+
22672305
});
22682306
});

0 commit comments

Comments
 (0)