Skip to content

Commit

Permalink
Do not forwardDeclare blacklisted types.
Browse files Browse the repository at this point in the history
Their types cannot be referenced, but neither can their modules.
  • Loading branch information
mprobst committed Oct 9, 2018
1 parent 9f47abe commit d6b3a5d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/module_type_translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ export class ModuleTypeTranslator {
if (this.host.untyped) return;
// Already imported? Do not emit a duplicate forward declare.
if (this.forwardDeclaredModules.has(moduleSymbol)) return;
if (this.host.typeBlackListPaths && this.host.typeBlackListPaths.has(importPath)) {
return; // Do not emit goog.forwardDeclare or goog.require for blacklisted paths.
}
const nsImport = googmodule.extractGoogNamespaceImport(importPath);
const forwardDeclarePrefix = `tsickle_forward_declare_${++this.forwardDeclareCounter}`;
const moduleNamespace = nsImport !== null ?
Expand Down Expand Up @@ -294,7 +297,6 @@ export class ModuleTypeTranslator {
this.error(decl, `declaration from module used in ambient type: ${sym.name}`);
return;
}

// Actually import the symbol.
const sourceFile = decl.getSourceFile();
if (sourceFile === ts.getOriginalNode(this.sourceFile)) return;
Expand Down
4 changes: 1 addition & 3 deletions test_files/jsdoc_types/initialized_unknown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
*
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
// This should not have a type annotation.
goog.module('test_files.jsdoc_types.initialized_unknown');
var module = module || { id: 'test_files/jsdoc_types/initialized_unknown.ts' };
module = module;
exports = {};
const tsickle_forward_declare_1 = goog.forwardDeclare("test_files.jsdoc_types.nevertyped");
goog.require('test_files.jsdoc_types.nevertyped'); // force type-only module to be loaded
// This should not have a type annotation.
const initializedUntyped = {
foo: 1
};
Expand Down
2 changes: 0 additions & 2 deletions test_files/jsdoc_types/jsdoc_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ exports = {};
const tsickle_forward_declare_1 = goog.forwardDeclare("test_files.jsdoc_types.module1");
const tsickle_forward_declare_2 = goog.forwardDeclare("test_files.jsdoc_types.module2");
const tsickle_forward_declare_3 = goog.forwardDeclare("test_files.jsdoc_types.default");
const tsickle_forward_declare_4 = goog.forwardDeclare("test_files.jsdoc_types.nevertyped");
goog.require('test_files.jsdoc_types.nevertyped'); // force type-only module to be loaded
/**
* This test tests importing a type across module boundaries,
* ensuring that the type gets the proper name in JSDoc comments.
Expand Down

0 comments on commit d6b3a5d

Please sign in to comment.