Skip to content

Commit 9ef98be

Browse files
authored
Add extra test cases for fixed reportNonexistentProperty crashes (microsoft#60690)
1 parent 12d9687 commit 9ef98be

7 files changed

+252
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
index.js(5,21): error TS2339: Property 'fn' does not exist on type '{ (...args: any[]): void; readonly name: string; }'.
2+
3+
4+
==== index.js (1 errors) ====
5+
export function test(fn) {
6+
const composed = function (...args) { }
7+
8+
Object.defineProperty(composed, 'name', {
9+
value: composed.fn + '_test'
10+
~~
11+
!!! error TS2339: Property 'fn' does not exist on type '{ (...args: any[]): void; readonly name: string; }'.
12+
})
13+
14+
return composed
15+
}
16+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////
2+
3+
//// [index.js]
4+
export function test(fn) {
5+
const composed = function (...args) { }
6+
7+
Object.defineProperty(composed, 'name', {
8+
value: composed.fn + '_test'
9+
})
10+
11+
return composed
12+
}
13+
14+
15+
//// [index.js]
16+
"use strict";
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.test = test;
19+
function test(fn) {
20+
var composed = function () {
21+
var args = [];
22+
for (var _i = 0; _i < arguments.length; _i++) {
23+
args[_i] = arguments[_i];
24+
}
25+
};
26+
Object.defineProperty(composed, 'name', {
27+
value: composed.fn + '_test'
28+
});
29+
return composed;
30+
}
31+
32+
33+
//// [index.d.ts]
34+
export function test(fn: any): {
35+
(...args: any[]): void;
36+
readonly name: string;
37+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////
2+
3+
=== index.js ===
4+
export function test(fn) {
5+
>test : Symbol(test, Decl(index.js, 0, 0))
6+
>fn : Symbol(fn, Decl(index.js, 0, 21))
7+
8+
const composed = function (...args) { }
9+
>composed : Symbol(composed, Decl(index.js, 1, 7))
10+
>args : Symbol(args, Decl(index.js, 1, 29))
11+
12+
Object.defineProperty(composed, 'name', {
13+
>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
14+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
15+
>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
16+
>composed : Symbol(composed, Decl(index.js, 1, 7))
17+
>'name' : Symbol(composed.name, Decl(index.js, 1, 41))
18+
19+
value: composed.fn + '_test'
20+
>value : Symbol(value, Decl(index.js, 3, 43))
21+
>composed : Symbol(composed, Decl(index.js, 1, 7))
22+
23+
})
24+
25+
return composed
26+
>composed : Symbol(composed, Decl(index.js, 1, 7))
27+
}
28+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////
2+
3+
=== index.js ===
4+
export function test(fn) {
5+
>test : (fn: any) => { (...args: any[]): void; readonly name: string; }
6+
> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
>fn : any
8+
> : ^^^
9+
10+
const composed = function (...args) { }
11+
>composed : { (...args: any[]): void; readonly name: string; }
12+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
>function (...args) { } : { (...args: any[]): void; readonly name: string; }
14+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
>args : any[]
16+
> : ^^^^^
17+
18+
Object.defineProperty(composed, 'name', {
19+
>Object.defineProperty(composed, 'name', { value: composed.fn + '_test' }) : { (...args: any[]): void; readonly name: string; }
20+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
22+
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
23+
>Object : ObjectConstructor
24+
> : ^^^^^^^^^^^^^^^^^
25+
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
26+
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
27+
>composed : { (...args: any[]): void; readonly name: string; }
28+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
>'name' : "name"
30+
> : ^^^^^^
31+
>{ value: composed.fn + '_test' } : { value: string; }
32+
> : ^^^^^^^^^^^^^^^^^^
33+
34+
value: composed.fn + '_test'
35+
>value : string
36+
> : ^^^^^^
37+
>composed.fn + '_test' : string
38+
> : ^^^^^^
39+
>composed.fn : any
40+
> : ^^^
41+
>composed : { (...args: any[]): void; readonly name: string; }
42+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
>fn : any
44+
> : ^^^
45+
>'_test' : "_test"
46+
> : ^^^^^^^
47+
48+
})
49+
50+
return composed
51+
>composed : { (...args: any[]): void; readonly name: string; }
52+
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53+
}
54+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// === findAllReferences ===
2+
// === /tests/cases/fourslash/src/parser.js ===
3+
// --- (line: 10) skipped ---
4+
// variable: function () {
5+
// let name;
6+
//
7+
// if (parserInput.currentChar() === "[|{| isInString: true |}@|]") {
8+
// return name[1];
9+
// }
10+
// },
11+
// --- (line: 18) skipped ---
12+
13+
// === /tests/cases/fourslash/./src/parser.js ===
14+
// --- (line: 10) skipped ---
15+
// variable: function () {
16+
// let name;
17+
//
18+
// if (parserInput.currentChar() === "/*FIND ALL REFS*/@") {
19+
// return name[1];
20+
// }
21+
// },
22+
// --- (line: 18) skipped ---
23+
24+
// === Definitions ===
25+
// === /tests/cases/fourslash/src/parser.js ===
26+
// --- (line: 10) skipped ---
27+
// variable: function () {
28+
// let name;
29+
//
30+
// if (parserInput.currentChar() === "[|@|]") {
31+
// return name[1];
32+
// }
33+
// },
34+
// --- (line: 18) skipped ---
35+
36+
// === Details ===
37+
[
38+
{
39+
"containerKind": "",
40+
"containerName": "",
41+
"kind": "var",
42+
"name": "@",
43+
"displayParts": [
44+
{
45+
"text": "\"@\"",
46+
"kind": "stringLiteral"
47+
}
48+
]
49+
}
50+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @declaration: true
4+
// @outDir: dist
5+
6+
// @filename: index.js
7+
8+
export function test(fn) {
9+
const composed = function (...args) { }
10+
11+
Object.defineProperty(composed, 'name', {
12+
value: composed.fn + '_test'
13+
})
14+
15+
return composed
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
// @allowJs: true
5+
// @checkJs: true
6+
7+
// @filename: ./src/parser-input.js
8+
//// export default () => {
9+
//// let input;
10+
////
11+
//// const parserInput = {};
12+
////
13+
//// parserInput.currentChar = () => input.charAt(parserInput.i);
14+
////
15+
//// parserInput.end = () => {
16+
//// const isFinished = parserInput.i >= input.length;
17+
////
18+
//// return {
19+
//// isFinished,
20+
//// furthest: parserInput.i,
21+
//// };
22+
//// };
23+
////
24+
//// return parserInput;
25+
//// };
26+
27+
// @filename: ./src/parser.js
28+
//// import getParserInput from "./parser-input";
29+
////
30+
//// const Parser = function Parser(context, imports, fileInfo, currentIndex) {
31+
//// currentIndex = currentIndex || 0;
32+
//// let parsers;
33+
//// const parserInput = getParserInput();
34+
////
35+
//// return {
36+
//// parserInput,
37+
//// parsers: (parsers = {
38+
//// variable: function () {
39+
//// let name;
40+
////
41+
//// if (parserInput.currentChar() === "/*1*/@") {
42+
//// return name[1];
43+
//// }
44+
//// },
45+
//// }),
46+
//// };
47+
//// };
48+
////
49+
//// export default Parser;
50+
51+
verify.baselineFindAllReferences("1");

0 commit comments

Comments
 (0)