Skip to content

Commit 6fe1ac7

Browse files
00-katlpil
authored andcommitted
Remove the fallback for NodeJS 14 from string.replace().
According to https://nodejs.org/en/about/previous-releases, NodeJS 14 has been EOL for a little over two years (with the last update to it being on 2023-02-16). All currently supported targets should hence have `String.prototype.replaceAll()` present, so the fallback added in 97b12bb is now unnecessary.
1 parent 4a8df96 commit 6fe1ac7

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- The fallback code for older NodeJS versions in the JavaScript target
6+
implementation of `string.replace` has been removed.
57
- The `inspect` function in the `string` module will now print lists of ascii
68
characters in a human readable format, to aid with debugging programs that use
79
Erlang character lists.

src/gleam_stdlib.mjs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,7 @@ export function int_from_base_string(string, base) {
115115
}
116116

117117
export function string_replace(string, target, substitute) {
118-
if (typeof string.replaceAll !== "undefined") {
119-
return string.replaceAll(target, substitute);
120-
}
121-
// Fallback for older Node.js versions:
122-
// 1. <https://stackoverflow.com/a/1144788>
123-
// 2. <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping>
124-
// TODO: This fallback could be remove once Node.js 14 is EOL
125-
// aka <https://nodejs.org/en/about/releases/> on or after 2024-04-30
126-
return string.replace(
127-
// $& means the whole matched string
128-
new RegExp(target.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
129-
substitute,
130-
);
118+
return string.replaceAll(target, substitute);
131119
}
132120

133121
export function string_reverse(string) {

0 commit comments

Comments
 (0)