diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 30637c3cebc..63db442ceba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2405,8 +2405,11 @@ namespace ts { // This way a chain of imports can be elided if ultimately the final input is only used in a type // position. if (isInternalModuleImportEqualsDeclaration(node)) { - // import foo = - checkExpressionCached(node.moduleReference); + const target = resolveSymbol(symbol); + if (target === unknownSymbol || target.flags & SymbolFlags.Value) { + // import foo = + checkExpressionCached(node.moduleReference); + } } } } diff --git a/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.symbols b/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.symbols new file mode 100644 index 00000000000..91a2bade757 --- /dev/null +++ b/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/file.d.ts === +declare namespace dojox { +>dojox : Symbol(dojox, Decl(file.d.ts, 0, 0)) + + namespace charting { +>charting : Symbol(charting, Decl(file.d.ts, 0, 25)) + + namespace axis2d { +>axis2d : Symbol(axis2d, Decl(file.d.ts, 1, 24)) + + export class Val { } +>Val : Symbol(Val, Decl(file.d.ts, 2, 26)) + + interface common { +>common : Symbol(common, Decl(file.d.ts, 3, 32), Decl(file.d.ts, 6, 13)) + + createText: object; +>createText : Symbol(common.createText, Decl(file.d.ts, 4, 30)) + } + namespace common { +>common : Symbol(common, Decl(file.d.ts, 3, 32), Decl(file.d.ts, 6, 13)) + + interface createText { +>createText : Symbol(createText, Decl(file.d.ts, 7, 30)) + + gfx(): string +>gfx : Symbol(createText.gfx, Decl(file.d.ts, 8, 38)) + } + } + } + } +} +declare module "dojox/charting/axis2d/common.createText" { +>"dojox/charting/axis2d/common.createText" : Symbol("dojox/charting/axis2d/common.createText", Decl(file.d.ts, 14, 1)) + + import exp = dojox.charting.axis2d.common +>exp : Symbol(exp, Decl(file.d.ts, 15, 58)) +>dojox : Symbol(dojox, Decl(file.d.ts, 0, 0)) +>charting : Symbol(dojox.charting, Decl(file.d.ts, 0, 25)) +>axis2d : Symbol(dojox.charting.axis2d, Decl(file.d.ts, 1, 24)) +>common : Symbol(exp, Decl(file.d.ts, 3, 32), Decl(file.d.ts, 6, 13)) + + export = exp; +>exp : Symbol(exp, Decl(file.d.ts, 15, 58)) +} diff --git a/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.types b/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.types new file mode 100644 index 00000000000..aa5a75ca6ec --- /dev/null +++ b/tests/baselines/reference/importDeclarationNotCheckedAsValueWhenTargetNonValue.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/file.d.ts === +declare namespace dojox { +>dojox : typeof dojox + + namespace charting { +>charting : typeof charting + + namespace axis2d { +>axis2d : typeof axis2d + + export class Val { } +>Val : Val + + interface common { + createText: object; +>createText : object + } + namespace common { + interface createText { + gfx(): string +>gfx : () => string + } + } + } + } +} +declare module "dojox/charting/axis2d/common.createText" { +>"dojox/charting/axis2d/common.createText" : typeof import("dojox/charting/axis2d/common.createText") + + import exp = dojox.charting.axis2d.common +>exp : any +>dojox : typeof dojox +>charting : typeof dojox.charting +>axis2d : typeof dojox.charting.axis2d +>common : exp + + export = exp; +>exp : exp +} diff --git a/tests/cases/compiler/importDeclarationNotCheckedAsValueWhenTargetNonValue.ts b/tests/cases/compiler/importDeclarationNotCheckedAsValueWhenTargetNonValue.ts new file mode 100644 index 00000000000..8e2061794fd --- /dev/null +++ b/tests/cases/compiler/importDeclarationNotCheckedAsValueWhenTargetNonValue.ts @@ -0,0 +1,20 @@ +// @filename: file.d.ts +declare namespace dojox { + namespace charting { + namespace axis2d { + export class Val { } + interface common { + createText: object; + } + namespace common { + interface createText { + gfx(): string + } + } + } + } +} +declare module "dojox/charting/axis2d/common.createText" { + import exp = dojox.charting.axis2d.common + export = exp; +} \ No newline at end of file diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 6fae09b67ec..1e471a00796 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 6fae09b67ec6f7b27259a5c133a6961d05a4161b +Subproject commit 1e471a007968b7490563b91ed6909ae6046f3fe8