Skip to content

Commit

Permalink
Merge branch 'main' into feature/ts-namepolicy-reserved-words
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson authored Jan 15, 2025
2 parents 986de9b + 83cc365 commit dda4829
Show file tree
Hide file tree
Showing 8 changed files with 1,311 additions and 649 deletions.
27 changes: 14 additions & 13 deletions packages/core/src/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,12 @@ export interface Binder {
): Ref<TScope | undefined>;

/**
* Resolve a fully qualified name to a symbol. The syntax for a fully
* qualified name is as follows:
* Resolve a fully qualified name to a symbol. Access a nested scope by name
* with `::`, a nested static member with `.` and a nested instance member
* with `#`.
*
* * `::` accesses a nested scope
* * `.` accesses a nested static member
* * `#` accesses a nested instance member
*
* Per-language packages may provide their own resolveFQN function
* that uses syntax more natural to that language.
* Per-language packages may provide their own resolveFQN function that uses
* syntax more natural to that language.
*/
resolveFQN<
TScope extends OutputScope = OutputScope,
Expand Down Expand Up @@ -365,11 +362,15 @@ export interface Binder {
* When we resolve the refkey for `bar` from within `namespace scope 2`, we will get the following
* resolution result:
*
* * **targetDeclaration**: symbol bar, the symbol we resolved.
* * **commonScope**: global scope, because this is the most specific scope that contains both the declaration and the reference.
* * **pathUp**: [namespace scope 2], because this is the scope between the reference and the common scope.
* * **pathDown**: [namespace scope 1], because this is the scope between the common scope and the declaration
* * **memberPath**: [foo, bar], because we resolved a member symbol and these are the symbols that lead from the base declaration to the member symbol.
* **targetDeclaration**: symbol bar, the symbol we resolved.
*
* **commonScope**: global scope, because this is the most specific scope that contains both the declaration and the reference.
*
* **pathUp**: [namespace scope 2], because this is the scope between the reference and the common scope.
*
* **pathDown**: [namespace scope 1], because this is the scope between the common scope and the declaration
*
* **memberPath**: [foo, bar], because we resolved a member symbol and these are the symbols that lead from the base declaration to the member symbol.
*/
export interface ResolutionResult<
TScope extends OutputScope,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/components/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ export function Output(props: OutputProps) {
}

return <BinderContext.Provider value={binder}>
{() => { extensionEffects.forEach(e => e())}}
{
{() => { extensionEffects.forEach(e => e())}}{
props.namePolicy ?
<NamePolicyContext.Provider value={props.namePolicy}>
{dir}
Expand Down
15 changes: 0 additions & 15 deletions packages/core/test/components/source-file.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,3 @@ it("can change its indent level", () => {
indented
`);
});

it.only("does things", () => {
function DebugMe() {
debug.component.stack();
}

const tree = render(
<Output>
<SourceFile path="hi.txt" filetype="text">
base
<DebugMe />
</SourceFile>
</Output>,
);
});
12 changes: 6 additions & 6 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/starlight": "^0.27.0",
"astro": "^4.15.3",
"@astrojs/check": "^0.9.4",
"@astrojs/starlight": "^0.31.0",
"astro": "^5.1.6",
"astro-expressive-code": "^0.36.1",
"sharp": "^0.32.5",
"typescript": "^5.5.4"
},
"devDependencies": {
"@alloy-js/core": "workspace:~",
"@alloy-js/csharp": "workspace:~",
"@alloy-js/java": "workspace:~",
"@alloy-js/typescript": "workspace:~",
"@microsoft/api-extractor": "^7.47.7",
"@microsoft/api-extractor-model": "^7.29.6",
"@microsoft/tsdoc": "^0.15.0",
"@alloy-js/typescript": "workspace:~",
"@alloy-js/java": "workspace:~",
"@alloy-js/csharp": "workspace:~",
"redent": "^4.0.0"
}
}
16 changes: 9 additions & 7 deletions packages/docs/scripts/components/InterfaceMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ export function InterfaceMembers(props: InterfaceMembersProps) {
<td>\`(${method.parameters
.map((param) => param.parameterTypeExcerpt.text)
.join(", ")}) => ${method.returnTypeExcerpt.text}\`</td>
<td>${
method.tsdocComment?.summarySection &&
TsDoc({
node: method.tsdocComment.summarySection,
context: method,
})
}</td>
<td>
${
method.tsdocComment?.summarySection &&
TsDoc({
node: method.tsdocComment.summarySection,
context: method,
})
}
</td>
</tr>
`;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript/src/components/ValueExpression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export function ValueExpression(props: ValueExpressionProps) {
return "undefined";
} else if (typeof jsValue === "number" || typeof jsValue === "boolean") {
return String(jsValue);
} else if (typeof jsValue === "bigint") {
return `${jsValue}n`;
} else if (typeof jsValue === "string") {
return `"${jsValue}"`;
return JSON.stringify(jsValue);
} else if (typeof jsValue === "object") {
if (jsValue === null) {
return "null";
Expand Down
39 changes: 39 additions & 0 deletions packages/typescript/test/value-expression.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { d } from "@alloy-js/core/testing";
import { expect, it } from "vitest";
import { ValueExpression } from "../src/index.js";
import { toSourceText } from "./utils.jsx";

it.each([
[undefined, "undefined"],
[null, "null"],
[true, "true"],
[false, "false"],
[42, "42"],
[42n, "42n"],
["abc", `"abc"`],
["a\nb\rc\\", `"a\\nb\\rc\\\\"`],
[
[1, 2, 3],
d`
[
1,
2,
3
]
`,
],
[
{ a: 1, b: 2, c: 3 },
d`
{
a: 1,
b: 2,
c: 3
}
`,
],
])("works - %o => %s", (jsValue, expectedSource) => {
expect(toSourceText(<ValueExpression jsValue={jsValue} />)).toBe(
expectedSource,
);
});
Loading

0 comments on commit dda4829

Please sign in to comment.