Package Exports
- eslint-scope-browser
Readme
eslint-scope-browser
This package provides eslint-scope-browser 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/espree/espree.js'></script>
https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.js
https://cdn.jsdelivr.net/npm/eslint-scope-browser/eslint-scope.js
test it out with this tool
html editor -- https://ext-code.com/utils/editors/html-editor/html-editor.html
For esm
import {scope} from 'https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.m.js';
//
var {espree} = await import('https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.m.js');
test it out with this tool
js console -- https://ext-code.com/utils/editors/js-console/js-console.html
Further Reading
https://github.com/eslint/js/tree/main/packages/eslint-scope
https://www.npmjs.com/package/eslint-scope
examples
<script type=module>
import {espree} from 'https://libs.ext-code.com/external/js/espree/espree.m.js';
import {estraverse} from 'https://libs.ext-code.com/external/js/estraverse/estraverse.m.js';
import {scope} from 'https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.m.js';
var code = `
function fn(){
console.log('123');
}//fn
`;
const options = {ecmaVersion:'latest',sourceType:"module"};
const ast = espree.parse(code, { range: true, ...options });
const scopeManager = scope.analyze(ast, options);
var currentScope = scopeManager.acquire(ast); // global scope
console.log(currentScope);
estraverse.traverse(ast, {
enter(node, parent) {
// do stuff
if (/Function/.test(node.type)) {
currentScope = scopeManager.acquire(node); // get current function scope
console.log(currentScope);
}
},
leave(node, parent) {
if (/Function/.test(node.type)) {
currentScope = currentScope.upper; // set to parent scope
console.log(currentScope);
}
// do stuff
},
});
</script>
<script type=module>
console.json=v=>console.log(JSON.stringify(v,null,4));
var [{espree},{estraverse},{scope}] = await Promise.all([
import('https://libs.ext-code.com/external/js/espree/espree.m.js'),
import('https://libs.ext-code.com/external/js/estraverse/estraverse.m.js'),
import('https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.m.js'),
]);
var code = `
function fn(){
console.log('123');
}//fn
`;
const options = {
ecmaVersion: 2022,
sourceType: "module",
};
const ast = espree.parse(code, { range: true, ...options });
const scopeManager = scope.analyze(ast, options);
var currentScope = scopeManager.acquire(ast); // global scope
console.log(currentScope);
estraverse.traverse(ast, {
enter(node, parent) {
// do stuff
if (/Function/.test(node.type)) {
currentScope = scopeManager.acquire(node); // get current function scope
console.log(currentScope);
}
},
leave(node, parent) {
if (/Function/.test(node.type)) {
currentScope = currentScope.upper; // set to parent scope
console.log(currentScope);
}
// do stuff
},
});
</script>
<script src='https://libs.ext-code.com/external/js/espree/espree.js'></script>
<script src='https://libs.ext-code.com/external/js/estraverse/estraverse.js'></script>
<script src='https://libs.ext-code.com/external/js/eslint-scope/eslint-scope.js'></script>
<script>
console.log(espree);
var code = `
function fn(){
console.log('123');
}//fn
`;
const options = {
ecmaVersion: 2022,
sourceType: "module",
};
const ast = espree.parse(code, { range: true, ...options });
const scopeManager = scope.analyze(ast, options);
var currentScope = scopeManager.acquire(ast); // global scope
console.log(currentScope);
estraverse.traverse(ast, {
enter(node, parent) {
// do stuff
if (/Function/.test(node.type)) {
currentScope = scopeManager.acquire(node); // get current function scope
console.log(currentScope);
}
},
leave(node, parent) {
if (/Function/.test(node.type)) {
currentScope = currentScope.upper; // set to parent scope
console.log(currentScope);
}
// do stuff
},
});
</script>