object-expression.js 5.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function() {
  2. 'use strict';
  3. var escope, expect;
  4. expect = require('chai').expect;
  5. escope = require('..');
  6. describe('object expression', function() {
  7. return it('doesn\'t require property type', function() {
  8. var ast, scope;
  9. ast = {
  10. type: 'Program',
  11. body: [
  12. {
  13. type: 'VariableDeclaration',
  14. declarations: [
  15. {
  16. type: 'VariableDeclarator',
  17. id: {
  18. type: 'Identifier',
  19. name: 'a'
  20. },
  21. init: {
  22. type: 'ObjectExpression',
  23. properties: [
  24. {
  25. kind: 'init',
  26. key: {
  27. type: 'Identifier',
  28. name: 'foo'
  29. },
  30. value: {
  31. type: 'Identifier',
  32. name: 'a'
  33. }
  34. }
  35. ]
  36. }
  37. }
  38. ]
  39. }
  40. ]
  41. };
  42. scope = escope.analyze(ast).scopes[0];
  43. expect(scope.variables).to.have.length(1);
  44. expect(scope.references).to.have.length(2);
  45. expect(scope.variables[0].name).to.be.equal('a');
  46. expect(scope.references[0].identifier.name).to.be.equal('a');
  47. return expect(scope.references[1].identifier.name).to.be.equal('a');
  48. });
  49. });
  50. }).call(this);
  51. //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9iamVjdC1leHByZXNzaW9uLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQztBQUFBLEVBQUEsWUFBQSxDQUFBO0FBQUEsTUFBQSxjQUFBOztBQUFBLEVBRUQsTUFBQSxHQUFTLE9BQUEsQ0FBUyxNQUFULENBQWUsQ0FBQyxNQUZ4QixDQUFBOztBQUFBLEVBR0QsTUFBQSxHQUFTLE9BQUEsQ0FBUyxJQUFULENBSFIsQ0FBQTs7QUFBQSxFQUtELFFBQUEsQ0FBVSxtQkFBVixFQUE4QixTQUFBLEdBQUE7V0FDMUIsRUFBQSxDQUFJLGdDQUFKLEVBQXFDLFNBQUEsR0FBQTtBQUlqQyxVQUFBLFV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4gICAgICAgICMgaXQgcGFyc2UgYSBwcm9ncmFtIHN0cmluZy5cbiAgICAgICAgYXN0ID1cbiAgICAgICAgICAgIHR5cGU6ICdQcm9ncmFtJ1xuICAgICAgICAgICAgYm9keTogW3tcbiAgICAgICAgICAgICAgICB0eXBlOiAnVmFyaWFibGVEZWNsYXJhdGlvbidcbiAgICAgICAgICAgICAgICBkZWNsYXJhdGlvbnM6IFt7XG4gICAgICAgICAgICAgICAgICAgIHR5cGU6ICdWYXJpYWJsZURlY2xhcmF0b3InXG4gICAgICAgICAgICAgICAgICAgIGlkOlxuICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogJ0lkZW50aWZpZXInXG4gICAgICAgICAgICAgICAgICAgICAgICBuYW1lOiAnYSdcbiAgICAgICAgICAgICAgICAgICAgaW5pdDpcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6ICdPYmplY3RFeHByZXNzaW9uJ1xuICAgICAgICAgICAgICAgICAgICAgICAgcHJvcGVydGllczogW3tcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBraW5kOiAnaW5pdCdcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZXk6XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6ICdJZGVudGlmaWVyJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuYW1lOiAnZm9vJ1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVlOlxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlOiAnSWRlbnRpZmllcidcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmFtZTogJ2EnXG4gICAgICAgICAgICAgICAgICAgICAgICB9XVxuICAgICAgICAgICAgICAgIH1dXG4gICAgICAgICAgICB9XVxuXG4gICAgICAgIHNjb3BlID0gZXNjb3BlLmFuYWx5emUoYXN0KS5zY29wZXNbMF1cbiAgICAgICAgZXhwZWN0KHNjb3BlLnZhcmlhYmxlcykudG8uaGF2ZS5sZW5ndGgoMSlcbiAgICAgICAgZXhwZWN0KHNjb3BlLnJlZmVyZW5jZXMpLnRvLmhhdmUubGVuZ3RoKDIpXG4gICAgICAgIGV4cGVjdChzY29wZS52YXJpYWJsZXNbMF0ubmFtZSkudG8uYmUuZXF1YWwoJ2EnKVxuICAgICAgICBleHBlY3Qoc2NvcGUucmVmZXJlbmNlc1swXS5pZGVudGlmaWVyLm5hbWUpLnRvLmJlLmVxdWFsKCdhJylcbiAgICAgICAgZXhwZWN0KHNjb3BlLnJlZmVyZW5jZXNbMV0uaWRlbnRpZmllci5uYW1lKS50by5iZS5lcXVhbCgnYScpXG4iXX0=