Skip to content

Commit 96d30de

Browse files
committed
Use numbers instead of strings for error codes
1 parent 462dcaa commit 96d30de

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

scripts/error-codes/__tests__/__snapshots__/minify-error-messages.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import invariant from 'shared/invariant';
3232
if (__DEV__) {
3333
throw _ReactError(\`Do not override existing functions.\`);
3434
} else {
35-
throw _ReactErrorProd('16');
35+
throw _ReactErrorProd(16);
3636
}
3737
}
3838
})();
@@ -41,7 +41,7 @@ import invariant from 'shared/invariant';
4141
if (__DEV__) {
4242
throw _ReactError(\`Do not override existing functions.\`);
4343
} else {
44-
throw _ReactErrorProd('16');
44+
throw _ReactErrorProd(16);
4545
}
4646
}
4747
})();"
@@ -57,7 +57,7 @@ import invariant from 'shared/invariant';
5757
if (__DEV__) {
5858
throw _ReactError(\`Do not override existing functions.\`);
5959
} else {
60-
throw _ReactErrorProd('16');
60+
throw _ReactErrorProd(16);
6161
}
6262
}
6363
})();"
@@ -73,7 +73,7 @@ import invariant from 'shared/invariant';
7373
if (__DEV__) {
7474
throw _ReactError(\`Expected a component class, got \${Foo}.\${Bar}\`);
7575
} else {
76-
throw _ReactErrorProd('18', [Foo, Bar]);
76+
throw _ReactErrorProd(18, [Foo, Bar]);
7777
}
7878
}
7979
})();"
@@ -89,7 +89,7 @@ import invariant from 'shared/invariant';
8989
if (__DEV__) {
9090
throw _ReactError(\`Expected \${foo} target to be an array; got \${bar}\`);
9191
} else {
92-
throw _ReactErrorProd('7', [foo, bar]);
92+
throw _ReactErrorProd(7, [foo, bar]);
9393
}
9494
}
9595
})();"

scripts/error-codes/minify-error-messages.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = function(babel) {
6565
);
6666
const errorMap = invertObject(existingErrorMap);
6767

68-
const prodErrorId = errorMap[errorMsgLiteral];
68+
let prodErrorId = errorMap[errorMsgLiteral];
6969
if (prodErrorId === undefined) {
7070
// There is no error code for this message. We use a lint rule to
7171
// enforce that messages can be minified, so assume this is
@@ -83,6 +83,7 @@ module.exports = function(babel) {
8383
);
8484
return;
8585
}
86+
prodErrorId = parseInt(prodErrorId, 10);
8687

8788
// Import ReactErrorProd
8889
const reactErrorProdIdentfier = file.addImport(
@@ -97,7 +98,7 @@ module.exports = function(babel) {
9798
t.callExpression(
9899
reactErrorProdIdentfier,
99100
[
100-
t.stringLiteral(prodErrorId),
101+
t.numericLiteral(prodErrorId),
101102
errorMsgExpressions.length > 0
102103
? t.arrayExpression(errorMsgExpressions)
103104
: undefined,

0 commit comments

Comments
 (0)