-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle deeply nested whole exports
- Loading branch information
1 parent
7c1120b
commit 1e5eda1
Showing
7 changed files
with
295 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import ts from 'typescript'; | ||
|
||
import { NamedExport } from './export/namedExport.js'; | ||
import { WholeExportDeclaration } from './export/wholeExportDeclaration.js'; | ||
|
||
export * as NamedExport from './export/namedExport.js'; | ||
export * as WholeExportDeclaration from './export/wholeExportDeclaration.js'; | ||
|
||
export type Export = NamedExport | WholeExportDeclaration; | ||
|
||
export const isNamedExport = (v: Export): v is NamedExport => 'name' in v; | ||
|
||
export const isWholeExportDeclaration = ( | ||
v: Export, | ||
): v is WholeExportDeclaration => | ||
v.kind === ts.SyntaxKind.ExportDeclaration && v.type === 'whole'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import ts from 'typescript'; | ||
|
||
export type ClassDeclaration = { | ||
kind: ts.SyntaxKind.ClassDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
isUnnamedDefaultExport?: boolean; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type EnumDeclaration = { | ||
kind: ts.SyntaxKind.EnumDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type ExportAssignment = { | ||
kind: ts.SyntaxKind.ExportAssignment; | ||
name: 'default'; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type FunctionDeclaration = { | ||
kind: ts.SyntaxKind.FunctionDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
isUnnamedDefaultExport?: boolean; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type InterfaceDeclaration = { | ||
kind: ts.SyntaxKind.InterfaceDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type NameExportDeclaration = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'named'; | ||
name: string[]; | ||
skip: boolean; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
start: number; | ||
}; | ||
|
||
export type NamespaceExportDeclaration = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'namespace'; | ||
name: string; | ||
start: number; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
}; | ||
|
||
export type TypeAliasDeclaration = { | ||
kind: ts.SyntaxKind.TypeAliasDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type VariableStatement = { | ||
kind: ts.SyntaxKind.VariableStatement; | ||
name: string[]; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
export type NamedExport = | ||
| ClassDeclaration | ||
| EnumDeclaration | ||
| ExportAssignment | ||
| FunctionDeclaration | ||
| InterfaceDeclaration | ||
| NameExportDeclaration | ||
| NamespaceExportDeclaration | ||
| TypeAliasDeclaration | ||
| VariableStatement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import ts from 'typescript'; | ||
|
||
/** | ||
* Whole export when the file is found within the destFiles | ||
*/ | ||
export type FileFound = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'whole'; | ||
file: string; | ||
specifier: string; | ||
start: number; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
}; | ||
|
||
/** | ||
* Whole export when the file is not found within the destFiles, i.e. the file is not part of the project | ||
*/ | ||
export type FileNotFound = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'whole'; | ||
file: null; | ||
specifier: string; | ||
start: number; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
}; | ||
|
||
export type WholeExportDeclaration = FileFound | FileNotFound; | ||
|
||
export const isFileFound = ( | ||
exportDeclaration: WholeExportDeclaration, | ||
): exportDeclaration is FileFound => exportDeclaration.file !== null; |
Oops, something went wrong.