<commit_before>/* jshint -W104 */
// DEV: The JSHint directive above ignores `const` usage
// Load in dependencies
var expect = require('chai').expect;
var scriptUtils = require('./utils/script');

// Run our tests
describe.only('ecma-variable-scope', function () {
  describe('marking up an AST with a `var`', function () {
    scriptUtils.interpretFnAst(function () {
      var hello = 'world';
    });

    it('is considered `lexical`', function () {
      // {Program} (ast) -> {var} (body[0]) -> hello (declarations[0].id)
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
    });

    it('scopes the variable to the top level', function () {
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scope.node).to.equal(this.ast);
    });
  });

  describe('marking up an AST with a `const`', function () {
    scriptUtils.interpretFnAst(function () {
      const hello = 'world';
    });

    it('is considered `lexical`', function () {
      // {Program} (ast) -> {var} (body[0]) -> hello (declarations[0].id)
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
    });

    it('scopes the variable to the top level', function () {
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scope.node).to.equal(this.ast);
    });
  });

  describe('marking up an AST with a function declaration', function () {
    scriptUtils.interpretFnAst(function () {
      function hello(world) {
        // Code goes here
      }
    });

    it('marks the function name as lexically scoped to the outer scope', function () {
      // {Program} (ast) -> {fn} (body[0]) -> hello (id)
      var identifier = this.ast.body[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast);
    });

    it('marks the function parameters as lexically scoped to the function', function () {
      // {Program} (ast) -> {fn} (body[0]) -> world (params[0])
      var identifier = this.ast.body[0].params[0];
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast.body[0]);
    });
  });

  describe.skip('marking up an AST with an unnamed function expression', function () {
    scriptUtils.interpretFnAst(function () {
      [].map(function (world) {
        // Code goes here
      });
    });

    it('does not cause errors', function () {
      // Errors would throw in `before`
    });
  });
});<commit_msg>Added test against function expression<commit_after>/* jshint -W104 */
// DEV: The JSHint directive above ignores `const` usage
// Load in dependencies
var expect = require('chai').expect;
var scriptUtils = require('./utils/script');

// Run our tests
describe('ecma-variable-scope', function () {
  describe('marking up an AST with a `var`', function () {
    scriptUtils.interpretFnAst(function () {
      var hello = 'world';
    });

    it('is considered `lexical`', function () {
      // {Program} (ast) -> {var} (body[0]) -> hello (declarations[0].id)
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
    });

    it('scopes the variable to the top level', function () {
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scope.node).to.equal(this.ast);
    });
  });

  describe('marking up an AST with a `const`', function () {
    scriptUtils.interpretFnAst(function () {
      const hello = 'world';
    });

    it('is considered `lexical`', function () {
      // {Program} (ast) -> {var} (body[0]) -> hello (declarations[0].id)
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
    });

    it('scopes the variable to the top level', function () {
      var identifier = this.ast.body[0].declarations[0].id;
      expect(identifier.scope.node).to.equal(this.ast);
    });
  });

  describe('marking up an AST with a function declaration', function () {
    scriptUtils.interpretFnAst(function () {
      function hello(world) {
        // Code goes here
      }
    });

    it('marks the function name as lexically scoped to the outer scope', function () {
      // {Program} (ast) -> {fn} (body[0]) -> hello (id)
      var identifier = this.ast.body[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast);
    });

    it('marks the function parameters as lexically scoped to the function', function () {
      // {Program} (ast) -> {fn} (body[0]) -> world (params[0])
      var identifier = this.ast.body[0].params[0];
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast.body[0]);
    });
  });

  describe.only('marking up an AST with function expression', function () {
    scriptUtils.interpretFnAst(function () {
      [].map(function hello (world) {
        // Code goes here
      });
    });

    it('marks the function name as lexically scoped to the outer scope', function () {
      // {Program} (ast) -> {[]} (body[0]) -> {fn} (expression.arguments[0]) -> hello (id)
      var identifier = this.ast.body[0].expression.arguments[0].id;
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast);
    });

    it.skip('marks the function parameters as lexically scoped to the function', function () {
      // {Program} (ast) -> {fn} (body[0]) -> world (params[0])
      var identifier = this.ast.body[0].params[0];
      expect(identifier.scopeInfo).to.have.property('type', 'lexical');
      expect(identifier.scope.node).to.equal(this.ast.body[0]);
    });
  });

  describe.skip('marking up an AST with an unnamed function expression', function () {
    scriptUtils.interpretFnAst(function () {
      [].map(function (world) {
        // Code goes here
      });
    });

    it('does not cause errors', function () {
      // Errors would throw in `before`
    });
  });
});
{'fraction_non_alphanumeric': 0.17430754536771728, 'fraction_numerical': 0.008436803565743395, 'mean_word_length': 3.0587855297157622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '59026', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1899, 'n_words': 449}