Skip to content

Commit f2dc879

Browse files
authored
fix(64883): fix asi before escaped keyword class members (#64885)
1 parent fa62f87 commit f2dc879

6 files changed

Lines changed: 1439 additions & 0 deletions

File tree

‎tsc/internal/parser/parser.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,6 +4751,9 @@ func (p *Parser) parseBinaryExpressionRest(precedence ast.OperatorPrecedence, le
47514751
if !shouldConsumeBinaryOperator(operator, newPrecedence, precedence) {
47524752
break
47534753
}
4754+
if p.hasPrecedingLineBreak() && (p.scanner.HasUnicodeEscape() || p.scanner.HasExtendedUnicodeEscape()) && ast.NodeIsPresent(leftOperand) {
4755+
break
4756+
}
47544757
if operator == ast.KindInKeyword && p.inDisallowInContext() {
47554758
break
47564759
}

‎tsc/testdata/baselines/reference/conformance/scannerUnicodeEscapeInKeyword2.errors.txt‎

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
c.ts(3,15): error TS1260: Keywords cannot contain escape characters.
2+
c.ts(4,14): error TS1260: Keywords cannot contain escape characters.
3+
d.js(3,15): error TS1260: Keywords cannot contain escape characters.
4+
d.js(4,14): error TS1260: Keywords cannot contain escape characters.
5+
e.ts(5,9): error TS1451: Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression
6+
f.js(5,9): error TS1451: Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression
17
file1.ts(3,5): error TS1260: Keywords cannot contain escape characters.
28
file1.ts(8,5): error TS1260: Keywords cannot contain escape characters.
39
file1.ts(13,1): error TS1260: Keywords cannot contain escape characters.
410
file2.ts(1,1): error TS1260: Keywords cannot contain escape characters.
511
file2.ts(5,5): error TS1260: Keywords cannot contain escape characters.
612
file2.ts(10,5): error TS1260: Keywords cannot contain escape characters.
713
file2.ts(15,1): error TS1260: Keywords cannot contain escape characters.
14+
g.ts(3,1): error TS1109: Expression expected.
15+
g.ts(3,8): error TS1109: Expression expected.
16+
h.ts(3,1): error TS1109: Expression expected.
17+
i.ts(3,5): error TS1005: ')' expected.
18+
i.ts(3,14): error TS1005: ';' expected.
19+
j.js(3,1): error TS1109: Expression expected.
20+
j.js(3,8): error TS1109: Expression expected.
21+
k.js(3,1): error TS1109: Expression expected.
22+
l.js(3,5): error TS1005: ')' expected.
23+
l.js(3,14): error TS1005: ';' expected.
824

925

1026
==== file1.ts (3 errors) ====
@@ -58,4 +74,194 @@ file2.ts(15,1): error TS1260: Keywords cannot contain escape characters.
5874

5975
const a = {def\u0061ult: 12}; // OK, `default` not in keyword position
6076
// chrome and jsc may still error on this, ref https://bugs.chromium.org/p/chromium/issues/detail?id=993000 and https://bugs.webkit.org/show_bug.cgi?id=200638
77+
78+
==== a.ts (0 errors) ====
79+
export {};
80+
81+
class A {
82+
a = 1
83+
\u{69}n
84+
b = 2
85+
\u{69}nstanceof
86+
}
87+
88+
class B {
89+
a = 1
90+
\u0069n
91+
b = 2
92+
\u0069nstanceof
93+
}
94+
95+
class C {
96+
a = () => 1
97+
\u{69}nstanceof
98+
b = 2
99+
\u0069n() {}
100+
}
101+
102+
class D {
103+
a = "a"
104+
in
105+
{ a: 1 }
106+
b = {}
107+
instanceof
108+
Object
109+
}
110+
111+
class E {
112+
a = 1;
113+
\u0069n = 2;
114+
b = 3;
115+
\u{69}nstanceof = 4;
116+
}
117+
118+
const a = Object.keys(new A());
119+
const b = Object.keys(new B());
120+
const c = new C();
121+
const d = new D();
122+
const e = 1;
123+
const f = \u0065
124+
+ 1;
125+
126+
==== b.js (0 errors) ====
127+
export {};
128+
129+
class A {
130+
a = 1
131+
\u{69}n
132+
b = 2
133+
\u{69}nstanceof
134+
}
135+
136+
class B {
137+
a = 1
138+
\u0069n
139+
b = 2
140+
\u0069nstanceof
141+
}
142+
143+
class C {
144+
a = () => 1
145+
\u{69}nstanceof
146+
b = 2
147+
\u0069n() {}
148+
}
149+
150+
class D {
151+
a = "a"
152+
in
153+
{ a: 1 }
154+
b = {}
155+
instanceof
156+
Object
157+
}
158+
159+
class E {
160+
a = 1;
161+
\u0069n = 2;
162+
b = 3;
163+
\u{69}nstanceof = 4;
164+
}
165+
166+
const a = Object.keys(new A());
167+
const b = Object.keys(new B());
168+
const c = new C();
169+
const d = new D();
170+
const e = 1;
171+
const f = \u0065
172+
+ 1;
173+
174+
==== c.ts (2 errors) ====
175+
export {};
176+
177+
const a = "a" \u0069n { a: 1 };
178+
~~~~~~~
179+
!!! error TS1260: Keywords cannot contain escape characters.
180+
const b = {} \u{69}nstanceof Object;
181+
~~~~~~~~~~~~~~~
182+
!!! error TS1260: Keywords cannot contain escape characters.
183+
184+
==== d.js (2 errors) ====
185+
export {};
186+
187+
const a = "a" \u0069n { a: 1 };
188+
~~~~~~~
189+
!!! error TS1260: Keywords cannot contain escape characters.
190+
const b = {} \u{69}nstanceof Object;
191+
~~~~~~~~~~~~~~~
192+
!!! error TS1260: Keywords cannot contain escape characters.
193+
194+
==== e.ts (1 errors) ====
195+
export {};
196+
197+
class A {
198+
#a;
199+
b = #a
200+
~~
201+
!!! error TS1451: Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression
202+
\u0069n
203+
}
204+
205+
==== f.js (1 errors) ====
206+
export {};
207+
208+
class A {
209+
#a;
210+
b = #a
211+
~~
212+
!!! error TS1451: Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression
213+
\u0069n
214+
}
215+
216+
==== g.ts (2 errors) ====
217+
declare var x: any, y: any;
218+
x
219+
\u0069n
220+
~~~~~~~
221+
!!! error TS1109: Expression expected.
222+
223+
!!! error TS1109: Expression expected.
224+
225+
==== h.ts (1 errors) ====
226+
declare var x: any, y: any;
227+
x
228+
\u{69}nstanceof y
229+
~~~~~~~~~~~~~~~
230+
!!! error TS1109: Expression expected.
231+
232+
==== i.ts (2 errors) ====
233+
declare var x: any, y: any;
234+
if (x
235+
\u0069n y) {}
236+
~~~~~~~
237+
!!! error TS1005: ')' expected.
238+
!!! related TS1007 i.ts:2:4: The parser expected to find a ')' to match the '(' token here.
239+
~
240+
!!! error TS1005: ';' expected.
241+
242+
==== j.js (2 errors) ====
243+
var x, y;
244+
x
245+
\u0069n
246+
~~~~~~~
247+
!!! error TS1109: Expression expected.
248+
249+
!!! error TS1109: Expression expected.
250+
251+
==== k.js (1 errors) ====
252+
var x, y;
253+
x
254+
\u{69}nstanceof y
255+
~~~~~~~~~~~~~~~
256+
!!! error TS1109: Expression expected.
257+
258+
==== l.js (2 errors) ====
259+
var x, y;
260+
if (x
261+
\u0069n y) {}
262+
~~~~~~~
263+
!!! error TS1005: ')' expected.
264+
!!! related TS1007 l.js:2:4: The parser expected to find a ')' to match the '(' token here.
265+
~
266+
!!! error TS1005: ';' expected.
61267

0 commit comments

Comments
 (0)