From 96ac5d62aa1b66eb78b274f294a0f93236355d64 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Thu, 27 Sep 2018 11:17:36 +0200 Subject: [PATCH] fix(jsii): better usage reporting of private types (#247) Anonymous types that are deduced by TypeScript get reported as: Cannot use private type __object in exported declarations The usage location would not be reported however, because the field 'symbol.valueDeclaration' was empty. There are locations in 'symbol.declarations' though, so we use that as a fallback instead, which works. --- packages/jsii/lib/assembler.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index 74f8feb620..38b666d03c 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -202,19 +202,21 @@ export class Assembler implements Emitter { private async _getFQN(type: ts.Type): Promise { const tsName = this._typeChecker.getFullyQualifiedName(type.symbol); const groups = tsName.match(/^\"([^\"]+)\"\.(.*)$/); + let node = type.symbol.valueDeclaration; + if (!node && type.symbol.declarations.length > 0) { node = type.symbol.declarations[0]; } if (!groups) { - this._diagnostic(type.symbol.valueDeclaration, ts.DiagnosticCategory.Error, `Cannot use private type ${tsName} in exported declarations`); + this._diagnostic(node, ts.DiagnosticCategory.Error, `Cannot use private type ${tsName} in exported declarations`); return tsName; } const [, modulePath, typeName, ] = groups; const pkg = await _findPackageInfo(modulePath); if (!pkg) { - this._diagnostic(type.symbol.valueDeclaration, ts.DiagnosticCategory.Error, `Could not find module for ${modulePath}`); + this._diagnostic(node, ts.DiagnosticCategory.Error, `Could not find module for ${modulePath}`); return `unknown.${typeName}`; } const fqn = `${pkg.name}.${typeName}`; if (pkg.name !== this.projectInfo.name && !this._dereference({ fqn }, type.symbol.valueDeclaration)) { - this._diagnostic(type.symbol.valueDeclaration, + this._diagnostic(node, ts.DiagnosticCategory.Error, `Use of foreign type not present in the ${pkg.name}'s assembly: ${fqn}`); }