Permalink
Browse files

tools, bugfix: correct exported static Class in some module(such as v…

…m) (#428)
  • Loading branch information...
richardo2016 authored and xicilion committed Jun 7, 2018
1 parent d20292a commit 652a0ac92c5d7db4dcd8bd1db362b9e144206580
Showing with 28 additions and 11 deletions.
  1. +19 −0 tools/util/gen_ts_type.js
  2. +9 −11 tools/util/tmpl/type.d.ts.txt
View
@@ -83,13 +83,30 @@ module.exports = function (defs, baseFolder) {
return typeMap[t] || t;
}
function _uglifyClassName(name) {
return `${name}_Classbase`
}
function uglifyInternalClassName(internalClassName) {
return _uglifyClassName(internalClassName)
}
function uglifyTypeInDefObjects(typeName) {
if (!defObjects[typeName]) {
return typeName
}
return _uglifyClassName(typeName)
}
function params2paramList(params, typeMap = typeMap) {
return (params || []).map(param => {
var hasDefault = param.default;
if (isRestArgs(param.type)) {
param.name = `...${param.name}`
}
var mappedType = typeMap[param.type] || 'any';
mappedType = uglifyTypeInDefObjects(mappedType, defObjects)
return `${param.name}${hasDefault ? '?' : ''}: ${mappedType}${hasDefault ? `/** = ${param.default.value}*/` : ''}`
})
}
@@ -153,6 +170,8 @@ module.exports = function (defs, baseFolder) {
get_type,
get_rtype,
params2paramList,
uglifyInternalClassName,
uglifyTypeInDefObjects,
isRestArgs,
transObjectName
},
@@ -87,8 +87,10 @@ declare global {
if (isInterface) {
var className = _fns.transObjectName(def.declare.name)
var extendClassName = _fns.transObjectName(def.declare.extend)
var renderClassParentRef = extendClassName && extendClassName !== '_object'
%>
declare class <%- className %> <%- extendClassName ? `extends ${extendClassName}` : '' %> {
<% if (renderClassParentRef) {%>/// <reference path="<%- extendClassName %>.d.ts" /><%}%>
declare class <%- _fns.uglifyInternalClassName(className) %> <%- extendClassName ? `extends ${_fns.uglifyInternalClassName(extendClassName)}` : '' %> {
<% for(var i=0; i<member_fns.length; i++) {
var fn = member_fns[i]
var isConstructor = fn.name === def.declare.name
@@ -102,7 +104,7 @@ declare class <%- className %> <%- extendClassName ? `extends ${extendClassName}
*/<%
var paramList = _fns.params2paramList(fn.params, typeMap)
var returnType = fn.type ? typeMap[fn.type] : 'void'
var returnType = fn.type ? _fns.uglifyTypeInDefObjects(typeMap[fn.type], defObjects) : 'void'
if (isConstructor)
returnType = ''
%>
@@ -134,21 +136,17 @@ declare module "<%- def.declare.name %>" {
<% } /** end of iteration 'member_constants' */ %>
<% for(var i=0; i<member_objects.length; i++) {
var internalObj = member_objects[i]
var objectName = internalObj.name
var objectTypeDesc = internalObj.type || internalObj.name
if (defModules[objectTypeDesc]) {
objectTypeDesc = `typeof ${objectTypeDesc}NS`
}
var str = JSON.stringify(internalObj)
var internalObj = member_objects[i]
var objectName = internalObj.type || internalObj.name
%>
/**
* <% var comments = internalObj.comments.split('\n'); for(var idx=0; idx<comments.length; idx++) {var comment = comments[idx].trim().replace('! @', '@') %>
* <%- comment %><% } %>
* <%- internalObj.deprecated ? '@deprecated' : '' %>
* <%- internalObj.async ? '@async' : '' %>
*/
export const <%- objectName %>: <%- objectTypeDesc %>;
export class <%- objectName %> extends <%- _fns.uglifyInternalClassName(objectName) %> {}
<% } /** end of iteration 'member_objects' */ %>
<% for(var i=0; i<member_fns.length; i++) {
@@ -162,7 +160,7 @@ declare module "<%- def.declare.name %>" {
*/<%
var paramList = _fns.params2paramList(fn.params, typeMap)
var returnType = fn.type ? typeMap[fn.type] : 'void'
var returnType = fn.type ? _fns.uglifyTypeInDefObjects(typeMap[fn.type], defObjects) : 'void'
%>
export function <%- fn.name %>(<%- paramList.join(', ') %>): <%- returnType || 'void' %>;
<% } /** end of iteration 'member_fns' */ %>

0 comments on commit 652a0ac

Please sign in to comment.