-
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.
Merge pull request #111 from FredericEspiau/fix/handle-deeply-nested-…
…whole-exports fix: handle deeply nested whole exports
- Loading branch information
Showing
5 changed files
with
303 additions
and
153 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,187 @@ | ||
import ts from 'typescript'; | ||
|
||
type ClassDeclaration = { | ||
kind: ts.SyntaxKind.ClassDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
isUnnamedDefaultExport?: boolean; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type EnumDeclaration = { | ||
kind: ts.SyntaxKind.EnumDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type ExportAssignment = { | ||
kind: ts.SyntaxKind.ExportAssignment; | ||
name: 'default'; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type FunctionDeclaration = { | ||
kind: ts.SyntaxKind.FunctionDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
isUnnamedDefaultExport?: boolean; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type InterfaceDeclaration = { | ||
kind: ts.SyntaxKind.InterfaceDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type NameExportDeclaration = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'named'; | ||
name: string[]; | ||
skip: boolean; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
start: number; | ||
}; | ||
|
||
type NamespaceExportDeclaration = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'namespace'; | ||
name: string; | ||
start: number; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
}; | ||
|
||
type TypeAliasDeclaration = { | ||
kind: ts.SyntaxKind.TypeAliasDeclaration; | ||
name: string; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type VariableStatement = { | ||
kind: ts.SyntaxKind.VariableStatement; | ||
name: string[]; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
skip: boolean; | ||
start: number; | ||
}; | ||
|
||
type NamedExport = | ||
| ClassDeclaration | ||
| EnumDeclaration | ||
| ExportAssignment | ||
| FunctionDeclaration | ||
| InterfaceDeclaration | ||
| NameExportDeclaration | ||
| NamespaceExportDeclaration | ||
| TypeAliasDeclaration | ||
| VariableStatement; | ||
|
||
type WholeExportDeclarationBase = { | ||
kind: ts.SyntaxKind.ExportDeclaration; | ||
type: 'whole'; | ||
specifier: string; | ||
start: number; | ||
change: { | ||
code: string; | ||
span: { | ||
start: number; | ||
length: number; | ||
}; | ||
}; | ||
}; | ||
|
||
/** | ||
* Whole export when the file is found within the destFiles | ||
*/ | ||
export type WholeExportDeclarationWithFile = WholeExportDeclarationBase & { | ||
file: string; | ||
}; | ||
|
||
/** | ||
* Whole export when the file is not found within the destFiles, i.e. the file is not part of the project | ||
*/ | ||
type WholeExportDeclarationWithoutFile = WholeExportDeclarationBase & { | ||
file: null; | ||
}; | ||
|
||
type WholeExportDeclaration = | ||
| WholeExportDeclarationWithFile | ||
| WholeExportDeclarationWithoutFile; | ||
|
||
export const isWholeExportDeclarationWithFile = ( | ||
exportDeclaration: WholeExportDeclaration, | ||
): exportDeclaration is WholeExportDeclarationWithFile => | ||
exportDeclaration.file !== null; | ||
|
||
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
Oops, something went wrong.