Skip to content

fix(47004): arguments detection for jsdoc / javascript has a false positive #47054

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

Merged
merged 1 commit into from
Dec 16, 2021
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
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12706,6 +12706,9 @@ namespace ts {
case SyntaxKind.ElementAccessExpression:
return traverse((node as PropertyAccessExpression | ElementAccessExpression).expression);

case SyntaxKind.PropertyAssignment:
return traverse((node as PropertyAssignment).initializer);

default:
return !nodeStartsNewLexicalEnvironment(node) && !isPartOfTypeNode(node) && !!forEachChild(node, traverse);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/a.js(9,7): error TS2554: Expected 0-1 arguments, but got 3.


==== tests/cases/compiler/a.js (1 errors) ====
const foo = {
f1: (params) => { }
}

function f2(x) {
foo.f1({ x, arguments: [] });
}

f2(1, 2, 3);
~~~~
!!! error TS2554: Expected 0-1 arguments, but got 3.

27 changes: 27 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [a.js]
const foo = {
f1: (params) => { }
}

function f2(x) {
foo.f1({ x, arguments: [] });
}

f2(1, 2, 3);


//// [a.js]
var foo = {
f1: function (params) { }
};
function f2(x) {
foo.f1({ x: x, arguments: [] });
}
f2(1, 2, 3);


//// [a.d.ts]
declare function f2(x: any): void;
declare namespace foo {
function f1(params: any): void;
}
24 changes: 24 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/a.js ===
const foo = {
>foo : Symbol(foo, Decl(a.js, 0, 5))

f1: (params) => { }
>f1 : Symbol(f1, Decl(a.js, 0, 13))
>params : Symbol(params, Decl(a.js, 1, 8))
}

function f2(x) {
>f2 : Symbol(f2, Decl(a.js, 2, 1))
>x : Symbol(x, Decl(a.js, 4, 12))

foo.f1({ x, arguments: [] });
>foo.f1 : Symbol(f1, Decl(a.js, 0, 13))
>foo : Symbol(foo, Decl(a.js, 0, 5))
>f1 : Symbol(f1, Decl(a.js, 0, 13))
>x : Symbol(x, Decl(a.js, 5, 10))
>arguments : Symbol(arguments, Decl(a.js, 5, 13))
}

f2(1, 2, 3);
>f2 : Symbol(f2, Decl(a.js, 2, 1))

33 changes: 33 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/compiler/a.js ===
const foo = {
>foo : { f1: (params: any) => void; }
>{ f1: (params) => { }} : { f1: (params: any) => void; }

f1: (params) => { }
>f1 : (params: any) => void
>(params) => { } : (params: any) => void
>params : any
}

function f2(x) {
>f2 : (x: any) => void
>x : any

foo.f1({ x, arguments: [] });
>foo.f1({ x, arguments: [] }) : void
>foo.f1 : (params: any) => void
>foo : { f1: (params: any) => void; }
>f1 : (params: any) => void
>{ x, arguments: [] } : { x: any; arguments: undefined[]; }
>x : any
>arguments : undefined[]
>[] : undefined[]
}

f2(1, 2, 3);
>f2(1, 2, 3) : void
>f2 : (x: any) => void
>1 : 1
>2 : 2
>3 : 3

17 changes: 17 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [a.js]
function f(x) {
arguments;
}

f(1, 2, 3);


//// [a.js]
function f(x) {
arguments;
}
f(1, 2, 3);


//// [a.d.ts]
declare function f(x: any, ...args: any[]): void;
12 changes: 12 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/a.js ===
function f(x) {
>f : Symbol(f, Decl(a.js, 0, 0))
>x : Symbol(x, Decl(a.js, 0, 11))

arguments;
>arguments : Symbol(arguments)
}

f(1, 2, 3);
>f : Symbol(f, Decl(a.js, 0, 0))

16 changes: 16 additions & 0 deletions tests/baselines/reference/argumentsPropertyNameInJsMode2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/a.js ===
function f(x) {
>f : (x: any, ...args: any[]) => void
>x : any

arguments;
>arguments : IArguments
}

f(1, 2, 3);
>f(1, 2, 3) : void
>f : (x: any, ...args: any[]) => void
>1 : 1
>2 : 2
>3 : 3

Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/a.js",
"position": 50,
"name": "1"
},
"quickInfo": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 50,
"length": 2
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "f2",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "x",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": []
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/a.js",
"position": 94,
"name": "2"
},
"quickInfo": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 94,
"length": 2
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "f2",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "x",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": []
}
}
]
Loading