Debian Codegraph @

packages/babel-types/test/validate.js

raw
1 import * as t from "../lib/index.js";
2
3 describe("validate", () => {
4 describe("TS", () => {
5 const id1 = t.identifier("foo");
6 const id2 = t.identifier("bar");
7 const lhs = [
8 t.tsAsExpression(id1, t.tsAnyKeyword()),
9 t.tsTypeAssertion(t.tsAnyKeyword(), id1),
10 t.tsNonNullExpression(id1),
11 ];
12 const validNodes = {
13 "AssignmentExpression(=)": lhs => t.assignmentExpression("=", lhs, id2),
14 "AssignmentExpression(+=)": lhs => t.assignmentExpression("+=", lhs, id2),
15 ForOfStatement: lhs => t.forOfStatement(lhs, id2, t.emptyStatement()),
16 ForInStatement: lhs => t.forInStatement(lhs, id2, t.emptyStatement()),
17 "ObjectPattern > ObjectProperty": lhs =>
18 t.objectPattern([t.objectProperty(t.stringLiteral("x"), lhs)]),
19 ArrayPattern: lhs => t.arrayPattern([lhs]),
20 AssignmentPattern: lhs => t.assignmentPattern(lhs, id2),
21 };
22 Object.keys(validNodes).forEach(name => {
23 lhs.forEach(lhs => {
24 it(`${lhs.type} is allowed in ${name}`, () => {
25 expect(() => t.validate(validNodes[name](lhs))).not.toThrow();
26 });
27 });
28 });
29 });
30 });