No reference to internal types in externs file

Currently we have things like like in the generated externs file (types.js):

/**
 * @type {ol.control.AttributionOptions|undefined}
 */
olx.control.DefaultsOptionsExtern.prototype.attributionOptions;

It doesn't make sense to have external object properties whose types are
internal (ol.control.AttributionOptions in the above example).

With this commit, the generate-exports.py script generates this:

/**
 * @type {olx.control.AttributionOptionsExtern|undefined}
 */
olx.control.DefaultsOptionsExtern.prototype.attributionOptions;
This commit is contained in:
Éric Lemoine
2013-08-19 13:54:26 +02:00
parent 94c4d420a6
commit 8d09be7134

View File

@@ -122,9 +122,10 @@ class Class(Exportable):
class ObjectLiteral(Exportable):
def __init__(self, name):
def __init__(self, name, objects):
Exportable.__init__(self, name)
self.prop_types = {}
self.objects = objects
__repr__ = simplerepr
@@ -138,7 +139,12 @@ class ObjectLiteral(Exportable):
for prop in sorted(self.prop_types.keys()):
lines.append('\n\n')
lines.append('/**\n')
lines.append(' * @type {%s}\n' % (self.prop_types[prop],))
prop_types = self.prop_types[prop].split('|')
for i, t in enumerate(prop_types):
if t in self.objects and isinstance(self.objects[t], ObjectLiteral):
prop_types[i] = self.objects[t].extern_name()
prop_types = '|'.join(prop_types)
lines.append(' * @type {%s}\n' % (prop_types,))
lines.append(' */\n')
lines.append('%s.prototype.%s;\n' % (self.extern_name(), prop))
return ''.join(lines)
@@ -221,7 +227,7 @@ def main(argv):
name = m.group('name')
if name in objects:
raise RuntimeError(line) # Name already defined
object_literal = ObjectLiteral(name)
object_literal = ObjectLiteral(name, objects)
objects[name] = object_literal
continue
m = re.match(r'\*\s*@property\s*{(?P<type>.*)}\s*(?P<prop>\S+)', line)