57 lines
12 KiB
JavaScript
57 lines
12 KiB
JavaScript
|
(function() {
|
||
|
var escope, expect, harmony;
|
||
|
|
||
|
expect = require('chai').expect;
|
||
|
|
||
|
harmony = require('../third_party/esprima');
|
||
|
|
||
|
escope = require('..');
|
||
|
|
||
|
describe('ES6 arrow function expression', function() {
|
||
|
it('materialize scope for arrow function expression', function() {
|
||
|
var ast, scope, scopeManager;
|
||
|
ast = harmony.parse("var arrow = () => {\n let i = 0;\n var j = 20;\n console.log(i);\n}");
|
||
|
scopeManager = escope.analyze(ast, {
|
||
|
ecmaVersion: 6
|
||
|
});
|
||
|
expect(scopeManager.scopes).to.have.length(2);
|
||
|
scope = scopeManager.scopes[0];
|
||
|
expect(scope.type).to.be.equal('global');
|
||
|
expect(scope.block.type).to.be.equal('Program');
|
||
|
expect(scope.isStrict).to.be["false"];
|
||
|
expect(scope.variables).to.have.length(1);
|
||
|
scope = scopeManager.scopes[1];
|
||
|
expect(scope.type).to.be.equal('function');
|
||
|
expect(scope.block.type).to.be.equal('ArrowFunctionExpression');
|
||
|
expect(scope.isStrict).to.be["true"];
|
||
|
expect(scope.variables).to.have.length(2);
|
||
|
expect(scope.variables[0].name).to.be.equal('i');
|
||
|
return expect(scope.variables[1].name).to.be.equal('j');
|
||
|
});
|
||
|
return it('generate bindings for parameters', function() {
|
||
|
var ast, scope, scopeManager;
|
||
|
ast = harmony.parse("var arrow = (a, b, c, d) => {\n}");
|
||
|
scopeManager = escope.analyze(ast, {
|
||
|
ecmaVersion: 6
|
||
|
});
|
||
|
expect(scopeManager.scopes).to.have.length(2);
|
||
|
scope = scopeManager.scopes[0];
|
||
|
expect(scope.type).to.be.equal('global');
|
||
|
expect(scope.block.type).to.be.equal('Program');
|
||
|
expect(scope.isStrict).to.be["false"];
|
||
|
expect(scope.variables).to.have.length(1);
|
||
|
scope = scopeManager.scopes[1];
|
||
|
expect(scope.type).to.be.equal('function');
|
||
|
expect(scope.block.type).to.be.equal('ArrowFunctionExpression');
|
||
|
expect(scope.isStrict).to.be["true"];
|
||
|
expect(scope.variables).to.have.length(4);
|
||
|
expect(scope.variables[0].name).to.be.equal('a');
|
||
|
expect(scope.variables[1].name).to.be.equal('b');
|
||
|
expect(scope.variables[2].name).to.be.equal('c');
|
||
|
return expect(scope.variables[3].name).to.be.equal('d');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
}).call(this);
|
||
|
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVzNi1hcnJvdy1mdW5jdGlvbi1leHByZXNzaW9uLmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUF1QkE7QUFBQSxNQUFBLHVCQUFBOztBQUFBLEVBQUEsTUFBQSxHQUFTLE9BQUEsQ0FBUyxNQUFULENBQWUsQ0FBQyxNQUF6QixDQUFBOztBQUFBLEVBQ0EsT0FBQSxHQUFVLE9BQUEsQ0FBUyx3QkFBVCxDQURWLENBQUE7O0FBQUEsRUFFQSxNQUFBLEdBQVMsT0FBQSxDQUFTLElBQVQsQ0FGVCxDQUFBOztBQUFBLEVBSUEsUUFBQSxDQUFVLCtCQUFWLEVBQTBDLFNBQUEsR0FBQTtBQUN0QyxJQUFBLEVBQUEsQ0FBSSxpREFBSixFQUFzRCxTQUFBLEdBQUE7QUFDbEQsVUFBQSx3QkFBQTtBQUFBLE1BQUEsR0FBQSxHQUFNLE9BQU8sQ0FBQyxLQUFSLENBQWlCLDhFQUFqQixDQUFOLENBQUE7QUFBQSxNQVFBLFlBQUEsR0FBZSxNQUFNLENBQUMsT0FBUCxDQUFlLEdBQWYsRUFBb0I7QUFBQSxRQUFBLFdBQUEsRUFBYSxDQUFiO09BQXBCLENBUmYsQ0FBQTtBQUFBLE1BU0EsTUFBQSxDQUFPLFlBQVksQ0FBQyxNQUFwQixDQUEyQixDQUFDLEVBQUUsQ0FBQyxJQUFJLENBQUMsTUFBcEMsQ0FBMkMsQ0FBM0MsQ0FUQSxDQUFBO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