File tree Expand file tree Collapse file tree
npm/estraverse-browser/scripts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,6 +93,55 @@ <h3>rollup example</h3>
9393
9494 await rollup ( ) ;
9595
96+ var uint8 = await webcontainer . fs . readFile ( 'estraverse.m.js' ) ;
97+ var blob = new Blob ( [ uint8 ] , { type :'text/javascript' } ) ;
98+ var url = window . URL . createObjectURL ( blob ) ;
99+
100+ console . log ( 'download...' ) ;
101+
102+ var a = document . createElement ( 'a' ) ;
103+ a . href = url ;
104+ a . download = 'estraverse.m.js' ;
105+ document . body . append ( a ) ;
106+ a . click ( ) ;
107+
108+ console . log ( 'done' ) ;
109+ return ;
110+
111+ var { espree} = await import ( 'https://libs.ext-code.com/external/js/espree/espree.m.js' ) ;
112+ var { estraverse} = await import ( url ) ;
113+
114+ var code = `
115+
116+ function fn(){
117+
118+ console.log('123');
119+
120+ }//fn
121+
122+ ` ;
123+
124+ var ast = espree . parse ( code ) ;
125+
126+ estraverse . traverse ( ast , {
127+ enter ( node ) {
128+ if ( node . type === 'FunctionDeclaration' ) {
129+ console . log ( 'FunctionDeclaration:' , node . id . name ) ;
130+ }
131+
132+ if (
133+ node . type === 'VariableDeclarator' &&
134+ node . init &&
135+ ( node . init . type === 'ArrowFunctionExpression' ||
136+ node . init . type === 'FunctionExpression' )
137+ ) {
138+ console . log ( 'Function assigned to variable:' , node . id . name ) ;
139+ }
140+ }
141+ } ) ;
142+
143+
144+
96145 console . log ( 'done.' ) ;
97146
98147
You can’t perform that action at this time.
0 commit comments