Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 44f4fb9

Browse files
committed
[spec] feedback from tc39/ecma262#3382 (review)
1 parent 80c682d commit 44f4fb9

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

spec.emu

+32-32
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ contributors:
2121
<h1>Properties of the RegExp Constructor</h1>
2222

2323
<ins>
24-
<emu-clause id="sec-regexp.escape" number="2">
24+
<emu-clause id="sec-regexp.escape" number="1">
2525
<h1>RegExp.escape ( _S_ )</h1>
2626
<p>This function returns a copy of _S_ in which characters that are potentially special in a regular expression |Pattern| have been replaced by equivalent escape sequences.</p>
2727
<p>It performs the following steps when called:</p>
2828

2929
<emu-alg>
30-
1. If _S_ is not a String, throw a TypeError exception.
30+
1. If _S_ is not a String, throw a *TypeError* exception.
3131
1. Let _escaped_ be the empty String.
3232
1. Let _cpList_ be StringToCodePoints(_S_).
33-
1. For each code point _c_ in _cpList_, do
33+
1. For each code point _c_ of _cpList_, do
3434
1. If _escaped_ is the empty String, and _c_ is matched by |DecimalDigit| or |AsciiLetter|, then
3535
1. NOTE: Escaping a leading digit ensures that output corresponds with pattern text which may be used after a `\0` character escape or a |DecimalEscape| such as `\1` and still match _S_ rather than be interpreted as an extension of the preceding escape sequence. Escaping a leading ASCII letter does the same for the context after `\c`.
3636
1. Let _numericValue_ be the numeric value of _c_.
@@ -45,37 +45,37 @@ contributors:
4545
<emu-note>
4646
<p>Despite having similar names, EscapeRegExpPattern and `RegExp.escape` do not perform similar actions. The former escapes a pattern for representation as a string, while this function escapes a string for representation inside a pattern.</p>
4747
</emu-note>
48-
</emu-clause>
4948

50-
<emu-clause id="sec-encodeforregexpescape" type="abstract operation">
51-
<h1>
52-
EncodeForRegExpEscape (
53-
_c_: a code point,
54-
): a String
55-
</h1>
56-
<dl class="header">
57-
<dt>description</dt>
58-
<dd>It returns a string representing a |Pattern| for matching _c_. If _c_ is white space or an ASCII punctuator, the returned value is an escape sequence. Otherwise, the returned value is a string representation of _c_ itself.</dd>
59-
</dl>
49+
<emu-clause id="sec-encodeforregexpescape" type="abstract operation">
50+
<h1>
51+
EncodeForRegExpEscape (
52+
_c_: a code point,
53+
): a String
54+
</h1>
55+
<dl class="header">
56+
<dt>description</dt>
57+
<dd>It returns a string representing a |Pattern| for matching _c_. If _c_ is white space or an ASCII punctuator, the returned value is an escape sequence. Otherwise, the returned value is a string representation of _c_ itself.</dd>
58+
</dl>
6059

61-
<emu-alg>
62-
1. If _c_ is matched by |SyntaxCharacter| or _c_ is U+002F (SOLIDUS), then
63-
1. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and UTF16EncodeCodePoint(_c_).
64-
1. Else if _c_ is the code point listed in some cell of the “Code Point” column of <emu-xref href="#table-controlescape-code-point-values"></emu-xref>, then
65-
1. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and the string in the “ControlEscape” column of the row whose “Code Point” column contains _c_.
66-
1. Let _otherPunctuators_ be the string-concatenation of *",-=<>#&!%:;@~'`"* and the code unit 0x0022 (QUOTATION MARK).
67-
1. Let _toEscape_ be StringToCodePoints(_otherPunctuators_).
68-
1. If _toEscape_ contains _c_, or _c_ is matched by |WhiteSpace| or |LineTerminator|, or _c_ has the same numeric value as a leading surrogate or trailing surrogate, then
69-
1. If _c_ ≤ 0xFF, then
70-
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
71-
1. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"x"*, and StringPad(_hex_, 2, *"0"*, ~start~).
72-
1. Let _escaped_ be the empty String.
73-
1. Let _codeUnits_ be UTF16EncodeCodePoint(_c_).
74-
1. For each code unit _cu_ of _codeUnits_, do
75-
1. Set _escaped_ to the string-concatenation of _escaped_ and UnicodeEscape(_cu_).
76-
1. Return _escaped_.
77-
1. Return UTF16EncodeCodePoint(_c_).
78-
</emu-alg>
60+
<emu-alg>
61+
1. If _c_ is matched by |SyntaxCharacter| or _c_ is U+002F (SOLIDUS), then
62+
1. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and UTF16EncodeCodePoint(_c_).
63+
1. Else if _c_ is the code point listed in some cell of the “Code Point” column of <emu-xref href="#table-controlescape-code-point-values"></emu-xref>, then
64+
1. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and the string in the “ControlEscape” column of the row whose “Code Point” column contains _c_.
65+
1. Let _otherPunctuators_ be the string-concatenation of *",-=&lt;>#&amp;!%:;@~'`"* and the code unit 0x0022 (QUOTATION MARK).
66+
1. Let _toEscape_ be StringToCodePoints(_otherPunctuators_).
67+
1. If _toEscape_ contains _c_, _c_ is matched by |WhiteSpace| or |LineTerminator|, or _c_ has the same numeric value as a leading surrogate or trailing surrogate, then
68+
1. If the numeric value of _c_ ≤ 0xFF, then
69+
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
70+
1. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"x"*, and StringPad(_hex_, 2, *"0"*, ~start~).
71+
1. Let _escaped_ be the empty String.
72+
1. Let _codeUnits_ be UTF16EncodeCodePoint(_c_).
73+
1. For each code unit _cu_ of _codeUnits_, do
74+
1. Set _escaped_ to the string-concatenation of _escaped_ and UnicodeEscape(_cu_).
75+
1. Return _escaped_.
76+
1. Return UTF16EncodeCodePoint(_c_).
77+
</emu-alg>
78+
</emu-clause>
7979
</emu-clause>
8080
</ins>
8181
</emu-clause>

0 commit comments

Comments
 (0)