Skip to content

Commit a9929d4

Browse files
committed
Consolidated namespaces under single component type
1 parent b41eada commit a9929d4

File tree

2 files changed

+10
-38
lines changed

2 files changed

+10
-38
lines changed

packages/typespec/src/components/source-file/source-file.tsx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Children } from "@alloy-js/core/jsx-runtime";
22
import { SourceFileScope } from "../../scopes/source-file.js";
3-
import { Block, computed, SourceFile as CoreSourceFile, Scope, useBinder } from "@alloy-js/core";
3+
import { Block, computed, SourceFile as CoreSourceFile, Scope, Show, useBinder } from "@alloy-js/core";
44
import {
55
useTypeSpecFormatOptions
66
} from "../../contexts/format-options.js";
@@ -35,9 +35,8 @@ export interface SourceFileProps {
3535
export function SourceFile(props: SourceFileProps) {
3636
const sourceFileScope = new SourceFileScope(props.path);
3737

38-
const nsContext = useNamespaceContext();
3938
const globalNs = getGlobalNamespace(useBinder());
40-
const nsSymbol = props?.namespace ?? (nsContext ? nsContext.symbol : globalNs);
39+
const nsSymbol = props?.namespace ?? globalNs;
4140

4241
const content = computed(() => (
4342
<NamespaceScopes symbol={nsSymbol}>{props.children}</NamespaceScopes>
@@ -52,26 +51,14 @@ export function SourceFile(props: SourceFileProps) {
5251
reference={Reference}
5352
{...options}
5453
>
55-
<Scope value={sourceFileScope}>
56-
{nsSymbol === globalNs ?
57-
content
58-
: <>
59-
namespace <NamespaceName symbol={nsSymbol} />
60-
{sourceFileScope.hasBlockNamespace ?
61-
<>
62-
{" "}
63-
<Block>{content}</Block>
64-
</>
65-
:<>
66-
;<hbr />
67-
<hbr />
68-
{content}
69-
</>
70-
71-
}
72-
</>
73-
}
74-
</Scope>
54+
<Scope value={sourceFileScope}>
55+
<Show when={nsSymbol !== globalNs}>
56+
namespace <NamespaceName symbol={nsSymbol} />;
57+
<hbr />
58+
<hbr />
59+
</Show>
60+
{content}
61+
</Scope>
7562
</CoreSourceFile>
7663
);
7764
}

packages/typespec/src/scopes/source-file.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ export class SourceFileScope extends OutputScope {
3535
addUsing(using: NamespaceSymbol) {
3636
this.#usings.add(using);
3737
}
38-
39-
#hasBlockNamespace: boolean = false;
40-
get hasBlockNamespace() {
41-
track(this, TrackOpTypes.GET, "hasBlockNamespace");
42-
return this.#hasBlockNamespace;
43-
}
44-
45-
set hasBlockNamespace(value: boolean) {
46-
const old = this.#hasBlockNamespace;
47-
if (this.#hasBlockNamespace === value) {
48-
return;
49-
}
50-
this.#hasBlockNamespace = value;
51-
trigger(this, TriggerOpTypes.SET, "hasBlockNamespace", value, old);
52-
}
5338
}
5439

5540
export function useSourceFileScope() {

0 commit comments

Comments
 (0)