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 ) => {
22 const charAhead = scriptSnapshot . getText ( position , position + 1 )
33 if ( charAhead === ' ' ) return entries
44 const bannedKeywords = [
@@ -20,15 +20,22 @@ export default (entries: ts.CompletionEntry[], scriptSnapshot: ts.IScriptSnapsho
2020 'continue' ,
2121 'break' ,
2222 'debugger' ,
23- 'default' ,
2423 'super' ,
2524 'import' ,
2625 ]
2726 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 ) )
2934 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 ) ) ) {
3136 return entry
37+ }
38+ if ( entry . name === 'default' && ! includeDefaultSpace ) return entry
3239 return { ...entry , insertText : `${ entry . name } ` }
3340 } )
3441}
0 commit comments