From 2fa432f71c2ce3efec45f29884c7d381011c44eb Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Thu, 28 Jul 2016 12:02:33 +0200 Subject: [PATCH] few fixes about flags to compile css class and comment directives conditionally --- docs/content/guide/production.ngdoc | 20 +++++++++---- src/ng/compile.js | 44 +++++++++++------------------ 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/docs/content/guide/production.ngdoc b/docs/content/guide/production.ngdoc index 5871cc97af9d..bf9e1369c70c 100644 --- a/docs/content/guide/production.ngdoc +++ b/docs/content/guide/production.ngdoc @@ -77,16 +77,23 @@ For more information, see the ## Disable comment and css class directives -By default AngularJS compiles and executes all directives inside comments and element classes. In order to perform this task, angular compiler must look for directives by: +By default AngularJS compiles and executes all directives inside comments and element classes. +In order to perform this task, angular compiler must look for directives by: - Parse all your application element classes. - Parse all your application html comments. -Nowadays most of the Angular projects are using only element and attribute directives, and in such projects there is no need to compile comments and classes. +Nowadays most of the Angular projects are using only element and attribute directives, +and in such projects there is no need to compile comments and classes. -If you are sure that your project only use element directives and attribute directives, and you are not using any 3rd part library that uses directives inside element classes or html comments, you can disable. -This results in a compilation performance gain, as the compiler does not have to check comments and element classes looking for directives. +If you are sure that your project only uses element and attribute directives, +and you are not using any 3rd part library that uses +directives inside element classes or html comments, +you can disable the compilation of directives on element classes and comments +for the whole application. +This results in a compilation performance gain, +as the compiler does not have to check comments and element classes looking for directives. To disable comment and css class directives use the `$compileProvider`: @@ -95,5 +102,8 @@ $compileProvider.commentDirectivesEnabled(false); $compileProvider.cssClassDirectivesEnabled(false); ``` -For more see the docs pages on {@link ng.$compileProvider#commentDirectivesEnabled `$compileProvider.commentDirectivesEnabled`} and {@link ng.$compileProvider#cssClassDirectivesEnabled `$compileProvider.cssClassDirectivesEnabled`}. +For more see the docs pages on +{@link ng.$compileProvider#commentDirectivesEnabled `$compileProvider.commentDirectivesEnabled`} +and +{@link ng.$compileProvider#cssClassDirectivesEnabled `$compileProvider.cssClassDirectivesEnabled`}. diff --git a/src/ng/compile.js b/src/ng/compile.js index ea0e8d4c44c0..0549ceaf32b7 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1386,7 +1386,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { return TTL; }; - var COMMENT_DIRECTIVES_ENABLED = true; + var commentDirectivesEnabledConfig = true; /** * @ngdoc method * @name $compileProvider#commentDirectivesEnabled @@ -1400,28 +1400,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { * on comments for the whole application. * This results in a compilation performance gain, * as the compiler doesn't have to check comments when looking for directives. - * This should however only be used if you are sure that no comment directives are used in the application - * (including any 3rd party directives). + * This should however only be used if you are sure that no comment directives are used in + * the application (including any 3rd party directives). * - * Example: - * - * ``` - * $compileProvider.commentDirectivesEnabled(false); - * ``` - * - * @param {boolean} false if the compiler may ignore directives on comments - * @returns {number|object} the current value (or `this` if called as a setter for chaining) + * @param {boolean} enabled `false` if the compiler may ignore directives on comments + * @returns {boolean|object} the current value (or `this` if called as a setter for chaining) */ this.commentDirectivesEnabled = function(value) { if (arguments.length) { - COMMENT_DIRECTIVES_ENABLED = value; + commentDirectivesEnabledConfig = value; return this; } - return COMMENT_DIRECTIVES_ENABLED; + return commentDirectivesEnabledConfig; }; - var CSS_CLASS_DIRECTIVES_ENABLED = true; + var cssClassDirectivesEnabledConfig = true; /** * @ngdoc method * @name $compileProvider#cssClassDirectivesEnabled @@ -1435,24 +1429,18 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { * on element classes for the whole application. * This results in a compilation performance gain, * as the compiler doesn't have to check element classes when looking for directives. - * This should however only be used if you are sure that no class directives are used in the application - * (including any 3rd party directives). - * - * Example: - * - * ``` - * $compileProvider.cssClassDirectivesEnabled(false); - * ``` + * This should however only be used if you are sure that no class directives are used in + * the application (including any 3rd party directives). * - * @param {boolean} false if the compiler may ignore directives on element classes - * @returns {number|object} the current value (or `this` if called as a setter for chaining) + * @param {boolean} enabled `false` if the compiler may ignore directives on element classes + * @returns {boolean|object} the current value (or `this` if called as a setter for chaining) */ this.cssClassDirectivesEnabled = function(value) { if (arguments.length) { - CSS_CLASS_DIRECTIVES_ENABLED = value; + cssClassDirectivesEnabledConfig = value; return this; } - return CSS_CLASS_DIRECTIVES_ENABLED; + return cssClassDirectivesEnabledConfig; }; this.$get = [ @@ -1465,8 +1453,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { var specialAttrHolder = window.document.createElement('div'); - var commentDirectivesEnabled = COMMENT_DIRECTIVES_ENABLED; - var cssClassDirectivesEnabled = CSS_CLASS_DIRECTIVES_ENABLED; + var commentDirectivesEnabled = commentDirectivesEnabledConfig; + var cssClassDirectivesEnabled = cssClassDirectivesEnabledConfig; var onChangesTtl = TTL;