1
- export default ( entries : ts . CompletionEntry [ ] , scriptSnapshot : ts . IScriptSnapshot , position : number , node ) => {
1
+ export default ( entries : ts . CompletionEntry [ ] , scriptSnapshot : ts . IScriptSnapshot , position : number , node : ts . Node | undefined ) => {
2
2
const charAhead = scriptSnapshot . getText ( position , position + 1 )
3
3
if ( charAhead === ' ' ) return entries
4
4
const bannedKeywords = [
@@ -20,15 +20,22 @@ export default (entries: ts.CompletionEntry[], scriptSnapshot: ts.IScriptSnapsho
20
20
'continue' ,
21
21
'break' ,
22
22
'debugger' ,
23
- 'default' ,
24
23
'super' ,
25
24
'import' ,
26
25
]
27
26
const bannedKeywordsWhenInType = [ 'const' , 'void' , 'import' ]
28
- const inType = isTypeNode ( node )
27
+ const inType = node && isTypeNode ( node )
28
+
29
+ const fileText = scriptSnapshot . getText ( 0 , position )
30
+ const textBeforeWord = fileText . slice ( 0 , / [ \w \d ] * $ / i. exec ( fileText ) ! . index )
31
+
32
+ const defaultSpaceValidBeforeContent = [ 'export ' , '@' ]
33
+ const includeDefaultSpace = defaultSpaceValidBeforeContent . some ( str => textBeforeWord . endsWith ( str ) )
29
34
return entries . map ( entry => {
30
- if ( entry . kind !== ts . ScriptElementKind . keyword || bannedKeywords . includes ( entry . name ) || ( inType && bannedKeywordsWhenInType . includes ( entry . name ) ) )
35
+ if ( entry . kind !== ts . ScriptElementKind . keyword || bannedKeywords . includes ( entry . name ) || ( inType && bannedKeywordsWhenInType . includes ( entry . name ) ) ) {
31
36
return entry
37
+ }
38
+ if ( entry . name === 'default' && ! includeDefaultSpace ) return entry
32
39
return { ...entry , insertText : `${ entry . name } ` }
33
40
} )
34
41
}
0 commit comments