(unit: RootUnit, specifier: string)
| 1459 | } |
| 1460 | |
| 1461 | writeSharedModule(unit: RootUnit, specifier: string): void { |
| 1462 | const declarations = this.declarations |
| 1463 | const returned = returnedOf(unit, this.baking) |
| 1464 | const writing: SharedUnit = { |
| 1465 | unit, |
| 1466 | returned, |
| 1467 | read: namesReadBy(unit, returned), |
| 1468 | own: unit.roots.filter(root => |
| 1469 | unit.refs.some( |
| 1470 | ref => isNode(ref) && unit.names[ref.id] === unit.names[root.id] |
| 1471 | ) |
| 1472 | ), |
| 1473 | params: [], |
| 1474 | args: [], |
| 1475 | imports: {}, |
| 1476 | shapesByName: {}, |
| 1477 | cellReads: {}, |
| 1478 | narrowedBy: {} |
| 1479 | } |
| 1480 | this.writing = writing |
| 1481 | this.declarations = createDeclarations() |
| 1482 | this.unit = unit |
| 1483 | for (const root of writing.own) { |
| 1484 | writing.shapesByName[unit.names[root.id]] = this.declareConst( |
| 1485 | root, |
| 1486 | "shape", |
| 1487 | "{}" |
| 1488 | ) |
| 1489 | } |
| 1490 | const refs = this.writeSharedRefs(writing) |
| 1491 | const links = writing.own.map(root => { |
| 1492 | const shape = writing.shapesByName[unit.names[root.id]] |
| 1493 | returned.push(shape) |
| 1494 | return this.writeFilledShape( |
| 1495 | root, |
| 1496 | shape, |
| 1497 | unit, |
| 1498 | this.traversalsOf(root, unit) |
| 1499 | ) |
| 1500 | }) |
| 1501 | const [moduleDeclarations, scope] = |
| 1502 | this.baking.flattens ? |
| 1503 | [this.writeFlatUnit(writing, refs, links)] |
| 1504 | : this.writeScopedUnit(writing, refs, links) |
| 1505 | moduleDeclarations.push(...this.writeUnitNodes(writing)) |
| 1506 | if (scope) { |
| 1507 | for (const root of unit.roots) { |
| 1508 | const name = unit.names[root.id] |
| 1509 | scope.nodes[name] = `runtime.freeze(${this.writeShape( |
| 1510 | root, |
| 1511 | name, |
| 1512 | unit, |
| 1513 | this.traversalsOf(root, unit) |
| 1514 | )})` |
| 1515 | } |
| 1516 | } |
| 1517 | this.declarations = declarations |
| 1518 | this.unit = undefined |
no test coverage detected