From 1f641c5933cca75a2a7021a8045207d88c1855c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 15 Mar 2013 18:01:53 +0100 Subject: [PATCH] Make the generated Export classes accept undefined We have constructors, like ol.View2D and ol.control.Attribution, whose "options" argument is optional (opt_options). But currently, we cannot do "new ol.View2D()" in uncompiled code that uses an ol3 build compiled in advanced mode. This commit fixes that by changing the generated Export constructors. --- bin/generate-exports.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/generate-exports.py b/bin/generate-exports.py index 28d7ad6e3d..6e98035ee2 100755 --- a/bin/generate-exports.py +++ b/bin/generate-exports.py @@ -52,9 +52,16 @@ class Class(Exportable): lines.append(' * @param {%s} options Options.\n' % (self.object_literal.extern_name(),)) lines.append(' */\n') lines.append('%sExport = function(options) {\n' % (self.name,)) - lines.append(' goog.base(this, {') - lines.extend(','.join('\n %s: options.%s' % (key, key) for key in sorted(self.object_literal.prop_types.keys()))) - lines.append('\n });\n') + lines.append(' /** @type {%s} */\n' % (self.object_literal.name,)) + lines.append(' var arg;\n'); + lines.append(' if (goog.isDefAndNotNull(options)) {\n') + lines.append(' arg = {') + lines.extend(','.join('\n %s: options.%s' % (key, key) for key in sorted(self.object_literal.prop_types.keys()))) + lines.append('\n };\n') + lines.append(' } else {\n') + lines.append(' arg = /** @type {%s} */ (options);\n' % (self.object_literal.name,)) + lines.append(' }\n') + lines.append(' goog.base(this, arg);\n') lines.append('};\n') lines.append('goog.inherits(%sExport, %s);\n' % (self.name, self.name)) lines.append('goog.exportSymbol(\n')