Skip to content

Commit 410ff90

Browse files
authored
Fix the third crash in the chrome user suite test by remembering to pass excludeThisKeyword (#33711)
1 parent 20f42f4 commit 410ff90

5 files changed

+77
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ namespace ts {
20602060
idText(expr.expression.expression) === "Object" &&
20612061
idText(expr.expression.name) === "defineProperty" &&
20622062
isStringOrNumericLiteralLike(expr.arguments[1]) &&
2063-
isBindableStaticNameExpression(expr.arguments[0]);
2063+
isBindableStaticNameExpression(expr.arguments[0], /*excludeThisKeyword*/ true);
20642064
}
20652065

20662066
export function isBindableStaticElementAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticElementAccessExpression {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js(5,36): error TS2339: Property '_prop' does not exist on type 'C'.
2+
3+
4+
==== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js (1 errors) ====
5+
class C {
6+
constructor() {
7+
// Neither of the following should be recognized as declarations yet
8+
Object.defineProperty(this, "_prop", { value: {} });
9+
Object.defineProperty(this._prop, "num", { value: 12 });
10+
~~~~~
11+
!!! error TS2339: Property '_prop' does not exist on type 'C'.
12+
}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js ===
2+
class C {
3+
>C : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0))
4+
5+
constructor() {
6+
// Neither of the following should be recognized as declarations yet
7+
Object.defineProperty(this, "_prop", { value: {} });
8+
>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
9+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
10+
>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
11+
>this : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0))
12+
>value : Symbol(value, Decl(jsCheckObjectDefineThisNoCrash.js, 3, 46))
13+
14+
Object.defineProperty(this._prop, "num", { value: 12 });
15+
>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
16+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
17+
>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
18+
>this : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0))
19+
>value : Symbol(value, Decl(jsCheckObjectDefineThisNoCrash.js, 4, 50))
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js ===
2+
class C {
3+
>C : C
4+
5+
constructor() {
6+
// Neither of the following should be recognized as declarations yet
7+
Object.defineProperty(this, "_prop", { value: {} });
8+
>Object.defineProperty(this, "_prop", { value: {} }) : any
9+
>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
10+
>Object : ObjectConstructor
11+
>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
12+
>this : this
13+
>"_prop" : "_prop"
14+
>{ value: {} } : { value: {}; }
15+
>value : {}
16+
>{} : {}
17+
18+
Object.defineProperty(this._prop, "num", { value: 12 });
19+
>Object.defineProperty(this._prop, "num", { value: 12 }) : any
20+
>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
21+
>Object : ObjectConstructor
22+
>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
23+
>this._prop : any
24+
>this : this
25+
>_prop : any
26+
>"num" : "num"
27+
>{ value: 12 } : { value: number; }
28+
>value : number
29+
>12 : 12
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @checkJs: true
2+
// @allowJs: true
3+
// @noEmit: true
4+
// @filename: jsCheckObjectDefineThisNoCrash.js
5+
class C {
6+
constructor() {
7+
// Neither of the following should be recognized as declarations yet
8+
Object.defineProperty(this, "_prop", { value: {} });
9+
Object.defineProperty(this._prop, "num", { value: 12 });
10+
}
11+
}

0 commit comments

Comments
 (0)