clutz icon indicating copy to clipboard operation
clutz copied to clipboard

Incremental Clutz can't distinguish imports from goog.module() files and goog.provide() files.

Open LucasSloan opened this issue 7 years ago • 6 comments

A goog.provide file:

goog.provide('goog.example');
/** @constructor */
goog.example = function() {};

Produces this .d.ts:

declare namespace ಠ_ಠ.clutz.goog {
  class example extends example_Instance {
  }
  class example_Instance {
    private noStructuralTyping_: any;
  }
}
declare module 'goog:goog.example' {
  import alias = ಠ_ಠ.clutz.goog.example;
  export default alias;
}

A goog.module file:

goog.module("goog.example");
/** @constructor */
const A = function() {};
exports.A = A;

Produces this .d.ts:

declare namespace ಠ_ಠ.clutz.module$exports$goog$example {
  class A extends A_Instance {
  }
  class A_Instance {
    private noStructuralTyping_: any;
  }
}
declare module 'goog:goog.example' {
  import alias = ಠ_ಠ.clutz.module$exports$goog$example;
  export = alias;
}

The goog.provide file generates the namespace ಠ_ಠ.clutz.goog, while the goog.module generates the namespace ಠ_ಠ.clutz.module$exports$goog$example.

A goog.module file could require goog.example:

goog.module('importer');
const import = goog.require('goog.example');

In incremental mode, Clutz doesn't know if goog.example is from a goog.provide file or a goog.module file, so Clutz don't know to emit ಠ_ಠ.clutz.goog or ಠ_ಠ.clutz.module$exports$goog$example.

The two styles of namespace declaration need to be united, so incremental mode doesn't need to know about the style of its dependencies.

LucasSloan avatar Nov 28 '17 19:11 LucasSloan

I suggest we put this one on the back burner until we get more compelling use cases.

rkirov avatar Dec 05 '17 00:12 rkirov

My expectation would be that it is very common to have code that's goog.provide()d in a goog.module. All protos and most of the Closure standard library still use goog.provide. OTOH I have no idea how common it is to have those appear in exported signatures.

mprobst avatar Dec 05 '17 16:12 mprobst

Is this fixed by #591?

evmar avatar Dec 05 '17 22:12 evmar

No, this bug is a known limitation with that PR.

mprobst avatar Dec 06 '17 08:12 mprobst

Just found one such case in the wild, so this is no longer purely hypothetical.

rkirov avatar Dec 22 '17 08:12 rkirov

reopening as this was rolledback

rkirov avatar Jan 23 '18 18:01 rkirov