Skip to content

Commit d12df0d

Browse files
committed
refactor(compiler) turn compiler into a service
BREAK - remove angular.compile() since the compile method is now a service and needs to be injected
1 parent d9b58f2 commit d12df0d

16 files changed

Lines changed: 687 additions & 678 deletions

‎src/Angular.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,6 @@ function toBoolean(value) {
854854
}
855855

856856

857-
/** @name angular.compile */
858-
function compile(element) {
859-
return new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget)
860-
.compile(element);
861-
}
862857
/////////////////////////////////////////////////
863858

864859
/**
@@ -956,7 +951,7 @@ function angularInit(config, document){
956951
injector = createInjector(),
957952
scope = injector('$rootScope');
958953

959-
compile(element)(scope);
954+
injector('$compile')(element)(scope);
960955
scope.$apply();
961956
}
962957
}

‎src/AngularPublic.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ angularService('$browser', function($log, $sniffer) {
1414
extend(angular, {
1515
// disabled for now until we agree on public name
1616
//'annotate': annotate,
17-
'compile': compile,
1817
'copy': copy,
1918
'extend': extend,
2019
'equals': equals,

‎src/service/compiler.js‎

Lines changed: 291 additions & 278 deletions
Large diffs are not rendered by default.

‎src/widget/select.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+
130130
angularWidget('select', function(element){
131131
this.directives(true);
132132
this.descend(true);
133-
return element.attr('ng:model') && annotate('$formFactory', function($formFactory, selectElement){
133+
return element.attr('ng:model') &&
134+
annotate('$formFactory', '$compile', function($formFactory, $compile, selectElement){
134135
var modelScope = this,
135136
match,
136137
form = $formFactory.forElement(selectElement),
@@ -245,7 +246,7 @@ angularWidget('select', function(element){
245246
// developer declared null option, so user should be able to select it
246247
nullOption = jqLite(option).remove();
247248
// compile the element since there might be bindings in it
248-
compile(nullOption)(modelScope);
249+
$compile(nullOption)(modelScope);
249250
}
250251
});
251252
selectElement.html(''); // clear contents

‎test/AngularSpec.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe('angular', function() {
423423

424424

425425
describe('directive', function() {
426-
it('should register directives with case-insensitive id', function() {
426+
it('should register directives with case-insensitive id', inject(function($compile) {
427427
angularDirective('ALLCAPS', function(val, el) {el.text('+' + val + '+')});
428428
angularDirective('lowercase', function(val, el) {el.text('-' + val + '-')});
429429

@@ -433,14 +433,14 @@ describe('angular', function() {
433433
'<span ALLCAPS="xx3"></span>' +
434434
'<span lowerCASE="XX4">xx4</span>' +
435435
'</div>');
436-
compile(el);
436+
$compile(el);
437437
expect(lowercase(sortedHtml(el))).toBe('<div>' +
438438
'<span allcaps="xx1">+xx1+</span>' +
439439
'<span allcaps="xx2">+xx2+</span>' +
440440
'<span allcaps="xx3">+xx3+</span>' +
441441
'<span lowercase="xx4">-xx4-</span>' +
442442
'</div>');
443-
});
443+
}));
444444
});
445445

446446

@@ -458,25 +458,25 @@ describe('angular', function() {
458458
});
459459

460460
describe('compile', function() {
461-
it('should link to existing node and create scope', inject(function($rootScope) {
461+
it('should link to existing node and create scope', inject(function($rootScope, $compile) {
462462
var template = angular.element('<div>{{greeting = "hello world"}}</div>');
463-
angular.compile(template)($rootScope);
463+
$compile(template)($rootScope);
464464
$rootScope.$digest();
465465
expect(template.text()).toEqual('hello world');
466466
expect($rootScope.greeting).toEqual('hello world');
467467
}));
468468

469-
it('should link to existing node and given scope', inject(function($rootScope) {
469+
it('should link to existing node and given scope', inject(function($rootScope, $compile) {
470470
var template = angular.element('<div>{{greeting = "hello world"}}</div>');
471-
angular.compile(template)($rootScope);
471+
$compile(template)($rootScope);
472472
$rootScope.$digest();
473473
expect(template.text()).toEqual('hello world');
474474
}));
475475

476-
it('should link to new node and given scope', inject(function($rootScope) {
476+
it('should link to new node and given scope', inject(function($rootScope, $compile) {
477477
var template = jqLite('<div>{{greeting = "hello world"}}</div>');
478478

479-
var templateFn = angular.compile(template);
479+
var templateFn = $compile(template);
480480
var templateClone = template.clone();
481481

482482
var element = templateFn($rootScope, function(clone){
@@ -490,9 +490,9 @@ describe('angular', function() {
490490
expect($rootScope.greeting).toEqual('hello world');
491491
}));
492492

493-
it('should link to cloned node and create scope', inject(function($rootScope) {
493+
it('should link to cloned node and create scope', inject(function($rootScope, $compile) {
494494
var template = jqLite('<div>{{greeting = "hello world"}}</div>');
495-
var element = angular.compile(template)($rootScope, noop);
495+
var element = $compile(template)($rootScope, noop);
496496
$rootScope.$digest();
497497
expect(template.text()).toEqual('');
498498
expect(element.text()).toEqual('hello world');

0 commit comments

Comments
 (0)