diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 42bb5d7793131..63c340d81dc8a 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1006,7 +1006,9 @@ namespace ts { if (!isPropertyAccessExpression(p.valueDeclaration)) { return undefined; } + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.valueDeclaration); const type = resolver.createTypeOfDeclaration(p.valueDeclaration, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker); + getSymbolAccessibilityDiagnostic = oldDiag; const varDecl = createVariableDeclaration(unescapeLeadingUnderscores(p.escapedName), type, /*initializer*/ undefined); return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([varDecl])); }); diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index b4c72c7901214..9a9aed99e4791 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -26,7 +26,8 @@ namespace ts { | ImportEqualsDeclaration | TypeAliasDeclaration | ConstructorDeclaration - | IndexSignatureDeclaration; + | IndexSignatureDeclaration + | PropertyAccessExpression; export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing { return isVariableDeclaration(node) || @@ -46,7 +47,8 @@ namespace ts { isImportEqualsDeclaration(node) || isTypeAliasDeclaration(node) || isConstructorDeclaration(node) || - isIndexSignatureDeclaration(node); + isIndexSignatureDeclaration(node) || + isPropertyAccessExpression(node); } export function createGetSymbolAccessibilityDiagnosticForNodeName(node: DeclarationDiagnosticProducing) { @@ -123,7 +125,7 @@ namespace ts { } export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing): (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic | undefined { - if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isBindingElement(node) || isConstructorDeclaration(node)) { + if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isPropertyAccessExpression(node) || isBindingElement(node) || isConstructorDeclaration(node)) { return getVariableDeclarationTypeVisibilityError; } else if (isSetAccessor(node) || isGetAccessor(node)) { @@ -164,7 +166,7 @@ namespace ts { } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit // The only exception here is if the constructor was marked as private. we are not emitting the constructor parameters at all. - else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || + else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.PropertySignature || (node.kind === SyntaxKind.Parameter && hasModifier(node.parent, ModifierFlags.Private))) { // TODO(jfreeman): Deal with computed properties in error reporting. if (hasModifier(node, ModifierFlags.Static)) { diff --git a/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.errors.txt b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.errors.txt new file mode 100644 index 0000000000000..343a3a5351a8f --- /dev/null +++ b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(4,1): error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"tests/cases/compiler/a"'. + + +==== tests/cases/compiler/a.ts (0 errors) ==== + interface I {} + export function f(): I { return null as I; } +==== tests/cases/compiler/b.ts (1 errors) ==== + import {f} from "./a"; + + export function q() {} + q.val = f(); + ~~~~~ +!!! error TS4032: Property 'val' of exported interface has or is using name 'I' from private module '"tests/cases/compiler/a"'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.js b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.js new file mode 100644 index 0000000000000..a40fb25276005 --- /dev/null +++ b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.js @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/declarationEmitExpandoPropertyPrivateName.ts] //// + +//// [a.ts] +interface I {} +export function f(): I { return null as I; } +//// [b.ts] +import {f} from "./a"; + +export function q() {} +q.val = f(); + + +//// [a.js] +"use strict"; +exports.__esModule = true; +function f() { return null; } +exports.f = f; +//// [b.js] +"use strict"; +exports.__esModule = true; +var a_1 = require("./a"); +function q() { } +exports.q = q; +q.val = a_1.f(); + + +//// [a.d.ts] +interface I { +} +export declare function f(): I; +export {}; diff --git a/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.symbols b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.symbols new file mode 100644 index 0000000000000..841620f036182 --- /dev/null +++ b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/a.ts === +interface I {} +>I : Symbol(I, Decl(a.ts, 0, 0)) + +export function f(): I { return null as I; } +>f : Symbol(f, Decl(a.ts, 0, 14)) +>I : Symbol(I, Decl(a.ts, 0, 0)) +>I : Symbol(I, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import {f} from "./a"; +>f : Symbol(f, Decl(b.ts, 0, 8)) + +export function q() {} +>q : Symbol(q, Decl(b.ts, 0, 22), Decl(b.ts, 2, 22)) + +q.val = f(); +>q.val : Symbol(q.val, Decl(b.ts, 2, 22)) +>q : Symbol(q, Decl(b.ts, 0, 22), Decl(b.ts, 2, 22)) +>val : Symbol(q.val, Decl(b.ts, 2, 22)) +>f : Symbol(f, Decl(b.ts, 0, 8)) + diff --git a/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.types b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.types new file mode 100644 index 0000000000000..7418b4140297b --- /dev/null +++ b/tests/baselines/reference/declarationEmitExpandoPropertyPrivateName.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/a.ts === +interface I {} +export function f(): I { return null as I; } +>f : () => I +>null as I : I +>null : null + +=== tests/cases/compiler/b.ts === +import {f} from "./a"; +>f : () => I + +export function q() {} +>q : typeof q + +q.val = f(); +>q.val = f() : I +>q.val : I +>q : typeof q +>val : I +>f() : I +>f : () => I + diff --git a/tests/cases/compiler/declarationEmitExpandoPropertyPrivateName.ts b/tests/cases/compiler/declarationEmitExpandoPropertyPrivateName.ts new file mode 100644 index 0000000000000..09be2a08ff89b --- /dev/null +++ b/tests/cases/compiler/declarationEmitExpandoPropertyPrivateName.ts @@ -0,0 +1,9 @@ +// @declaration: true +// @filename: a.ts +interface I {} +export function f(): I { return null as I; } +// @filename: b.ts +import {f} from "./a"; + +export function q() {} +q.val = f(); diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index 6b9706810b55a..40bdb4eadabc9 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit 6b9706810b55af326a93b9aa59cb17815a30bb32 +Subproject commit 40bdb4eadabc9fbed7d83e3f26817a931c0763b6 diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 6e0de0812231c..67f1c4877ee10 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 6e0de0812231c3a48387d398d092418749aa39f1 +Subproject commit 67f1c4877ee1090b66d468a847caccca411a6f82 diff --git a/tests/cases/user/webpack/webpack b/tests/cases/user/webpack/webpack index a28f44f613276..10282ea20648b 160000 --- a/tests/cases/user/webpack/webpack +++ b/tests/cases/user/webpack/webpack @@ -1 +1 @@ -Subproject commit a28f44f613276446fb764dec7fab38b7cff8a07c +Subproject commit 10282ea20648b465caec6448849f24fc34e1ba3e