@@ -2065,7 +2065,7 @@ export interface IsolatedComposition {
20652065}
20662066
20672067// Runs in the page. False once every inline, template and same-origin script is read and none
2068- // mentions __timelines; an unreadable script or a page still loading answers true.
2068+ // mentions __timelines or imports code ; an unreadable or module script, or a page still loading, answers true.
20692069export async function authorScriptsMayRegisterTimelines (
20702070 runtimeAttr : string ,
20712071 authoredBegin : string ,
@@ -2078,7 +2078,11 @@ export async function authorScriptsMayRegisterTimelines(
20782078 Array . from ( t . content . querySelectorAll ( "script" ) ) ,
20792079 ) ,
20802080 ] . filter ( ( script ) => ! script . hasAttribute ( runtimeAttr ) ) ;
2081+ // Code that imports another file may register through it, which is not read here.
2082+ const mayRegister = ( code : string ) =>
2083+ code . includes ( "__timelines" ) || / \b i m p o r t \s * \( | ^ \s * i m p o r t \s * [ \w { * " ' ] / m. test ( code ) ;
20812084 for ( const script of scripts ) {
2085+ if ( script . type === "module" ) return true ;
20822086 if ( ! script . src ) {
20832087 const text = script . textContent ?? "" ;
20842088 const authored = text . includes ( authoredBegin )
@@ -2088,13 +2092,13 @@ export async function authorScriptsMayRegisterTimelines(
20882092 . map ( ( region ) => region . split ( authoredEnd ) [ 0 ] )
20892093 . join ( "\n" )
20902094 : text ;
2091- if ( authored . includes ( "__timelines" ) ) return true ;
2095+ if ( mayRegister ( authored ) ) return true ;
20922096 continue ;
20932097 }
20942098 const url = new URL ( script . src , location . href ) ;
20952099 if ( url . origin !== location . origin ) return true ;
20962100 try {
2097- if ( ( await ( await fetch ( url ) ) . text ( ) ) . includes ( "__timelines" ) ) return true ;
2101+ if ( mayRegister ( await ( await fetch ( url ) ) . text ( ) ) ) return true ;
20982102 } catch {
20992103 return true ;
21002104 }
0 commit comments