@@ -30,8 +30,8 @@ <h3>rollup example</h3>
3030 var files = { } ;
3131
3232
33- var packages = [ 'acorn ' ] ;
34- var filename = 'acorn .js' ;
33+ var packages = [ 'eslint-scope ' ] ;
34+ var filename = 'esline-scope.m .js' ;
3535
3636
3737
@@ -90,7 +90,7 @@ <h3>rollup example</h3>
9090 var url = window . URL . createObjectURL ( blob ) ;
9191
9292
93- if ( 1 ) {
93+ if ( 0 ) {
9494 console . log ( 'download...' ) ;
9595 var a = document . createElement ( 'a' ) ;
9696 a . href = url ;
@@ -101,7 +101,9 @@ <h3>rollup example</h3>
101101 return ;
102102 }
103103
104- var { acorn} = await import ( url ) ;
104+ var { espree} = await import ( 'https://libs.ext-code.com/external/js/espree-browser/espree.m.js' ) ;
105+ var { estraverse} = await import ( 'https://libs.ext-code.com/external/js/extraverse-browser/estraverse.m.js' ) ;
106+ var { scope} = await import ( url ) ;
105107
106108 var code = `
107109
@@ -113,32 +115,36 @@ <h3>rollup example</h3>
113115
114116 ` ;
115117
116- var ast = acorn . parse ( code ) ;
117- console . log ( ast ) ;
118-
119-
120-
121- /*
122- estraverse.traverse(ast, {
123- enter(node) {
124- if (node.type === 'FunctionDeclaration') {
125- console.log('FunctionDeclaration:', node.id.name);
126- }
127-
128- if (
129- node.type === 'VariableDeclarator' &&
130- node.init &&
131- (node.init.type === 'ArrowFunctionExpression' ||
132- node.init.type === 'FunctionExpression')
133- ) {
134- console.log('Function assigned to variable:', node.id.name);
135- }
136- }
137- });
138- */
139-
140-
141-
118+
119+ const options = {
120+ ecmaVersion : 2022 ,
121+ sourceType : "module" ,
122+ } ;
123+
124+ const ast = espree . parse ( code , { range : true , ...options } ) ;
125+ const scopeManager = scope . analyze ( ast , options ) ;
126+
127+ const currentScope = scopeManager . acquire ( ast ) ; // global scope
128+
129+ estraverse . traverse ( ast , {
130+ enter ( node , parent ) {
131+ // do stuff
132+
133+ if ( / F u n c t i o n / . test ( node . type ) ) {
134+ currentScope = scopeManager . acquire ( node ) ; // get current function scope
135+ }
136+ } ,
137+ leave ( node , parent ) {
138+ if ( / F u n c t i o n / . test ( node . type ) ) {
139+ currentScope = currentScope . upper ; // set to parent scope
140+ }
141+
142+ // do stuff
143+ } ,
144+ } ) ;
145+
146+
147+
142148 console . log ( 'done.' ) ;
143149
144150
@@ -220,10 +226,10 @@ <h3>rollup example</h3>
220226
221227 files [ 'entry.js' ] = `
222228
223- import * as acorn from 'acorn ';
224- // export {acorn };
229+ import * as scope from 'eslint-scope ';
230+ export {scope };
225231
226- export default espree; // iife / umd
232+ // export default espree; // iife / umd
227233
228234 ` ;
229235
@@ -250,11 +256,11 @@ <h3>rollup example</h3>
250256 input : 'entry.js',
251257 output : {
252258 file : '${ filename } ',
253- // format : 'es'
259+ format : 'es'
254260
255- format : 'iife', // or 'umd'
256- name : 'espree', // This becomes window.espree
257- exports : 'default',
261+ // format : 'iife', // or 'umd'
262+ // name : 'espree', // This becomes window.espree
263+ // exports : 'default',
258264
259265 },
260266 plugins : [
0 commit comments