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

Commit bd530e2

Browse files
committed
chore($compile): remove obsolete <<CONTENT>> transclusion
This stuff was never documented and is an accidental leftover from the time when the compiler was rewritten. If any code depends on this, it should be rewritten to use ngTransclude directive intead.
1 parent 843f762 commit bd530e2

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

src/ng/compile.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ function $CompileProvider($provide) {
127127
Suffix = 'Directive',
128128
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
129129
CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
130-
CONTENT_REGEXP = /\<\<content\>\>/i,
131130
HAS_ROOT_ELEMENT = /^\<[\s\S]*\>$/;
132131

133132

@@ -569,9 +568,7 @@ function $CompileProvider($provide) {
569568
assertNoDuplicate('template', templateDirective, directive, element);
570569
templateDirective = directive;
571570

572-
// include the contents of the original element into the template and replace the element
573-
var content = directiveValue.replace(CONTENT_REGEXP, element.html());
574-
templateNode = jqLite(content)[0];
571+
templateNode = jqLite(directiveValue)[0];
575572
if (directive.replace) {
576573
replaceWith(rootElement, element, templateNode);
577574

@@ -593,7 +590,7 @@ function $CompileProvider($provide) {
593590

594591
ii = directives.length;
595592
} else {
596-
element.html(content);
593+
element.html(directiveValue);
597594
}
598595
}
599596

@@ -828,7 +825,6 @@ function $CompileProvider($provide) {
828825

829826
$http.get(asyncWidgetDirective.templateUrl, {cache: $templateCache}).
830827
success(function(content) {
831-
content = trim(content).replace(CONTENT_REGEXP, html);
832828
if (replace && !content.match(HAS_ROOT_ELEMENT)) {
833829
throw Error('Template must have exactly one root element: ' + content);
834830
}

test/ng/compileSpec.js

+30-24
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,15 @@ describe('$compile', function() {
364364
$compileProvider.directive('replace', valueFn({
365365
restrict: 'CAM',
366366
replace: true,
367-
template: '<div class="log" style="width: 10px" high-log>Hello: <<CONTENT>></div>',
367+
template: '<div class="log" style="width: 10px" high-log>Replace!</div>',
368368
compile: function(element, attr) {
369369
attr.$set('compiled', 'COMPILED');
370370
expect(element).toBe(attr.$$element);
371371
}
372372
}));
373373
$compileProvider.directive('append', valueFn({
374374
restrict: 'CAM',
375-
template: '<div class="log" style="width: 10px" high-log>Hello: <<CONTENT>></div>',
375+
template: '<div class="log" style="width: 10px" high-log>Append!</div>',
376376
compile: function(element, attr) {
377377
attr.$set('compiled', 'COMPILED');
378378
expect(element).toBe(attr.$$element);
@@ -382,34 +382,34 @@ describe('$compile', function() {
382382

383383

384384
it('should replace element with template', inject(function($compile, $rootScope) {
385-
element = $compile('<div><div replace>content</div><div>')($rootScope);
386-
expect(element.text()).toEqual('Hello: content');
385+
element = $compile('<div><div replace>ignore</div><div>')($rootScope);
386+
expect(element.text()).toEqual('Replace!');
387387
expect(element.find('div').attr('compiled')).toEqual('COMPILED');
388388
}));
389389

390390

391391
it('should append element with template', inject(function($compile, $rootScope) {
392-
element = $compile('<div><div append>content</div><div>')($rootScope);
393-
expect(element.text()).toEqual('Hello: content');
392+
element = $compile('<div><div append>ignore</div><div>')($rootScope);
393+
expect(element.text()).toEqual('Append!');
394394
expect(element.find('div').attr('compiled')).toEqual('COMPILED');
395395
}));
396396

397397

398-
it('should compile replace template', inject(function($compile, $rootScope, log) {
399-
element = $compile('<div><div replace medium-log>{{ "angular" }}</div><div>')
398+
it('should compile template when replacing', inject(function($compile, $rootScope, log) {
399+
element = $compile('<div><div replace medium-log>ignore</div><div>')
400400
($rootScope);
401401
$rootScope.$digest();
402-
expect(element.text()).toEqual('Hello: angular');
402+
expect(element.text()).toEqual('Replace!');
403403
// HIGH goes after MEDIUM since it executes as part of replaced template
404404
expect(log).toEqual('MEDIUM; HIGH; LOG');
405405
}));
406406

407407

408-
it('should compile append template', inject(function($compile, $rootScope, log) {
409-
element = $compile('<div><div append medium-log>{{ "angular" }}</div><div>')
408+
it('should compile template when appending', inject(function($compile, $rootScope, log) {
409+
element = $compile('<div><div append medium-log>ignore</div><div>')
410410
($rootScope);
411411
$rootScope.$digest();
412-
expect(element.text()).toEqual('Hello: angular');
412+
expect(element.text()).toEqual('Append!');
413413
expect(log).toEqual('HIGH; LOG; MEDIUM');
414414
}));
415415

@@ -436,23 +436,23 @@ describe('$compile', function() {
436436
}
437437
}));
438438

439-
it('should play nice with repeater when inline', inject(function($compile, $rootScope) {
439+
it('should play nice with repeater when replacing', inject(function($compile, $rootScope) {
440440
element = $compile(
441441
'<div>' +
442-
'<div ng-repeat="i in [1,2]" replace>{{i}}; </div>' +
442+
'<div ng-repeat="i in [1,2]" replace></div>' +
443443
'</div>')($rootScope);
444444
$rootScope.$digest();
445-
expect(element.text()).toEqual('Hello: 1; Hello: 2; ');
445+
expect(element.text()).toEqual('Replace!Replace!');
446446
}));
447447

448448

449-
it('should play nice with repeater when append', inject(function($compile, $rootScope) {
449+
it('should play nice with repeater when appending', inject(function($compile, $rootScope) {
450450
element = $compile(
451451
'<div>' +
452-
'<div ng-repeat="i in [1,2]" append>{{i}}; </div>' +
452+
'<div ng-repeat="i in [1,2]" append></div>' +
453453
'</div>')($rootScope);
454454
$rootScope.$digest();
455-
expect(element.text()).toEqual('Hello: 1; Hello: 2; ');
455+
expect(element.text()).toEqual('Append!Append!');
456456
}));
457457

458458

@@ -494,8 +494,12 @@ describe('$compile', function() {
494494

495495
beforeEach(module(
496496
function($compileProvider) {
497-
$compileProvider.directive('hello', valueFn({ restrict: 'CAM', templateUrl: 'hello.html' }));
498-
$compileProvider.directive('cau', valueFn({ restrict: 'CAM', templateUrl:'cau.html' }));
497+
$compileProvider.directive('hello', valueFn({
498+
restrict: 'CAM', templateUrl: 'hello.html', transclude: true
499+
}));
500+
$compileProvider.directive('cau', valueFn({
501+
restrict: 'CAM', templateUrl:'cau.html'
502+
}));
499503

500504
$compileProvider.directive('cError', valueFn({
501505
restrict: 'CAM',
@@ -930,9 +934,10 @@ describe('$compile', function() {
930934
}));
931935

932936

933-
it('should work when widget is in root element', inject(
937+
it('should work when directive is on the root element', inject(
934938
function($compile, $httpBackend, $rootScope) {
935-
$httpBackend.expect('GET', 'hello.html').respond('<span>3==<<content>></span>');
939+
$httpBackend.expect('GET', 'hello.html').
940+
respond('<span>3==<span ng-transclude></span></span>');
936941
element = jqLite('<b class="hello">{{1+2}}</b>');
937942
$compile(element)($rootScope);
938943

@@ -942,9 +947,10 @@ describe('$compile', function() {
942947
));
943948

944949

945-
it('should work when widget is a repeater', inject(
950+
it('should work when directive is a repeater', inject(
946951
function($compile, $httpBackend, $rootScope) {
947-
$httpBackend.expect('GET', 'hello.html').respond('<span>i=<<content>>;</span>');
952+
$httpBackend.expect('GET', 'hello.html').
953+
respond('<span>i=<span ng-transclude></span>;</span>');
948954
element = jqLite('<div><b class=hello ng-repeat="i in [1,2]">{{i}}</b></div>');
949955
$compile(element)($rootScope);
950956

0 commit comments

Comments
 (0)