Skip to content

Suggested changes to #2026 (Implement RegExp literal syntax checking)#2107

Closed
graphemecluster wants to merge 20 commits intomicrosoft:jabaile/regexp-errorsfrom
graphemecluster:regexp-errors
Closed

Suggested changes to #2026 (Implement RegExp literal syntax checking)#2107
graphemecluster wants to merge 20 commits intomicrosoft:jabaile/regexp-errorsfrom
graphemecluster:regexp-errors

Conversation

@graphemecluster
Copy link
Contributor

@graphemecluster graphemecluster commented Nov 17, 2025

The merge target of this PR is jabaile/regexp-errors, not main. It is intended as a supplement of #2026.
Feel free to fast-forward/cherry-pick/rebase some of the commits here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is from microsoft/TypeScript#60249; I should've extract the changes out as a separate Strada PR

Comment on lines -1101 to -1102
} else {
v.error(diagnostics.Unexpected_0_Did_you_mean_to_escape_it_with_backslash, v.pos, 1, string(ch))
Copy link
Contributor Author

@graphemecluster graphemecluster Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed in order to partially get rid of microsoft/TypeScript#62707 (not a full fix). I won't port microsoft/TypeScript#62716 until it gets a minimal review

atomStart := v.pos
atom := v.scanClassAtom()
if v.charAtOffset(0) == '-' && v.charAtOffset(1) != ']' {
if v.charAtOffset(0) == '-' {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant check

}
if v.charAtOffset(0) == '}' {
v.pos++
} else if hasDigits {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant check

if v.anyUnicodeModeOrNonAnnexB {
v.error(diagnostics.X_c_must_be_followed_by_an_ASCII_letter, v.pos-2, 2)
} else if atomEscape {
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, but in Annex B, \c are really two characters regardless of whether it is an atom escape. I believe it is due to the ClassAtomNoDash production.
Also some changes from microsoft/TypeScript#60249; didn't file a separate PR due to insignificance.

Comment on lines -621 to +652
if ch != 0 && (scanner.IsIdentifierStart(ch) || ch == '_' || ch == '$') {
if ch != 0 && scanner.IsIdentifierStart(ch) {
v.pos++
for v.pos < v.end {
ch = v.charAtOffset(0)
if scanner.IsIdentifierPart(ch) || ch == '_' || ch == '$' {
if scanner.IsIdentifierPart(ch) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, some redundant checks


propertyNameOrValueStart := v.pos
v.scanIdentifier(v.charAtOffset(0))
v.scanWordCharacters(v.charAtOffset(0))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if your original intention in relaxing the checks was to suppress the "Expected '}'" error when the } appears after a several exotic identifier characters. If so, you might want to revert that commit.

@graphemecluster
Copy link
Contributor Author

Closing since #3061 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant