(module: SourceModule)
| 1026 | |
| 1027 | // the runtime, units it reads by the names they declare, its declarations and their export |
| 1028 | const isUnitModule = (module: SourceModule): boolean => |
| 1029 | module.program.body.every(statement => { |
| 1030 | switch (statement.type) { |
| 1031 | case "ImportDeclaration": |
| 1032 | return statement.source.value === runtimeSource ? |
| 1033 | statement.specifiers.length === 1 && |
| 1034 | statement.specifiers[0].type === "ImportNamespaceSpecifier" && |
| 1035 | statement.specifiers[0].local.name === "runtime" |
| 1036 | : statement.source.value.startsWith("~arktype/") && |
| 1037 | statement.specifiers.every( |
| 1038 | specifier => |
| 1039 | specifier.type === "ImportSpecifier" && |
| 1040 | exportNameOf(specifier.imported) === specifier.local.name |
| 1041 | ) |
| 1042 | case "VariableDeclaration": |
| 1043 | return ( |
| 1044 | statement.kind === "const" && |
| 1045 | statement.declarations.length === 1 && |
| 1046 | statement.declarations[0].id.type === "Identifier" && |
| 1047 | !!statement.declarations[0].init |
| 1048 | ) |
| 1049 | case "ExportNamedDeclaration": |
| 1050 | return ( |
| 1051 | !statement.source && |
| 1052 | !statement.declaration && |
| 1053 | statement.specifiers.every( |
| 1054 | specifier => |
| 1055 | exportNameOf(specifier.exported) === exportNameOf(specifier.local) |
| 1056 | ) |
| 1057 | ) |
| 1058 | } |
| 1059 | return false |
| 1060 | }) |
| 1061 | |
| 1062 | type Call = Extract<Node, { type: "CallExpression" }> |
| 1063 | type Arrow = Extract<Node, { type: "ArrowFunctionExpression" }> |
no test coverage detected