/
es6-catch.test.ts
64 lines (57 loc) · 1.86 KB
/
es6-catch.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
expectToBeBlockScope,
expectToBeCatchScope,
expectToBeGlobalScope,
parseAndAnalyze,
} from '../util';
describe('ES6 catch', () => {
it('takes binding pattern', () => {
const { scopeManager } = parseAndAnalyze(`
try {
} catch ({ a, b, c, d }) {
let e = 20;
a;
b;
c;
d;
}
`);
expect(scopeManager.scopes).toHaveLength(4);
let scope = scopeManager.scopes[0];
expectToBeGlobalScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.Program);
expect(scope.isStrict).toBeFalsy();
expect(scope.variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);
scope = scopeManager.scopes[1];
expectToBeBlockScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.BlockStatement);
expect(scope.isStrict).toBeFalsy();
expect(scope.variables).toHaveLength(0);
expect(scope.references).toHaveLength(0);
scope = scopeManager.scopes[2];
expectToBeCatchScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.CatchClause);
expect(scope.isStrict).toBeFalsy();
expect(scope.variables).toHaveLength(4);
expect(scope.variables[0].name).toBe('a');
expect(scope.variables[1].name).toBe('b');
expect(scope.variables[2].name).toBe('c');
expect(scope.variables[3].name).toBe('d');
expect(scope.references).toHaveLength(0);
scope = scopeManager.scopes[3];
expectToBeBlockScope(scope);
expect(scope.block.type).toBe(AST_NODE_TYPES.BlockStatement);
expect(scope.isStrict).toBeFalsy();
expect(scope.variables).toHaveLength(1);
expect(scope.variables.map(variable => variable.name)).toEqual(['e']);
expect(scope.references.map(ref => ref.identifier.name)).toEqual([
'e',
'a',
'b',
'c',
'd',
]);
});
});