Treat unknown opt types as Object in ol externs
This commit is contained in:
@@ -39,6 +39,7 @@ function generateExterns(typedefs, symbols, externs, base) {
|
|||||||
var lines = [];
|
var lines = [];
|
||||||
var processedSymbols = {};
|
var processedSymbols = {};
|
||||||
var constructors = {};
|
var constructors = {};
|
||||||
|
var constructorOptionsTypes = {};
|
||||||
|
|
||||||
function addNamespaces(name) {
|
function addNamespaces(name) {
|
||||||
var parts = name.split('.');
|
var parts = name.split('.');
|
||||||
@@ -74,6 +75,16 @@ function generateExterns(typedefs, symbols, externs, base) {
|
|||||||
return typesWithoutGoog;
|
return typesWithoutGoog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store in "constructorOptionsTypes" type names that start
|
||||||
|
// with "ol." and end with "Options".
|
||||||
|
function findConstructorOptionsTypes(types) {
|
||||||
|
types.forEach(function(type) {
|
||||||
|
if (type.match(/^ol\..*Options$/)) {
|
||||||
|
constructorOptionsTypes[type] = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function processSymbol(symbol) {
|
function processSymbol(symbol) {
|
||||||
addNamespaces(symbol.name.split('#')[0]);
|
addNamespaces(symbol.name.split('#')[0]);
|
||||||
|
|
||||||
@@ -105,6 +116,7 @@ function generateExterns(typedefs, symbols, externs, base) {
|
|||||||
var args = [];
|
var args = [];
|
||||||
if (symbol.params) {
|
if (symbol.params) {
|
||||||
symbol.params.forEach(function(param) {
|
symbol.params.forEach(function(param) {
|
||||||
|
findConstructorOptionsTypes(param.types);
|
||||||
args.push(param.name);
|
args.push(param.name);
|
||||||
lines.push(' * @param {' +
|
lines.push(' * @param {' +
|
||||||
(param.variable ? '...' : '') +
|
(param.variable ? '...' : '') +
|
||||||
@@ -137,6 +149,10 @@ function generateExterns(typedefs, symbols, externs, base) {
|
|||||||
symbols.forEach(processSymbol);
|
symbols.forEach(processSymbol);
|
||||||
|
|
||||||
typedefs.forEach(function(typedef) {
|
typedefs.forEach(function(typedef) {
|
||||||
|
// we're about to add a @typedef for "typedef.name" so remove that
|
||||||
|
// type from constructorOptionsTypes
|
||||||
|
delete constructorOptionsTypes[typedef.name];
|
||||||
|
|
||||||
addNamespaces(typedef.name);
|
addNamespaces(typedef.name);
|
||||||
lines.push('/**');
|
lines.push('/**');
|
||||||
lines.push(' * @typedef {' + noGoogTypes(typedef.types).join('|') + '}');
|
lines.push(' * @typedef {' + noGoogTypes(typedef.types).join('|') + '}');
|
||||||
@@ -145,6 +161,25 @@ function generateExterns(typedefs, symbols, externs, base) {
|
|||||||
lines.push('\n');
|
lines.push('\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// At this point constructorOptionsTypes includes options types for which we
|
||||||
|
// did not have a @typedef yet. For those we add @typedef {Object}.
|
||||||
|
//
|
||||||
|
// This is used for abstract base classes. Abstract base classes should be
|
||||||
|
// defined as types in the ol externs file. But the corresponding @typedef's
|
||||||
|
// are not marked with an @api annotation because abstract base classes are
|
||||||
|
// not instantiated by applications. Yet, we need to have a type defined
|
||||||
|
// in the ol externs file for these options types. So we just use
|
||||||
|
// @typedef {Object}.
|
||||||
|
Object.keys(constructorOptionsTypes).forEach(function(key) {
|
||||||
|
lines.push('/**');
|
||||||
|
lines.push(' * No `@api` annotation for `' + key + '`, use `Object`.');
|
||||||
|
lines.push(' * @typedef {Object}');
|
||||||
|
lines.push(' */');
|
||||||
|
lines.push(nameToJS(key) + ';');
|
||||||
|
lines.push('\n');
|
||||||
|
});
|
||||||
|
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user