From 9af3a556d4aad6d0b18c021677c2e5709db3ac5a Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 26 Sep 2018 14:42:58 +0200 Subject: [PATCH] fix(jsii): better usage reporting of private types Anonymous types that are deduced by TypeScript get reported as: Cannot use private type __object in exported declarations But the usage location would not be reported, because the field 'valueDeclaration' of the Symbol would be empty. Looking into the .declarations member does give a declaration in that case, so we now use that as a fallback so we can show exactly where that type is referenced. --- 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 672db268af..75fe54b882 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -195,19 +195,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 })) { - this._diagnostic(type.symbol.valueDeclaration, + this._diagnostic(node, ts.DiagnosticCategory.Error, `Use of foreign type not present in the ${pkg.name}'s assembly: ${fqn}`); }