import * as ast from "../ast" ; import { List } from "./index" ; import { normalizeActionName } from "./normalize-action-name" ; /** returns all activities found in the given ast.NodeLists */ export function extractDynamic ( docs , regionMarker ) { const result = [ ] ; for ( const doc of docs ) { result . push ( ... extractFromAST ( doc , regionMarker ) ) ; } return result ; } /** returns the activities contained in the given NodeList */ function extractFromAST ( doc , regionMarker ) { const result = [ ] ; for ( const node of doc ) { if ( isActiveBlockTag ( node , regionMarker ) ) { result . push ( { actionName : normalizeActionName ( node . attributes [ regionMarker ] , node . location ) , location : node . location , region : doc . nodesFor ( node ) , document : doc , } ) ; } } return result ; } /** returns whether the given AstNode marks an active region in the document */ function isActiveBlockTag ( node , activeAttributeName ) { return ! ! node . attributes [ activeAttributeName ] ; }