File tree Expand file tree Collapse file tree 1 file changed +10
-18
lines changed
src/code-validator/guest/runtime/src Expand file tree Collapse file tree 1 file changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -510,26 +510,18 @@ pub fn extract_all_imports(source: &str) -> Vec<String> {
510510 }
511511 // Also check for `from "..."` pattern on continuation lines.
512512 // Only match when `from` is at the START of the trimmed line or
513- // immediately after `}` at the start. Using `starts_with ` prevents
513+ // immediately after `}` at the start. Using `strip_prefix ` prevents
514514 // false positives from `from` appearing mid-line inside strings.
515- if trimmed. starts_with ( "from " )
516- || trimmed. starts_with ( "} from " )
517- || trimmed. starts_with ( "}from " )
515+ let from_rest = trimmed
516+ . strip_prefix ( "from " )
517+ . or_else ( || trimmed. strip_prefix ( "} from " ) )
518+ . or_else ( || trimmed. strip_prefix ( "}from " ) ) ;
519+
520+ if let Some ( rest) = from_rest
521+ && let Ok ( ( _, specifier) ) = string_literal ( rest. trim ( ) )
522+ && !imports. iter ( ) . any ( |s : & String | s == specifier)
518523 {
519- let rest = if trimmed. starts_with ( "from " ) {
520- & trimmed[ 5 ..]
521- } else if trimmed. starts_with ( "} from " ) {
522- & trimmed[ 7 ..]
523- } else {
524- // "}from "
525- & trimmed[ 6 ..]
526- } ;
527-
528- if let Ok ( ( _, specifier) ) = string_literal ( rest. trim ( ) )
529- && !imports. iter ( ) . any ( |s : & String | s == specifier)
530- {
531- imports. push ( String :: from ( specifier) ) ;
532- }
524+ imports. push ( String :: from ( specifier) ) ;
533525 }
534526 }
535527
You can’t perform that action at this time.
0 commit comments