implicit-global-reference.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function() {
  2. 'use strict';
  3. var escope, esprima, expect;
  4. expect = require('chai').expect;
  5. escope = require('..');
  6. esprima = require('esprima');
  7. describe('implicit global reference', function() {
  8. it('assignments global scope', function() {
  9. var ast, scopes;
  10. ast = esprima.parse("var x = 20;\nx = 300;");
  11. scopes = escope.analyze(ast).scopes;
  12. expect(scopes.map(function(scope) {
  13. return scope.variables.map(function(variable) {
  14. return variable.defs.map(function(def) {
  15. return def.type;
  16. });
  17. });
  18. })).to.be.eql([[['Variable']]]);
  19. return expect(scopes[0].implicit.variables.map(function(variable) {
  20. return variable.name;
  21. })).to.be.eql([]);
  22. });
  23. it('assignments global scope without definition', function() {
  24. var ast, scopes;
  25. ast = esprima.parse("x = 300;\nx = 300;");
  26. scopes = escope.analyze(ast).scopes;
  27. expect(scopes.map(function(scope) {
  28. return scope.variables.map(function(variable) {
  29. return variable.defs.map(function(def) {
  30. return def.type;
  31. });
  32. });
  33. })).to.be.eql([[]]);
  34. return expect(scopes[0].implicit.variables.map(function(variable) {
  35. return variable.name;
  36. })).to.be.eql(['x']);
  37. });
  38. it('assignments global scope without definition eval', function() {
  39. var ast, scopes;
  40. ast = esprima.parse("function inner() {\n eval(str);\n x = 300;\n}");
  41. scopes = escope.analyze(ast).scopes;
  42. expect(scopes.map(function(scope) {
  43. return scope.variables.map(function(variable) {
  44. return variable.defs.map(function(def) {
  45. return def.type;
  46. });
  47. });
  48. })).to.be.eql([[['FunctionName']], [[]]]);
  49. return expect(scopes[0].implicit.variables.map(function(variable) {
  50. return variable.name;
  51. })).to.be.eql([]);
  52. });
  53. it('assignment leaks', function() {
  54. var ast, scopes;
  55. ast = esprima.parse("function outer() {\n x = 20;\n}");
  56. scopes = escope.analyze(ast).scopes;
  57. expect(scopes.map(function(scope) {
  58. return scope.variables.map(function(variable) {
  59. return variable.name;
  60. });
  61. })).to.be.eql([['outer'], ['arguments']]);
  62. return expect(scopes[0].implicit.variables.map(function(variable) {
  63. return variable.name;
  64. })).to.be.eql(['x']);
  65. });
  66. it('assignment doesn\'t leak', function() {
  67. var ast, scopes;
  68. ast = esprima.parse("function outer() {\n function inner() {\n x = 20;\n }\n var x;\n}");
  69. scopes = escope.analyze(ast).scopes;
  70. expect(scopes.map(function(scope) {
  71. return scope.variables.map(function(variable) {
  72. return variable.name;
  73. });
  74. })).to.be.eql([['outer'], ['arguments', 'inner', 'x'], ['arguments']]);
  75. return expect(scopes[0].implicit.variables.map(function(variable) {
  76. return variable.name;
  77. })).to.be.eql([]);
  78. });
  79. it('for-in-statement leaks', function() {
  80. var ast, scopes;
  81. ast = esprima.parse("function outer() {\n for (x in y) { }\n}");
  82. scopes = escope.analyze(ast).scopes;
  83. expect(scopes.map(function(scope) {
  84. return scope.variables.map(function(variable) {
  85. return variable.name;
  86. });
  87. })).to.be.eql([['outer'], ['arguments']]);
  88. return expect(scopes[0].implicit.variables.map(function(variable) {
  89. return variable.name;
  90. })).to.be.eql(['x']);
  91. });
  92. return it('for-in-statement doesn\'t leaks', function() {
  93. var ast, scopes;
  94. ast = esprima.parse("function outer() {\n function inner() {\n for (x in y) { }\n }\n var x;\n}");
  95. scopes = escope.analyze(ast).scopes;
  96. expect(scopes.map(function(scope) {
  97. return scope.variables.map(function(variable) {
  98. return variable.name;
  99. });
  100. })).to.be.eql([['outer'], ['arguments', 'inner', 'x'], ['arguments']]);
  101. return expect(scopes[0].implicit.variables.map(function(variable) {
  102. return variable.name;
  103. })).to.be.eql([]);
  104. });
  105. });
  106. }).call(this);
  107. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImltcGxpY2l0LWdsb2JhbC1yZWZlcmVuY2UuY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXNCQztBQUFBLEVBQUEsWUFBQSxDQUFBO0F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ElBQklMSVRZLCBPUiBUT1JUXG4jIChJTkNMVURJTkcgTkVHTElHRU5DRSBPUiBPVEhFUldJU0UpIEFSSVNJTkcgSU4gQU5ZIFdBWSBPVVQgT0YgVEhFIFVTRSBPRlxuIyBUSElTIFNPRlRXQVJFLCBFVkVOIElGIEFEVklTRUQgT0YgVEhFIFBPU1NJQklMSVRZIE9GIFNVQ0ggREFNQUdFLlxuXG4ndXNlIHN0cmljdCdcblxuZXhwZWN0ID0gcmVxdWlyZSgnY2hhaScpLmV4cGVjdFxuZXNjb3BlID0gcmVxdWlyZSAnLi4nXG5lc3ByaW1hID0gcmVxdWlyZSAnZXNwcmltYSdcblxuZGVzY3JpYmUgJ2ltcGxpY2l0IGdsb2JhbCByZWZlcmVuY2UnLCAtPlxuICAgIGl0ICdhc3NpZ25tZW50cyBnbG9iYWwgc2NvcGUnLCAtPlxuICAgICAgICBhc3QgPSBlc3ByaW1hLnBhcnNlIFwiXCJcIlxuICAgICAgICB2YXIgeCA9IDIwO1xuICAgICAgICB4ID0gMzAwO1xuICAgICAgICBcIlwiXCJcblxuICAgICAgICBzY29wZXMgPSBlc2NvcGUuYW5hbHl6ZShhc3QpLnNjb3Blc1xuXG4gICAgICAgIGV4cGVjdChzY29wZXMubWFwKChzY29wZSkgLT5cbiAgICAgICAgICAgIHNjb3BlLnZhcmlhYmxlcy5tYXAoKHZhcmlhYmxlKSAtPlxuICAgICAgICAgICAgICAgIHZhcmlhYmxlLmRlZnMubWFwKChkZWYpIC0+IGRlZi50eXBlKSkpKS50by5iZS5lcWwoXG4gICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICAgICAnVmFyaWFibGUnXG4gICAgICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBdXG4gICAgICAgICAgICBdXG4gICAgICAgIClcblxuICAgICAgICBleHBlY3Qoc2NvcGVzWzBdLmltcGxpY2l0LnZhcmlhYmxlcy5tYXAoKHZhcmlhYmxlKSAtPiB2YXJpYWJsZS5uYW1lKSkudG8uYmUuZXFsKFtdKVxuXG4gICAgaXQgJ2Fzc2lnbm1lbnRzIGdsb2JhbCBzY29wZSB3aXRob3V0IGRlZmluaXRpb24nLCAtPlxuICAgICAgICBhc3QgPSBlc3ByaW1hLnBhcnNlIFwiXCJcIlxuICAgICAgICB4ID0gMzAwO1xuICAgICAgICB4ID0gMzAwO1xuICAgICAgICBcIlwiXCJcblxuICAgICAgICBzY29wZXMgPSBlc2NvcGUuYW5hbHl6ZShhc3QpLnNjb3Blc1xuXG4gICAgICAgIGV4cGVjdChzY29wZXMubWFwKChzY29wZSkgLT5cbiAgICAgICAgICAgIHNjb3BlLnZhcmlhYmxlcy5tYXAoKHZhcmlhYmxlKSAtPlxuICAgICAgICAgICAgICAgIHZhcmlhYmxlLmRlZnMubWFwKChkZWYpIC0+IGRlZi50eXBlKSkpKS50by5iZS5lcWwoXG4gICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgIF1cbiAgICAgICAgKVxuXG4gICAgICAgIGV4cGVjdChzY29wZXNbMF0uaW1wbGljaXQudmFyaWFibGVzLm1hcCgodmFyaWFibGUpIC0+IHZhcmlhYmxlLm5hbWUpKS50by5iZS5lcWwoXG4gICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgJ3gnXG4gICAgICAgICAgICBdXG4gICAgICAgIClcblxuICAgIGl0ICdhc3NpZ25tZW50cyBnbG9iYWwgc2NvcGUgd2l0aG91dCBkZWZpbml0aW9uIGV2YWwnLCAtPlxuICAgICAgICBhc3QgPSBlc3ByaW1hLnBhcnNlIFwiXCJcIlxuICAgICAgICBmdW5jdGlvbiBpbm5lcigpIHtcbiAgICAgICAgICAgIGV2YWwoc3RyKTtcbiAgICAgICAgICAgIHggPSAzMDA7XG4gICAgICAgIH1cbiAgICAgICAgXCJcIlwiXG5cbiAgICAgICAgc2NvcGVzID0gZXNjb3BlLmFuYWx5emUoYXN0KS5zY29wZXNcblxuICAgICAgICBleHBlY3Qoc2NvcGVzLm1hcCgoc2NvcGUpIC0+XG4gICAgICAgICAgICBzY29wZS52YXJpYWJsZXMubWFwKCh2YXJpYWJsZSkgLT5cbiAgICAgICAgICAgICAgICB2YXJpYWJsZS5kZWZzLm1hcCgoZGVmKSAtPiBkZWYudHlwZSkpKSkudG8uYmUuZXFsKFxuICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgICAgICAgICAgJ0Z1bmN0aW9uTmFtZSdcbiAgICAgICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgIF1cbiAgICAgICAgKVxuXG4gICAgICAgIGV4cGVjdChzY29wZXNbMF0uaW1wbGljaXQudmFyaWFibGVzLm1hcCgodmFyaWFibGUpIC0+IHZhcmlhYmxlLm5hbWUpKS50by5iZS5lcWwoW10pXG5cbiAgICBpdCAnYXNzaWdubWVudCBsZWFrcycsIC0+XG4gICAgICAgIGFzdCA9IGVzcHJpbWEucGFyc2UgXCJcIlwiXG4gICAgICAgIGZ1bmN0aW9uIG91dGVyKCkge1xuICAgICAgICAgICAgeCA9IDIwO1xuICAgICAgICB9XG4gICAgICAgIFwiXCJcIlxuXG4gICAgICAgIHNjb3BlcyA9IGVzY29wZS5hbmFseXplKGFzdCkuc2NvcGVzXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blcy5tYXAoKHNjb3BlKSAtPlxuICAgICAgICAgICAgc2NvcGUudmFyaWFibGVzLm1hcCgodmFyaWFibGUpIC0+IHZhcmlhYmxlLm5hbWUpKSkudG8uYmUuZXFsKFxuICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgJ291dGVyJ1xuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICdhcmd1bWVudHMnXG4gICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgXVxuICAgICAgICApXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blc1swXS5pbXBsaWNpdC52YXJpYWJsZXMubWFwKCh2YXJpYWJsZSkgLT4gdmFyaWFibGUubmFtZSkpLnRvLmJlLmVxbChcbiAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAneCdcbiAgICAgICAgICAgIF1cbiAgICAgICAgKVxuXG4gICAgaXQgJ2Fzc2lnbm1lbnQgZG9lc25cXCd0IGxlYWsnLCAtPlxuICAgICAgICBhc3QgPSBlc3ByaW1hLnBhcnNlIFwiXCJcIlxuICAgICAgICBmdW5jdGlvbiBvdXRlcigpIHtcbiAgICAgICAgICAgIGZ1bmN0aW9uIGlubmVyKCkge1xuICAgICAgICAgICAgICAgIHggPSAyMDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHZhciB4O1xuICAgICAgICB9XG4gICAgICAgIFwiXCJcIlxuXG4gICAgICAgIHNjb3BlcyA9IGVzY29wZS5hbmFseXplKGFzdCkuc2NvcGVzXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blcy5tYXAoKHNjb3BlKSAtPlxuICAgICAgICAgICAgc2NvcGUudmFyaWFibGVzLm1hcCgodmFyaWFibGUpIC0+IHZhcmlhYmxlLm5hbWUpKSkudG8uYmUuZXFsKFxuICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgJ291dGVyJ1xuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICdhcmd1bWVudHMnXG4gICAgICAgICAgICAgICAgICAgICdpbm5lcidcbiAgICAgICAgICAgICAgICAgICAgJ3gnXG4gICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgJ2FyZ3VtZW50cydcbiAgICAgICAgICAgICAgICBdXG4gICAgICAgICAgICBdXG4gICAgICAgIClcblxuICAgICAgICBleHBlY3Qoc2NvcGVzWzBdLmltcGxpY2l0LnZhcmlhYmxlcy5tYXAoKHZhcmlhYmxlKSAtPiB2YXJpYWJsZS5uYW1lKSkudG8uYmUuZXFsKFtdKVxuXG5cbiAgICBpdCAnZm9yLWluLXN0YXRlbWVudCBsZWFrcycsIC0+XG4gICAgICAgIGFzdCA9IGVzcHJpbWEucGFyc2UgXCJcIlwiXG4gICAgICAgIGZ1bmN0aW9uIG91dGVyKCkge1xuICAgICAgICAgICAgZm9yICh4IGluIHkpIHsgfVxuICAgICAgICB9XG4gICAgICAgIFwiXCJcIlxuXG4gICAgICAgIHNjb3BlcyA9IGVzY29wZS5hbmFseXplKGFzdCkuc2NvcGVzXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blcy5tYXAoKHNjb3BlKSAtPlxuICAgICAgICAgICAgc2NvcGUudmFyaWFibGVzLm1hcCgodmFyaWFibGUpIC0+IHZhcmlhYmxlLm5hbWUpKSkudG8uYmUuZXFsKFxuICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAgICAgJ291dGVyJ1xuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICdhcmd1bWVudHMnXG4gICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgXVxuICAgICAgICApXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blc1swXS5pbXBsaWNpdC52YXJpYWJsZXMubWFwKCh2YXJpYWJsZSkgLT4gdmFyaWFibGUubmFtZSkpLnRvLmJlLmVxbChcbiAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAneCdcbiAgICAgICAgICAgIF1cbiAgICAgICAgKVxuXG4gICAgaXQgJ2Zvci1pbi1zdGF0ZW1lbnQgZG9lc25cXCd0IGxlYWtzJywgLT5cbiAgICAgICAgYXN0ID0gZXNwcmltYS5wYXJzZSBcIlwiXCJcbiAgICAgICAgZnVuY3Rpb24gb3V0ZXIoKSB7XG4gICAgICAgICAgICBmdW5jdGlvbiBpbm5lcigpIHtcbiAgICAgICAgICAgICAgICBmb3IgKHggaW4geSkgeyB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YXIgeDtcbiAgICAgICAgfVxuICAgICAgICBcIlwiXCJcblxuICAgICAgICBzY29wZXMgPSBlc2NvcGUuYW5hbHl6ZShhc3QpLnNjb3Blc1xuXG4gICAgICAgIGV4cGVjdChzY29wZXMubWFwKChzY29wZSkgLT5cbiAgICAgICAgICAgIHNjb3BlLnZhcmlhYmxlcy5tYXAoKHZhcmlhYmxlKSAtPiB2YXJpYWJsZS5uYW1lKSkpLnRvLmJlLmVxbChcbiAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICdvdXRlcidcbiAgICAgICAgICAgICAgICBdXG4gICAgICAgICAgICAgICAgW1xuICAgICAgICAgICAgICAgICAgICAnYXJndW1lbnRzJ1xuICAgICAgICAgICAgICAgICAgICAnaW5uZXInXG4gICAgICAgICAgICAgICAgICAgICd4J1xuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgICAgICBbXG4gICAgICAgICAgICAgICAgICAgICdhcmd1bWVudHMnXG4gICAgICAgICAgICAgICAgXVxuICAgICAgICAgICAgXVxuICAgICAgICApXG5cbiAgICAgICAgZXhwZWN0KHNjb3Blc1swXS5pbXBsaWNpdC52YXJpYWJsZXMubWFwKCh2YXJpYWJsZSkgLT4gdmFyaWFibGUubmFtZSkpLnRvLmJlLmVxbChbXSlcbiJdfQ==