@@ -85,28 +85,40 @@ describe('optimizer-scan:script-test', () => {
8585 } )
8686
8787 test ( 'imports regex should work' , ( ) => {
88- const shouldMatchArray = [
89- `import 'vue'` ,
90- `import { foo } from 'vue'` ,
91- `import foo from 'vue'` ,
92- `;import foo from 'vue'` ,
93- ` import foo from 'vue'` ,
94- `import { foo
88+ const shouldMatchArray : [ code : string , expected : string ] [ ] = [
89+ [ `import 'vue'` , `'vue'` ] ,
90+ [ `import { foo } from 'vue'` , `'vue'` ] ,
91+ [ `import foo from 'vue'` , `'vue'` ] ,
92+ [ `;import foo from 'vue'` , `'vue'` ] ,
93+ [ ` import foo from 'vue'` , `'vue'` ] ,
94+ [
95+ `import { foo
9596 } from 'vue'` ,
96- `import bar, { foo } from 'vue'` ,
97- `import foo from 'vue';` ,
98- `*/ import foo from 'vue';` ,
99- `import foo from 'vue';//comment` ,
100- `import foo from 'vue';/*comment
97+ `'vue'` ,
98+ ] ,
99+ [ `import bar, { foo } from 'vue'` , `'vue'` ] ,
100+ [ `import foo from 'vue';` , `'vue'` ] ,
101+ [ `*/ import foo from 'vue';` , `'vue'` ] ,
102+ [ `import foo from 'vue';//comment` , `'vue'` ] ,
103+ [
104+ `import foo from 'vue';/*comment
101105 */` ,
102- // Skipped, false negatives with current regex
103- // `import typescript from 'typescript'`,
104- // import type, {foo} from 'vue'
106+ `'vue'` ,
107+ ] ,
108+ // https://github.com/vitejs/vite/issues/23471
109+ // bindings starting with "type" should not be treated as type-only imports
110+ [ `import typescript from 'typescript'` , `'typescript'` ] ,
111+ [ `import typeorm from 'typeorm'` , `'typeorm'` ] ,
112+ [ `import types from 'types'` , `'types'` ] ,
113+ // still a known false negative: a default binding literally named `type`
114+ // (`import type, {foo} from 'vue'`, `import type from 'vue'`) is a valid
115+ // value import, but the word boundary cannot tell it apart from the
116+ // `import type` modifier. Missed deps are discovered again at runtime.
105117 ]
106118
107- shouldMatchArray . forEach ( ( str ) => {
119+ shouldMatchArray . forEach ( ( [ str , expected ] ) => {
108120 importsRE . lastIndex = 0
109- expect ( importsRE . exec ( str ) ! [ 1 ] ) . toEqual ( "'vue'" )
121+ expect ( importsRE . exec ( str ) ! [ 1 ] ) . toEqual ( expected )
110122 } )
111123
112124 const shouldFailArray = [
0 commit comments