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

fix(*): do not break when modules are used with angular-loader #14794

Closed
wants to merge 7 commits into from
2 changes: 1 addition & 1 deletion karma-modules.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: modules', logFile: 'karma-modules.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaModules', 'angularSrcModules'),
files: angularFiles.mergeFilesFor('karmaModules'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


junitReporter: {
outputFile: 'test_out/modules.xml',
Expand Down
117 changes: 65 additions & 52 deletions src/ngAnimate/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,81 @@
"window": false,

"angular": false,
"noop": false,

"copy": false,
"forEach": false,
"extend": false,
"jqLite": false,
"isArray": false,
"isString": false,
"isObject": false,
"isUndefined": false,
"isDefined": false,
"isFunction": false,
"isElement": false,
/* ng helpers */
"copy": true,
"extend": true,
"forEach": true,
"isArray": true,
"isDefined": true,
"isElement": true,
"isFunction": true,
"isObject": true,
"isString": true,
"isUndefined": true,
"jqLite": true,
"noop": true,

"ELEMENT_NODE": false,
"COMMENT_NODE": false,
"NG_ANIMATE_CLASSNAME": false,
"NG_ANIMATE_CHILDREN_DATA": false,
/* ngAnimate constants */
"COMMENT_NODE": true,
"ELEMENT_NODE": true,
"NG_ANIMATE_CLASSNAME": true,
"NG_ANIMATE_CHILDREN_DATA": true,

"ADD_CLASS_SUFFIX": false,
"REMOVE_CLASS_SUFFIX": false,
"EVENT_CLASS_PREFIX": false,
"ACTIVE_CLASS_SUFFIX": false,
"PREPARE_CLASS_SUFFIX": false,
/* ngAnimate className constants */
"ADD_CLASS_SUFFIX": true,
"REMOVE_CLASS_SUFFIX": true,
"EVENT_CLASS_PREFIX": true,
"ACTIVE_CLASS_SUFFIX": true,
"PREPARE_CLASS_SUFFIX": true,

"TRANSITION_DURATION_PROP": false,
"TRANSITION_DELAY_PROP": false,
"TRANSITION_PROP": false,
"PROPERTY_KEY": false,
"DURATION_KEY": false,
"DELAY_KEY": false,
"TIMING_KEY": false,
"ANIMATION_DURATION_PROP": false,
"ANIMATION_DELAY_PROP": false,
"ANIMATION_PROP": false,
"ANIMATION_ITERATION_COUNT_KEY": false,
"SAFE_FAST_FORWARD_DURATION_VALUE": false,
"TRANSITIONEND_EVENT": false,
"ANIMATIONEND_EVENT": false,
/* ngAnimate CSS constants */
"ANIMATION_DELAY_PROP": true,
"ANIMATION_DURATION_PROP": true,
"ANIMATION_ITERATION_COUNT_KEY": true,
"ANIMATION_PROP": true,
"ANIMATIONEND_EVENT": true,
"DELAY_KEY": true,
"DURATION_KEY": true,
"PROPERTY_KEY": true,
"SAFE_FAST_FORWARD_DURATION_VALUE": true,
"TIMING_KEY": true,
"TRANSITION_DELAY_PROP": true,
"TRANSITION_DURATION_PROP": true,
"TRANSITION_PROP": true,
"TRANSITIONEND_EVENT": true,

"assertArg": false,
"isPromiseLike": false,
"mergeClasses": false,
"mergeAnimationDetails": false,
"prepareAnimationOptions": false,
"applyAnimationStyles": false,
/* ngAnimate helpers */
"applyAnimationClassesFactory": false,
"applyAnimationFromStyles": false,
"applyAnimationStyles": false,
"applyAnimationToStyles": false,
"applyAnimationClassesFactory": false,
"pendClasses": false,
"normalizeCssProp": false,
"applyGeneratedPreparationClasses": false,
"applyInlineStyle": false,
"assertArg": false,
"blockKeyframeAnimations": false,
"blockTransitions": false,
"clearGeneratedClasses": false,
"concatWithSpace": false,
"extractElementNode": false,
"getDomNode": false,
"mergeAnimationDetails": false,
"mergeClasses": false,
"packageStyles": false,
"pendClasses": false,
"prepareAnimationOptions": false,
"removeFromArray": false,
"stripCommentsFromElement": false,
"extractElementNode": false,
"getDomNode": false,

"applyGeneratedPreparationClasses": false,
"clearGeneratedClasses": false,
"blockTransitions": false,
"blockKeyframeAnimations": false,
"applyInlineStyle": false,
"concatWithSpace": false
/* ngAnimate directives/services */
"ngAnimateSwapDirective": true,
"$$rAFSchedulerFactory": true,
"$$AnimateChildrenDirective": true,
"$$AnimateQueueProvider": true,
"$$AnimationProvider": true,
"$AnimateCssProvider": true,
"$$AnimateCssDriverProvider": true,
"$$AnimateJsProvider": true,
"$$AnimateJsDriverProvider": true
}
}
2 changes: 1 addition & 1 deletion src/ngAnimate/animateChildrenDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var $$AnimateChildrenDirective = ['$interpolate', function($interpolate) {
return {
link: function(scope, element, attrs) {
var val = attrs.ngAnimateChildren;
if (angular.isString(val) && val.length === 0) { //empty attribute
if (isString(val) && val.length === 0) { //empty attribute
element.data(NG_ANIMATE_CHILDREN_DATA, true);
} else {
// Interpolate and set the value, so that it is available to
Expand Down
2 changes: 1 addition & 1 deletion src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
},

off: function(event, container, callback) {
if (arguments.length === 1 && !angular.isString(arguments[0])) {
if (arguments.length === 1 && !isString(arguments[0])) {
container = arguments[0];
for (var eventType in callbackRegistry) {
callbackRegistry[eventType] = filterFromRegistry(callbackRegistry[eventType], container);
Expand Down
44 changes: 29 additions & 15 deletions src/ngAnimate/module.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
'use strict';

/* global angularAnimateModule: true,

ngAnimateSwapDirective,
$$AnimateAsyncRunFactory,
$$rAFSchedulerFactory,
$$AnimateChildrenDirective,
$$AnimateQueueProvider,
$$AnimationProvider,
$AnimateCssProvider,
$$AnimateCssDriverProvider,
$$AnimateJsProvider,
$$AnimateJsDriverProvider,
*/

/**
* @ngdoc module
* @name ngAnimate
Expand Down Expand Up @@ -730,6 +716,19 @@
* (Note that you will need to trigger a digest within the callback to get angular to notice any scope-related changes.)
*/

var copy;
var extend;
var forEach;
var isArray;
var isDefined;
var isElement;
var isFunction;
var isObject;
var isString;
var isUndefined;
var jqLite;
var noop;

/**
* @ngdoc service
* @name $animate
Expand All @@ -740,7 +739,22 @@
*
* Click here {@link ng.$animate to learn more about animations with `$animate`}.
*/
angular.module('ngAnimate', [])
angular.module('ngAnimate', [], function initAngularHelpers() {
// Access helpers from angular core.
// Do it inside a `config` block to ensure `window.angular` is available.
noop = angular.noop;
copy = angular.copy;
extend = angular.extend;
jqLite = angular.element;
forEach = angular.forEach;
isArray = angular.isArray;
isString = angular.isString;
isObject = angular.isObject;
isUndefined = angular.isUndefined;
isDefined = angular.isDefined;
isFunction = angular.isFunction;
isElement = angular.isElement;
})
.directive('ngAnimateSwap', ngAnimateSwapDirective)

.directive('ngAnimateChildren', $$AnimateChildrenDirective)
Expand Down
28 changes: 4 additions & 24 deletions src/ngAnimate/shared.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
'use strict';

/* jshint ignore:start */
var noop = angular.noop;
var copy = angular.copy;
var extend = angular.extend;
var jqLite = angular.element;
var forEach = angular.forEach;
var isArray = angular.isArray;
var isString = angular.isString;
var isObject = angular.isObject;
var isUndefined = angular.isUndefined;
var isDefined = angular.isDefined;
var isFunction = angular.isFunction;
var isElement = angular.isElement;

var ELEMENT_NODE = 1;
var COMMENT_NODE = 8;

Expand All @@ -38,7 +24,7 @@ var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMA
// Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
// therefore there is no reason to test anymore for other vendor prefixes:
// http://caniuse.com/#search=transition
if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionend)) {
if ((window.ontransitionend === void 0) && (window.onwebkittransitionend !== void 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?
isUndefined and isDefined are in the closure from module.js, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are initialized in the config phase. Here they are accessed before that. If we move the initialization of the constant inside a provider or config block, then we need to ensure that everything that depends on them doesn't run before they are available.

I opted for the shortest viable fix 😄

CSS_PREFIX = '-webkit-';
TRANSITION_PROP = 'WebkitTransition';
TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
Expand All @@ -47,7 +33,7 @@ if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionen
TRANSITIONEND_EVENT = 'transitionend';
}

if (isUndefined(window.onanimationend) && isDefined(window.onwebkitanimationend)) {
if ((window.onanimationend === void 0) && (window.onwebkitanimationend !== void 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

CSS_PREFIX = '-webkit-';
ANIMATION_PROP = 'WebkitAnimation';
ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
Expand All @@ -69,10 +55,6 @@ var ANIMATION_DURATION_PROP = ANIMATION_PROP + DURATION_KEY;
var TRANSITION_DELAY_PROP = TRANSITION_PROP + DELAY_KEY;
var TRANSITION_DURATION_PROP = TRANSITION_PROP + DURATION_KEY;

var isPromiseLike = function(p) {
return p && p.then ? true : false;
};

var ngMinErr = angular.$$minErr('ng');
function assertArg(arg, name, reason) {
if (!arg) {
Expand Down Expand Up @@ -128,7 +110,6 @@ function stripCommentsFromElement(element) {
switch (element.length) {
case 0:
return element;
break;

case 1:
// there is no point of stripping anything if the element
Expand All @@ -141,7 +122,6 @@ function stripCommentsFromElement(element) {

default:
return jqLite(extractElementNode(element));
break;
}
}

Expand Down Expand Up @@ -182,7 +162,7 @@ function applyAnimationClassesFactory($$jqLite) {
$$removeClass($$jqLite, element, options.removeClass);
options.removeClass = null;
}
}
};
}

function prepareAnimationOptions(options) {
Expand Down Expand Up @@ -318,7 +298,7 @@ function resolveElementClasses(existing, toAdd, toRemove) {
}

function getDomNode(element) {
return (element instanceof angular.element) ? element[0] : element;
return (element instanceof jqLite) ? element[0] : element;
}

function applyGeneratedPreparationClasses(element, event, options) {
Expand Down
8 changes: 3 additions & 5 deletions src/ngMessageFormat/messageFormatCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using
// constructs incompatible with that mode.

var $interpolateMinErr = window['angular']['$interpolateMinErr'];

var noop = window['angular']['noop'],
isFunction = window['angular']['isFunction'],
toJson = window['angular']['toJson'];
/* global isFunction: false */
/* global noop: false */
/* global toJson: false */

function stringify(value) {
if (value == null /* null/undefined */) { return ''; }
Expand Down
15 changes: 14 additions & 1 deletion src/ngMessageFormat/messageFormatService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using
// constructs incompatible with that mode.

/* global $interpolateMinErr: false */
/* global $interpolateMinErr: true */
/* global isFunction: true */
/* global noop: true */
/* global toJson: true */
/* global MessageFormatParser: false */
/* global stringify: false */

Expand Down Expand Up @@ -207,8 +210,18 @@ var $$interpolateDecorator = ['$$messageFormat', '$delegate', function $$interpo
return interpolate;
}];

var $interpolateMinErr;
var isFunction;
var noop;
var toJson;

var module = window['angular']['module']('ngMessageFormat', ['ng']);
module['factory']('$$messageFormat', $$MessageFormatFactory);
module['config'](['$provide', function($provide) {
$interpolateMinErr = window['angular']['$interpolateMinErr'];
isFunction = window['angular']['isFunction'];
noop = window['angular']['noop'];
toJson = window['angular']['toJson'];

$provide['decorator']('$interpolate', $$interpolateDecorator);
}]);
8 changes: 8 additions & 0 deletions src/ngMessages/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../.jshintrc-base",
"globals": {
"window": false,

"angular": false
}
}
20 changes: 12 additions & 8 deletions src/ngMessages/messages.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict';

/* jshint ignore:start */
// this code is in the core, but not in angular-messages.js
var isArray = angular.isArray;
var forEach = angular.forEach;
var isString = angular.isString;
var jqLite = angular.element;
/* jshint ignore:end */
var forEach;
var isArray;
var isString;
var jqLite;

/**
* @ngdoc module
Expand Down Expand Up @@ -262,7 +259,14 @@ var jqLite = angular.element;
*
* {@link ngAnimate Click here} to learn how to use JavaScript animations or to learn more about ngAnimate.
*/
angular.module('ngMessages', [])
angular.module('ngMessages', [], function initAngularHelpers() {
// Access helpers from angular core.
// Do it inside a `config` block to ensure `window.angular` is available.
forEach = angular.forEach;
isArray = angular.isArray;
isString = angular.isString;
jqLite = angular.element;
})

/**
* @ngdoc directive
Expand Down
Loading