({
intoSites,
exposesAllows = false,
declaresEach = false
}: LinkPass)
| 1032 | } |
| 1033 | |
| 1034 | link({ |
| 1035 | intoSites, |
| 1036 | exposesAllows = false, |
| 1037 | declaresEach = false |
| 1038 | }: LinkPass): boolean { |
| 1039 | // e.g. a statement writing a checker read once, which a copy of it wouldn't have |
| 1040 | for (const unit of this.units) { |
| 1041 | const unread = unit.isSite ? unreadCreationsOf(unit) : undefined |
| 1042 | for (const reference of unit.module.scopes.references) { |
| 1043 | const statement = statementOf(reference.id) |
| 1044 | if ( |
| 1045 | unread ? !unread.has(statement) : runs(statement, unit.module.source) |
| 1046 | ) |
| 1047 | this.read(unit, reference) |
| 1048 | } |
| 1049 | } |
| 1050 | if (intoSites) { |
| 1051 | this.declareCreated(exposesAllows, declaresEach) |
| 1052 | this.readAllowsAsCreated() |
| 1053 | } |
| 1054 | // a declaration written into can't be copied before it's read again |
| 1055 | const written = new Set<Node>() |
| 1056 | let linked = false |
| 1057 | for (const [binding, reads] of this.readsByBinding) { |
| 1058 | if ( |
| 1059 | reads.length !== 1 || |
| 1060 | this.declaresCreated.has(binding) || |
| 1061 | this.readAsCreated.has(binding) |
| 1062 | ) |
| 1063 | continue |
| 1064 | const owner = this.ownerByBinding.get(binding)! |
| 1065 | const [read] = reads |
| 1066 | const into = statementOf(read.reference.id) |
| 1067 | if ( |
| 1068 | read.unit.isSite !== intoSites || |
| 1069 | // a name a site exports can't be written as what declares it |
| 1070 | read.reference.id.parent?.type === "ExportSpecifier" || |
| 1071 | // nor a validator an earlier link declared where the site's own code |
| 1072 | // reads it: written there, it would be created each time that runs |
| 1073 | (read.unit.isSite && createsValidator(owner, binding)) || |
| 1074 | written.has(statementOf(binding.declaration)) || |
| 1075 | !this.inline(owner, binding, read) |
| 1076 | ) |
| 1077 | continue |
| 1078 | written.add(into) |
| 1079 | linked = true |
| 1080 | } |
| 1081 | this.removeUnread() |
| 1082 | return linked |
| 1083 | } |
| 1084 | |
| 1085 | // An import of a unit whose every read a link wrote over still names it, so |
| 1086 | // what decides which units a module reads, by the names its imports list, |
no test coverage detected