Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 10000d6

Browse files
fix($compile): swap keys and values for transclude definition object
1 parent 4785304 commit 10000d6

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/ng/compile.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,33 +1868,39 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18681868
} else {
18691869

18701870
var slots = createMap();
1871+
18711872
$template = jqLite(jqLiteClone(compileNode)).contents();
18721873

18731874
if (isObject(directiveValue)) {
18741875

1875-
// We have transclusion slots - collect them up and compile them and store their
1876-
// transclusion functions
1876+
// We have transclusion slots,
1877+
// collect them up, compile them and store their transclusion functions
18771878
$template = [];
1878-
var slotNames = createMap();
1879+
1880+
var slotMap = createMap();
18791881
var filledSlots = createMap();
18801882

1881-
// Parse the slot names: if they start with a ? then they are optional
1882-
forEach(directiveValue, function(slotName, key) {
1883-
var optional = (slotName.charAt(0) === '?');
1884-
slotName = optional ? slotName.substring(1) : slotName;
1885-
slotNames[key] = slotName;
1883+
// Parse the element selectors
1884+
forEach(directiveValue, function(elementSelector, slotName) {
1885+
// If an element selector starts with a ? then it is optional
1886+
var optional = (elementSelector.charAt(0) === '?');
1887+
elementSelector = optional ? elementSelector.substring(1) : elementSelector;
1888+
1889+
slotMap[elementSelector] = slotName;
1890+
18861891
// We explicitly assign `null` since this implies that a slot was defined but not filled.
18871892
// Later when calling boundTransclusion functions with a slot name we only error if the
18881893
// slot is `undefined`
18891894
slots[slotName] = null;
1895+
18901896
// filledSlots contains `true` for all slots that are either optional or have been
18911897
// filled. This is used to check that we have not missed any required slots
18921898
filledSlots[slotName] = optional;
18931899
});
18941900

18951901
// Add the matching elements into their slot
18961902
forEach($compileNode.contents(), function(node) {
1897-
var slotName = slotNames[directiveNormalize(nodeName_(node))];
1903+
var slotName = slotMap[nodeName_(node)];
18981904
if (slotName) {
18991905
filledSlots[slotName] = true;
19001906
slots[slotName] = slots[slotName] || [];

test/ng/compileSpec.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33

4-
describe('$compile', function() {
4+
ddescribe('$compile', function() {
55
function isUnknownElement(el) {
66
return !!el.toString().match(/Unknown/);
77
}
@@ -7660,7 +7660,7 @@ describe('$compile', function() {
76607660
restrict: 'E',
76617661
scope: {},
76627662
transclude: {
7663-
boss: 'bossSlot'
7663+
bossSlot: 'boss'
76647664
},
76657665
template:
76667666
'<div class="other" ng-transclude></div>'
@@ -7722,7 +7722,7 @@ describe('$compile', function() {
77227722
restrict: 'E',
77237723
scope: {},
77247724
transclude: {
7725-
boss: 'bossSlot'
7725+
bossSlot: 'boss'
77267726
},
77277727
template:
77287728
'<div class="other" ng-transclude></div>'
@@ -7751,8 +7751,8 @@ describe('$compile', function() {
77517751
restrict: 'E',
77527752
scope: {},
77537753
transclude: {
7754-
minion: 'minionSlot',
7755-
boss: 'bossSlot'
7754+
minionSlot: 'minion',
7755+
bossSlot: 'boss'
77567756
},
77577757
template:
77587758
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -7784,8 +7784,8 @@ describe('$compile', function() {
77847784
restrict: 'E',
77857785
scope: {},
77867786
transclude: {
7787-
minion: 'minionSlot',
7788-
boss: 'bossSlot'
7787+
minionSlot: 'minion',
7788+
bossSlot: 'boss'
77897789
},
77907790
template:
77917791
'<ng-transclude class="boss" ng-transclude-slot="bossSlot"></ng-transclude>' +
@@ -7816,8 +7816,8 @@ describe('$compile', function() {
78167816
restrict: 'E',
78177817
scope: {},
78187818
transclude: {
7819-
minion: 'minionSlot',
7820-
boss: 'bossSlot'
7819+
minionSlot: 'minion',
7820+
bossSlot: 'boss'
78217821
},
78227822
template:
78237823
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -7845,8 +7845,8 @@ describe('$compile', function() {
78457845
restrict: 'E',
78467846
scope: {},
78477847
transclude: {
7848-
minion: 'minionSlot',
7849-
boss: '?bossSlot'
7848+
minionSlot: 'minion',
7849+
bossSlot: '?boss'
78507850
},
78517851
template:
78527852
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -7875,7 +7875,7 @@ describe('$compile', function() {
78757875
restrict: 'E',
78767876
scope: {},
78777877
transclude: {
7878-
minion: 'minionSlot'
7878+
minionSlot: 'minion'
78797879
},
78807880
template:
78817881
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -7923,14 +7923,14 @@ describe('$compile', function() {
79237923
});
79247924

79257925

7926-
it('should match against the normalized form of the element', function() {
7926+
it('should not normalize the element name', function() {
79277927
module(function() {
79287928
directive('foo', function() {
79297929
return {
79307930
restrict: 'E',
79317931
scope: {},
79327932
transclude: {
7933-
fooBar: 'fooBarSlot'
7933+
fooBarSlot: 'foo-bar'
79347934
},
79357935
template:
79367936
'<div class="other" ng-transclude="fooBarSlot"></div>'
@@ -7956,8 +7956,8 @@ describe('$compile', function() {
79567956
restrict: 'E',
79577957
scope: {},
79587958
transclude: {
7959-
minion: 'minionSlot',
7960-
boss: 'bossSlot'
7959+
minionSlot: 'minion',
7960+
bossSlot: 'boss'
79617961
},
79627962
template:
79637963
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -8011,8 +8011,8 @@ describe('$compile', function() {
80118011
restrict: 'E',
80128012
scope: {},
80138013
transclude: {
8014-
minion: 'minionSlot',
8015-
boss: '?bossSlot'
8014+
minionSlot: 'minion',
8015+
bossSlot: '?boss'
80168016
},
80178017
link: function(s, e, a, c, transcludeFn) {
80188018
capturedTranscludeFn = transcludeFn;
@@ -8038,8 +8038,8 @@ describe('$compile', function() {
80388038
restrict: 'E',
80398039
scope: {},
80408040
transclude: {
8041-
minion: 'minionSlot',
8042-
boss: '?bossSlot'
8041+
minionSlot: 'minion',
8042+
bossSlot: '?boss'
80438043
},
80448044
template:
80458045
'<div class="boss" ng-transclude="bossSlot">default boss content</div>' +

0 commit comments

Comments
 (0)