Permalink
Browse files

tools, bugfix: correct exportance for reference to internal module in…

… some module(such as encoding). (#434)
  • Loading branch information...
richardo2016 authored and xicilion committed Jun 9, 2018
1 parent 6cb8e61 commit 18b080f22b30a2d74aae347710f72c6ca003eade
Showing with 31 additions and 8 deletions.
  1. +21 −4 tools/util/gen_ts_type.js
  2. +10 −4 tools/util/tmpl/type.d.ts.txt
View
@@ -4,6 +4,8 @@ var path = require('path');
var ejs = require('ejs');
module.exports = function (defs, baseFolder) {
const buildInfo = util.buildInfo()
const defNames = Object.keys(defs)
const defModules = {}
const defObjetMirror = {}
@@ -65,6 +67,10 @@ module.exports = function (defs, baseFolder) {
return className === 'object' ? '_object' : className
}
function getAliasNameForRefModule(refModuleName) {
return `${refModuleName}NS`
}
var txts = [];
var refers = [];
var hasNew = false;
@@ -84,6 +90,8 @@ module.exports = function (defs, baseFolder) {
}
function _uglifyClassName(name) {
name = transObjectName(name)
return `Class_${name}`
}
@@ -100,14 +108,21 @@ module.exports = function (defs, baseFolder) {
}
function params2paramList(params, typeMap = typeMap) {
return (params || []).map(param => {
var latestOptionalIndex = -1
return (params || []).map((param, index) => {
var hasDefault = param.default;
if (isRestArgs(param.type)) {
var _isRestArgs = isRestArgs(param.type);
if (hasDefault) {
latestOptionalIndex = index
}
var isOptional = !!hasDefault || (!_isRestArgs && latestOptionalIndex > -1 && index >= latestOptionalIndex)
if (_isRestArgs) {
param.name = `...${param.name}`
}
var mappedType = typeMap[param.type] || 'any';
mappedType = uglifyTypeInDefObjects(mappedType, defObjects)
return `${param.name}${hasDefault ? '?' : ''}: ${mappedType}${hasDefault ? `/** = ${param.default.value}*/` : ''}`
return `${param.name}${isOptional ? '?' : ''}: ${mappedType}${hasDefault ? `/** = ${param.default.value}*/` : ''}`
})
}
@@ -159,6 +174,7 @@ module.exports = function (defs, baseFolder) {
member_objects: def.members.filter(x => x.memType === 'object'),
member_constants: def.members.filter(x => x.memType === 'const'),
member_props: def.members.filter(x => x.memType === 'prop'),
buildInfo,
typeMap,
defModules,
defObjects,
@@ -173,7 +189,8 @@ module.exports = function (defs, baseFolder) {
uglifyInternalClassName,
uglifyTypeInDefObjects,
isRestArgs,
transObjectName
transObjectName,
getAliasNameForRefModule
},
filename: def.filename || ''
}
@@ -1,6 +1,9 @@
/***************************************************************************
* *
* This file was automatically generated with idlc.js *
* This file was automatically generated with idlc.js *
* build info: *
* - fibjs : <%- (buildInfo.fibjs + '').padEnd(45, ' ') %> *
* - date : <%- (buildInfo.date + '').padEnd(44, ' ') %> *
* *
***************************************************************************/
@@ -144,7 +147,7 @@ declare module "<%- def.declare.name %>" {
<% for(var i=0; i<refers.length; i++) {
var refClassName = refers[i]
if(defModules[refClassName]) {%>
import <%- refClassName %>NS = require('<%- refClassName %>')<%}}%>
import <%- _fns.getAliasNameForRefModule(refClassName) %> = require('<%- refClassName %>')<%}}%>
module <%- def.declare.name %> {
<% for(var i=0; i<member_constants.length; i++) {
@@ -164,15 +167,18 @@ declare module "<%- def.declare.name %>" {
<% for(var i=0; i<member_objects.length; i++) {
var internalObj = member_objects[i]
var objectName = internalObj.type || internalObj.name
// var str = JSON.stringify(internalObj)
var isInternalClass = !!defObjects[objectName]
var isInternalModule = !!defModules[objectName]
%>
/**
* <% 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 class <%- objectName %> extends <%- _fns.uglifyInternalClassName(objectName) %> {}
<% if (isInternalClass) {%>export class <%- objectName %> extends <%- _fns.uglifyInternalClassName(objectName) %> {}<%}%>
<% if (isInternalModule) {%>export const <%- objectName %>: typeof <%- _fns.getAliasNameForRefModule(objectName) %><%}%>
<% } /** end of iteration 'member_objects' */ %>
<% for(var i=0; i<member_fns.length; i++) {

0 comments on commit 18b080f

Please sign in to comment.