Skip to content

Commit

Permalink
feat: support not emitting use
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Jun 18, 2020
1 parent 78e4407 commit b9831ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,9 @@ export function emitFile(
const moduleName = getImportModuleName(importNode);
node.forEachChild((element: ts.ImportSpecifier) => {
if (isClassLike(element.name, typeChecker)) {
if (state.modules[moduleName] && state.modules[moduleName].used) {
return;
}
writePunctuation("use");
writeSpace();
const namespace = state.modules[moduleName] && state.modules[moduleName].namespace;
Expand Down
5 changes: 5 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export interface ModuleInfo {
**/
namespace?: string | false;

/**
* 是否已经 use 过
*/
used?: boolean;

/**
* 是否已经被引入,如果是 true,不会输出 require_once
*
Expand Down

0 comments on commit b9831ff

Please sign in to comment.