Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra test cases for fixed reportNonexistentProperty crashes #60690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
index.js(5,21): error TS2339: Property 'fn' does not exist on type '{ (...args: any[]): void; readonly name: string; }'.


==== index.js (1 errors) ====
export function test(fn) {
const composed = function (...args) { }

Object.defineProperty(composed, 'name', {
value: composed.fn + '_test'
~~
!!! error TS2339: Property 'fn' does not exist on type '{ (...args: any[]): void; readonly name: string; }'.
})

return composed
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////

//// [index.js]
export function test(fn) {
const composed = function (...args) { }

Object.defineProperty(composed, 'name', {
value: composed.fn + '_test'
})

return composed
}


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.test = test;
function test(fn) {
var composed = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
};
Object.defineProperty(composed, 'name', {
value: composed.fn + '_test'
});
return composed;
}


//// [index.d.ts]
export function test(fn: any): {
(...args: any[]): void;
readonly name: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////

=== index.js ===
export function test(fn) {
>test : Symbol(test, Decl(index.js, 0, 0))
>fn : Symbol(fn, Decl(index.js, 0, 21))

const composed = function (...args) { }
>composed : Symbol(composed, Decl(index.js, 1, 7))
>args : Symbol(args, Decl(index.js, 1, 29))

Object.defineProperty(composed, 'name', {
>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, --, --))
>composed : Symbol(composed, Decl(index.js, 1, 7))
>'name' : Symbol(composed.name, Decl(index.js, 1, 41))

value: composed.fn + '_test'
>value : Symbol(value, Decl(index.js, 3, 43))
>composed : Symbol(composed, Decl(index.js, 1, 7))

})

return composed
>composed : Symbol(composed, Decl(index.js, 1, 7))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//// [tests/cases/compiler/checkingObjectDefinePropertyOnFunctionNonexistentPropertyNoCrash1.ts] ////

=== index.js ===
export function test(fn) {
>test : (fn: any) => { (...args: any[]): void; readonly name: string; }
> : ^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>fn : any
> : ^^^

const composed = function (...args) { }
>composed : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>function (...args) { } : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>args : any[]
> : ^^^^^

Object.defineProperty(composed, 'name', {
>Object.defineProperty(composed, 'name', { value: composed.fn + '_test' }) : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>Object : ObjectConstructor
> : ^^^^^^^^^^^^^^^^^
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
> : ^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>composed : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>'name' : "name"
> : ^^^^^^
>{ value: composed.fn + '_test' } : { value: string; }
> : ^^^^^^^^^^^^^^^^^^

value: composed.fn + '_test'
>value : string
> : ^^^^^^
>composed.fn + '_test' : string
> : ^^^^^^
>composed.fn : any
> : ^^^
>composed : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>fn : any
> : ^^^
>'_test' : "_test"
> : ^^^^^^^

})

return composed
>composed : { (...args: any[]): void; readonly name: string; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// === findAllReferences ===
// === /tests/cases/fourslash/src/parser.js ===
// --- (line: 10) skipped ---
// variable: function () {
// let name;
//
// if (parserInput.currentChar() === "[|{| isInString: true |}@|]") {
// return name[1];
// }
// },
// --- (line: 18) skipped ---

// === /tests/cases/fourslash/./src/parser.js ===
// --- (line: 10) skipped ---
// variable: function () {
// let name;
//
// if (parserInput.currentChar() === "/*FIND ALL REFS*/@") {
// return name[1];
// }
// },
// --- (line: 18) skipped ---

// === Definitions ===
// === /tests/cases/fourslash/src/parser.js ===
// --- (line: 10) skipped ---
// variable: function () {
// let name;
//
// if (parserInput.currentChar() === "[|@|]") {
// return name[1];
// }
// },
// --- (line: 18) skipped ---

// === Details ===
[
{
"containerKind": "",
"containerName": "",
"kind": "var",
"name": "@",
"displayParts": [
{
"text": "\"@\"",
"kind": "stringLiteral"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @allowJs: true
// @checkJs: true
// @declaration: true
// @outDir: dist

// @filename: index.js

export function test(fn) {
const composed = function (...args) { }

Object.defineProperty(composed, 'name', {
value: composed.fn + '_test'
})

return composed
}
51 changes: 51 additions & 0 deletions tests/cases/fourslash/findAllRefsNonexistentPropertyNoCrash1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @allowJs: true
// @checkJs: true

// @filename: ./src/parser-input.js
//// export default () => {
//// let input;
////
//// const parserInput = {};
////
//// parserInput.currentChar = () => input.charAt(parserInput.i);
////
//// parserInput.end = () => {
//// const isFinished = parserInput.i >= input.length;
////
//// return {
//// isFinished,
//// furthest: parserInput.i,
//// };
//// };
////
//// return parserInput;
//// };

// @filename: ./src/parser.js
//// import getParserInput from "./parser-input";
////
//// const Parser = function Parser(context, imports, fileInfo, currentIndex) {
//// currentIndex = currentIndex || 0;
//// let parsers;
//// const parserInput = getParserInput();
////
//// return {
//// parserInput,
//// parsers: (parsers = {
//// variable: function () {
//// let name;
////
//// if (parserInput.currentChar() === "/*1*/@") {
//// return name[1];
//// }
//// },
//// }),
//// };
//// };
////
//// export default Parser;

verify.baselineFindAllReferences("1");
Loading