File tree Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -898,20 +898,30 @@ describe('parser', () => {
898
898
899
899
describe ( 'getDefaultExportForFile' , ( ) => {
900
900
it ( 'should filter out forbidden symbols' , ( ) => {
901
- // @ts -ignore
902
- const result = getDefaultExportForFile ( { fileName : 'a-b' } )
901
+ const result = getDefaultExportForFile ( {
902
+ fileName : 'a-b'
903
+ } as ts . SourceFile ) ;
903
904
assert . equal ( result , 'ab' ) ;
904
905
} ) ;
905
906
906
907
it ( 'should remove leading non-letters' , ( ) => {
907
- // @ts -ignore
908
- const result = getDefaultExportForFile ( { fileName : '---123aba' } )
908
+ const result = getDefaultExportForFile ( {
909
+ fileName : '---123aba'
910
+ } as ts . SourceFile ) ;
909
911
assert . equal ( result , 'aba' ) ;
910
912
} ) ;
911
913
914
+ it ( 'should preserve numbers in the middle' , ( ) => {
915
+ const result = getDefaultExportForFile ( {
916
+ fileName : '1Body2Text3'
917
+ } as ts . SourceFile ) ;
918
+ assert . equal ( result , 'Body2Text3' ) ;
919
+ } ) ;
920
+
912
921
it ( 'should not return empty string' , ( ) => {
913
- // @ts -ignore
914
- const result = getDefaultExportForFile ( { fileName : '---123' } )
922
+ const result = getDefaultExportForFile ( {
923
+ fileName : '---123'
924
+ } as ts . SourceFile ) ;
915
925
assert . equal ( result . length > 0 , true ) ;
916
926
} ) ;
917
927
} ) ;
Original file line number Diff line number Diff line change @@ -846,9 +846,11 @@ export function getDefaultExportForFile(source: ts.SourceFile) {
846
846
847
847
// JS identifiers must starts with a letter, and contain letters and/or numbers
848
848
// So, you could not take filename as is
849
- const identifier = filename . replace ( / [ ^ A - Z a - z ] * | [ ^ 0 - 9 . ] * / g, '' )
849
+ const identifier = filename
850
+ . replace ( / ^ [ ^ A - Z ] * / gi, '' )
851
+ . replace ( / [ ^ A - Z 0 - 9 ] * / gi, '' ) ;
850
852
851
- return identifier . length ? identifier : 'DefaultName'
853
+ return identifier . length ? identifier : 'DefaultName' ;
852
854
}
853
855
854
856
function getParentType ( prop : ts . Symbol ) : ParentType | undefined {
You can’t perform that action at this time.
0 commit comments