checkScopeInfo.js 633 B

1234567891011121314151617181920212223
  1. // checkScopeInfo.js
  2. module.exports = () => {
  3. return {
  4. visitor: {
  5. Program: {
  6. exit(programPath) {
  7. // so that this plugin is always called after the transform-destructuring plugin
  8. programPath.traverse({
  9. VariableDeclarator(path) {
  10. const names = Object.keys(path.getBindingIdentifiers());
  11. for (const name of names) {
  12. const b = path.scope.getBinding(name);
  13. if (!b) {
  14. throw new Error(`No binding for ${name}`);
  15. }
  16. }
  17. },
  18. });
  19. },
  20. },
  21. },
  22. };
  23. };