| 1088 | // each import it held, as `ns.name;`. One stays where what the link wrote |
| 1089 | // names it, as a declaration of the module copied within it does |
| 1090 | private removeUnread(): void { |
| 1091 | for (const unit of this.units) { |
| 1092 | let text: string | undefined |
| 1093 | for (const statement of unit.module.program.body) { |
| 1094 | if ( |
| 1095 | statement.type !== "ImportDeclaration" || |
| 1096 | !statement.source.value.startsWith("~arktype/") || |
| 1097 | !statement.specifiers.length || |
| 1098 | unit.unread.includes(statement) |
| 1099 | ) |
| 1100 | continue |
| 1101 | const isUnread = statement.specifiers.every(({ local }) => { |
| 1102 | const binding = unit.module.scopes.bindingsById.get(local) |
| 1103 | if (!binding?.references.some(read => this.inlined.has(read))) |
| 1104 | return false |
| 1105 | text ??= unit.edits.toString() |
| 1106 | // named once, by this import |
| 1107 | return namesOf(text, binding.name) === 1 |
| 1108 | }) |
| 1109 | if (!isUnread) continue |
| 1110 | // its line stays, as imports a link adds are written after the |
| 1111 | // last import, before the line break ending it |
| 1112 | unit.edits.remove(statement.start, statement.end) |
| 1113 | unit.unread.push(statement) |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // a validator read only as `.allows` is read as the checker it's created from |
| 1119 | private readAllowsAsCreated(): void { |