diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 26ba5be32f6..f5aed2e1d5c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12581,7 +12581,7 @@ namespace ts { if (!node) return false; switch (node.kind) { case SyntaxKind.Identifier: - return (node as Identifier).escapedText === argumentsSymbol.escapedName && getResolvedSymbol(node as Identifier) === argumentsSymbol; + return (node as Identifier).escapedText === argumentsSymbol.escapedName && getReferencedValueSymbol(node as Identifier) === argumentsSymbol; case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: diff --git a/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.errors.txt b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.errors.txt new file mode 100644 index 00000000000..1c26e2e6011 --- /dev/null +++ b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.errors.txt @@ -0,0 +1,32 @@ +/a.js(16,9): error TS18004: No value exists in scope for the shorthand property 'arguments'. Either declare one or provide an initializer. + + +==== /a.js (1 errors) ==== + const a = () => { + return { + arguments: [], + }; + }; + + const b = () => { + const c = { + arguments: [], + } + return c; + }; + + const c = () => { + return { + arguments, + ~~~~~~~~~ +!!! error TS18004: No value exists in scope for the shorthand property 'arguments'. Either declare one or provide an initializer. + }; + } + + const d = () => { + const arguments = undefined; + return { + arguments, + }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.js b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.js new file mode 100644 index 00000000000..39c849a90ec --- /dev/null +++ b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.js @@ -0,0 +1,51 @@ +//// [a.js] +const a = () => { + return { + arguments: [], + }; +}; + +const b = () => { + const c = { + arguments: [], + } + return c; +}; + +const c = () => { + return { + arguments, + }; +} + +const d = () => { + const arguments = undefined; + return { + arguments, + }; +} + + +//// [a.js] +const a = () => { + return { + arguments: [], + }; +}; +const b = () => { + const c = { + arguments: [], + }; + return c; +}; +const c = () => { + return { + arguments, + }; +}; +const d = () => { + const arguments = undefined; + return { + arguments, + }; +}; diff --git a/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.symbols b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.symbols new file mode 100644 index 00000000000..e2e56a3cb37 --- /dev/null +++ b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.symbols @@ -0,0 +1,49 @@ +=== /a.js === +const a = () => { +>a : Symbol(a, Decl(a.js, 0, 5)) + + return { + arguments: [], +>arguments : Symbol(arguments, Decl(a.js, 1, 12)) + + }; +}; + +const b = () => { +>b : Symbol(b, Decl(a.js, 6, 5)) + + const c = { +>c : Symbol(c, Decl(a.js, 7, 9)) + + arguments: [], +>arguments : Symbol(arguments, Decl(a.js, 7, 15)) + } + return c; +>c : Symbol(c, Decl(a.js, 7, 9)) + +}; + +const c = () => { +>c : Symbol(c, Decl(a.js, 13, 5)) + + return { + arguments, +>arguments : Symbol(arguments, Decl(a.js, 14, 12)) + + }; +} + +const d = () => { +>d : Symbol(d, Decl(a.js, 19, 5)) + + const arguments = undefined; +>arguments : Symbol(arguments, Decl(a.js, 20, 9)) +>undefined : Symbol(undefined) + + return { + arguments, +>arguments : Symbol(arguments, Decl(a.js, 21, 12)) + + }; +} + diff --git a/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.types b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.types new file mode 100644 index 00000000000..8be8786acc8 --- /dev/null +++ b/tests/baselines/reference/argumentsReferenceInObjectLiteral_Js.types @@ -0,0 +1,62 @@ +=== /a.js === +const a = () => { +>a : () => { arguments: any[]; } +>() => { return { arguments: [], };} : () => { arguments: any[]; } + + return { +>{ arguments: [], } : { arguments: undefined[]; } + + arguments: [], +>arguments : undefined[] +>[] : undefined[] + + }; +}; + +const b = () => { +>b : () => { arguments: any[]; } +>() => { const c = { arguments: [], } return c;} : () => { arguments: any[]; } + + const c = { +>c : { arguments: any[]; } +>{ arguments: [], } : { arguments: undefined[]; } + + arguments: [], +>arguments : undefined[] +>[] : undefined[] + } + return c; +>c : { arguments: any[]; } + +}; + +const c = () => { +>c : () => { arguments: any; } +>() => { return { arguments, };} : () => { arguments: any; } + + return { +>{ arguments, } : { arguments: any; } + + arguments, +>arguments : any + + }; +} + +const d = () => { +>d : () => { arguments: any; } +>() => { const arguments = undefined; return { arguments, };} : () => { arguments: any; } + + const arguments = undefined; +>arguments : any +>undefined : undefined + + return { +>{ arguments, } : { arguments: any; } + + arguments, +>arguments : any + + }; +} + diff --git a/tests/cases/compiler/argumentsReferenceInObjectLiteral_Js.ts b/tests/cases/compiler/argumentsReferenceInObjectLiteral_Js.ts new file mode 100644 index 00000000000..92fadcd6001 --- /dev/null +++ b/tests/cases/compiler/argumentsReferenceInObjectLiteral_Js.ts @@ -0,0 +1,31 @@ +// @checkJs: true +// @allowJs: true +// @target: es6 +// @outDir: ./out +// @filename: /a.js + +const a = () => { + return { + arguments: [], + }; +}; + +const b = () => { + const c = { + arguments: [], + } + return c; +}; + +const c = () => { + return { + arguments, + }; +} + +const d = () => { + const arguments = undefined; + return { + arguments, + }; +}