diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index ebd2985dd45c2..d01713304176b 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1237,14 +1237,23 @@ namespace ts { enclosingDeclaration = prevEnclosingDeclaration; } - function emitPropertyDeclaration(node: Declaration) { - if (hasDynamicName(node) && !resolver.isLateBound(node)) { + function hasNoncollidingLateBoundPropertyName(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) { + if (!hasModifier(node, ModifierFlags.Private)) { + return false; + } + const entityName = (node as NamedDeclaration as LateBoundDeclaration).name.expression; + const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration); + return visibilityResult.accessibility !== SymbolAccessibility.Accessible; + } + + function emitPropertyDeclaration(node: ParameterDeclaration | PropertyDeclaration) { + if (hasDynamicName(node) && (!resolver.isLateBound(node) || hasNoncollidingLateBoundPropertyName(node))) { return; } emitJsDocComments(node); emitClassMemberDeclarationFlags(getModifierFlags(node)); - emitVariableDeclaration(node); + emitVariableDeclaration(node); write(";"); writeLine(); } diff --git a/tests/baselines/reference/privateSymbolNoDeclarationEmit.js b/tests/baselines/reference/privateSymbolNoDeclarationEmit.js new file mode 100644 index 0000000000000..f4f58ea5b72a4 --- /dev/null +++ b/tests/baselines/reference/privateSymbolNoDeclarationEmit.js @@ -0,0 +1,23 @@ +//// [privateSymbolNoDeclarationEmit.ts] +const _data = Symbol('data'); + +export class User { + private [_data] : any; +}; + +//// [privateSymbolNoDeclarationEmit.js] +"use strict"; +exports.__esModule = true; +var _data = Symbol('data'); +var User = /** @class */ (function () { + function User() { + } + return User; +}()); +exports.User = User; +; + + +//// [privateSymbolNoDeclarationEmit.d.ts] +export declare class User { +} diff --git a/tests/baselines/reference/privateSymbolNoDeclarationEmit.symbols b/tests/baselines/reference/privateSymbolNoDeclarationEmit.symbols new file mode 100644 index 0000000000000..e6d4d73273a58 --- /dev/null +++ b/tests/baselines/reference/privateSymbolNoDeclarationEmit.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/privateSymbolNoDeclarationEmit.ts === +const _data = Symbol('data'); +>_data : Symbol(_data, Decl(privateSymbolNoDeclarationEmit.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) + +export class User { +>User : Symbol(User, Decl(privateSymbolNoDeclarationEmit.ts, 0, 29)) + + private [_data] : any; +>_data : Symbol(_data, Decl(privateSymbolNoDeclarationEmit.ts, 0, 5)) + +}; diff --git a/tests/baselines/reference/privateSymbolNoDeclarationEmit.types b/tests/baselines/reference/privateSymbolNoDeclarationEmit.types new file mode 100644 index 0000000000000..17f569bc0e62b --- /dev/null +++ b/tests/baselines/reference/privateSymbolNoDeclarationEmit.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/privateSymbolNoDeclarationEmit.ts === +const _data = Symbol('data'); +>_data : unique symbol +>Symbol('data') : unique symbol +>Symbol : SymbolConstructor +>'data' : "data" + +export class User { +>User : User + + private [_data] : any; +>_data : unique symbol + +}; diff --git a/tests/cases/compiler/privateSymbolNoDeclarationEmit.ts b/tests/cases/compiler/privateSymbolNoDeclarationEmit.ts new file mode 100644 index 0000000000000..9dc0008578dad --- /dev/null +++ b/tests/cases/compiler/privateSymbolNoDeclarationEmit.ts @@ -0,0 +1,7 @@ +// @lib: es6 +// @declaration: true +const _data = Symbol('data'); + +export class User { + private [_data] : any; +}; \ No newline at end of file