import { BuildableTree } from "../builder/buildable-tree" ; import { BuildingTree } from "../builder/building-tree" ; import { Key } from "../foundation/key" ; import { removeLastSemicolon } from "../utils" ; export class Widget extends BuildableTree { readonly key ? : Key ; constructor ( p ? ) { super ( ) ; this . key = p ?. key ; } build ( ) { return super . build ( ) ; } static prebuilt ( code , args ? ) { if ( ! args ?. root ) { code = removeLastSemicolon ( code ) ; } return new PrebuiltWidget ( code ) ; } } /**
 * this is used for containing prebuilt code snippet as an widget
 */ export class PrebuiltWidget extends Widget { widget : string | Widget ; constructor ( widget ) { super ( ) ; this . widget = widget ; } build ( ) { if ( this . widget instanceof Widget ) { return this . widget . build ( ) ; } else { return new PrebuiltBuildingTree ( this . widget ) ; } } } class PrebuiltBuildingTree extends BuildingTree { final : string ; constructor ( final ) { super ( ) ; this . final = final ; } build ( ) { return this ; } lookup ( ) { return this . final ; } }