Skip to content

Commit 2481aa8

Browse files
authored
[spec] address feedback from plenary
Merge pull request tc39#77 from bakkot/address-feedback
2 parents b07b6cb + 27eee05 commit 2481aa8

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

spec.emu

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ contributors:
3131
1. Let _escaped_ be the empty String.
3232
1. Let _cpList_ be StringToCodePoints(_S_).
3333
1. For each code point _c_ in _cpList_, do
34-
1. If _escaped_ is the empty String and _c_ is matched by |DecimalDigit|, then
35-
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.
36-
1. Set _escaped_ to the string-concatenation of _escaped_, the code unit 0x005C (REVERSE SOLIDUS), *"x3"*, and the code unit whose numeric value is the numeric value of _c_.
34+
1. If _escaped_ is the empty String, and _c_ is matched by |DecimalDigit| or |AsciiLetter|, then
35+
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`.
36+
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
37+
1. Assert: The length of _hex_ is 2.
38+
1. Set _escaped_ to the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"x"*, and _hex_.
3739
1. Else,
3840
1. Set _escaped_ to the string-concatenation of _escaped_ and EncodeForRegExpEscape(_c_).
3941
1. Return _escaped_.
@@ -52,13 +54,17 @@ contributors:
5254
</h1>
5355
<dl class="header">
5456
<dt>description</dt>
55-
<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 (corresponding with |HexEscapeSequence| if possible, or otherwise with |RegExpUnicodeEscapeSequence|). Otherwise, the returned value is a string representation of _c_ itself.</dd>
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>
5658
</dl>
5759

5860
<emu-alg>
59-
1. Let _punctuators_ be the string-concatenation of *"(){}[]|,.?\*+-^$=<>/#&!%:;@~'`"*, the code unit 0x0022 (QUOTATION MARK), and the code unit 0x005C (REVERSE SOLIDUS).
60-
1. Let _toEscape_ be StringToCodePoints(_punctuators_).
61-
1. If _toEscape_ contains _c_ or _c_ is matched by |WhiteSpace|, then
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 *",-=<>#&!%:;@~'`"* 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
6268
1. If _c_ ≤ 0xFF, then
6369
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
6470
1. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"x"*, and StringPad(_hex_, 2, *"0"*, ~start~).

0 commit comments

Comments
 (0)