Update vendored modules, delete unused
Closes #1090
Paul O’Shannessy committed
Feb 15, 2014 at 13:49 UTC
e872cd0a7c0e88fa29b0e23f46717c6741c01000
11 files changed
+70
-329
src/vendor/core/CSSCore.js
+22
-21
@@ -22,29 +22,11 @@ var invariant = require('invariant');
22
/**
23
* The CSSCore module specifies the API (and implements most of the methods)
24
* that should be used when dealing with the display of elements (via their
25
- * CSS classes and visibility on screeni. It is an API focused on mutating the
25
+ * CSS classes and visibility on screen. It is an API focused on mutating the
26
* display and not reading it as no logical state should be encoded in the
27
* display of elements.
28
*/
29
30
-/**
31
- * Tests whether the element has the class specified.
32
- *
33
- * Note: This function is not exported in CSSCore because CSS classNames should
34
- * not store any logical information about the element. Use DataStore to store
35
- * information on an element.
36
- *
37
- * @param {DOMElement} element the element to set the class on
38
- * @param {string} className the CSS className
39
- * @returns {boolean} true if the element has the class, false if not
40
- */
41
-function hasClass(element, className) {
42
- if (element.classList) {
43
- return !!className && element.classList.contains(className);
44
- }
45
- return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
46
-}
47
-
30
var CSSCore = {
31
32
/**
@@ -64,7 +46,7 @@ var CSSCore = {
46
if (className) {
47
if (element.classList) {
48
element.classList.add(className);
67
- } else if (!hasClass(element, className)) {
49
+ } else if (!CSSCore.hasClass(element, className)) {
50
element.className = element.className + ' ' + className;
51
}
52
}
@@ -88,7 +70,7 @@ var CSSCore = {
70
if (className) {
71
if (element.classList) {
72
element.classList.remove(className);
91
- } else if (hasClass(element, className)) {
73
+ } else if (CSSCore.hasClass(element, className)) {
74
element.className = element.className
75
.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)', 'g'), '$1')
76
.replace(/\s+/g, ' ') // multiple spaces to one
@@ -108,7 +90,26 @@ var CSSCore = {
90
*/
91
conditionClass: function(element, className, bool) {
92
return (bool ? CSSCore.addClass : CSSCore.removeClass)(element, className);
93
+ },
94
+
95
+ /**
96
+ * Tests whether the element has the class specified.
97
+ *
98
+ * @param {DOMNode|DOMWindow} element the element to set the class on
99
+ * @param {string} className the CSS className
100
+ * @returns {boolean} true if the element has the class, false if not
101
+ */
102
+ hasClass: function(element, className) {
103
+ invariant(
104
+ !/\s/.test(className),
105
+ 'CSS.hasClass takes only a single class name.'
106
+ );
107
+ if (element.classList) {
108
+ return !!className && element.classList.contains(className);
109
+ }
110
+ return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
111
}
112
+
113
};
114
115
module.exports = CSSCore;
src/vendor/core/invariant.js
+4
-1
@@ -29,7 +29,10 @@
29
30
function invariant(condition) {
31
if (!condition) {
32
- var error = new Error('Invariant Violation');
32
+ var error = new Error(
33
+ 'Minified exception occured, use the non-minified dev environment for ' +
34
+ 'the full error message and additional helpful warnings.'
35
+ );
36
error.framesToPop = 1;
37
throw error;
38
}
src/vendor/error/__tests__/erx-test.js
deleted
-58
@@ -1,58 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * Copyright 2004-present Facebook. All Rights Reserved.
17
- *
18
- * @emails catchen@fb.com
19
- * @emails javascript@lists.facebook.com
20
- */
21
-
22
-require('mock-modules')
23
- .dontMock('erx')
24
- .dontMock('ex');
25
-
26
-describe('erx', function() {
27
- var erx = require('erx');
28
- var ex = require('ex');
29
-
30
- it('should always reverse ex if placeholder and argument match', function() {
31
- expect(erx(ex('zero argument'))).toEqual(['zero argument']);
32
- expect(erx(ex('one argument: %s', 'one')))
33
- .toEqual(['one argument: %s', 'one']);
34
- expect(erx(ex('two arguments: %s, %s', 'one', 2)))
35
- .toEqual(['two arguments: %s, %s', 'one', '2']);
36
- expect(erx(ex('three arguments: %s, %s, %s', 'one', 2, { value: 3 })))
37
- .toEqual(['three arguments: %s, %s, %s', 'one', '2', '[object Object]']);
38
- });
39
-
40
- it('should be idempotent', function() {
41
- var messageWithParams = erx(ex('one argument: %s', 'one'));
42
- expect(messageWithParams).toEqual(erx(messageWithParams));
43
- });
44
-
45
- it('should treat plain text as it was ex-ed with no argument', function() {
46
- expect(erx('plain text')).toEqual(['plain text']);
47
- });
48
-
49
- it('should work when text was appended/prepended to ex-ed text', function() {
50
- expect(erx('prepended text|' + ex('zero argument') + '|appended text'))
51
- .toEqual(['prepended text|zero argument|appended text']);
52
- expect(erx(
53
- 'prepended text|' +
54
- ex('one argument: %s', 'one') +
55
- '|appended text'
56
- )).toEqual(['prepended text|one argument: %s|appended text', 'one']);
57
- });
58
-});
src/vendor/error/__tests__/ex-test.js
deleted
-43
@@ -1,43 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * Copyright 2004-present Facebook. All Rights Reserved.
17
- *
18
- * @emails catchen@fb.com
19
- * @emails javascript@lists.facebook.com
20
- */
21
-
22
-require('mock-modules')
23
- .dontMock('ex');
24
-
25
-describe('ex', function() {
26
- var ex = require('ex');
27
-
28
- it('should convert whatever arguments into one string', function() {
29
- expect(typeof ex('zero argument')).toEqual('string');
30
- expect(typeof ex('one argument: %s', 'one')).toEqual('string');
31
- expect(typeof ex('two arguments: %s, %s', 'one', 2))
32
- .toEqual('string');
33
- expect(typeof ex('three arguments: %s, %s, %s', 'one', 2, { value: 3 }))
34
- .toEqual('string');
35
- });
36
-
37
- it('should handle placeholder and argument number mismatch', function() {
38
- expect(typeof ex('zero placeholder and one argument', 'one'))
39
- .toEqual('string');
40
- expect(typeof ex('one placeholder and zero argument: %s'))
41
- .toEqual('string');
42
- });
43
-});
src/vendor/error/erx.js
deleted
-71
@@ -1,71 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule erx
17
- * @typechecks
18
- * @nostacktrace
19
- */
20
-
21
-var ex = require('ex');
22
-
23
-/**
24
- * This function reverse transform done by `ex()`.
25
- *
26
- * This function only transforms plain text message back to error message with
27
- * arguments. If the error message is minified by the server, it has to be
28
- * looked up on the server.
29
- *
30
- * This function is designed to be idempotent, so erx(erx(whatever)) will be
31
- * the same as erx(whatever).
32
- *
33
- * @param {string|array<string>} transformedMessage
34
- */
35
-
36
-var erx = function(transformedMessage) {
37
- if (typeof transformedMessage !== 'string') {
38
- // possibly double `erx`ed and return original value
39
- return transformedMessage;
40
- }
41
-
42
- var prefixLeft = transformedMessage.indexOf(ex._prefix);
43
- var suffixLeft = transformedMessage.lastIndexOf(ex._suffix);
44
- if (prefixLeft < 0 || suffixLeft < 0) {
45
- // plain error message without any transformation
46
- return [transformedMessage];
47
- }
48
-
49
- var prefixRight = prefixLeft + ex._prefix.length;
50
- var suffixRight = suffixLeft + ex._suffix.length;
51
- if (prefixRight >= suffixLeft) {
52
- return ['erx slice failure: %s', transformedMessage];
53
- }
54
-
55
- var leftSlice = transformedMessage.substring(0, prefixLeft);
56
- var rightSlice = transformedMessage.substring(suffixRight);
57
- transformedMessage = transformedMessage.substring(prefixRight, suffixLeft);
58
-
59
- var messageWithParams;
60
- try {
61
- messageWithParams = JSON.parse(transformedMessage);
62
- messageWithParams[0] =
63
- leftSlice + messageWithParams[0] + rightSlice;
64
- } catch(err) {
65
- return ['erx parse failure: %s', transformedMessage];
66
- }
67
-
68
- return messageWithParams;
69
-};
70
-
71
-module.exports = erx;
src/vendor/error/ex.js
deleted
-45
@@ -1,45 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule ex
17
- * @typechecks
18
- * @nostacktrace
19
- */
20
-
21
-/**
22
- * This function transforms error message with arguments into plain text error
23
- * message, so that it can be passed to window.onerror without losing anything.
24
- * It can then be transformed back by `erx()` function.
25
- *
26
- * Usage:
27
- * throw new Error(ex('Error %s from %s', errorCode, userID));
28
- *
29
- * @param {string} errorMessage
30
- */
31
-
32
-var ex = function(...args) {
33
- args = args.map((arg) => String(arg));
34
- if (args[0].split('%s').length !== args.length) {
35
- // something wrong with the formatting string
36
- return ex('ex args number mismatch: %s', JSON.stringify(args));
37
- }
38
-
39
- return ex._prefix + JSON.stringify(args) + ex._suffix;
40
-};
41
-
42
-ex._prefix = '<![EX[';
43
-ex._suffix = ']]>';
44
-
45
-module.exports = ex;
src/vendor/stubs/Env.js
deleted
-20
@@ -1,20 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule Env
17
- */
18
-
19
-module.exports = {};
20
-
src/vendor/stubs/EventListener.js
+42
-34
@@ -1,59 +1,67 @@
1
/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
2
* @providesModule EventListener
3
*/
4
5
+var emptyFunction = require('emptyFunction');
6
+
7
/**
8
* Upstream version of event listener. Does not take into account specific
9
* nature of platform.
10
*/
11
var EventListener = {
12
/**
25
- * Listens to bubbled events on a DOM node.
13
+ * Listen to DOM events during the bubble phase.
14
*
27
- * @param {Element} el DOM element to register listener on.
28
- * @param {string} handlerBaseName 'click'/'mouseover'
29
- * @param {Function!} cb Callback function
15
+ * @param {DOMEventTarget} target DOM element to register listener on.
16
+ * @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
17
+ * @param {function} callback Callback function.
18
+ * @return {object} Object with a `remove` method.
19
*/
31
- listen: function(el, handlerBaseName, cb) {
32
- if (el.addEventListener) {
33
- el.addEventListener(handlerBaseName, cb, false);
34
- } else if (el.attachEvent) {
35
- el.attachEvent('on' + handlerBaseName, cb);
20
+ listen: function(target, eventType, callback) {
21
+ if (target.addEventListener) {
22
+ target.addEventListener(eventType, callback, false);
23
+ return {
24
+ remove: function() {
25
+ target.removeEventListener(eventType, callback, false);
26
+ }
27
+ };
28
+ } else if (target.attachEvent) {
29
+ target.attachEvent('on' + eventType, callback);
30
+ return {
31
+ remove: function() {
32
+ target.detachEvent(eventType, callback);
33
+ }
34
+ };
35
}
36
},
37
38
/**
40
- * Listens to captured events on a DOM node.
39
+ * Listen to DOM events during the capture phase.
40
*
42
- * @see `EventListener.listen` for params.
43
- * @throws Exception if addEventListener is not supported.
41
+ * @param {DOMEventTarget} target DOM element to register listener on.
42
+ * @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
43
+ * @param {function} callback Callback function.
44
+ * @return {object} Object with a `remove` method.
45
*/
45
- capture: function(el, handlerBaseName, cb) {
46
- if (!el.addEventListener) {
46
+ capture: function(target, eventType, callback) {
47
+ if (!target.addEventListener) {
48
if (__DEV__) {
49
console.error(
49
- 'You are attempting to use addEventListener ' +
50
- 'in a browser that does not support it.' +
51
- 'This likely means that you will not receive events that ' +
52
- 'your application relies on (such as scroll).');
50
+ 'Attempted to listen to events during the capture phase on a ' +
51
+ 'browser that does not support the capture phase. Your application ' +
52
+ 'will not receive some events.'
53
+ );
54
}
54
- return;
55
+ return {
56
+ remove: emptyFunction
57
+ };
58
} else {
56
- el.addEventListener(handlerBaseName, cb, true);
59
+ target.addEventListener(eventType, callback, true);
60
+ return {
61
+ remove: function() {
62
+ target.removeEventListener(eventType, callback, true);
63
+ }
64
+ };
65
}
66
}
67
};
src/vendor/stubs/README
deleted
-8
@@ -1,8 +0,0 @@
1
-This project defines stubs for platform-specific explicit dependencies used by
2
-other upstream modules.
3
-
4
-Do not check this project into www or m downstreams.
5
-
6
-All downstreams that want to use the any static_upstream project who has a
7
-dependency on something in this project should implement their own versions of
8
-the modules in this project.
src/vendor/stubs/URI.js
deleted
-26
@@ -1,26 +0,0 @@
1
-/**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule URI
17
- */
18
-
19
-/**
20
- * We expect downstream reps to implement URI as an extension of URIBase.
21
- * URIBase in turn is not used by other upstream modules but rather URI is used.
22
- * This stubs exists so that tests for the other upstream modules run correctly.
23
- */
24
-var URIBase = require('URIBase');
25
-
26
-module.exports = URIBase;
src/vendor/stubs/cx.js
+2
-2
@@ -33,8 +33,8 @@
33
*/
34
function cx(classNames) {
35
if (typeof classNames == 'object') {
36
- return Object.keys(classNames).map(function(className) {
37
- return classNames[className] ? className : '';
36
+ return Object.keys(classNames).filter(function(className) {
37
+ return classNames[className];
38
}).join(' ');
39
} else {
40
return Array.prototype.join.call(arguments, ' ');