Permalink
Browse files

tools, bugfix: remove unnecessary `import` statement on top of module…

… declartion file. (#436)
  • Loading branch information...
richardo2016 authored and xicilion committed Jun 14, 2018
1 parent 69b25bb commit 3d7dc1dfe0d6e95332a78a82c2d9dd052d064de3
Showing with 36 additions and 20 deletions.
  1. +12 −10 tools/util/gen_ts_type.js
  2. +24 −10 tools/util/tmpl/type.d.ts.txt
View
@@ -25,15 +25,17 @@ module.exports = function (defs, baseFolder) {
const defModuleNames = Object.keys(defModules)
const defObjectNames = Object.keys(defObjects)
// white list of Object would be declared in global index.d.ts
const topLevelVariablesInGlobalModule = [
'__dirname',
'__filename',
'require',
'Master',
'setHrInterval',
'clearHrInterval',
'GC',
'repl',
const excludedTopLevelVariablesInGlobalModule = [
'console',
'process',
'global',
'run',
'setTimeout',
'clearTimeout',
'setInterval',
'clearInterval',
'setImmediate',
'clearImmediate'
]
function gen_ts_type_code(cls, def) {
@@ -180,7 +182,7 @@ module.exports = function (defs, baseFolder) {
defObjects,
defModuleNames,
defObjectNames,
topLevelVariablesInGlobalModule,
excludedTopLevelVariablesInGlobalModule,
refers: build_refer(def),
_fns: {
get_type,
@@ -26,32 +26,46 @@
import _Global from 'global';
import _Process from 'process';
declare const process: typeof _Process;
declare const global: typeof _Global;
declare const __filename: string;
declare const __dirname: string;
declare const require: typeof _Global.require;
// declare const process: typeof _Process;
// declare const global: typeof _Global;
// declare const __filename: string;
// declare const __dirname: string;
// declare const require: typeof _Global.require;
type GlobalExportsType = any;
interface ModuleType {
exports: GlobalExportsType;
}
type O_Process = typeof _Process
interface RealProcess extends O_Process {
env: {
[key: string]: string;
}
}
declare global {
var exports: GlobalExportsType;
const module: ModuleType;
const __filename: string;
const __dirname: string;
const process: RealProcess;
const global: typeof _Global;
<% for(var i=0; i<defModules['global'].members.length; i++) {
var member = defModules['global'].members[i]
console.log('global member', member.memType, member.name, member.type)
if (!topLevelVariablesInGlobalModule.includes(member.name)) {%>
if (excludedTopLevelVariablesInGlobalModule.includes(member.name)) {%>
/** const <%- member.name %>: <%- member.type || 'null' %>; */<%
continue;
}
if (member.memType === 'method') {%>
const <%- member.name %>: typeof _Global.<%- member.name %><%
} else if (typeMap[member.type]) { /** else if of iteration`defModules['global'].members` */ %>
const <%- member.name %>: <%- typeMap[member.type] %>;
<% }
} else if (defObjects[member.type]) { /** else if of iteration`defModules['global'].members` */ %>
const <%- member.name %>: typeof <%- _fns.uglifyInternalClassName(typeMap[member.type]) %>;<%
} else if (defModules[member.type]) { /** else if of iteration`defModules['global'].members` */ %>
const <%- member.name %>: typeof <%- member.type %>
<% }
} /** end of iteration`defModules['global'].members` */ %>
}
@@ -76,7 +90,7 @@ declare global {
<% for(var i=0; i<refers.length; i++) {
var refClassName = refers[i]
if(defObjects[refClassName]) {%>/// <reference path="<%- refClassName %>.d.ts" /><%
} else if (defModules[refClassName]){%>import <%- refClassName %> = require('<%- refClassName %>')<%}
} else if (false && defModules[refClassName]){%>import <%- refClassName %> from '<%- refClassName %>'<%}
%>
<% } /** end of `iteration about refers` */ %>

0 comments on commit 3d7dc1d

Please sign in to comment.