@@ -38,19 +38,33 @@ class VueProgram {
38
38
*/
39
39
public static resolveNonTsModuleName ( moduleName : string , containingFile : string , basedir : string , options : ts . CompilerOptions ) {
40
40
const baseUrl = options . baseUrl ? options . baseUrl : basedir ;
41
- const wildcard = options . wildcard ? options . wildcard : '@' ;
42
- const pattern = options . paths ? options . paths [ `${ wildcard } /*` ] : undefined ;
43
- const substitution = pattern ? options . paths [ `${ wildcard } /*` ] [ 0 ] . replace ( '*' , '' ) : 'src' ;
44
- const isWildcard = moduleName . substr ( 0 , 2 ) === `${ wildcard } /` ;
45
- const isRelative = ! path . isAbsolute ( moduleName ) ;
46
-
47
- if ( isWildcard ) {
48
- moduleName = path . resolve ( baseUrl , substitution , moduleName . substr ( 2 ) ) ;
49
- } else if ( isRelative ) {
50
- moduleName = path . resolve ( path . dirname ( containingFile ) , moduleName ) ;
51
- }
52
-
53
- return moduleName ;
41
+ const discartedSymbols = [ '.' , '..' , '/' ] ;
42
+ let wildcards = [ ] ;
43
+ Object . keys ( options . paths ) . forEach ( path => {
44
+ const pathSymbol = path [ 0 ] ;
45
+ if ( ! discartedSymbols . includes ( pathSymbol ) && ! wildcards . includes ( pathSymbol ) ) {
46
+ wildcards . push ( pathSymbol ) ;
47
+ }
48
+ } ) ;
49
+
50
+ const isRelative = ! path . isAbsolute ( moduleName ) ;
51
+ let correctWildcard ;
52
+
53
+ wildcards . forEach ( wildcard => {
54
+ if ( moduleName . substr ( 0 , 2 ) === `${ wildcard } /` ) {
55
+ correctWildcard = wildcard ;
56
+ }
57
+ } ) ;
58
+
59
+ if ( correctWildcard ) {
60
+ const pattern = options . paths ? options . paths [ `${ correctWildcard } /*` ] : undefined ;
61
+ const substitution = pattern ? options . paths [ `${ correctWildcard } /*` ] [ 0 ] . replace ( '*' , '' ) : 'src' ;
62
+ moduleName = path . resolve ( baseUrl , substitution , moduleName . substr ( 2 ) ) ;
63
+ }
64
+ else if ( isRelative ) {
65
+ moduleName = path . resolve ( path . dirname ( containingFile ) , moduleName ) ;
66
+ }
67
+ return moduleName ;
54
68
}
55
69
56
70
public static isVue ( filePath : string ) {
0 commit comments