Avoid bogus circularity error on context sensitive expando assingment (#50487)

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Zzzen 2023-03-17 01:12:23 +08:00 committed by GitHub
parent e0124040f0
commit cfd550e397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 231 additions and 1 deletions

View File

@ -28947,7 +28947,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return undefined;
}
}
return isInJSFile(decl) ? undefined : getTypeOfExpression(binaryExpression.left);
return isInJSFile(decl) || decl === binaryExpression.left ? undefined : getTypeOfExpression(binaryExpression.left);
}
case AssignmentDeclarationKind.ExportsProperty:
case AssignmentDeclarationKind.Prototype:

View File

@ -0,0 +1,19 @@
//// [contextualReturnTypeOfIIFE2.ts]
declare namespace app {
function foo(): void;
}
app.foo.bar = (function () {
const someFun = (arg: number) => {};
return { someFun };
})();
app.foo.bar.someFun(1);
//// [contextualReturnTypeOfIIFE2.js]
app.foo.bar = (function () {
var someFun = function (arg) { };
return { someFun: someFun };
})();
app.foo.bar.someFun(1);

View File

@ -0,0 +1,33 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
declare namespace app {
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
function foo(): void;
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
}
app.foo.bar = (function () {
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
const someFun = (arg: number) => {};
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 5, 7))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE2.ts, 5, 19))
return { someFun };
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
})();
app.foo.bar.someFun(1);
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))

View File

@ -0,0 +1,41 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
declare namespace app {
>app : typeof app
function foo(): void;
>foo : typeof foo
}
app.foo.bar = (function () {
>app.foo.bar = (function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : typeof app.foo
>app : typeof app
>foo : typeof app.foo
>bar : { someFun: (arg: number) => void; }
>(function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
>(function () { const someFun = (arg: number) => {}; return { someFun };}) : () => { someFun: (arg: number) => void; }
>function () { const someFun = (arg: number) => {}; return { someFun };} : () => { someFun: (arg: number) => void; }
const someFun = (arg: number) => {};
>someFun : (arg: number) => void
>(arg: number) => {} : (arg: number) => void
>arg : number
return { someFun };
>{ someFun } : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void
})();
app.foo.bar.someFun(1);
>app.foo.bar.someFun(1) : void
>app.foo.bar.someFun : (arg: number) => void
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : typeof app.foo
>app : typeof app
>foo : typeof app.foo
>bar : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void
>1 : 1

View File

@ -0,0 +1,21 @@
//// [contextualReturnTypeOfIIFE3.ts]
declare namespace app {
var foo: {
bar: {
someFun: (arg: number) => void;
};
};
}
app.foo.bar = (function () {
return { someFun(arg) {} };
})();
app.foo.bar.someFun(1);
//// [contextualReturnTypeOfIIFE3.js]
app.foo.bar = (function () {
return { someFun: function (arg) { } };
})();
app.foo.bar.someFun(1);

View File

@ -0,0 +1,40 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
declare namespace app {
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
var foo: {
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
bar: {
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
someFun: (arg: number) => void;
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 3, 16))
};
};
}
app.foo.bar = (function () {
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
return { someFun(arg) {} };
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 9, 10))
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 9, 19))
})();
app.foo.bar.someFun(1);
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))

View File

@ -0,0 +1,47 @@
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
declare namespace app {
>app : typeof app
var foo: {
>foo : { bar: { someFun: (arg: number) => void; }; }
bar: {
>bar : { someFun: (arg: number) => void; }
someFun: (arg: number) => void;
>someFun : (arg: number) => void
>arg : number
};
};
}
app.foo.bar = (function () {
>app.foo.bar = (function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : { bar: { someFun: (arg: number) => void; }; }
>app : typeof app
>foo : { bar: { someFun: (arg: number) => void; }; }
>bar : { someFun: (arg: number) => void; }
>(function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
>(function () { return { someFun(arg) {} };}) : () => { someFun(arg: number): void; }
>function () { return { someFun(arg) {} };} : () => { someFun(arg: number): void; }
return { someFun(arg) {} };
>{ someFun(arg) {} } : { someFun(arg: number): void; }
>someFun : (arg: number) => void
>arg : number
})();
app.foo.bar.someFun(1);
>app.foo.bar.someFun(1) : void
>app.foo.bar.someFun : (arg: number) => void
>app.foo.bar : { someFun: (arg: number) => void; }
>app.foo : { bar: { someFun: (arg: number) => void; }; }
>app : typeof app
>foo : { bar: { someFun: (arg: number) => void; }; }
>bar : { someFun: (arg: number) => void; }
>someFun : (arg: number) => void
>1 : 1

View File

@ -0,0 +1,13 @@
// @lib: esnext
// @noImplicitAny: true
declare namespace app {
function foo(): void;
}
app.foo.bar = (function () {
const someFun = (arg: number) => {};
return { someFun };
})();
app.foo.bar.someFun(1);

View File

@ -0,0 +1,16 @@
// @lib: esnext
// @noImplicitAny: true
declare namespace app {
var foo: {
bar: {
someFun: (arg: number) => void;
};
};
}
app.foo.bar = (function () {
return { someFun(arg) {} };
})();
app.foo.bar.someFun(1);