@@ -22,7 +22,12 @@ export function resolve_aliases(input, file, content, aliases) {
2222 */
2323 const replace_import_path = ( match , quote , import_path ) => {
2424 for ( const [ alias , value ] of Object . entries ( aliases ) ) {
25- if ( import_path !== alias && ! import_path . startsWith ( alias + '/' ) ) continue ;
25+ if (
26+ import_path !== alias &&
27+ ! import_path . startsWith ( alias + ( alias . endsWith ( '/' ) ? '' : '/' ) )
28+ ) {
29+ continue ;
30+ }
2631
2732 const full_path = path . join ( input , file ) ;
2833 const full_import_path = path . join ( value , import_path . slice ( alias . length ) ) ;
@@ -33,24 +38,22 @@ export function resolve_aliases(input, file, content, aliases) {
3338 return match ;
3439 } ;
3540
36- // import/export ... from ...
41+ // import/export (type) (xxx | xxx,) { ... } from ...
3742 content = content . replace (
38- // Regex parts for import/export ... from ... statements:
39- // 1. \b(import|export) - Match 'import' or 'export' at a word boundary
40- // 2. (?:\s+type)? - Optionally match ' type'
41- // 3. \s+ - At least one whitespace
42- // 4. ( - Start of specifier group
43- // (?:(?:\*\s+as\s+)?\p{L}[\p{L}0-9]*\s+) - default import/export, e.g. 'name', or named star import/export, e.g. '* as name '
44- // | (?:\*\s+) - e.g. star import/export, e.g. '* '
45- // | (?:(?:\p{L}[\p{L}0-9]*\s*,\s*)?\{[^}]*\ }\s*) - e.g. named imports/exports with optional default import/export, e.g. 'name, { ... }' or '{ ... }'
46- // )
47- // 5. from\s* - Match 'from' with optional whitespace
48- // 6. (['"]) - Capture quote
49- // 7. ([^'";]+) - Capture import path
50- // 8. \3 - Match the same quote as before
51- / \b ( i m p o r t | e x p o r t ) (?: \s + t y p e ) ? \s + ( (?: (?: \* \s + a s \s + ) ? \p{ L} [ \p{ L} 0 - 9 ] * \s + ) | (?: \* \s + ) | (?: (?: \p{ L} [ \p{ L} 0 - 9 ] * \s * , \s * ) ? \{ [ ^ } ] * \} \s * ) ) f r o m \s * ( [ ' " ] ) ( [ ^ ' " ; ] + ) \3/ gmu,
52- ( match , _keyword , _specifier , quote , import_path ) =>
53- replace_import_path ( match , quote , import_path )
43+ / \b (?: i m p o r t | e x p o r t ) (?: \s + t y p e ) ? (?: (?: \s + \p{ L} [ \p{ L} 0 - 9 ] * \s + ) | (?: (?: \s + \p{ L} [ \p{ L} 0 - 9 ] * \s * , \s * ) ? \s * \{ [ ^ } ] * \} \s * ) ) f r o m \s * ( [ ' " ] ) ( [ ^ ' " ; ] + ) \1/ gmu,
44+ ( match , quote , import_path ) => replace_import_path ( match , quote , import_path )
45+ ) ;
46+
47+ // import/export (type) * as xxx from ...
48+ content = content . replace (
49+ / \b (?: i m p o r t | e x p o r t ) (?: \s + t y p e ) ? \s * \* \s * a s \s + \p{ L} [ \p{ L} 0 - 9 ] * \s + f r o m \s * ( [ ' " ] ) ( [ ^ ' " ; ] + ) \1/ gmu,
50+ ( match , quote , import_path ) => replace_import_path ( match , quote , import_path )
51+ ) ;
52+
53+ // export (type) * from ...
54+ content = content . replace (
55+ / \b (?: e x p o r t ) (?: \s + t y p e ) ? \s * \* \s * f r o m \s * ( [ ' " ] ) ( [ ^ ' " ; ] + ) \1/ gmu,
56+ ( match , quote , import_path ) => replace_import_path ( match , quote , import_path )
5457 ) ;
5558
5659 // import(...)
0 commit comments