@@ -21,7 +21,7 @@ import { findFirstOccurrenceOutsideComment, type RenderOptions } from '../../uti
2121import type { InclusionContext } from '../ExecutionContext' ;
2222import type ChildScope from '../scopes/ChildScope' ;
2323import type { ObjectPath } from '../utils/PathTracker' ;
24- import { UnknownKey } from '../utils/PathTracker' ;
24+ import { UNKNOWN_PATH , UnknownKey } from '../utils/PathTracker' ;
2525import type NamespaceVariable from '../variables/NamespaceVariable' ;
2626import ArrowFunctionExpression from './ArrowFunctionExpression' ;
2727import AwaitExpression from './AwaitExpression' ;
@@ -68,6 +68,14 @@ export default class ImportExpression extends NodeBase {
6868 private resolution : Module | ExternalModule | string | null = null ;
6969 private resolutionString : string | null = null ;
7070
71+ get shouldIncludeDynamicAttributes ( ) {
72+ return isFlagSet ( this . flags , Flag . shouldIncludeDynamicAttributes ) ;
73+ }
74+
75+ set shouldIncludeDynamicAttributes ( value : boolean ) {
76+ this . flags = setFlag ( this . flags , Flag . shouldIncludeDynamicAttributes , value ) ;
77+ }
78+
7179 get withinTopLevelAwait ( ) {
7280 return isFlagSet ( this . flags , Flag . withinTopLevelAwait ) ;
7381 }
@@ -76,9 +84,9 @@ export default class ImportExpression extends NodeBase {
7684 this . flags = setFlag ( this . flags , Flag . withinTopLevelAwait , value ) ;
7785 }
7886
79- // Do not bind attributes
8087 bind ( ) : void {
8188 this . source . bind ( ) ;
89+ this . options ?. bind ( ) ;
8290 }
8391
8492 /**
@@ -185,18 +193,21 @@ export default class ImportExpression extends NodeBase {
185193 }
186194
187195 include ( context : InclusionContext , includeChildrenRecursively : IncludeChildren ) : void {
188- if ( ! this . included ) this . includeNode ( ) ;
196+ if ( ! this . included ) this . includeNode ( context ) ;
189197 this . source . include ( context , includeChildrenRecursively ) ;
198+ if ( this . shouldIncludeDynamicAttributes )
199+ this . options ?. include ( context , includeChildrenRecursively ) ;
190200 }
191201
192- includeNode ( ) {
202+ includeNode ( context : InclusionContext ) {
193203 this . included = true ;
204+ if ( this . shouldIncludeDynamicAttributes ) this . options ?. includePath ( UNKNOWN_PATH , context ) ;
194205 this . scope . context . includeDynamicImport ( this ) ;
195206 this . scope . addAccessedDynamicImport ( this ) ;
196207 }
197208
198- includePath ( path : ObjectPath ) : void {
199- if ( ! this . included ) this . includeNode ( ) ;
209+ includePath ( path : ObjectPath , context : InclusionContext ) : void {
210+ if ( ! this . included ) this . includeNode ( context ) ;
200211 // Technically, this is not correct as dynamic imports return a Promise.
201212 if ( this . hasUnknownAccessedKey ) return ;
202213 if ( path [ 0 ] === UnknownKey ) {
0 commit comments