source: trip-planner-front/node_modules/@babel/types/scripts/generators/asserts.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import definitions from "../../lib/definitions/index.js";
2
3function addAssertHelper(type) {
4 const result =
5 definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]
6 ? `node is t.${type}`
7 : "boolean";
8
9 return `export function assert${type}(node: object | null | undefined, opts?: object | null): asserts ${
10 result === "boolean" ? "node" : result
11 } {
12 assert("${type}", node, opts) }
13 `;
14}
15
16export default function generateAsserts() {
17 let output = `/*
18 * This file is auto-generated! Do not modify it directly.
19 * To re-generate run 'make build'
20 */
21import is from "../../validators/is";
22import type * as t from "../..";
23
24function assert(type: string, node: any, opts?: any): void {
25 if (!is(type, node, opts)) {
26 throw new Error(
27 \`Expected type "\${type}" with option \${JSON.stringify(opts)}, \` +
28 \`but instead got "\${node.type}".\`,
29 );
30 }
31}\n\n`;
32
33 Object.keys(definitions.VISITOR_KEYS).forEach(type => {
34 output += addAssertHelper(type);
35 });
36
37 Object.keys(definitions.FLIPPED_ALIAS_KEYS).forEach(type => {
38 output += addAssertHelper(type);
39 });
40
41 Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
42 const newType = definitions.DEPRECATED_KEYS[type];
43 output += `export function assert${type}(node: any, opts: any): void {
44 console.trace("The node type ${type} has been renamed to ${newType}");
45 assert("${type}", node, opts);
46}\n`;
47 });
48
49 return output;
50}
Note: See TracBrowser for help on using the repository browser.