Skip to content

Commit fa75406

Browse files
committed
Replace '' + obj pattern with ''.concat(obj)
Using the `+` operator to concatenate strings and objects is problematic because `+` calls `valueOf` on the object. `valueOf` will throw for some types of objects. See facebook#20594 for details. This commit globally replaces `'' + obj` with `''.concat(obj)`, which does the same thing but doesn't call `valueOf` before converting to a string. It also updates the code example in the lint rule that encouaged use of this problematic pattern.
1 parent fd7b4a5 commit fa75406

File tree

55 files changed

+144
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+144
-126
lines changed

fixtures/dom/src/components/fixtures/error-handling/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ErrorBoundary extends React.Component {
4141
if (this.state.error) {
4242
return <p>Captured an error: {this.state.error.message}</p>;
4343
} else {
44-
return <p>Captured an error: {'' + this.state.error}</p>;
44+
return <p>Captured an error: {''.concat(this.state.error)}</p>;
4545
}
4646
}
4747
if (this.state.shouldThrow) {

fixtures/legacy-jsx-runtimes/react-14/cjs/react-jsx-dev-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function printWarning(level, format, args) {
104104
}
105105

106106
var argsWithFormat = args.map(function (item) {
107-
return '' + item;
107+
return ''.concat(item);
108108
}); // Careful: RN currently depends on this prefix
109109

110110
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -483,11 +483,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
483483
// key is explicitly declared to be undefined or not.
484484

485485
if (maybeKey !== undefined) {
486-
key = '' + maybeKey;
486+
key = ''.concat(maybeKey);
487487
}
488488

489489
if (hasValidKey(config)) {
490-
key = '' + config.key;
490+
key = ''.concat(config.key);
491491
}
492492

493493
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-14/cjs/react-jsx-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function printWarning(level, format, args) {
103103
}
104104

105105
var argsWithFormat = args.map(function (item) {
106-
return '' + item;
106+
return ''.concat(item);
107107
}); // Careful: RN currently depends on this prefix
108108

109109
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -487,11 +487,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
487487
// key is explicitly declared to be undefined or not.
488488

489489
if (maybeKey !== undefined) {
490-
key = '' + maybeKey;
490+
key = ''.concat(maybeKey);
491491
}
492492

493493
if (hasValidKey(config)) {
494-
key = '' + config.key;
494+
key = ''.concat(config.key);
495495
}
496496

497497
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-15/cjs/react-jsx-dev-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function printWarning(level, format, args) {
109109
}
110110

111111
var argsWithFormat = args.map(function (item) {
112-
return '' + item;
112+
return ''.concat(item);
113113
}); // Careful: RN currently depends on this prefix
114114

115115
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -488,11 +488,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
488488
// key is explicitly declared to be undefined or not.
489489

490490
if (maybeKey !== undefined) {
491-
key = '' + maybeKey;
491+
key = ''.concat(maybeKey);
492492
}
493493

494494
if (hasValidKey(config)) {
495-
key = '' + config.key;
495+
key = ''.concat(config.key);
496496
}
497497

498498
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-15/cjs/react-jsx-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function printWarning(level, format, args) {
108108
}
109109

110110
var argsWithFormat = args.map(function (item) {
111-
return '' + item;
111+
return ''.concat(item);
112112
}); // Careful: RN currently depends on this prefix
113113

114114
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -492,11 +492,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
492492
// key is explicitly declared to be undefined or not.
493493

494494
if (maybeKey !== undefined) {
495-
key = '' + maybeKey;
495+
key = ''.concat(maybeKey);
496496
}
497497

498498
if (hasValidKey(config)) {
499-
key = '' + config.key;
499+
key = ''.concat(config.key);
500500
}
501501

502502
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-16/cjs/react-jsx-dev-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function printWarning(level, format, args) {
115115
}
116116

117117
var argsWithFormat = args.map(function (item) {
118-
return '' + item;
118+
return ''.concat(item);
119119
}); // Careful: RN currently depends on this prefix
120120

121121
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -509,11 +509,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
509509
// key is explicitly declared to be undefined or not.
510510

511511
if (maybeKey !== undefined) {
512-
key = '' + maybeKey;
512+
key = ''.concat(maybeKey);
513513
}
514514

515515
if (hasValidKey(config)) {
516-
key = '' + config.key;
516+
key = ''.concat(config.key);
517517
}
518518

519519
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-16/cjs/react-jsx-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function printWarning(level, format, args) {
114114
}
115115

116116
var argsWithFormat = args.map(function (item) {
117-
return '' + item;
117+
return ''.concat(item);
118118
}); // Careful: RN currently depends on this prefix
119119

120120
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -513,11 +513,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
513513
// key is explicitly declared to be undefined or not.
514514

515515
if (maybeKey !== undefined) {
516-
key = '' + maybeKey;
516+
key = ''.concat(maybeKey);
517517
}
518518

519519
if (hasValidKey(config)) {
520-
key = '' + config.key;
520+
key = ''.concat(config.key);
521521
}
522522

523523
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-17/cjs/react-jsx-dev-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function printWarning(level, format, args) {
107107
}
108108

109109
var argsWithFormat = args.map(function (item) {
110-
return '' + item;
110+
return ''.concat(item);
111111
}); // Careful: RN currently depends on this prefix
112112

113113
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -815,11 +815,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
815815
// key is explicitly declared to be undefined or not.
816816

817817
if (maybeKey !== undefined) {
818-
key = '' + maybeKey;
818+
key = ''.concat(maybeKey);
819819
}
820820

821821
if (hasValidKey(config)) {
822-
key = '' + config.key;
822+
key = ''.concat(config.key);
823823
}
824824

825825
if (hasValidRef(config)) {

fixtures/legacy-jsx-runtimes/react-17/cjs/react-jsx-runtime.development.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function printWarning(level, format, args) {
107107
}
108108

109109
var argsWithFormat = args.map(function (item) {
110-
return '' + item;
110+
return ''.concat(item);
111111
}); // Careful: RN currently depends on this prefix
112112

113113
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
@@ -815,11 +815,11 @@ function jsxDEV(type, config, maybeKey, source, self) {
815815
// key is explicitly declared to be undefined or not.
816816

817817
if (maybeKey !== undefined) {
818-
key = '' + maybeKey;
818+
key = ''.concat(maybeKey);
819819
}
820820

821821
if (hasValidKey(config)) {
822-
key = '' + config.key;
822+
key = ''.concat(config.key);
823823
}
824824

825825
if (hasValidRef(config)) {

packages/react-devtools-extensions/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function createPanelIfReactLoaded() {
8282

8383
function initBridgeAndStore() {
8484
const port = chrome.runtime.connect({
85-
name: '' + tabId,
85+
name: ''.concat(tabId),
8686
});
8787
// Looks like `port.onDisconnect` does not trigger on in-tab navigation like new URL or back/forward navigation,
8888
// so it makes no sense to handle it here.

0 commit comments

Comments
 (0)