Skip to content

Commit

Permalink
move RegExp.escape to stage 3
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 29, 2024
1 parent b13a97f commit 5b2874c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog
##### Unreleased
- [`RegExp.escape` proposal](https://github.com/tc39/proposal-regex-escaping):
- Built-ins:
- `RegExp.escape`
- Moved to stage 3, [June 2024](https://github.com/tc39/proposals/commit/4b8ee265248abfa2c88ed71b3c541ddd5a2eaffe) and [July 2024](https://github.com/tc39/proposals/commit/bdb2eea6c5e41a52f2d6047d7de1a31b5d188c4f) TC39 meetings
- Updated the way of escaping, [regex-escaping/77](https://github.com/tc39/proposal-regex-escaping/pull/77)
- Throw an error on non-strings, [regex-escaping/58](https://github.com/tc39/proposal-regex-escaping/pull/58)
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
- [`Promise.try` proposal](https://github.com/tc39/proposal-promise-try):
- Built-ins:
- `Promise.try`
Expand All @@ -16,12 +23,6 @@
- Added `Uint8Array.prototype.toBase64` `omitPadding` option, [proposal-arraybuffer-base64/60](https://github.com/tc39/proposal-arraybuffer-base64/pull/60)
- Added throwing a `TypeError` on arrays backed by detached buffers
- Unconditional forced replacement changed to feature detection
- [`RegExp.escape` proposal](https://github.com/tc39/proposal-regex-escaping):
- Built-ins:
- `RegExp.escape`
- Moved to stage 2.7, [June 2024 TC39 meeting](https://github.com/tc39/proposals/commit/4b8ee265248abfa2c88ed71b3c541ddd5a2eaffe)
- Updated the way of escaping, [regex-escaping/77](https://github.com/tc39/proposal-regex-escaping/pull/77)
- Throw an error on non-strings, [regex-escaping/58](https://github.com/tc39/proposal-regex-escaping/pull/58)
- Fixed `RegExp` named capture groups polyfill in combination with non-capturing groups, [#1352](https://github.com/zloirock/core-js/pull/1352), thanks [**@Ulop**](https://github.com/Ulop)
- Improved some cases of environment detection
- Uses [`process.getBuiltinModule`](https://nodejs.org/docs/latest/api/process.html#processgetbuiltinmoduleid) for getting built-in NodeJS modules where it's available
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [`Uint8Array` to / from base64 and hex](#uint8array-to--from-base64-and-hex)
- [Explicit resource management](#explicit-resource-management)
- [`Promise.try`](#promisetry)
- [`RegExp` escaping](#regexp-escaping)
- [`Symbol.metadata` for decorators metadata proposal](#symbolmetadata-for-decorators-metadata-proposal)
- [Stage 2.7 proposals](#stage-27-proposals)
- [`Math.sumPrecise`](#mathsumprecise)
- [`RegExp` escaping](#regexp-escaping)
- [Stage 2 proposals](#stage-2-proposals)
- [`AsyncIterator` helpers](#asynciterator-helpers)
- [`Iterator.range`](#iteratorrange)
Expand Down Expand Up @@ -2544,6 +2544,31 @@ Promise.try(async () => { throw 42; }).catch(it => console.log(`Promise, rejecte
Promise.try(it => it, 42).then(it => console.log(`Promise, resolved as ${ it }`));
```
##### [`RegExp` escaping](https://github.com/tc39/proposal-regex-escaping)[⬆](#index)
Module [`esnext.regexp.escape`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.regexp.escape.js)
```js
class RegExp {
static escape(value: string): string
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/regexp-escaping
core-js(-pure)/full/regexp/escape
```
[*Example*](https://tinyurl.com/ykac4qgy):
```js
console.log(RegExp.escape('10$')); // => '\\x310\\$'
console.log(RegExp.escape('abcdefg_123456')); // => '\\x61bcdefg_123456'
console.log(RegExp.escape('Привет')); // => 'Привет'
console.log(RegExp.escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'));
// => '\\(\\)\\{\\}\\[\\]\\|\\x2c\\.\\?\\*\\+\\x2d\\^\\$\\x3d\\x3c\\x3e\\\\\\/\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x22\\x60'
console.log(RegExp.escape('\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'));
// => '\\\t\\\n\\\v\\\f\\\r\\x20\\xa0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\u2028\\u2029\\ufeff'
console.log(RegExp.escape('💩')); // => '💩'
console.log(RegExp.escape('\uD83D')); // => '\\ud83d'
```
##### [`Symbol.metadata` for decorators metadata proposal](https://github.com/tc39/proposal-decorator-metadata)[⬆](#index)
Modules [`esnext.symbol.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js) and [`esnext.function.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.function.metadata.js).
```js
Expand Down Expand Up @@ -2586,31 +2611,6 @@ core-js(-pure)/full/math/sum-precise
Math.sumPrecise([1e20, 0.1, -1e20]); // => 0.1
```
##### [`RegExp` escaping](https://github.com/tc39/proposal-regex-escaping)[⬆](#index)
Module [`esnext.regexp.escape`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.regexp.escape.js)
```js
class RegExp {
static escape(value: string): string
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/regexp-escaping
core-js(-pure)/full/regexp/escape
```
[*Example*](https://tinyurl.com/ykac4qgy):
```js
console.log(RegExp.escape('10$')); // => '\\x310\\$'
console.log(RegExp.escape('abcdefg_123456')); // => '\\x61bcdefg_123456'
console.log(RegExp.escape('Привет')); // => 'Привет'
console.log(RegExp.escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'));
// => '\\(\\)\\{\\}\\[\\]\\|\\x2c\\.\\?\\*\\+\\x2d\\^\\$\\x3d\\x3c\\x3e\\\\\\/\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x22\\x60'
console.log(RegExp.escape('\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'));
// => '\\\t\\\n\\\v\\\f\\\r\\x20\\xa0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\u2028\\u2029\\ufeff'
console.log(RegExp.escape('💩')); // => '💩'
console.log(RegExp.escape('\uD83D')); // => '\\ud83d'
```
#### Stage 2 proposals[⬆](#index)
[*CommonJS entry points:*](#commonjs-api)
```
Expand Down
5 changes: 5 additions & 0 deletions packages/core-js/actual/regexp/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
require('../../modules/esnext.regexp.escape');
var path = require('../../internals/path');

module.exports = path.RegExp.escape;
1 change: 1 addition & 0 deletions packages/core-js/actual/regexp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
var parent = require('../../stable/regexp');
require('../../modules/esnext.regexp.escape');

module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/full/regexp/escape.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
require('../../modules/esnext.regexp.escape');
var path = require('../../internals/path');
var parent = require('../../actual/regexp/escape');

module.exports = path.RegExp.escape;
module.exports = parent;
1 change: 0 additions & 1 deletion packages/core-js/full/regexp/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
var parent = require('../../actual/regexp');
require('../../modules/esnext.regexp.escape');

module.exports = parent;
2 changes: 1 addition & 1 deletion packages/core-js/modules/esnext.regexp.escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var escapeChar = function (chr) {

// `RegExp.escape` method
// https://github.com/tc39/proposal-regex-escaping
$({ target: 'RegExp', stat: true, forced: true }, {
$({ target: 'RegExp', stat: true }, {
escape: function escape(S) {
aString(S);
var length = S.length;
Expand Down
1 change: 0 additions & 1 deletion packages/core-js/stage/2.7.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
var parent = require('./3');

require('../proposals/math-sum');
require('../proposals/regexp-escaping');

module.exports = parent;
1 change: 1 addition & 0 deletions packages/core-js/stage/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require('../proposals/float16');
require('../proposals/iterator-helpers-stage-3-2');
require('../proposals/json-parse-with-source');
require('../proposals/promise-try');
require('../proposals/regexp-escaping');
// TODO: Obsolete versions, remove from `core-js@4`
require('../proposals/array-grouping-stage-3');
require('../proposals/array-grouping-stage-3-2');
Expand Down
2 changes: 1 addition & 1 deletion tests/entries/unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(typeof load(NS, 'json/raw-json')(42) == 'object');
ok(load(NS, 'math/f16round')(1.337) === 1.3369140625);
ok(load(NS, 'promise/try')(() => 42) instanceof load(NS, 'promise'));
ok(load(NS, 'regexp/escape')('10$') === '\\x310\\$');
ok(load(NS, 'symbol/dispose'));
ok(load(NS, 'symbol/metadata'));
ok(new (load(NS, 'suppressed-error'))(1, 2).suppressed === 2);
Expand Down Expand Up @@ -818,7 +819,6 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(typeof load(NS, 'reflect/has-metadata') == 'function');
ok(typeof load(NS, 'reflect/has-own-metadata') == 'function');
ok(typeof load(NS, 'reflect/metadata') == 'function');
ok(load(NS, 'regexp/escape')('10$') === '\\x310\\$');
ok(load(NS, 'set/add-all')(new Set([1, 2, 3]), 4, 5).size === 5);
ok(load(NS, 'set/delete-all')(new Set([1, 2, 3]), 4, 5) === false);
ok(load(NS, 'set/every')(new Set([1, 2, 3]), it => typeof it == 'number'));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-pure/esnext.regexp.escape.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @stylistic/js/max-len -- ok*/
import escape from 'core-js-pure/full/regexp/escape';
import escape from 'core-js-pure/actual/regexp/escape';

QUnit.test('RegExp.escape', assert => {
assert.isFunction(escape);
Expand Down

0 comments on commit 5b2874c

Please sign in to comment.