From 91c171b5604edcbd474a0938acd57754a949b5bb Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 1 Oct 2019 12:50:23 -0700 Subject: [PATCH] Fix the third crash in the chrome user suite test by remembering to pass excludeThisKeyword --- src/compiler/utilities.ts | 2 +- .../jsCheckObjectDefineThisNoCrash.errors.txt | 13 ++++++++ .../jsCheckObjectDefineThisNoCrash.symbols | 21 +++++++++++++ .../jsCheckObjectDefineThisNoCrash.types | 31 +++++++++++++++++++ .../jsCheckObjectDefineThisNoCrash.ts | 11 +++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsCheckObjectDefineThisNoCrash.errors.txt create mode 100644 tests/baselines/reference/jsCheckObjectDefineThisNoCrash.symbols create mode 100644 tests/baselines/reference/jsCheckObjectDefineThisNoCrash.types create mode 100644 tests/cases/compiler/jsCheckObjectDefineThisNoCrash.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 00447edd42add..c9aff842c8c6b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2060,7 +2060,7 @@ namespace ts { idText(expr.expression.expression) === "Object" && idText(expr.expression.name) === "defineProperty" && isStringOrNumericLiteralLike(expr.arguments[1]) && - isBindableStaticNameExpression(expr.arguments[0]); + isBindableStaticNameExpression(expr.arguments[0], /*excludeThisKeyword*/ true); } export function isBindableStaticElementAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticElementAccessExpression { diff --git a/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.errors.txt b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.errors.txt new file mode 100644 index 0000000000000..cc6c7e7f0d72f --- /dev/null +++ b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js(5,36): error TS2339: Property '_prop' does not exist on type 'C'. + + +==== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js (1 errors) ==== + class C { + constructor() { + // Neither of the following should be recognized as declarations yet + Object.defineProperty(this, "_prop", { value: {} }); + Object.defineProperty(this._prop, "num", { value: 12 }); + ~~~~~ +!!! error TS2339: Property '_prop' does not exist on type 'C'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.symbols b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.symbols new file mode 100644 index 0000000000000..f15fec2005bee --- /dev/null +++ b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js === +class C { +>C : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0)) + + constructor() { + // Neither of the following should be recognized as declarations yet + Object.defineProperty(this, "_prop", { value: {} }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>this : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0)) +>value : Symbol(value, Decl(jsCheckObjectDefineThisNoCrash.js, 3, 46)) + + Object.defineProperty(this._prop, "num", { value: 12 }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>this : Symbol(C, Decl(jsCheckObjectDefineThisNoCrash.js, 0, 0)) +>value : Symbol(value, Decl(jsCheckObjectDefineThisNoCrash.js, 4, 50)) + } +} diff --git a/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.types b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.types new file mode 100644 index 0000000000000..5b771cb514228 --- /dev/null +++ b/tests/baselines/reference/jsCheckObjectDefineThisNoCrash.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/jsCheckObjectDefineThisNoCrash.js === +class C { +>C : C + + constructor() { + // Neither of the following should be recognized as declarations yet + Object.defineProperty(this, "_prop", { value: {} }); +>Object.defineProperty(this, "_prop", { value: {} }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>this : this +>"_prop" : "_prop" +>{ value: {} } : { value: {}; } +>value : {} +>{} : {} + + Object.defineProperty(this._prop, "num", { value: 12 }); +>Object.defineProperty(this._prop, "num", { value: 12 }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>this._prop : any +>this : this +>_prop : any +>"num" : "num" +>{ value: 12 } : { value: number; } +>value : number +>12 : 12 + } +} diff --git a/tests/cases/compiler/jsCheckObjectDefineThisNoCrash.ts b/tests/cases/compiler/jsCheckObjectDefineThisNoCrash.ts new file mode 100644 index 0000000000000..15fbbb1433a34 --- /dev/null +++ b/tests/cases/compiler/jsCheckObjectDefineThisNoCrash.ts @@ -0,0 +1,11 @@ +// @checkJs: true +// @allowJs: true +// @noEmit: true +// @filename: jsCheckObjectDefineThisNoCrash.js +class C { + constructor() { + // Neither of the following should be recognized as declarations yet + Object.defineProperty(this, "_prop", { value: {} }); + Object.defineProperty(this._prop, "num", { value: 12 }); + } +} \ No newline at end of file