-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: JS substr()
is deprecated, using slice()
instead
#37136
Conversation
Note: I haven't applied this change to some generated files e.g. https://github.com/facebook/react-native/blob/30da58733651b9c1e4104c17e37f46ace00b95a7/tools/eslint/rules/sort-imports.js Seems, it needs to be regenerated at InternalFB side. |
substr()
is deprecated, using slice()
insteadsubstr()
is deprecated, using slice()
instead
Base commit: 243a148 |
I know this is a WIP but just let you know that there is API difference between two,
|
Yup, also the reason that I'm not using the most obvious alternative |
a547ba2
to
24e5e32
Compare
--
@jacdebug done, also rebased! |
- `substr()` is not part of the core JS since ~2018 - No wonder why no one noticed this :) - Though its supported by modern browsers, its deprecated - Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr Why `slice()` and not `substring()`? > Beacuse I like pizza ;) jk The reason, that I'm not using the most obvious alternative substring() is; it swaps the args passed, when; `startIndex > endIndex`, which I think is not a property of good fn and also does not reflects in it's name, and could lead to more bugs in most of the cases also, it doesn't support negative args, which I think reduces flexibility to work with it. - Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#differences_between_substring_and_slice - `slice`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice - `substring`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
24e5e32
to
eee7a00
Compare
@jacdebug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Yeah, exactly, I was trying to convey that only. Testing them as "whole entity" is the way to go, to avoid individual tests and ensure everything works as intended; even after refactors like this one ;) I'll try to come back to this, after I finish with my Uni. Exams 😅. |
…ook#37136) Summary: Fixes: facebook#37135 - `substr()` is not part of the core JS since ~2018 - No wonder why no one noticed this :) - Though its supported by modern browsers, its deprecated - Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr ### Why `slice()` and not `substring()`? > Beacuse I like pizza ;) jk The reason, that I'm not using the most obvious alternative `substring()` is; - It _swaps the args_ passed, when; `startIndex > endIndex` —which I think is not a property of _good_ fn and also does not reflects the same in it's name. - It _doesn't support negative args_, which I think reduces flexibility to work with it. - It could lead to more bugs in most of the cases. ### Refecrences: - Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#differences_between_substring_and_slice - Ref. for `slice()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice - Ref. for `substring()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring ## Changelog: [GENERAL][FIXED] - Refactor: `substr()` is deprecated, using `slice()` instead across RN codebase Pull Request resolved: facebook#37136 Test Plan: - `yarn lint && yarn flow && yarn test-ci` --> _should be green_ Reviewed By: christophpurrer Differential Revision: D45477910 Pulled By: jacdebug fbshipit-source-id: 96a80893477599b9a549918924157627b9b0c3f4
Summary:
Fixes: #37135
substr()
is not part of the core JS since ~2018Why
slice()
and notsubstring()
?The reason, that I'm not using the most obvious alternative
substring()
is;startIndex > endIndex
—which I think is not a property of good fnand also does not reflects the same in it's name.
Refecrences:
slice()
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slicesubstring()
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substringChangelog:
[GENERAL][FIXED] - Refactor:
substr()
is deprecated, usingslice()
instead across RN codebaseTest Plan:
yarn lint && yarn flow && yarn test-ci
--> should be green