Package Exports
- escope-browser
Readme
escope-browser
This package provides node-forge bundled for use in the browser without the need to npm install anything
you can use this tool to see what is exposed in both the script src and esm modules
global state diff -- https://ext-code.com/utils/misc/global-state-diff/global-state-diff.html
this tool can be used to experiment with the package
nodejs terminal -- https://ext-code.com/utils/misc/nodejs-terminal/nodejs-terminal.html
For script
<script src='https://libs.ext-code.com/external/js/escope/escope.js'></script>
test it out with this tool
html editor -- https://ext-code.com/utils/editors/html-editor/html-editor.html
For esm
import {escope} from 'https://libs.ext-code.com/external/js/escope/escope.m.js';
//
var {escope} = await import('https://libs.ext-code.com/external/js/escope/escope.m.js');
test it out with this tool
js console -- https://ext-code.com/utils/editors/js-console/js-console.html
locally hosted
the scripts can be hosted locally, by doing
npm i escope-browser
the scripts can then either be copied to a prefered location or reference via
import {escope} from '/node_modules/escope-browser/escope.m.js';
//
var {escope} = await import('/node_modules/escope-browser/escope.m.js');
<script src='/node_modules/escope-browser/escope.js'></script>
Further Reading
https://github.com/estools/escope
https://www.npmjs.com/package/escope
See also
https://www.npmjs.com/package/espree-browser https://www.npmjs.com/package/estraverse-browser https://www.npmjs.com/package/estraverse-browser https://www.npmjs.com/package/acorn-browser https://www.npmjs.com/package/esrecurse-browser https://www.npmjs.com/package/estree-walker-browser
examples
<script type=module>
import {escope} from 'https://libs.ext-code.com/external/js/escope/escope.m.js';
import {espree} from 'https://libs.ext-code.com/external/js/espree/espree.m.js';
var code = `
function foo(a){
var b = 2;
function bar(c){
return a+b+c;
}
return bar(3);
}//foo
`;
var ast = espree.parse(code,{ecmaVersion:'latest',sourceType:'script',loc:true});
var scopeManager = escope.analyze(ast);
var globalScope = scopeManager.globalScope;
console.log("Global variables :");
globalScope.variables.forEach(v=>console.log(" -",v.name));
console.log("\nAll scopes :");
scopeManager.scopes.forEach(scope=>{
console.log(`\nScope type : ${scope.type}`);
console.log("Variables :");
scope.variables.forEach(v => console.log(" -",v.name));
});
</script>
<script type=module>
var [{escope},{espree}] = await Promise.all([
import('https://libs.ext-code.com/external/js/escope/escope.m.js'),
import('https://libs.ext-code.com/external/js/espree/espree.m.js'),
]);
var code = `
function foo(a){
var b = 2;
function bar(c){
return a+b+c;
}
return bar(3);
}//foo
`;
var ast = espree.parse(code,{ecmaVersion:'latest',sourceType:'script',loc:true});
var scopeManager = escope.analyze(ast);
var globalScope = scopeManager.globalScope;
console.log("Global variables :");
globalScope.variables.forEach(v=>console.log(" -",v.name));
console.log("\nAll scopes :");
scopeManager.scopes.forEach(scope=>{
console.log(`\nScope type : ${scope.type}`);
console.log("Variables :");
scope.variables.forEach(v => console.log(" -",v.name));
});
</script>
<script src='https://libs.ext-code.com/external/js/escope/escope.js'></script>
<script src='https://libs.ext-code.com/external/js/espree/espree.js'></script>
<script>
var code = `
function foo(a){
var b = 2;
function bar(c){
return a+b+c;
}
return bar(3);
}//foo
`;
var ast = espree.parse(code,{ecmaVersion:'latest',sourceType:'script',loc:true});
var scopeManager = escope.analyze(ast);
var globalScope = scopeManager.globalScope;
console.log("Global variables :");
globalScope.variables.forEach(v=>console.log(" -",v.name));
console.log("\nAll scopes :");
scopeManager.scopes.forEach(scope=>{
console.log(`\nScope type : ${scope.type}`);
console.log("Variables :");
scope.variables.forEach(v => console.log(" -",v.name));
});
</script>