@@ -20,8 +20,7 @@ const newFileContents = (contents: string, fileName = entrypoint) => {
20
20
const cursorPositions : number [ ] = [ ]
21
21
const replacement = '/*|*/'
22
22
let cursorIndex
23
- while ( ( cursorIndex = contents . indexOf ( replacement ) ) ) {
24
- if ( cursorIndex === - 1 ) break
23
+ while ( ( cursorIndex = contents . indexOf ( replacement ) ) !== - 1 ) {
25
24
contents = contents . slice ( 0 , cursorIndex ) + contents . slice ( cursorIndex + replacement . length )
26
25
cursorPositions . push ( cursorIndex )
27
26
}
@@ -58,13 +57,15 @@ test('Banned positions', () => {
58
57
} )
59
58
60
59
test ( 'Builtin method snippet banned positions' , ( ) => {
61
- const cursorPositions = newFileContents ( /* ts */ `
62
- import {/*|*/} from 'test'
63
- const obj = { m$1e$2thod() {}, arrow: () => {} }
64
- type A = typeof obj["/*|*/"];
65
- const test = () => ({ method() {} })
66
- const {/*|*/} = test()
67
- const {something, met/*|*/} = test()
60
+ const cursorPositions = newFileContents ( /* tsx */ `
61
+ import {/*|*/} from 'test'
62
+ const obj = { m$1e$2thod() {}, arrow: () => {} }
63
+ type A = typeof obj["/*|*/"];
64
+ const test = () => ({ method() {} })
65
+ const {/*|*/} = test()
66
+ const {something, met/*|*/} = test()
67
+ ;<Test/*|*/ />
68
+ ;<Test/*|*/></Test>
68
69
` )
69
70
for ( const [ i , pos ] of cursorPositions . entries ( ) ) {
70
71
const result = isGoodPositionBuiltinMethodCompletion ( ts , getSourceFile ( ) , pos )
@@ -75,17 +76,19 @@ test('Builtin method snippet banned positions', () => {
75
76
} )
76
77
77
78
test ( 'Additional banned positions for our method snippets' , ( ) => {
78
- const cursorPositions = newFileContents ( /* ts */ `
79
+ const cursorPositions = newFileContents ( /* tsx */ `
79
80
const test = () => ({ method() {} })
80
81
test({
81
82
method/*|*/
82
83
})
83
84
test({
84
85
/*|*/
85
86
})
87
+ ;<Test/*|*/ />
88
+ ;<Test/*|*/></Test>
86
89
` )
87
90
for ( const [ i , pos ] of cursorPositions . entries ( ) ) {
88
- const result = isGoodPositionMethodCompletion ( ts , entrypoint , getSourceFile ( ) , pos , languageService )
91
+ const result = isGoodPositionMethodCompletion ( ts , entrypoint , getSourceFile ( ) , pos - 1 , languageService )
89
92
expect ( result , i . toString ( ) ) . toBeFalsy ( )
90
93
}
91
94
} )
@@ -97,6 +100,9 @@ test('Not banned positions for our method snippets', () => {
97
100
test({
98
101
method: /*|*/
99
102
})
103
+ test({
104
+ method: setTimeout/*|*/
105
+ })
100
106
test2/*|*/
101
107
` )
102
108
for ( const [ i , pos ] of cursorPositions . entries ( ) ) {
0 commit comments