Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsii): better usage reporting of private types #247

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,21 @@ export class Assembler implements Emitter {
private async _getFQN(type: ts.Type): Promise<string> {
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}`);
}
Expand Down