├── .npmrc ├── packages ├── create │ ├── .gitignore │ ├── tsconfig.json │ └── deps.json ├── cli │ ├── CHANGELOG.md │ ├── cmd │ │ └── alloy.js │ ├── tsconfig.build.json │ └── tsconfig.json ├── core │ ├── src │ │ ├── inspect.ts │ │ ├── index.browser.ts │ │ ├── inspect.browser.ts │ │ ├── context │ │ │ ├── declaration.ts │ │ │ ├── index.ts │ │ │ ├── name-policy.ts │ │ │ ├── source-directory.ts │ │ │ ├── source-file.ts │ │ │ ├── member-scope.ts │ │ │ ├── scope.ts │ │ │ ├── member-declaration.ts │ │ │ └── binder.ts │ │ ├── components │ │ │ ├── Name.tsx │ │ │ ├── Show.tsx │ │ │ ├── stc │ │ │ │ └── sti.ts │ │ │ ├── MemberName.tsx │ │ │ ├── StatementList.tsx │ │ │ ├── ReferenceOrContent.tsx │ │ │ └── index.tsx │ │ ├── symbols │ │ │ ├── index.ts │ │ │ └── basic-scope.ts │ │ └── library-symbol-reference.ts │ ├── testing │ │ ├── index.ts │ │ └── vitest.d.ts │ ├── tsdoc.json │ ├── vitest.config.ts │ ├── api-extractor.json │ ├── tsconfig.json │ └── test │ │ ├── reactivity │ │ ├── memo.test.tsx │ │ └── untrack.test.ts │ │ ├── name-policy.test.tsx │ │ ├── symbols │ │ └── symbol-table.test.ts │ │ ├── children.test.tsx │ │ ├── control-flow │ │ └── show.test.tsx │ │ ├── components │ │ └── declaration.test.tsx │ │ └── rendering │ │ └── memoization.test.tsx ├── java │ ├── src │ │ ├── builtins │ │ │ └── index.ts │ │ ├── symbols │ │ │ ├── scopes.ts │ │ │ ├── index.ts │ │ │ ├── java-lexical-scope.ts │ │ │ ├── java-package-scope.ts │ │ │ └── reference.ts │ │ ├── index.ts │ │ ├── components │ │ │ ├── Name.tsx │ │ │ ├── Reference.tsx │ │ │ ├── ExtendsClause.tsx │ │ │ ├── ImplementsClause.tsx │ │ │ ├── Parameters.tsx │ │ │ ├── Value.tsx │ │ │ ├── ImportStatement.tsx │ │ │ ├── Variable.tsx │ │ │ ├── ArgumentList.tsx │ │ │ ├── ObjectDeclaration.tsx │ │ │ ├── NamedArgumentList.tsx │ │ │ └── Constructor.tsx │ │ ├── utils.ts │ │ └── name-policy.ts │ ├── test │ │ ├── vitest.setup.ts │ │ ├── package.test.tsx │ │ └── values.test.tsx │ ├── api-extractor.json │ ├── vitest.config.ts │ └── tsconfig.json ├── python │ ├── vitest.setup.ts │ ├── api-extractor.json │ ├── vitest.config.ts │ ├── src │ │ ├── index.ts │ │ ├── symbols │ │ │ ├── index.ts │ │ │ ├── python-member-scope.ts │ │ │ ├── python-lexical-scope.ts │ │ │ └── scopes.ts │ │ ├── components │ │ │ ├── TypeArguments.tsx │ │ │ ├── UnionTypeExpression.tsx │ │ │ ├── Reference.tsx │ │ │ ├── StatementList.tsx │ │ │ ├── MemberScope.tsx │ │ │ ├── PythonBlock.tsx │ │ │ └── FunctionCallExpression.tsx │ │ ├── name-conflict-resolver.ts │ │ ├── utils.ts │ │ ├── parameter-descriptor.ts │ │ └── builtins │ │ │ └── python.ts │ └── tsconfig.json ├── csharp │ ├── test │ │ └── vitest.setup.ts │ ├── testing │ │ ├── index.ts │ │ └── create-wrapper.tsx │ ├── src │ │ ├── builtins │ │ │ ├── index.ts │ │ │ ├── System │ │ │ │ ├── CodeDom │ │ │ │ │ └── index.ts │ │ │ │ ├── Text │ │ │ │ │ └── Encodings │ │ │ │ │ │ └── index.ts │ │ │ │ ├── Configuration │ │ │ │ │ └── index.ts │ │ │ │ ├── Formats │ │ │ │ │ └── index.ts │ │ │ │ ├── Windows │ │ │ │ │ ├── index.ts │ │ │ │ │ └── Input │ │ │ │ │ │ └── index.ts │ │ │ │ └── Runtime │ │ │ │ │ └── Remoting │ │ │ │ │ └── index.ts │ │ │ └── Microsoft │ │ │ │ ├── CSharp │ │ │ │ └── index.ts │ │ │ │ └── index.ts │ │ ├── symbols │ │ │ ├── index.ts │ │ │ └── method.ts │ │ ├── index.ts │ │ ├── scopes │ │ │ ├── index.ts │ │ │ ├── lexical.ts │ │ │ ├── class.ts │ │ │ ├── method.ts │ │ │ └── csharp.ts │ │ ├── components │ │ │ ├── Name.tsx │ │ │ ├── region │ │ │ │ ├── region.tsx │ │ │ │ └── region.test.tsx │ │ │ ├── using │ │ │ │ └── using.test.tsx │ │ │ ├── Reference.tsx │ │ │ ├── Declaration.tsx │ │ │ ├── stc │ │ │ │ └── index.ts │ │ │ ├── if │ │ │ │ └── if-statement.test.tsx │ │ │ └── namespace │ │ │ │ └── namespace-name.tsx │ │ └── contexts │ │ │ ├── format-options.ts │ │ │ ├── namespace.ts │ │ │ └── reference-context.ts │ ├── tsdoc.json │ ├── api-extractor.json │ ├── vitest.config.ts │ └── tsconfig.json ├── go │ ├── test │ │ └── vitest.setup.ts │ ├── api-extractor.json │ ├── src │ │ ├── symbols │ │ │ ├── index.ts │ │ │ └── type-parameter.ts │ │ ├── index.ts │ │ ├── builtins │ │ │ └── index.ts │ │ ├── components │ │ │ ├── pointer │ │ │ │ └── pointer.tsx │ │ │ ├── Name.tsx │ │ │ ├── Reference.tsx │ │ │ ├── ModuleDirectory.tsx │ │ │ └── index.ts │ │ ├── scopes │ │ │ ├── index.ts │ │ │ ├── lexical.ts │ │ │ ├── go.ts │ │ │ └── function.ts │ │ └── context │ │ │ └── package.ts │ ├── vitest.config.ts │ ├── tsconfig.json │ └── CHANGELOG.md ├── json │ ├── test │ │ ├── vitest.setup.ts │ │ └── utils.tsx │ ├── src │ │ ├── context │ │ │ ├── index.ts │ │ │ └── JsonFileContext.ts │ │ ├── index.ts │ │ └── components │ │ │ ├── index.ts │ │ │ ├── stc │ │ │ └── index.ts │ │ │ ├── primitives.test.tsx │ │ │ └── reference.tsx │ ├── api-extractor.json │ ├── vitest.config.ts │ └── tsconfig.json ├── markdown │ ├── src │ │ ├── index.ts │ │ ├── components │ │ │ ├── index.ts │ │ │ ├── SourceFile.tsx │ │ │ ├── Link.tsx │ │ │ ├── Heading.tsx │ │ │ ├── Code.tsx │ │ │ ├── Frontmatter.tsx │ │ │ └── Section.tsx │ │ └── context │ │ │ └── section.ts │ ├── api-extractor.json │ ├── vitest.config.ts │ ├── test │ │ ├── utils.tsx │ │ └── vitest.d.ts │ ├── tsconfig.json │ └── CHANGELOG.md ├── msbuild │ ├── test │ │ └── vitest.setup.ts │ ├── src │ │ ├── components │ │ │ └── index.tsx │ │ └── index.ts │ ├── tsdoc.json │ ├── api-extractor.json │ ├── CHANGELOG.md │ ├── vitest.config.ts │ └── tsconfig.json ├── typescript │ ├── test │ │ ├── vitest.setup.ts │ │ ├── if-statement.test.tsx │ │ └── block-scope.test.tsx │ ├── testing │ │ ├── index.ts │ │ └── create-wrapper.tsx │ ├── src │ │ ├── builtins │ │ │ └── index.ts │ │ ├── context │ │ │ ├── index.ts │ │ │ ├── package-metadata.ts │ │ │ └── type-ref-context.tsx │ │ ├── index.ts │ │ ├── symbols │ │ │ └── ts-lexical-scope.ts │ │ ├── components │ │ │ ├── SingleLineCommentBlock.tsx │ │ │ ├── CommaList.tsx │ │ │ ├── JSDoc.tsx │ │ │ ├── JSDocComment.tsx │ │ │ ├── FunctionCallExpression.tsx │ │ │ ├── JSDocExample.tsx │ │ │ ├── NewExpression.tsx │ │ │ ├── TypeDeclaration.tsx │ │ │ ├── Reference.tsx │ │ │ └── ExportStatement.tsx │ │ ├── name-conflict-resolver.ts │ │ └── source-directory-data.ts │ ├── api-extractor.json │ ├── vitest.config.ts │ └── tsconfig.json ├── docs │ ├── tsconfig.json │ ├── src │ │ ├── env.d.ts │ │ ├── assets │ │ │ └── houston.webp │ │ └── content │ │ │ ├── config.ts │ │ │ └── docs │ │ │ └── index.mdx │ ├── docs │ │ ├── assets │ │ │ ├── navigation.js │ │ │ └── search.js │ │ └── .nojekyll │ ├── .vscode │ │ ├── extensions.json │ │ └── launch.json │ ├── scripts │ │ ├── contexts │ │ │ ├── content-root-dir.ts │ │ │ ├── api-model.ts │ │ │ ├── package-docs.ts │ │ │ ├── ts-doc.ts │ │ │ └── section.ts │ │ ├── components │ │ │ ├── MdxParagraph.ts │ │ │ ├── MdxSourceFile.ts │ │ │ ├── Code.ts │ │ │ ├── context │ │ │ │ ├── ContextSignature.ts │ │ │ │ ├── ContextInterface.ts │ │ │ │ └── ContextFactory.ts │ │ │ ├── Frontmatter.ts │ │ │ ├── component │ │ │ │ └── ComponentProps.ts │ │ │ ├── Remarks.ts │ │ │ ├── PackageDocs.ts │ │ │ ├── function │ │ │ │ ├── FunctionReturn.ts │ │ │ │ ├── FunctionDoc.ts │ │ │ │ └── FunctionSignature.ts │ │ │ ├── Summary.ts │ │ │ ├── MdxSection.ts │ │ │ ├── DocDeclaration.ts │ │ │ ├── variable │ │ │ │ └── VariableDoc.ts │ │ │ └── type │ │ │ │ └── TypeDoc.ts │ │ └── symbols │ │ │ └── doc-symbol.ts │ ├── scripts.tsconfig.json │ ├── .gitignore │ └── public │ │ └── favicon.svg ├── babel-plugin-alloy │ ├── test │ │ ├── fixtures │ │ │ ├── lb-ownership │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── no-leading-lb │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── custom-printer │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── last-not-text │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── just-text │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── blank-lines │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── fragments │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── indentation │ │ │ │ ├── multiple-line-indents │ │ │ │ │ ├── output.js │ │ │ │ │ └── code.js │ │ │ │ └── simple-cases │ │ │ │ │ ├── output.js │ │ │ │ │ └── code.js │ │ │ ├── weird-cases │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ └── real-world-sample │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ └── basic.test.ts │ ├── vitest.config.ts │ ├── tsconfig.json │ ├── src │ │ └── types.d.ts │ └── CHANGELOG.md ├── babel-plugin-jsx-dom-expressions │ ├── .npmignore │ ├── test │ │ ├── __whitespace_fixtures__ │ │ │ └── simple-case │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ ├── __dynamic_fixtures__ │ │ │ ├── namespaceElements │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ │ ├── customElements │ │ │ │ └── code.js │ │ │ └── simpleElements │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ ├── __dom_fixtures__ │ │ │ ├── namespaceElements │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ │ ├── customElements │ │ │ │ └── code.js │ │ │ └── simpleElements │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ ├── whitespace.spec.js │ │ ├── universal.spec.js │ │ ├── dynamic-universal.spec.js │ │ ├── ssr.spec.js │ │ ├── __dom_hydratable_fixtures__ │ │ │ ├── flags │ │ │ │ └── code.js │ │ │ ├── customElements │ │ │ │ └── code.js │ │ │ ├── eventExpressions │ │ │ │ └── code.js │ │ │ └── simpleElements │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ ├── __ssr_hydratable_fixtures__ │ │ │ ├── flags │ │ │ │ └── code.js │ │ │ ├── customElements │ │ │ │ └── code.js │ │ │ └── simpleElements │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ ├── dom-hydratable.spec.js │ │ ├── dom.spec.js │ │ ├── ssr-hydratable.spec.js │ │ ├── dom-wrapperless.spec.js │ │ ├── __ssr_fixtures__ │ │ │ ├── customElements │ │ │ │ └── code.js │ │ │ └── simpleElements │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ └── __universal_fixtures__ │ │ │ └── simpleElements │ │ │ └── code.js │ ├── jest.config.js │ ├── src │ │ ├── VoidElements.js │ │ ├── config.js │ │ └── index.js │ ├── CHANGELOG.md │ └── rollup.config.js ├── rollup-plugin │ ├── CHANGELOG.md │ ├── tsconfig.build.json │ ├── tsconfig.json │ └── src │ │ └── index.ts └── babel-preset-alloy │ ├── CHANGELOG.md │ ├── package.json │ └── index.js ├── tsconfig.json ├── .prettierrc.yaml ├── eng └── utils │ └── constants.ts ├── .chronus └── changes │ ├── feature-python-2025-6-30-11-17-1.md │ └── feature-golang-2025-8-26-16-14-31.md ├── samples ├── scaffold-generator │ ├── content │ │ ├── readme.md │ │ └── package.json │ ├── vitest.config.ts │ ├── tsconfig.json │ └── package.json ├── client-emitter │ ├── src │ │ ├── components │ │ │ ├── index.ts │ │ │ ├── Client.tsx │ │ │ ├── Model.tsx │ │ │ └── ModelProperty.tsx │ │ └── context │ │ │ └── api.ts │ ├── vitest.config.ts │ ├── tsconfig.json │ └── package.json ├── go-example │ ├── vitest.config.ts │ └── tsconfig.json ├── python-example │ ├── vitest.config.ts │ ├── src │ │ ├── components │ │ │ ├── index.ts │ │ │ ├── Model.tsx │ │ │ ├── Client.tsx │ │ │ └── Usage.tsx │ │ └── context │ │ │ └── api.ts │ └── tsconfig.json └── basic-project │ ├── vitest.config.ts │ └── tsconfig.json ├── .editorconfig ├── vitest.config.ts ├── cspell.yaml ├── tsconfig.ws.json ├── test └── performance │ ├── vitest.config.ts │ ├── tsconfig.json │ ├── scenarios │ └── render-long-file │ │ └── index.tsx │ └── package.json ├── .vscode └── settings.json ├── tsdoc.base.json ├── .prettierignore ├── .github ├── actions │ └── setup │ │ └── action.yml ├── workflows │ ├── prepare-release-pr.yml │ └── commenter.yml └── copilot-instructions.md ├── api-extractor.base.json └── tsconfig.base.json /.npmrc: -------------------------------------------------------------------------------- 1 | manage-package-manager-versions=true 2 | -------------------------------------------------------------------------------- /packages/create/.gitignore: -------------------------------------------------------------------------------- 1 | deps-versions.json -------------------------------------------------------------------------------- /packages/cli/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/cli -------------------------------------------------------------------------------- /packages/core/src/inspect.ts: -------------------------------------------------------------------------------- 1 | export { inspect } from "util"; 2 | -------------------------------------------------------------------------------- /packages/java/src/builtins/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./util.js"; 2 | -------------------------------------------------------------------------------- /packages/python/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /packages/csharp/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/go/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/java/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/json/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/markdown/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./components/index.js"; 2 | -------------------------------------------------------------------------------- /packages/cli/cmd/alloy.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import "../dist/cli.js"; 3 | -------------------------------------------------------------------------------- /packages/csharp/testing/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./create-wrapper.jsx"; 2 | -------------------------------------------------------------------------------- /packages/json/src/context/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./JsonFileContext.js"; 2 | -------------------------------------------------------------------------------- /packages/msbuild/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/typescript/test/vitest.setup.ts: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | -------------------------------------------------------------------------------- /packages/typescript/testing/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./create-wrapper.jsx"; 2 | -------------------------------------------------------------------------------- /packages/docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "astro/tsconfigs/strict" 3 | } 4 | -------------------------------------------------------------------------------- /packages/typescript/src/builtins/index.ts: -------------------------------------------------------------------------------- 1 | export * as node from "./node.js"; 2 | -------------------------------------------------------------------------------- /packages/msbuild/src/components/index.tsx: -------------------------------------------------------------------------------- 1 | export * from "./elements.generated.js"; 2 | -------------------------------------------------------------------------------- /packages/msbuild/src/index.ts: -------------------------------------------------------------------------------- 1 | // nothing here yet check @alloy-js/msbuild/components 2 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/lb-ownership/output.js: -------------------------------------------------------------------------------- 1 | const v = <>aa; -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/lb-ownership/code.js: -------------------------------------------------------------------------------- 1 | const v = <> 2 | a 3 | 4 | a 5 | 6 | -------------------------------------------------------------------------------- /packages/docs/src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | experimentalTernaries: true 2 | plugins: 3 | - ./node_modules/prettier-plugin-organize-imports/index.js 4 | -------------------------------------------------------------------------------- /eng/utils/constants.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from "pathe"; 2 | 3 | export const repoRoot = resolve(import.meta.dirname, "../.."); 4 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/no-leading-lb/output.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | return hello! how are you; 3 | } -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | rollup.config.js 3 | test/ 4 | coverage/ 5 | .travis.yml 6 | *.config.js -------------------------------------------------------------------------------- /packages/docs/src/assets/houston.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alloy-framework/alloy/HEAD/packages/docs/src/assets/houston.webp -------------------------------------------------------------------------------- /.chronus/changes/feature-python-2025-6-30-11-17-1.md: -------------------------------------------------------------------------------- 1 | --- 2 | changeKind: feature 3 | packages: 4 | - python-example 5 | --- 6 | 7 | -------------------------------------------------------------------------------- /packages/docs/docs/assets/navigation.js: -------------------------------------------------------------------------------- 1 | window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAA4uOBQApu0wNAgAAAA==" -------------------------------------------------------------------------------- /packages/core/testing/index.ts: -------------------------------------------------------------------------------- 1 | import "./extend-expect.js"; 2 | export * from "./create-test-wrapper.jsx"; 3 | export * from "./render.js"; 4 | -------------------------------------------------------------------------------- /packages/docs/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["astro-build.astro-vscode"], 3 | "unwantedRecommendations": [] 4 | } 5 | -------------------------------------------------------------------------------- /packages/rollup-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/rollup-plugin 2 | 3 | 4 | 5 | ## 0.1.0 6 | 7 | No changes, version bump only. 8 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/no-leading-lb/code.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | return hello! 3 | how are 4 | you 5 | ; 6 | } -------------------------------------------------------------------------------- /packages/json/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./components/index.js"; 2 | export * from "./context/index.js"; 3 | export * from "./symbols/index.js"; 4 | -------------------------------------------------------------------------------- /samples/scaffold-generator/content/readme.md: -------------------------------------------------------------------------------- 1 | ## Readme for {{ project_name }} 2 | 3 | Welcome to {{ project_name }}! 4 | 5 | {{ call_to_action }} 6 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/custom-printer/output.js: -------------------------------------------------------------------------------- 1 | function fooWithNestedComponent2() { 2 | return hello!children; 3 | } -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/last-not-text/output.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | const a = hello! {sub}; 3 | const b = {sub}; 4 | } -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/custom-printer/code.js: -------------------------------------------------------------------------------- 1 | function fooWithNestedComponent2() { 2 | return hello! 3 | children; 4 | } -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/last-not-text/code.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | const a = 3 | hello! {sub} 4 | const b = {sub} 5 | } -------------------------------------------------------------------------------- /packages/csharp/src/builtins/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Microsoft } from "./Microsoft/index.js"; 2 | export { default as System } from "./System/index.js"; 3 | -------------------------------------------------------------------------------- /packages/core/tsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", 3 | "extends": ["../../tsdoc.base.json"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/csharp/tsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", 3 | "extends": ["../../tsdoc.base.json"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/docs/docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /packages/core/src/index.browser.ts: -------------------------------------------------------------------------------- 1 | export * from "./host/alloy-host.browser.js"; // Override writeOutput for browsers 2 | export * from "./index.js"; // Re-export everything 3 | -------------------------------------------------------------------------------- /packages/msbuild/tsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", 3 | "extends": ["../../tsdoc.base.json"] 4 | } 5 | -------------------------------------------------------------------------------- /.chronus/changes/feature-golang-2025-8-26-16-14-31.md: -------------------------------------------------------------------------------- 1 | --- 2 | changeKind: feature 3 | packages: 4 | - go-example 5 | --- 6 | 7 | Initial implementation of golang support for alloy. -------------------------------------------------------------------------------- /packages/typescript/src/context/index.ts: -------------------------------------------------------------------------------- 1 | // type ref context isn't exported because it conflicts with the component of the same name. 2 | export * from "./package-metadata.js"; 3 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vitest/config"; 2 | 3 | export default defineConfig({ 4 | test: { 5 | globals: true, 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/core/src/inspect.browser.ts: -------------------------------------------------------------------------------- 1 | // inspection is not supported in browsers 2 | export function inspect() { 3 | return "custom inspect"; 4 | } 5 | 6 | inspect.custom = Symbol(); 7 | -------------------------------------------------------------------------------- /samples/client-emitter/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Client.jsx"; 2 | export * from "./ClientMethod.jsx"; 3 | export * from "./Model.jsx"; 4 | export * from "./ModelProperty.jsx"; 5 | -------------------------------------------------------------------------------- /samples/scaffold-generator/content/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scaffolded-project", 3 | "private": "true", 4 | "version": "1.0.0", 5 | "description": "", 6 | "main": "index.js" 7 | } 8 | -------------------------------------------------------------------------------- /packages/csharp/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/go/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/java/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/json/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/python/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | indent_style = space 6 | end_of_line = lf 7 | insert_final_newline = true 8 | charset = utf-8 9 | 10 | [*.cs] 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/just-text/output.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | return hello!; 3 | } 4 | function fooWithNestedComponent() { 5 | return hello!children; 6 | } -------------------------------------------------------------------------------- /packages/docs/scripts/contexts/content-root-dir.ts: -------------------------------------------------------------------------------- 1 | import { createContext, type ComponentContext } from "@alloy-js/core"; 2 | 3 | export const ContentRootDir: ComponentContext = createContext(); 4 | -------------------------------------------------------------------------------- /packages/markdown/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/msbuild/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/typescript/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__whitespace_fixtures__/simple-case/code.js: -------------------------------------------------------------------------------- 1 | function PythonFunction({name}) { 2 | return <> 3 | def {name}(): 4 | 5 | 6 | } -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vitest/config"; 2 | 3 | export default defineConfig({ 4 | test: { 5 | projects: ["packages/*", "!packages/babel-plugin-jsx-dom-expressions/"], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/blank-lines/output.js: -------------------------------------------------------------------------------- 1 | function blankLines() { 2 | return hello how are you; 3 | } 4 | function blankLinesWithIndent() { 5 | return hello how are you there; 6 | } -------------------------------------------------------------------------------- /packages/json/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./json-array.jsx"; 2 | export * from "./json-object.jsx"; 3 | export * from "./json-value.jsx"; 4 | export * from "./reference.jsx"; 5 | export * from "./source-file.jsx"; 6 | -------------------------------------------------------------------------------- /packages/docs/scripts.tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "noEmit": true 5 | }, 6 | "include": ["scripts/**/*.ts"], 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /cspell.yaml: -------------------------------------------------------------------------------- 1 | version: "0.2" 2 | language: en 3 | allowCompoundWords: true 4 | dictionaries: 5 | - node 6 | - typescript 7 | words: 8 | - arrayify 9 | - cref 10 | - msbuild 11 | useGitignore: true 12 | enableGlobDot: true 13 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/fragments/output.js: -------------------------------------------------------------------------------- 1 | function multipleIndentComponent() { 2 | return <>hello!; 3 | } 4 | function multipleIndentComponentAndText() { 5 | return <>hello! abc; 6 | } -------------------------------------------------------------------------------- /packages/go/src/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./factories.js"; 2 | export * from "./function.js"; 3 | export * from "./go.js"; 4 | export * from "./named-type.js"; 5 | export * from "./package.js"; 6 | export * from "./reference.js"; 7 | -------------------------------------------------------------------------------- /packages/java/src/symbols/scopes.ts: -------------------------------------------------------------------------------- 1 | import { JavaPackageScope } from "./java-package-scope.js"; 2 | import { JavaProjectScope } from "./java-project-scope.js"; 3 | 4 | export type JavaOutputScope = JavaProjectScope | JavaPackageScope; 5 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dynamic_fixtures__/namespaceElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ; 2 | const template2 = ; 3 | const template3 = ; 4 | const template4 = ; 5 | -------------------------------------------------------------------------------- /packages/csharp/src/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./csharp.js"; 2 | export * from "./factories.js"; 3 | export * from "./method.js"; 4 | export * from "./named-type.js"; 5 | export * from "./namespace.js"; 6 | export * from "./reference.js"; 7 | -------------------------------------------------------------------------------- /packages/docs/src/content/config.ts: -------------------------------------------------------------------------------- 1 | import { defineCollection } from 'astro:content'; 2 | import { docsSchema } from '@astrojs/starlight/schema'; 3 | 4 | export const collections = { 5 | docs: defineCollection({ schema: docsSchema() }), 6 | }; 7 | -------------------------------------------------------------------------------- /packages/docs/docs/assets/search.js: -------------------------------------------------------------------------------- 1 | window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAAz2MQQqDMBRE7zLr4MKuzA16ATfioiQjfDD/S0xtQby7pEp384bH25Hts8IPo4No5Bd+x8a8iik82ubRdHCYhHOsGvSVCIdgKVELHKKF92+Ot9YzFMv/5sZcGJ9Xu16LLJxFWek4TiJTfzuBAAAA"; -------------------------------------------------------------------------------- /packages/java/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./builtins/index.js"; 2 | export * from "./components/index.js"; 3 | export * from "./create-library.js"; 4 | export * from "./name-policy.js"; 5 | export * from "./symbols/index.js"; 6 | export * from "./utils.js"; 7 | -------------------------------------------------------------------------------- /packages/docs/scripts/contexts/api-model.ts: -------------------------------------------------------------------------------- 1 | import { createContext, type ComponentContext } from "@alloy-js/core"; 2 | import { ApiModel } from "@microsoft/api-extractor-model"; 3 | 4 | export const ApiModelContext: ComponentContext = createContext(); 5 | -------------------------------------------------------------------------------- /packages/go/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./builtins/index.js"; 2 | export * from "./components/index.js"; 3 | export * from "./create-module.js"; 4 | export * from "./name-policy.js"; 5 | export * from "./scopes/index.js"; 6 | export * from "./symbols/index.js"; 7 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/indentation/multiple-line-indents/output.js: -------------------------------------------------------------------------------- 1 | function multipleIndentComponent() { 2 | return hello!; 3 | } 4 | function multipleIndentComponentAndText() { 5 | return hello! abc; 6 | } -------------------------------------------------------------------------------- /packages/cli/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "dist" 6 | }, 7 | "references": [], 8 | "include": ["src"], 9 | "exclude": ["**/*.test.*", "test/**/*"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/java/src/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./java-lexical-scope.js"; 2 | export * from "./java-output-symbol.js"; 3 | export * from "./java-package-scope.js"; 4 | export * from "./java-project-scope.js"; 5 | export * from "./reference.js"; 6 | export * from "./scopes.js"; 7 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/just-text/code.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | return 3 | hello! 4 | ; 5 | } 6 | 7 | function fooWithNestedComponent() { 8 | return 9 | hello! 10 | 11 | children 12 | 13 | ; 14 | } -------------------------------------------------------------------------------- /packages/go/src/builtins/index.ts: -------------------------------------------------------------------------------- 1 | import { fmt } from "./fmt/fmt.js"; 2 | import { io } from "./io/io.js"; 3 | import { net } from "./net/net.js"; 4 | import { time } from "./time/time.js"; 5 | 6 | export const std = { 7 | io, 8 | fmt, 9 | net, 10 | time, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/markdown/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Code.jsx"; 2 | export * from "./Frontmatter.jsx"; 3 | export * from "./Heading.jsx"; 4 | export * from "./Link.jsx"; 5 | export * from "./List.jsx"; 6 | export * from "./Section.jsx"; 7 | export * from "./SourceFile.jsx"; 8 | -------------------------------------------------------------------------------- /packages/rollup-plugin/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "dist" 6 | }, 7 | "references": [], 8 | "include": ["src"], 9 | "exclude": ["**/*.test.*", "test/**/*"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/msbuild/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/msbuild 2 | 3 | ## 0.22.0 4 | 5 | No changes, version bump only. 6 | 7 | 8 | 9 | ## 0.21.0 10 | 11 | ### Bug Fixes 12 | 13 | - [#313](https://github.com/alloy-framework/alloy/pull/313) Skip undefined attributes 14 | 15 | -------------------------------------------------------------------------------- /packages/docs/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "command": "./node_modules/.bin/astro dev", 6 | "name": "Development server", 7 | "request": "launch", 8 | "type": "node-terminal" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /packages/docs/scripts/contexts/package-docs.ts: -------------------------------------------------------------------------------- 1 | import { createContext, type ComponentContext } from "@alloy-js/core"; 2 | 3 | export interface PackageDocsContext { 4 | name: string; 5 | } 6 | 7 | export const PackageDocContext: ComponentContext = 8 | createContext(); 9 | -------------------------------------------------------------------------------- /tsconfig.ws.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { "path": "packages/core" }, 5 | { "path": "packages/typescript" }, 6 | { "path": "packages/java" }, 7 | { "path": "samples/client-emitter" }, 8 | { "path": "samples/basic-project" } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/core/src/context/declaration.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createNamedContext } from "../context.js"; 2 | import type { OutputSymbol } from "../symbols/output-symbol.js"; 3 | 4 | export const DeclarationContext: ComponentContext = 5 | createNamedContext("Declaration"); 6 | -------------------------------------------------------------------------------- /packages/core/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/MdxParagraph.ts: -------------------------------------------------------------------------------- 1 | import type { Children } from "@alloy-js/core"; 2 | 3 | export interface MdxParagraphProps { 4 | children?: Children; 5 | } 6 | 7 | export function MdxParagraph(props: MdxParagraphProps) { 8 | return [props.children, "\n\n"]; 9 | } 10 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__whitespace_fixtures__/simple-case/output.js: -------------------------------------------------------------------------------- 1 | import { createComponent as _$createComponent } from "r-custom"; 2 | function PythonFunction({ name }) { 3 | return ["\n def ", name, "():\n ", _$createComponent(PythonFunctionBody, {}), "\n "]; 4 | } 5 | -------------------------------------------------------------------------------- /packages/java/src/components/Name.tsx: -------------------------------------------------------------------------------- 1 | import { DeclarationContext, useContext } from "@alloy-js/core"; 2 | 3 | export function Name() { 4 | const declSymbol = useContext(DeclarationContext); 5 | if (!declSymbol) { 6 | return ""; 7 | } 8 | 9 | return <>{declSymbol.name}; 10 | } 11 | -------------------------------------------------------------------------------- /packages/markdown/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /packages/python/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /samples/go-example/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /test/performance/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "moduleDirectories": ["node_modules", "packages"], 3 | "testEnvironment": "jsdom", 4 | "collectCoverageFrom": [ 5 | "./index.js" 6 | ], 7 | "transform": { 8 | "^.+\\.jsx?$": "babel-jest" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/java/src/symbols/java-lexical-scope.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope } from "@alloy-js/core"; 2 | 3 | export class JavaLexicalScope extends OutputScope { 4 | public static readonly declarationSpaces = ["symbols"]; 5 | 6 | get symbols() { 7 | return this.spaceFor("symbols")!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/python/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./builtins/python.js"; 2 | export * from "./components/index.js"; 3 | export * from "./create-module.js"; 4 | export * from "./name-policy.js"; 5 | export * from "./parameter-descriptor.js"; 6 | export * from "./symbols/index.js"; 7 | export * from "./utils.js"; 8 | -------------------------------------------------------------------------------- /samples/python-example/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | plugins: [alloyPlugin()], 10 | }); 11 | -------------------------------------------------------------------------------- /samples/python-example/src/components/index.ts: -------------------------------------------------------------------------------- 1 | // barrel file for components 2 | export { Client } from "./Client.jsx"; 3 | export { ClientMethod } from "./ClientMethod.jsx"; 4 | export { Model } from "./Model.jsx"; 5 | export { ModelProperty } from "./ModelProperty.jsx"; 6 | export { Usage } from "./Usage.jsx"; 7 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_fixtures__/namespaceElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ; 2 | const template2 = ; 3 | const template3 = ; 4 | const template4 = ; 5 | const template5 = ; 6 | const template6 = ; 7 | -------------------------------------------------------------------------------- /packages/python/src/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./factories.js"; 2 | export * from "./python-lexical-scope.js"; 3 | export * from "./python-member-scope.js"; 4 | export * from "./python-module-scope.js"; 5 | export * from "./python-output-symbol.js"; 6 | export * from "./reference.js"; 7 | export * from "./scopes.js"; 8 | -------------------------------------------------------------------------------- /packages/python/src/symbols/python-member-scope.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope } from "@alloy-js/core"; 2 | import { PythonOutputSymbol } from "./python-output-symbol.js"; 3 | 4 | export class PythonMemberScope extends OutputScope { 5 | get ownerSymbol() { 6 | return super.ownerSymbol as PythonOutputSymbol; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "emitDeclarationOnly": false 6 | }, 7 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 8 | "exclude": ["node_modules", "dist"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/src/VoidElements.js: -------------------------------------------------------------------------------- 1 | export default [ 2 | 'area', 3 | 'base', 4 | 'br', 5 | 'col', 6 | 'embed', 7 | 'hr', 8 | 'img', 9 | 'input', 10 | 'keygen', 11 | 'link', 12 | 'menuitem', 13 | 'meta', 14 | 'param', 15 | 'source', 16 | 'track', 17 | 'wbr' 18 | ] -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "search.exclude": { 5 | "**/node_modules": true, 6 | "**/.temp": true, 7 | "**/temp": true, 8 | "**/dist": true 9 | }, 10 | "typescript.tsdk": "node_modules/typescript/lib" 11 | } 12 | -------------------------------------------------------------------------------- /tsdoc.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", 3 | "tagDefinitions": [ 4 | { 5 | "tagName": "@reactive", 6 | "syntaxKind": "modifier" 7 | }, 8 | { 9 | "tagName": "@default", 10 | "syntaxKind": "block" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/go/src/components/pointer/pointer.tsx: -------------------------------------------------------------------------------- 1 | import { Children } from "@alloy-js/core"; 2 | 3 | export interface PointerProps { 4 | children: Children; 5 | } 6 | 7 | /** 8 | * A Go pointer type that wraps the given type. 9 | */ 10 | export function Pointer(props: PointerProps) { 11 | return <>*{props.children}; 12 | } 13 | -------------------------------------------------------------------------------- /packages/markdown/test/utils.tsx: -------------------------------------------------------------------------------- 1 | import { Children, Output } from "@alloy-js/core"; 2 | import { SourceFile } from "../src/components/SourceFile.jsx"; 3 | 4 | export function mdTest(children: Children) { 5 | return ( 6 | 7 | {children} 8 | 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /packages/csharp/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./access.jsx"; 2 | export * from "./components/index.js"; 3 | export * from "./contexts/format-options.js"; 4 | export * from "./create-library.js"; 5 | export * from "./modifiers.js"; 6 | export * from "./name-policy.js"; 7 | export * from "./scopes/index.js"; 8 | export * from "./symbols/index.js"; 9 | -------------------------------------------------------------------------------- /packages/go/src/scopes/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./contexts.js"; 2 | export * from "./factories.js"; 3 | export * from "./function.js"; 4 | export * from "./go.js"; 5 | export * from "./lexical.js"; 6 | export * from "./module.js"; 7 | export * from "./named-type.js"; 8 | export * from "./package.js"; 9 | export * from "./source-file.js"; 10 | -------------------------------------------------------------------------------- /packages/core/src/components/Name.tsx: -------------------------------------------------------------------------------- 1 | import { useContext } from "../context.js"; 2 | import { DeclarationContext } from "../context/declaration.js"; 3 | 4 | export function Name() { 5 | const declSymbol = useContext(DeclarationContext); 6 | if (!declSymbol) { 7 | return ""; 8 | } 9 | 10 | return <>{declSymbol.name}; 11 | } 12 | -------------------------------------------------------------------------------- /packages/csharp/src/scopes/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./class.js"; 2 | export * from "./contexts.js"; 3 | export * from "./csharp.js"; 4 | export * from "./factories.js"; 5 | export * from "./lexical.js"; 6 | export * from "./method.js"; 7 | export * from "./named-type.js"; 8 | export * from "./namespace.js"; 9 | export * from "./source-file.js"; 10 | -------------------------------------------------------------------------------- /packages/docs/.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist/ 3 | # generated types 4 | .astro/ 5 | 6 | # dependencies 7 | node_modules/ 8 | 9 | # logs 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | 15 | 16 | # environment variables 17 | .env 18 | .env.production 19 | 20 | # macOS-specific files 21 | .DS_Store 22 | -------------------------------------------------------------------------------- /packages/java/src/components/Reference.tsx: -------------------------------------------------------------------------------- 1 | import { Refkey } from "@alloy-js/core"; 2 | import { ref } from "../symbols/index.js"; 3 | 4 | export interface ReferenceProps { 5 | refkey: Refkey; 6 | } 7 | 8 | export function Reference(props: ReferenceProps) { 9 | const reference = ref(props.refkey); 10 | 11 | return <>{reference}; 12 | } 13 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/blank-lines/code.js: -------------------------------------------------------------------------------- 1 | function blankLines() { 2 | return 3 | 4 | hello 5 | 6 | how 7 | 8 | 9 | are you 10 | ; 11 | } 12 | 13 | function blankLinesWithIndent() { 14 | return 15 | 16 | hello 17 | 18 | how 19 | 20 | 21 | are you 22 | 23 | there 24 | ; 25 | } -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/fragments/code.js: -------------------------------------------------------------------------------- 1 | function multipleIndentComponent() { 2 | return <> 3 | hello! 4 | 5 | 6 | ; 7 | } 8 | 9 | function multipleIndentComponentAndText() { 10 | return <> 11 | hello! 12 | a 13 | 14 | b 15 | 16 | c 17 | ; 18 | } -------------------------------------------------------------------------------- /packages/core/src/components/Show.tsx: -------------------------------------------------------------------------------- 1 | import type { Children } from "../runtime/component.js"; 2 | 3 | export interface ShowProps { 4 | children: Children; 5 | fallback?: Children; 6 | when: boolean | undefined | null; 7 | } 8 | 9 | export function Show(props: ShowProps) { 10 | return () => (props.when ? props.children : props.fallback); 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/api-extractor.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "extends": "../../api-extractor.base.json", 4 | "messages": { 5 | "extractorMessageReporting": { 6 | "ae-wrong-input-file-type": { 7 | "logLevel": "none" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/go/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/java/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/json/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/csharp/src/components/Name.tsx: -------------------------------------------------------------------------------- 1 | import * as core from "@alloy-js/core"; 2 | 3 | // the name within the current declaration 4 | export function Name() { 5 | const declSymbol = core.useContext(core.DeclarationContext); 6 | if (!declSymbol) { 7 | throw new Error("missing declaration context"); 8 | } 9 | 10 | return <>{declSymbol.name}; 11 | } 12 | -------------------------------------------------------------------------------- /packages/csharp/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/msbuild/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/typescript/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | esbuild: { 6 | jsx: "preserve", 7 | sourcemap: "both", 8 | }, 9 | test: { 10 | setupFiles: ["./test/vitest.setup.ts"], 11 | }, 12 | plugins: [alloyPlugin()], 13 | }); 14 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/src/types.d.ts: -------------------------------------------------------------------------------- 1 | declare module "@babel/plugin-syntax-jsx" { 2 | var x: any; 3 | export default x; 4 | } 5 | 6 | declare module "@babel/generator/lib/printer.js" { 7 | var x: any; 8 | type x = any; 9 | export default x; 10 | } 11 | 12 | declare module "@babel/helper-module-imports" { 13 | var x: any; 14 | export default x; 15 | } 16 | -------------------------------------------------------------------------------- /packages/core/src/symbols/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./basic-scope.js"; 2 | export * from "./basic-symbol.js"; 3 | export * from "./decl.js"; 4 | export * from "./output-scope.js"; 5 | export * from "./output-space.js"; 6 | export * from "./output-symbol.js"; 7 | export * from "./symbol-flow.js"; 8 | export * from "./symbol-slot.js"; 9 | export * from "./symbol-table.js"; 10 | -------------------------------------------------------------------------------- /packages/java/src/symbols/java-package-scope.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope } from "@alloy-js/core"; 2 | 3 | export class JavaPackageScope extends OutputScope { 4 | public static readonly declarationSpaces = ["symbols"] as const; 5 | 6 | get kind() { 7 | return "package"; 8 | } 9 | 10 | get symbols() { 11 | return this.spaceFor("symbols")!; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/System/CodeDom/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as Compiler } from "./Compiler/index.js"; 3 | 4 | type CodeDomLibrary = LibrarySymbolReference & { 5 | 6 | }; 7 | const CodeDom: CodeDomLibrary = createLibrary("System.CodeDom", {}); 8 | export default CodeDom 9 | -------------------------------------------------------------------------------- /packages/docs/src/content/docs/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Alloy framework 3 | description: Documentation for the Alloy framework 4 | template: splash 5 | hero: 6 | tagline: Code generation made easy 7 | image: 8 | file: ../../assets/houston.webp 9 | actions: 10 | - text: Getting started 11 | link: guides/getting-started/ 12 | icon: right-arrow 13 | --- 14 | -------------------------------------------------------------------------------- /packages/go/src/components/Name.tsx: -------------------------------------------------------------------------------- 1 | import { DeclarationContext, useContext } from "@alloy-js/core"; 2 | 3 | // the name within the current declaration 4 | export function Name() { 5 | const declSymbol = useContext(DeclarationContext); 6 | if (!declSymbol) { 7 | throw new Error("missing declaration context"); 8 | } 9 | 10 | return <>{declSymbol.name}; 11 | } 12 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/basic.test.ts: -------------------------------------------------------------------------------- 1 | import { pluginTester } from "babel-plugin-tester"; 2 | import { join } from "node:path"; 3 | import "vitest"; 4 | import plugin from "../src/index.js"; 5 | 6 | pluginTester({ 7 | plugin, 8 | title: "Convert JSX", 9 | fixtures: join(import.meta.dirname, "fixtures"), 10 | snapshot: true, 11 | formatResult: (r) => r, 12 | }); 13 | -------------------------------------------------------------------------------- /packages/csharp/src/scopes/lexical.ts: -------------------------------------------------------------------------------- 1 | import { type OutputSpace } from "@alloy-js/core"; 2 | import { CSharpScope } from "./csharp.js"; 3 | 4 | export class CSharpLexicalScope extends CSharpScope { 5 | public static readonly declarationSpaces = ["local-variables"]; 6 | 7 | get localVariables(): OutputSpace { 8 | return this.spaceFor("local-variables")!; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/docs/scripts/contexts/ts-doc.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createContext, 3 | useContext, 4 | type ComponentContext, 5 | } from "@alloy-js/core"; 6 | import type { ApiItem } from "@microsoft/api-extractor-model"; 7 | 8 | export const TsDocContext: ComponentContext = createContext(); 9 | export function useTsDoccontext() { 10 | return useContext(TsDocContext)!; 11 | } 12 | -------------------------------------------------------------------------------- /packages/markdown/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "references": [{ "path": "../core" }], 9 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 10 | "exclude": ["node_modules", "dist"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/indentation/multiple-line-indents/code.js: -------------------------------------------------------------------------------- 1 | function multipleIndentComponent() { 2 | return 3 | hello! 4 | 5 | 6 | ; 7 | } 8 | 9 | function multipleIndentComponentAndText() { 10 | return 11 | hello! 12 | a 13 | 14 | b 15 | 16 | c 17 | ; 18 | } -------------------------------------------------------------------------------- /packages/csharp/src/builtins/Microsoft/CSharp/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as RuntimeBinder } from "./RuntimeBinder/index.js"; 3 | 4 | type CSharpLibrary = LibrarySymbolReference & { 5 | 6 | }; 7 | const CSharp: CSharpLibrary = createLibrary("Microsoft.CSharp", {}); 8 | export default CSharp 9 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/System/Text/Encodings/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as Web } from "./Web/index.js"; 3 | 4 | type EncodingsLibrary = LibrarySymbolReference & { 5 | 6 | }; 7 | const Encodings: EncodingsLibrary = createLibrary("System.Text.Encodings", {}); 8 | export default Encodings 9 | -------------------------------------------------------------------------------- /test/performance/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.tsx", 11 | "scenarios/**/*.ts", 12 | "scenarios/**/*.tsx" 13 | ], 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/core/src/components/stc/sti.ts: -------------------------------------------------------------------------------- 1 | import { sti } from "../../sti.js"; 2 | 3 | export const indent = sti("indent"); 4 | export const group = sti("group"); 5 | export const ifBreak = sti("ifBreak"); 6 | export const hbr = sti("hbr"); 7 | export const sbr = sti("sbr"); 8 | export const lbr = sti("lbr"); 9 | export const br = sti("br"); 10 | export const dedentToRoot = sti("dedentToRoot"); 11 | -------------------------------------------------------------------------------- /packages/core/src/components/MemberName.tsx: -------------------------------------------------------------------------------- 1 | import { useContext } from "../context.js"; 2 | import { MemberDeclarationContext } from "../context/member-declaration.js"; 3 | 4 | export function MemberName() { 5 | const declSymbol = useContext(MemberDeclarationContext); 6 | if (!declSymbol) { 7 | return "(no member declaration context)"; 8 | } 9 | 10 | return <>{declSymbol.name}; 11 | } 12 | -------------------------------------------------------------------------------- /packages/rollup-plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "outDir": "dist" 6 | }, 7 | "include": [ 8 | "src/**/*.ts", 9 | "src/**/*.tsx", 10 | "test/**/*.ts", 11 | "test/**/*.tsx", 12 | "testing/**/*.ts", 13 | "testing/**/*.d.ts" 14 | ], 15 | "exclude": ["node_modules", "dist"] 16 | } 17 | -------------------------------------------------------------------------------- /packages/csharp/src/components/region/region.tsx: -------------------------------------------------------------------------------- 1 | import { Children, code, List } from "@alloy-js/core"; 2 | 3 | export interface RegionProps { 4 | name: string; 5 | children: Children; 6 | } 7 | 8 | export function Region(props: RegionProps) { 9 | return ( 10 | 11 | {code`#region ${props.name}`} 12 | {props.children} 13 | {code`#endregion`} 14 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /packages/core/src/context/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./assignment.js"; 2 | export * from "./binder.js"; 3 | export * from "./declaration.js"; 4 | export * from "./format-options.js"; 5 | export * from "./member-declaration.js"; 6 | export * from "./member-scope.js"; 7 | export * from "./name-policy.js"; 8 | export * from "./scope.js"; 9 | export * from "./source-directory.js"; 10 | export * from "./source-file.js"; 11 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/System/Configuration/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as Assemblies } from "./Assemblies/index.js"; 3 | 4 | type ConfigurationLibrary = LibrarySymbolReference & { 5 | 6 | }; 7 | const Configuration: ConfigurationLibrary = createLibrary("System.Configuration", {}); 8 | export default Configuration 9 | -------------------------------------------------------------------------------- /packages/typescript/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./builtins/index.js"; 2 | export * from "./components/index.js"; 3 | export * from "./context/index.js"; 4 | export * from "./create-package.js"; 5 | export * from "./name-conflict-resolver.js"; 6 | export * from "./name-policy.js"; 7 | export * from "./parameter-descriptor.js"; 8 | export * from "./source-directory-data.js"; 9 | export * from "./symbols/index.js"; 10 | -------------------------------------------------------------------------------- /packages/docs/scripts/contexts/section.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createContext, 3 | useContext, 4 | type ComponentContext, 5 | } from "@alloy-js/core"; 6 | 7 | export interface SectionContext { 8 | level: number; 9 | } 10 | export const SectionContext: ComponentContext = createContext({ 11 | level: 1, 12 | }); 13 | export function useSectionContext() { 14 | return useContext(SectionContext)!; 15 | } 16 | -------------------------------------------------------------------------------- /packages/csharp/src/components/using/using.test.tsx: -------------------------------------------------------------------------------- 1 | import { expect, it } from "vitest"; 2 | import { Usings } from "./using.jsx"; 3 | 4 | it("single using", () => { 5 | expect().toRenderTo(` 6 | using Foo; 7 | `); 8 | }); 9 | 10 | it("multiple using", () => { 11 | expect().toRenderTo(` 12 | using Bar; 13 | using Foo; 14 | `); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/System/Formats/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as Asn1 } from "./Asn1/index.js"; 3 | export { default as Tar } from "./Tar/index.js"; 4 | 5 | type FormatsLibrary = LibrarySymbolReference & { 6 | 7 | }; 8 | const Formats: FormatsLibrary = createLibrary("System.Formats", {}); 9 | export default Formats 10 | -------------------------------------------------------------------------------- /packages/go/src/scopes/lexical.ts: -------------------------------------------------------------------------------- 1 | import { type OutputSpace } from "@alloy-js/core"; 2 | import { GoScope } from "./go.js"; 3 | 4 | export class GoLexicalScope extends GoScope { 5 | public static readonly declarationSpaces = ["values", "types"]; 6 | 7 | get values(): OutputSpace { 8 | return this.spaceFor("values")!; 9 | } 10 | 11 | get types(): OutputSpace { 12 | return this.spaceFor("types")!; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/java/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "types": ["@alloy-js/core/testing/matchers"], 7 | "outDir": "dist" 8 | }, 9 | "references": [{ "path": "../core" }], 10 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 11 | "exclude": ["node_modules", "dist"] 12 | } 13 | -------------------------------------------------------------------------------- /packages/json/test/utils.tsx: -------------------------------------------------------------------------------- 1 | import { Output } from "@alloy-js/core"; 2 | import { JsonValue } from "../src/components/json-value.jsx"; 3 | import { SourceFile } from "../src/components/source-file.jsx"; 4 | 5 | export function jsonTest(jsValue: unknown) { 6 | return ( 7 | 8 | 9 | 10 | 11 | 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /packages/json/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist", 7 | "types": ["@alloy-js/core/testing/matchers"] 8 | }, 9 | "references": [{ "path": "../core" }], 10 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 11 | "exclude": ["node_modules", "dist"] 12 | } 13 | -------------------------------------------------------------------------------- /samples/basic-project/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | test: { 6 | include: ["test/**/*.ts", "test/**/*.tsx"], 7 | exclude: ["test/**/*.util.ts", "test/**/*.d.ts"], 8 | }, 9 | esbuild: { 10 | jsx: "preserve", 11 | sourcemap: "both", 12 | }, 13 | plugins: [alloyPlugin()], 14 | }); 15 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "verbatimModuleSyntax": true, 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.tsx", 11 | "test/**/*.ts", 12 | "test/**/*.tsx", 13 | "testing/**/*.ts", 14 | "testing/**/*.d.ts" 15 | ], 16 | "exclude": ["node_modules", "dist"] 17 | } 18 | -------------------------------------------------------------------------------- /packages/create/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.tsx", 11 | "test/**/*.ts", 12 | "test/**/*.tsx", 13 | "testing/**/*.ts", 14 | "testing/**/*.d.ts" 15 | ], 16 | "exclude": ["node_modules", "dist"] 17 | } 18 | -------------------------------------------------------------------------------- /packages/python/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist", 7 | "types": ["@alloy-js/core/testing/matchers"] 8 | }, 9 | "references": [{ "path": "../core" }], 10 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 11 | "exclude": ["node_modules", "dist"] 12 | } 13 | -------------------------------------------------------------------------------- /samples/basic-project/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "outDir": "dist" 6 | }, 7 | "references": [ 8 | { "path": "../../packages/core" }, 9 | { "path": "../../packages/typescript" } 10 | ], 11 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 12 | "exclude": ["node_modules", "dist"] 13 | } 14 | -------------------------------------------------------------------------------- /samples/client-emitter/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | test: { 6 | include: ["test/**/*.ts", "test/**/*.tsx"], 7 | exclude: ["test/**/*.util.ts", "test/**/*.d.ts"], 8 | }, 9 | esbuild: { 10 | jsx: "preserve", 11 | sourcemap: "both", 12 | }, 13 | plugins: [alloyPlugin()], 14 | }); 15 | -------------------------------------------------------------------------------- /samples/scaffold-generator/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import alloyPlugin from "@alloy-js/rollup-plugin"; 2 | import { defineConfig } from "vitest/config"; 3 | 4 | export default defineConfig({ 5 | test: { 6 | include: ["test/**/*.ts", "test/**/*.tsx"], 7 | exclude: ["test/**/*.util.ts", "test/**/*.d.ts"], 8 | }, 9 | esbuild: { 10 | jsx: "preserve", 11 | sourcemap: "both", 12 | }, 13 | plugins: [alloyPlugin()], 14 | }); 15 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/System/Windows/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as Input } from "./Input/index.js"; 3 | export { default as Markup } from "./Markup/index.js"; 4 | 5 | type WindowsLibrary = LibrarySymbolReference & { 6 | 7 | }; 8 | const Windows: WindowsLibrary = createLibrary("System.Windows", {}); 9 | export default Windows 10 | -------------------------------------------------------------------------------- /packages/csharp/src/scopes/class.ts: -------------------------------------------------------------------------------- 1 | import type { OutputSpace } from "@alloy-js/core"; 2 | import { CSharpNamedTypeScope } from "./named-type.js"; 3 | 4 | export class CSharpClassScope extends CSharpNamedTypeScope { 5 | /** 6 | * For now, we stuff class parameters into the member scope. This is to ensure 7 | * name conflicts are handled correctly. 8 | */ 9 | get parameters(): OutputSpace { 10 | return this.members; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/go/src/context/package.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createContext, useContext } from "@alloy-js/core"; 2 | import { PackageSymbol } from "../symbols/package.js"; 3 | 4 | interface PackageContext { 5 | symbol: PackageSymbol; 6 | } 7 | 8 | export const PackageContext: ComponentContext = 9 | createContext(); 10 | 11 | export function usePackageContext() { 12 | return useContext(PackageContext); 13 | } 14 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dynamic_fixtures__/namespaceElements/output.js: -------------------------------------------------------------------------------- 1 | import { template as _$template } from "r-dom"; 2 | import { createComponent as _$createComponent } from "r-custom"; 3 | var _tmpl$ = /*#__PURE__*/ _$template(``); 4 | const template = _$createComponent(module.A, {}); 5 | const template2 = _$createComponent(module.a.B, {}); 6 | const template3 = _$createComponent(module.A.B, {}); 7 | const template4 = _tmpl$(); 8 | -------------------------------------------------------------------------------- /packages/csharp/src/contexts/format-options.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CommonFormatOptions, 3 | createFormatOptionsContextFor, 4 | } from "@alloy-js/core"; 5 | 6 | export interface CSharpFormatOptions extends CommonFormatOptions {} 7 | 8 | export const { 9 | Provider: CSharpFormatOptions, 10 | useFormatOptions: useCsharpFormatOptions, 11 | } = createFormatOptionsContextFor("csharp", { 12 | tabWidth: 4, 13 | printWidth: 120, 14 | }); 15 | -------------------------------------------------------------------------------- /packages/csharp/src/contexts/namespace.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createContext, useContext } from "@alloy-js/core"; 2 | import { NamespaceSymbol } from "../symbols/namespace.js"; 3 | 4 | export interface NamespaceContext { 5 | symbol: NamespaceSymbol; 6 | } 7 | 8 | export const NamespaceContext: ComponentContext = 9 | createContext(); 10 | 11 | export function useNamespaceContext() { 12 | return useContext(NamespaceContext); 13 | } 14 | -------------------------------------------------------------------------------- /samples/client-emitter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "references": [ 9 | { "path": "../../packages/core" }, 10 | { "path": "../../packages/typescript" } 11 | ], 12 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 13 | "exclude": ["node_modules", "dist"] 14 | } 15 | -------------------------------------------------------------------------------- /samples/scaffold-generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "references": [ 9 | { "path": "../../packages/core" }, 10 | { "path": "../../packages/typescript" } 11 | ], 12 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 13 | "exclude": ["node_modules", "dist"] 14 | } 15 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/whitespace.spec.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const pluginTester = require("babel-plugin-tester").default; 3 | const plugin = require("../index"); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: "r-custom", 9 | generate: "dom", 10 | preserveWhitespace: true 11 | }, 12 | title: "Convert JSX", 13 | fixtures: path.join(__dirname, "__whitespace_fixtures__"), 14 | snapshot: true 15 | }); 16 | -------------------------------------------------------------------------------- /packages/markdown/test/vitest.d.ts: -------------------------------------------------------------------------------- 1 | import "vitest"; 2 | 3 | interface ToRenderToRenderOptions { 4 | printWidth?: number; 5 | tabWidth?: number; 6 | useTabs?: boolean; 7 | } 8 | 9 | interface CustomMatchers { 10 | toRenderTo: (str: string, options?: ToRenderToRenderOptions) => R; 11 | } 12 | 13 | declare module "vitest" { 14 | interface Assertion extends CustomMatchers {} 15 | interface AsymmetricMatchersContaining extends CustomMatchers {} 16 | } 17 | -------------------------------------------------------------------------------- /packages/core/src/components/StatementList.tsx: -------------------------------------------------------------------------------- 1 | import type { Children } from "../runtime/component.js"; 2 | import { List } from "./List.jsx"; 3 | 4 | export interface StatementListProps { 5 | children: Children; 6 | } 7 | 8 | /** 9 | * Join child elements with semicolons and hardlines. 10 | */ 11 | export function StatementList(props: StatementListProps) { 12 | return ( 13 | 14 | {props.children} 15 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/babel-preset-alloy/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/babel-preset 2 | 3 | ## 0.2.1 4 | 5 | No changes, version bump only. 6 | 7 | ## 0.2.0 8 | 9 | ### Features 10 | 11 | - [#56](https://github.com/alloy-framework/alloy/pull/56) Added `legacyWhitespace` option to preserve the old whitespace handling behavior (not recommended). 12 | 13 | 14 | 15 | 16 | ## 0.1.1 17 | 18 | ### Bug Fixes 19 | 20 | - [#31](https://github.com/alloy-framework/alloy/pull/31) Update license to MIT 21 | 22 | -------------------------------------------------------------------------------- /packages/babel-preset-alloy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@alloy-js/babel-preset", 3 | "version": "0.2.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies": { 10 | "@alloy-js/babel-plugin": "workspace:~", 11 | "@alloy-js/babel-plugin-jsx-dom-expressions": "workspace:~" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "MIT", 16 | "type": "module" 17 | } 18 | -------------------------------------------------------------------------------- /packages/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "include": [ 9 | "src/**/*.ts", 10 | "src/**/*.tsx", 11 | "test/**/*.ts", 12 | "test/**/*.tsx", 13 | "testing/**/*.ts", 14 | "testing/**/*.tsx", 15 | "testing/**/*.d.ts", 16 | "testing/extend-expect.test.tsx" 17 | ], 18 | "exclude": ["node_modules", "dist"] 19 | } 20 | -------------------------------------------------------------------------------- /packages/markdown/src/components/SourceFile.tsx: -------------------------------------------------------------------------------- 1 | import { Children, SourceFile as CoreSourceFile, List } from "@alloy-js/core"; 2 | import { Link } from "./Link.jsx"; 3 | 4 | export interface SourceFileProps { 5 | path: string; 6 | children: Children; 7 | } 8 | export function SourceFile(props: SourceFileProps) { 9 | return ( 10 | 11 | {props.children} 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /samples/go-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "references": [ 9 | { "path": "../../packages/core" }, 10 | { "path": "../../packages/go" }, 11 | { "path": "../../packages/typescript" } 12 | ], 13 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/csharp/src/builtins/Microsoft/index.ts: -------------------------------------------------------------------------------- 1 | import { createLibrary } from "#createLibrary"; 2 | import { LibrarySymbolReference } from "@alloy-js/core";export { default as CSharp } from "./CSharp/index.js"; 3 | export { default as VisualBasic } from "./VisualBasic/index.js"; 4 | export { default as Win32 } from "./Win32/index.js"; 5 | 6 | type MicrosoftLibrary = LibrarySymbolReference & { 7 | 8 | }; 9 | const Microsoft: MicrosoftLibrary = createLibrary("Microsoft", {}); 10 | export default Microsoft 11 | -------------------------------------------------------------------------------- /packages/typescript/testing/create-wrapper.tsx: -------------------------------------------------------------------------------- 1 | import { SourceFile } from "#components/index.js"; 2 | import { createTestWrapper, type TestWrapper } from "@alloy-js/core/testing"; 3 | import { TSOutputSymbol, useTSScope } from "../src/index.js"; 4 | 5 | export function createTSTestWrapper(): TestWrapper { 6 | return createTestWrapper({ 7 | filePath: "test.ts", 8 | useScope: useTSScope, 9 | makeSymbol: (nk, scope) => new TSOutputSymbol(nk, scope.spaces), 10 | SourceFile, 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /samples/python-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist" 7 | }, 8 | "references": [ 9 | { "path": "../../packages/core" }, 10 | { "path": "../../packages/python" }, 11 | { "path": "../../packages/typescript" } 12 | ], 13 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/src/config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | moduleName: "dom", 3 | generate: "dom", 4 | hydratable: false, 5 | delegateEvents: true, 6 | delegatedEvents: [], 7 | builtIns: [], 8 | requireImportSource: false, 9 | wrapConditionals: true, 10 | omitNestedClosingTags: false, 11 | contextToCustomElements: false, 12 | staticMarker: "@once", 13 | effectWrapper: "effect", 14 | memoWrapper: "memo", 15 | validate: true, 16 | preserveWhitespace: false, 17 | }; 18 | -------------------------------------------------------------------------------- /packages/go/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist", 7 | "types": ["@alloy-js/core/testing/matchers"], 8 | "paths": { 9 | "#components/*": ["./src/components/*"] 10 | } 11 | }, 12 | "references": [{ "path": "../core" }], 13 | "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"], 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/indentation/simple-cases/output.js: -------------------------------------------------------------------------------- 1 | function simple() { 2 | return hello! indented!; 3 | } 4 | function indentedComponent() { 5 | return hello!content; 6 | } 7 | function multipleIndent() { 8 | return hello! indented! another indented?; 9 | } 10 | function multipleIndentComponent() { 11 | return hello!; 12 | } 13 | function multipleIndentComponentAndText() { 14 | return hello! abc; 15 | } -------------------------------------------------------------------------------- /packages/csharp/src/components/Reference.tsx: -------------------------------------------------------------------------------- 1 | import * as core from "@alloy-js/core"; 2 | import { ref } from "../symbols/reference.js"; 3 | 4 | export interface ReferenceProps { 5 | refkey: core.Refkey; 6 | } 7 | 8 | // used to resolve refkey references within source files 9 | export function Reference({ refkey }: ReferenceProps) { 10 | const reference = ref(refkey); 11 | const symbolRef = core.computed(() => reference()[1]); 12 | 13 | core.emitSymbol(symbolRef); 14 | return <>{reference()[0]}; 15 | } 16 | -------------------------------------------------------------------------------- /packages/csharp/testing/create-wrapper.tsx: -------------------------------------------------------------------------------- 1 | import { SourceFile } from "#components/index.js"; 2 | import { createTestWrapper, type TestWrapper } from "@alloy-js/core/testing"; 3 | import { CSharpSymbol, useSourceFileScope } from "../src/index.js"; 4 | 5 | export function createCSharpTestWrapper(): TestWrapper { 6 | return createTestWrapper({ 7 | filePath: "test.cs", 8 | useScope: useSourceFileScope, 9 | makeSymbol: (nk, scope) => new CSharpSymbol(nk, scope.spaces), 10 | SourceFile, 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/MdxSourceFile.ts: -------------------------------------------------------------------------------- 1 | import { type Children } from "@alloy-js/core"; 2 | import { SourceFile } from "@alloy-js/core/stc"; 3 | import { Reference } from "./Reference.js"; 4 | 5 | export interface MdxSourceFileProps { 6 | path: string; 7 | children?: Children; 8 | } 9 | 10 | export function MdxSourceFile(props: MdxSourceFileProps) { 11 | return SourceFile({ 12 | path: props.path, 13 | reference: Reference, 14 | filetype: "mdx", 15 | }).children(props.children); 16 | } 17 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/universal.spec.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const pluginTester = require("babel-plugin-tester").default; 3 | const plugin = require("../index"); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: "r-custom", 9 | builtIns: ["For", "Show"], 10 | generate: "universal", 11 | staticMarker: "@once" 12 | }, 13 | title: "Convert JSX", 14 | fixtures: path.join(__dirname, "__universal_fixtures__"), 15 | snapshot: true 16 | }); 17 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/dynamic-universal.spec.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const pluginTester = require("babel-plugin-tester").default; 3 | const plugin = require("../index"); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: "r-custom", 9 | builtIns: ["For", "Show"], 10 | generate: "dynamic", 11 | staticMarker: "@once" 12 | }, 13 | title: "Convert JSX", 14 | fixtures: path.join(__dirname, "__universal_fixtures__"), 15 | snapshot: true 16 | }); 17 | -------------------------------------------------------------------------------- /packages/core/test/reactivity/memo.test.tsx: -------------------------------------------------------------------------------- 1 | import { ref } from "@vue/reactivity"; 2 | import { expect, it } from "vitest"; 3 | import { memo } from "../../src/reactivity.js"; 4 | 5 | it("doesn't recalculate when dependencies don't change", () => { 6 | const signal = ref(0); 7 | let callCount = 0; 8 | const m = memo(() => { 9 | callCount += 1; 10 | return signal.value; 11 | }); 12 | expect(callCount).toBe(1); 13 | m(); 14 | expect(callCount).toBe(1); 15 | m(); 16 | expect(callCount).toBe(1); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/Code.ts: -------------------------------------------------------------------------------- 1 | import { text, type Children } from "@alloy-js/core"; 2 | import { dedentToRoot, hbr, indent } from "@alloy-js/core/stc"; 3 | 4 | export interface CodeProps { 5 | language: string; 6 | children: Children; 7 | } 8 | export function Code(props: CodeProps) { 9 | return text` 10 | 17 | `; 18 | } 19 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/context/ContextSignature.ts: -------------------------------------------------------------------------------- 1 | import { code } from "@alloy-js/core"; 2 | import type { ContextApi } from "../../build-json.js"; 3 | import { Code, MdxParagraph } from "../stc/index.js"; 4 | 5 | export interface ContextSignatureProps { 6 | context: ContextApi; 7 | } 8 | 9 | export function ContextSignature(props: ContextSignatureProps) { 10 | const c = code`const ${props.context.contextVariable.excerpt.text}`; 11 | return MdxParagraph().children(Code({ language: "ts" }).children(c)); 12 | } 13 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/Frontmatter.ts: -------------------------------------------------------------------------------- 1 | import { code } from "@alloy-js/core"; 2 | 3 | export interface FrontmatterProps { 4 | title: string; 5 | } 6 | 7 | export function Frontmatter(props: FrontmatterProps) { 8 | return code` 9 | --- 10 | title: ${props.title} 11 | --- 12 | 13 | import { Tabs, TabItem } from '@astrojs/starlight/components'; 14 | import { Code } from '@astrojs/starlight/components'; 15 | import { Badge } from '@astrojs/starlight/components'; 16 | 17 | 18 | `; 19 | } 20 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/component/ComponentProps.ts: -------------------------------------------------------------------------------- 1 | import type { ApiInterface } from "@microsoft/api-extractor-model"; 2 | import { InterfaceMembers, MdxSection } from "../stc/index.js"; 3 | 4 | export interface ComponentPropsProps { 5 | propType?: ApiInterface; 6 | } 7 | 8 | export function ComponentProps(props: ComponentPropsProps) { 9 | if (!props.propType) return ""; 10 | 11 | return MdxSection({ title: "Props" }).children( 12 | InterfaceMembers({ iface: props.propType, flatten: true }), 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /packages/docs/scripts/symbols/doc-symbol.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BasicSymbol, 3 | type OutputSpace, 4 | type OutputSymbolOptions, 5 | } from "@alloy-js/core"; 6 | 7 | export class DocSymbol extends BasicSymbol { 8 | #path: string; 9 | get path() { 10 | return this.#path; 11 | } 12 | 13 | constructor( 14 | name: string, 15 | spaces: OutputSpace[] | OutputSpace, 16 | path: string, 17 | options?: OutputSymbolOptions, 18 | ) { 19 | super(name, spaces, options); 20 | this.#path = path; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/json/src/components/stc/index.ts: -------------------------------------------------------------------------------- 1 | import * as core from "@alloy-js/core"; 2 | import * as Jsx from "../index.js"; 3 | 4 | export const JsonArray = core.stc(Jsx.JsonArray); 5 | export const JsonArrayElement = core.stc(Jsx.JsonArrayElement); 6 | export const JsonObject = core.stc(Jsx.JsonObject); 7 | export const JsonObjectProperty = core.stc(Jsx.JsonObjectProperty); 8 | export const JsonValue = core.stc(Jsx.JsonValue); 9 | export const Reference = core.stc(Jsx.Reference); 10 | export const SourceFile = core.stc(Jsx.SourceFile); 11 | -------------------------------------------------------------------------------- /packages/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist", 7 | "types": ["@alloy-js/core/testing/matchers"] 8 | }, 9 | "references": [{ "path": "../core" }], 10 | "include": [ 11 | "src/**/*.ts", 12 | "src/**/*.tsx", 13 | "test/**/*.ts", 14 | "test/**/*.tsx", 15 | "testing/**/*.ts", 16 | "testing/**/*.tsx" 17 | ], 18 | "exclude": ["node_modules", "dist"] 19 | } 20 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | pnpm-lock.yaml 2 | packages/babel-plugin-alloy/test/fixtures/**/* 3 | packages/babel-plugin-jsx-dom-expressions/test/__*_fixtures__/**/* 4 | 5 | # Don't format this package for now to keep closer to original 6 | packages/babel-plugin-jsx-dom-expressions/** 7 | 8 | # mostly autogenerated content 9 | packages/docs/dist 10 | packages/docs/dist-build 11 | packages/docs/public 12 | packages/docs/docs 13 | packages/docs/src 14 | packages/csharp/src/builtins 15 | 16 | 17 | .chronus/changes/ 18 | CHANGELOG.md 19 | 20 | *.generated.* -------------------------------------------------------------------------------- /packages/csharp/src/components/Declaration.tsx: -------------------------------------------------------------------------------- 1 | import * as core from "@alloy-js/core"; 2 | 3 | // properties for creating a declaration 4 | export interface DeclarationProps { 5 | name: string; 6 | refkey?: core.Refkey | core.Refkey[]; 7 | children?: core.Children; 8 | } 9 | 10 | // declares a symbol in the program (class, enum, interface etc) 11 | export function Declaration(props: DeclarationProps) { 12 | throw new Error("Not supported"); 13 | 14 | //return {props.children}; 15 | } 16 | -------------------------------------------------------------------------------- /packages/java/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { useScope } from "@alloy-js/core"; 2 | import { JavaLexicalScope } from "./symbols/java-lexical-scope.js"; 3 | 4 | export function useLexicalScope(): JavaLexicalScope | undefined { 5 | const scopeContext = useScope(); 6 | if (!scopeContext) { 7 | return undefined; 8 | } 9 | 10 | if (!(scopeContext instanceof JavaLexicalScope)) { 11 | throw new Error( 12 | "A lexical scope is required but the current scope is not a lexical scope", 13 | ); 14 | } 15 | 16 | return scopeContext; 17 | } 18 | -------------------------------------------------------------------------------- /packages/markdown/src/components/Link.tsx: -------------------------------------------------------------------------------- 1 | import { Refkey } from "@alloy-js/core"; 2 | 3 | export interface LinkPropsWithRefkey { 4 | refkey: Refkey; 5 | } 6 | 7 | export interface LinkPropsWithHref { 8 | href: string; 9 | title: string; 10 | } 11 | 12 | export type LinkProps = LinkPropsWithRefkey | LinkPropsWithHref; 13 | 14 | export function Link(props: LinkProps) { 15 | if ("refkey" in props) { 16 | return "refkey"; 17 | } 18 | 19 | return ( 20 | <> 21 | [{props.title}]({props.href}) 22 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/babel-plugin-jsx-dom-expressions 2 | 3 | ## 0.39.1 4 | 5 | ### Bug Fixes 6 | 7 | - [#255](https://github.com/alloy-framework/alloy/pull/255) Handle commented nodes 8 | 9 | 10 | ## 0.39.0 11 | 12 | ### Features 13 | 14 | - [#105](https://github.com/alloy-framework/alloy/pull/105) Updated dependencies 15 | 16 | 17 | 18 | 19 | ## 0.38.0 20 | 21 | ### Features 22 | 23 | - [#56](https://github.com/alloy-framework/alloy/pull/56) Added support for intrinsic elements. 24 | 25 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/ssr.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default; 3 | const plugin = require('../index'); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: 'r-server', 9 | builtIns: ['For', 'Show'], 10 | generate: "ssr", 11 | contextToCustomElements: true, 12 | staticMarker: "@once" 13 | }, 14 | title: 'Convert JSX', 15 | fixtures: path.join(__dirname, '__ssr_fixtures__'), 16 | snapshot: true 17 | }); 18 | -------------------------------------------------------------------------------- /packages/json/src/components/primitives.test.tsx: -------------------------------------------------------------------------------- 1 | import { jsonTest } from "#test/utils.jsx"; 2 | import "@alloy-js/core/testing"; 3 | import { expect, it } from "vitest"; 4 | 5 | it.each([ 6 | ["boolean (true)", true, "true"], 7 | ["boolean (false)", false, "false"], 8 | ["integer", 10, "10"], 9 | ["negative integer", -10, "-10"], 10 | ["float", 1.314, "1.314"], 11 | ["string", "Hello, world!", `"Hello, world!"`], 12 | ["null", null, "null"], 13 | ])("%s", (_, data, expected) => { 14 | expect(jsonTest(data)).toRenderTo(expected); 15 | }); 16 | -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Install dependencies 2 | description: Setup for node. pnpm and dependencies 3 | inputs: 4 | node-version: 5 | required: false 6 | description: Node version for setup-node 7 | default: 20.x 8 | 9 | runs: 10 | using: composite 11 | 12 | steps: 13 | - name: Install pnpm 14 | uses: pnpm/action-setup@v3 15 | 16 | - name: Set node version to ${{ inputs.node-version }} 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ inputs.node-version }} 20 | cache: pnpm 21 | -------------------------------------------------------------------------------- /packages/go/src/scopes/go.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope, OutputScopeOptions } from "@alloy-js/core"; 2 | import { PackageSymbol } from "../symbols/package.js"; 3 | 4 | export class GoScope extends OutputScope { 5 | constructor( 6 | name: string, 7 | parent: GoScope | undefined, 8 | options?: OutputScopeOptions, 9 | ) { 10 | super(name, parent, options); 11 | this.#packageSymbol = parent?.enclosingPackage; 12 | } 13 | 14 | #packageSymbol: PackageSymbol | undefined; 15 | get enclosingPackage() { 16 | return this.#packageSymbol; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_hydratable_fixtures__/flags/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 |

Hello

4 | 5 | {state.interpolation} 6 | More Text 7 |
8 | ); 9 | 10 | const template2 = ( 11 | 12 |
13 | 14 | ); 15 | 16 | const template3 = ( 17 | 18 |
19 | 20 | 21 | ); 22 | 23 | const template4 = ( 24 | <> 25 |
26 | 27 | ); -------------------------------------------------------------------------------- /packages/core/src/context/name-policy.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentContext, 3 | createNamedContext, 4 | useContext, 5 | } from "../context.js"; 6 | import type { NamePolicy } from "../name-policy.js"; 7 | 8 | export const NamePolicyContext: ComponentContext> = 9 | createNamedContext>("NamePolicy", { 10 | getName(name) { 11 | return name; 12 | }, 13 | for(element) { 14 | return (name) => name; 15 | }, 16 | }); 17 | 18 | export function useNamePolicy() { 19 | return useContext(NamePolicyContext)!; 20 | } 21 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/weird-cases/output.js: -------------------------------------------------------------------------------- 1 | function noLeadingLb() { 2 | const t1 = oh {sub} hi {sub} there how; 3 | const t2 = oh {sub} hi {sub}there; 4 | const t3 = oh {sub} hi {sub} there how; 5 | const t4 = oh {sub} hi {sub}there; 6 | } 7 | function leadingLb() { 8 | const t1 = oh {sub} hi {sub} there how; 9 | const t2 = oh {sub} hi {sub}there; 10 | } 11 | function noTrailingLb() { 12 | const t1 = oh {sub} hi {sub} there how; 13 | const t2 = oh {sub} hi {sub}there; 14 | } -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_hydratable_fixtures__/flags/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 |

Hello

4 | 5 | {state.interpolation} 6 | More Text 7 |
8 | ); 9 | 10 | const template2 = ( 11 | 12 |
13 | 14 | ); 15 | 16 | const template3 = ( 17 | 18 |
19 | 20 | 21 | ); 22 | 23 | const template4 = ( 24 | <> 25 |
26 | 27 | ); 28 | -------------------------------------------------------------------------------- /packages/core/test/name-policy.test.tsx: -------------------------------------------------------------------------------- 1 | import { createNamePolicy, Output, useNamePolicy } from "@alloy-js/core"; 2 | import { expect, it } from "vitest"; 3 | import "../testing/extend-expect.js"; 4 | 5 | it("is applied by output", () => { 6 | const policy = createNamePolicy((name) => { 7 | return "name" + name; 8 | }); 9 | 10 | function Foo() { 11 | const namer = useNamePolicy(); 12 | return namer!.getName("hi", "name"); 13 | } 14 | expect( 15 | 16 | 17 | , 18 | ).toRenderTo("namehi"); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/java/src/components/ExtendsClause.tsx: -------------------------------------------------------------------------------- 1 | import { Children, List, Show } from "@alloy-js/core"; 2 | 3 | export interface ExtendsClauseProps { 4 | extends: Children[] | undefined; 5 | } 6 | 7 | /** 8 | * The extends clause for a class or interface. 9 | */ 10 | export function ExtendsClause(props: ExtendsClauseProps) { 11 | return ( 12 | 0}> 13 | 14 |
15 | extends 16 |
17 |
18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/markdown/src/components/Heading.tsx: -------------------------------------------------------------------------------- 1 | import { Refkey } from "@alloy-js/core"; 2 | import { Children } from "@alloy-js/core/jsx-runtime"; 3 | import { useSectionContext } from "../context/section.js"; 4 | 5 | export interface HeadingProps { 6 | level?: number; 7 | children: Children; 8 | refkey?: Refkey; 9 | } 10 | 11 | export function Heading(props: HeadingProps) { 12 | const level = 13 | props.level !== undefined ? props.level : useSectionContext().level; 14 | return ( 15 | <> 16 | {"#".repeat(level)} {props.children} 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/markdown/src/context/section.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createContext, useContext } from "@alloy-js/core"; 2 | 3 | export interface SectionContext { 4 | level: number; 5 | } 6 | 7 | export const SectionContext: ComponentContext = 8 | createContext({ level: 1 }); 9 | 10 | export function useSectionContext(): SectionContext { 11 | const context = useContext(SectionContext); 12 | 13 | if (context === undefined) { 14 | throw new Error("useSectionContext must be used within a Section"); 15 | } 16 | return context; 17 | } 18 | -------------------------------------------------------------------------------- /packages/python/src/components/TypeArguments.tsx: -------------------------------------------------------------------------------- 1 | import { Children, For } from "@alloy-js/core"; 2 | 3 | export interface TypeArgumentsProps { 4 | args: Children[]; 5 | } 6 | 7 | /** 8 | * Render Python-style type arguments, e.g. [T, P]. 9 | */ 10 | export function TypeArguments(props: TypeArgumentsProps) { 11 | if (!props.args || props.args.length === 0) { 12 | return undefined; 13 | } 14 | 15 | return ( 16 | <> 17 | [ 18 | 19 | {(arg) => arg} 20 | 21 | ] 22 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_fixtures__/namespaceElements/output.js: -------------------------------------------------------------------------------- 1 | import { template as _$template } from "r-dom"; 2 | import { createComponent as _$createComponent } from "r-dom"; 3 | var _tmpl$ = /*#__PURE__*/ _$template(``); 4 | const template = _$createComponent(module.A, {}); 5 | const template2 = _$createComponent(module.a.B, {}); 6 | const template3 = _$createComponent(module.A.B, {}); 7 | const template4 = _$createComponent(module["a-b"], {}); 8 | const template5 = _$createComponent(module["a-b"]["c-d"], {}); 9 | const template6 = _tmpl$(); 10 | -------------------------------------------------------------------------------- /packages/go/src/components/Reference.tsx: -------------------------------------------------------------------------------- 1 | import { computed, emitSymbol, Refkey } from "@alloy-js/core"; 2 | import { ref } from "../symbols/index.js"; 3 | 4 | export interface ReferenceProps { 5 | refkey: Refkey; 6 | } 7 | 8 | // used to resolve refkey references within source files 9 | export function Reference({ refkey }: ReferenceProps) { 10 | const reference = ref(refkey); 11 | 12 | const computedRef = computed(() => reference()); 13 | if (computedRef.value[1]) { 14 | emitSymbol(computedRef.value[1]); 15 | } 16 | 17 | return <>{computedRef.value[0]}; 18 | } 19 | -------------------------------------------------------------------------------- /packages/typescript/src/context/package-metadata.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createNamedContext } from "@alloy-js/core"; 2 | import { TSPackageScope } from "../symbols/ts-package-scope.js"; 3 | 4 | export interface PackageMetadataContext { 5 | versionSpecifiers: Map; 6 | dependencyType: Map< 7 | TSPackageScope, 8 | "dependencies" | "peerDependencies" | "devDependencies" 9 | >; 10 | } 11 | 12 | export const PackageMetadataContext: ComponentContext = 13 | createNamedContext("PackageMetadataContext"); 14 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/src/index.js: -------------------------------------------------------------------------------- 1 | import SyntaxJSX from "@babel/plugin-syntax-jsx"; 2 | import { transformJSX } from "./shared/transform"; 3 | import postprocess from "./shared/postprocess"; 4 | import preprocess from "./shared/preprocess"; 5 | 6 | export default () => { 7 | return { 8 | name: "JSX DOM Expressions", 9 | inherits: SyntaxJSX.default, 10 | visitor: { 11 | JSXElement: transformJSX, 12 | JSXFragment: transformJSX, 13 | Program: { 14 | enter: preprocess, 15 | exit: postprocess 16 | } 17 | } 18 | }; 19 | }; 20 | -------------------------------------------------------------------------------- /packages/core/src/context/source-directory.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createNamedContext } from "../context.js"; 2 | import type { CopyFileContext, SourceFileContext } from "./source-file.js"; 3 | 4 | export interface SourceDirectoryContext { 5 | contents: (SourceDirectoryContext | SourceFileContext | CopyFileContext)[]; 6 | addContent( 7 | content: SourceDirectoryContext | SourceFileContext | CopyFileContext, 8 | ): void; 9 | path: string; 10 | } 11 | 12 | export const SourceDirectoryContext: ComponentContext = 13 | createNamedContext("SourceDirectory"); 14 | -------------------------------------------------------------------------------- /packages/core/src/context/source-file.ts: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createNamedContext } from "../context.js"; 2 | import type { Refkey } from "../refkey.js"; 3 | import { ComponentDefinition } from "../runtime/component.js"; 4 | 5 | export interface CopyFileContext { 6 | path: string; 7 | sourcePath: string; 8 | } 9 | 10 | export interface SourceFileContext { 11 | path: string; 12 | filetype: string; 13 | reference?: ComponentDefinition<{ refkey: Refkey }>; 14 | } 15 | 16 | export const SourceFileContext: ComponentContext = 17 | createNamedContext("SourceFile"); 18 | -------------------------------------------------------------------------------- /packages/typescript/src/symbols/ts-lexical-scope.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope } from "@alloy-js/core"; 2 | 3 | /** 4 | * A lexical scope for TypeScript, which contains declaration spaces for types 5 | * and values. This scope is used to hold symbols for things like variable or 6 | * interface declarations. 7 | */ 8 | export class TSLexicalScope extends OutputScope { 9 | public static readonly declarationSpaces = ["values", "types"]; 10 | 11 | get values() { 12 | return this.spaceFor("values")!; 13 | } 14 | 15 | get types() { 16 | return this.spaceFor("types")!; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/dom-hydratable.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default; 3 | const plugin = require('../index'); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: 'r-dom', 9 | builtIns: ['For', 'Show'], 10 | generate: "dom", 11 | hydratable: true, 12 | contextToCustomElements: true, 13 | staticMarker: "@once" 14 | }, 15 | title: 'Convert JSX', 16 | fixtures: path.join(__dirname, '__dom_hydratable_fixtures__'), 17 | snapshot: true 18 | }); 19 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/dom.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default; 3 | const plugin = require('../index'); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: 'r-dom', 9 | builtIns: ['For', 'Show'], 10 | generate: "dom", 11 | wrapConditionals: true, 12 | contextToCustomElements: true, 13 | staticMarker: "@once", 14 | requireImportSource: false, 15 | }, 16 | title: 'Convert JSX', 17 | fixtures: path.join(__dirname, '__dom_fixtures__'), 18 | snapshot: true 19 | }); 20 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/ssr-hydratable.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default; 3 | const plugin = require('../index'); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: 'r-server', 9 | builtIns: ['For', 'Show'], 10 | generate: "ssr", 11 | hydratable: true, 12 | contextToCustomElements: true, 13 | staticMarker: "@once" 14 | }, 15 | title: 'Convert JSX', 16 | fixtures: path.join(__dirname, '__ssr_hydratable_fixtures__'), 17 | snapshot: true 18 | }); 19 | -------------------------------------------------------------------------------- /packages/core/testing/vitest.d.ts: -------------------------------------------------------------------------------- 1 | import "vitest"; 2 | 3 | interface ToRenderToRenderOptions { 4 | printWidth?: number; 5 | tabWidth?: number; 6 | useTabs?: boolean; 7 | } 8 | 9 | interface CustomMatchers { 10 | toRenderTo: ( 11 | str: string | Record, 12 | options?: ToRenderToRenderOptions, 13 | ) => R; 14 | toRenderToAsync: ( 15 | str: string | Record, 16 | options?: ToRenderToRenderOptions, 17 | ) => Promise; 18 | } 19 | 20 | declare module "vitest" { 21 | interface Matchers extends CustomMatchers {} 22 | } 23 | -------------------------------------------------------------------------------- /packages/go/src/components/ModuleDirectory.tsx: -------------------------------------------------------------------------------- 1 | import { Children, Scope, SourceDirectory } from "@alloy-js/core"; 2 | import { createGoModuleScope } from "../scopes/module.js"; 3 | 4 | export interface ModuleDirectoryProps { 5 | children?: Children; 6 | name: string; 7 | path?: string; 8 | } 9 | 10 | export function ModuleDirectory(props: ModuleDirectoryProps) { 11 | const moduleScope = createGoModuleScope(props.name); 12 | 13 | return ( 14 | 15 | {props.children} 16 | 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/real-world-sample/output.js: -------------------------------------------------------------------------------- 1 | function emit() { 2 | return This is a sample output project.await ("./package.json");const foo = 1;const v = ;; 3 | } -------------------------------------------------------------------------------- /packages/go/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/go 2 | 3 | ## 0.2.0 4 | 5 | ### Features 6 | 7 | - [#333](https://github.com/alloy-framework/alloy/pull/333) Add build-in time module and export `createModule` function. 8 | 9 | 10 | ## 0.1.0 11 | 12 | ### Bug Fixes 13 | 14 | - [#315](https://github.com/alloy-framework/alloy/pull/315) Moved type parameters to actual symbols in a member space of named type symbols. Added `receiverSymbol` to function symbols. 15 | 16 | ### Features 17 | 18 | - [#272](https://github.com/alloy-framework/alloy/pull/272) Initial implementation of golang support for alloy. 19 | 20 | -------------------------------------------------------------------------------- /packages/python/src/symbols/python-lexical-scope.ts: -------------------------------------------------------------------------------- 1 | import { OutputScope } from "@alloy-js/core"; 2 | 3 | export class PythonLexicalScope extends OutputScope { 4 | public static readonly declarationSpaces: readonly string[] = ["symbols"]; 5 | 6 | get symbols() { 7 | return this.spaceFor("symbols")!; 8 | } 9 | 10 | // Lexical scopes do not have an owner symbol. This ensures that we get the 11 | // correct type when using `usePythonScope` (i.e. we don't get the 12 | // OutputScope's `OutputSymbol | undefined` type). 13 | get ownerSymbol(): undefined { 14 | return undefined; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/dom-wrapperless.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default; 3 | const plugin = require('../index'); 4 | 5 | pluginTester({ 6 | plugin, 7 | pluginOptions: { 8 | moduleName: 'r-dom', 9 | builtIns: ['For', 'Show'], 10 | generate: "dom", 11 | wrapConditionals: false, 12 | delegateEvents: false, 13 | effectWrapper: false, 14 | memoWrapper: false, 15 | }, 16 | title: 'Convert JSX', 17 | fixtures: path.join(__dirname, '__dom_wrapperless_fixtures__'), 18 | snapshot: true 19 | }); 20 | -------------------------------------------------------------------------------- /packages/java/src/components/ImplementsClause.tsx: -------------------------------------------------------------------------------- 1 | import { Children, List, Show } from "@alloy-js/core"; 2 | 3 | export interface ImplementsClauseProps { 4 | interfaces: Children[] | undefined; 5 | } 6 | 7 | /** 8 | * The implements clause for a class, interface, or enum. 9 | */ 10 | export function ImplementsClause(props: ImplementsClauseProps) { 11 | return ( 12 | 0}> 13 | 14 |
15 | implements 16 |
17 |
18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/markdown/src/components/Code.tsx: -------------------------------------------------------------------------------- 1 | import { List } from "@alloy-js/core"; 2 | import { Children } from "@alloy-js/core/jsx-runtime"; 3 | 4 | export interface CodeProps { 5 | /** Language of the code block */ 6 | lang?: string; 7 | 8 | /** Body of the code block */ 9 | children?: Children; 10 | } 11 | 12 | /** 13 | * Render a Markdown code block 14 | */ 15 | export function Code(props: CodeProps) { 16 | const tripleBackticks = "```"; 17 | return ( 18 | 19 | {tripleBackticks + props.lang} 20 | {props.children} 21 | {tripleBackticks} 22 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/typescript/src/components/SingleLineCommentBlock.tsx: -------------------------------------------------------------------------------- 1 | import { Prose, type Children } from "@alloy-js/core"; 2 | 3 | export interface SingleLineCommentBlockProps { 4 | children: Children; 5 | } 6 | 7 | /** 8 | * A single line comment block. The children are rendered as a prose element, which means that they 9 | * are broken into multiple lines 10 | */ 11 | export function SingleLineCommentBlock(props: SingleLineCommentBlockProps) { 12 | return ( 13 | <> 14 | //{" "} 15 | 16 | {props.children} 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog - @alloy-js/babel-plugin 2 | 3 | ## 0.2.1 4 | 5 | ### Bug Fixes 6 | 7 | - [#260](https://github.com/alloy-framework/alloy/pull/260) Fix memory leak 8 | 9 | 10 | 11 | 12 | ## 0.2.0 13 | 14 | ### Breaking Changes 15 | 16 | - [#56](https://github.com/alloy-framework/alloy/pull/56) Automatic indenting and significant literal linebreaks have been removed and replaced with explicit formatting primitives. Additionally, any amount of whitespace within text nodes is replaced by a single space. Leading and trailing whitespace in a text node is trimmed as before. 17 | 18 | -------------------------------------------------------------------------------- /packages/core/src/context/member-scope.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentContext, 3 | createNamedContext, 4 | useContext, 5 | } from "../context.js"; 6 | import { OutputSymbol } from "../symbols/output-symbol.js"; 7 | 8 | /** 9 | * The member context provides the symbol upon which new member symbols 10 | * should be created. 11 | */ 12 | export interface MemberContext { 13 | ownerSymbol: OutputSymbol; 14 | } 15 | 16 | export const MemberContext: ComponentContext = 17 | createNamedContext("MemberContext"); 18 | 19 | export function useMemberContext() { 20 | return useContext(MemberContext); 21 | } 22 | -------------------------------------------------------------------------------- /packages/typescript/src/components/CommaList.tsx: -------------------------------------------------------------------------------- 1 | import { Children, List, splitProps } from "@alloy-js/core"; 2 | 3 | export interface CommaListProps { 4 | children: Children; 5 | hardline?: boolean; 6 | softline?: boolean; 7 | } 8 | 9 | /** 10 | * A comma-separated list of items (e.g. arguments to a function call, 11 | * parameters, etc). 12 | */ 13 | export function CommaList(props: CommaListProps) { 14 | return ( 15 | 20 | {props.children} 21 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /packages/core/src/context/scope.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentContext, 3 | createNamedContext, 4 | useContext, 5 | } from "../context.js"; 6 | import type { OutputScope } from "../symbols/output-scope.js"; 7 | 8 | export const ScopeContext: ComponentContext = 9 | createNamedContext("Scope"); 10 | 11 | export function useScope() { 12 | return useContext(ScopeContext)!; 13 | } 14 | 15 | export function useMemberScope() { 16 | const scope = useScope(); 17 | if (!scope.isMemberScope) { 18 | throw new Error("Expected a member scope, but got a non-member scope."); 19 | } 20 | 21 | return scope; 22 | } 23 | -------------------------------------------------------------------------------- /packages/core/src/library-symbol-reference.ts: -------------------------------------------------------------------------------- 1 | import { RefkeyableObject } from "./refkey.js"; 2 | import { OutputSymbol } from "./symbols/output-symbol.js"; 3 | 4 | export const TO_SYMBOL: unique symbol = Symbol( 5 | "Alloy.RefkeyableObject.TO_SYMBOL", 6 | ); 7 | 8 | export interface LibrarySymbolReference extends RefkeyableObject { 9 | [TO_SYMBOL](): OutputSymbol; 10 | } 11 | 12 | export function isLibrarySymbolReference( 13 | value: unknown, 14 | ): value is LibrarySymbolReference { 15 | return ( 16 | typeof value === "object" && 17 | value !== null && 18 | Object.hasOwn(value, TO_SYMBOL) 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/Remarks.ts: -------------------------------------------------------------------------------- 1 | import type { ApiItem } from "@microsoft/api-extractor-model"; 2 | import type { DocComment } from "@microsoft/tsdoc"; 3 | import { MdxSection, TsDoc } from "./stc/index.js"; 4 | 5 | export interface RemarksProps { 6 | type: ApiItem & { tsdocComment?: DocComment }; 7 | } 8 | 9 | export function Remarks(props: RemarksProps) { 10 | if (!props.type.tsdocComment || !props.type.tsdocComment.remarksBlock) 11 | return ""; 12 | 13 | return MdxSection({ title: "Remarks" }).children( 14 | TsDoc({ node: props.type.tsdocComment.remarksBlock, context: props.type }), 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /packages/typescript/src/components/JSDoc.tsx: -------------------------------------------------------------------------------- 1 | import { List, childrenArray, type Children } from "@alloy-js/core"; 2 | import { JSDocComment } from "./JSDocComment.jsx"; 3 | 4 | export interface JSDocProps { 5 | children: Children; 6 | } 7 | 8 | /** 9 | * A JSDoc comment. The children of this component are joined with two hard 10 | * linebreaks. This is useful for creating JSDoc comments with multiple paragraphs. 11 | */ 12 | export function JSDoc(props: JSDocProps) { 13 | return ( 14 | 15 | {childrenArray(() => props.children)} 16 | 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/typescript/src/components/JSDocComment.tsx: -------------------------------------------------------------------------------- 1 | import { type Children } from "@alloy-js/core"; 2 | 3 | export interface JSDocCommentProps { 4 | children: Children; 5 | } 6 | 7 | /** 8 | * A JSDoc comment block. This is a low-level component that merely creates the 9 | * block. Consider using {@link JSDoc} if you want to create more complex 10 | * comments. 11 | */ 12 | export function JSDocComment(props: JSDocCommentProps) { 13 | return ( 14 | <> 15 | /** 16 | 17 | 18 | {props.children} 19 | 20 | */ 21 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /packages/typescript/src/context/type-ref-context.tsx: -------------------------------------------------------------------------------- 1 | import { ComponentContext, createContext, useContext } from "@alloy-js/core"; 2 | 3 | interface TypeRefContext { 4 | /** If in a type context */ 5 | type?: boolean; 6 | } 7 | 8 | /** 9 | * Provides scopes for instance and static private members. 10 | */ 11 | export const TypeRefContext: ComponentContext = 12 | createContext(); 13 | 14 | /** 15 | * @returns 'true' if in a type context, 'false' if in a value context. 16 | */ 17 | export function isTypeRefContext(): boolean { 18 | return useContext(TypeRefContext)?.type ?? false; 19 | } 20 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_fixtures__/customElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 | 3 | ); 4 | 5 | const template2 = ( 6 | 12 | ); 13 | 14 | const template3 = ( 15 | 16 |
Title
17 |
18 | ); 19 | 20 | const template4 = ( 21 | <> 22 | 23 | 24 | ); 25 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_fixtures__/customElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 | 3 | ); 4 | 5 | const template2 = ( 6 | 12 | ); 13 | 14 | const template3 = ( 15 | 16 |
Title
17 |
18 | ); 19 | 20 | const template4 = ( 21 | <> 22 | 23 | 24 | ); 25 | -------------------------------------------------------------------------------- /packages/create/deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { "package": "@alloy-js/core", "jsx": true, "stc": true }, 4 | { "package": "@alloy-js/typescript", "jsx": true, "stc": true } 5 | ], 6 | "devDependencies": [ 7 | { "package": "@alloy-js/cli", "jsx": true, "stc": false }, 8 | { "package": "@alloy-js/rollup-plugin", "jsx": true, "stc": false }, 9 | { "package": "@types/node", "jsx": true, "stc": true }, 10 | { "package": "concurrently", "jsx": true, "stc": false }, 11 | { "package": "typescript", "jsx": true, "stc": true }, 12 | { "package": "vitest", "jsx": true, "stc": true } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dynamic_fixtures__/customElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 | 3 | ); 4 | 5 | const template2 = ( 6 | 12 | ); 13 | 14 | const template3 = ( 15 | 16 |
Title
17 |
18 | ); 19 | 20 | const template4 = ( 21 | <> 22 | 23 | 24 | ); 25 | -------------------------------------------------------------------------------- /packages/java/test/package.test.tsx: -------------------------------------------------------------------------------- 1 | import { expect, it } from "vitest"; 2 | import * as jv from "../src/components/index.js"; 3 | import { findFile, testRender } from "./utils.js"; 4 | 5 | it("emits correct package directory", () => { 6 | const res = testRender( 7 | <> 8 | 9 | 10 | 11 | , 12 | ); 13 | 14 | // Assert directory file is in is correct 15 | const testFile = findFile(res, "Test.java"); 16 | expect(testFile.path).toBe("me/test/code/my/emit/package/Test.java"); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/rollup.config.js: -------------------------------------------------------------------------------- 1 | import nodeResolve from "@rollup/plugin-node-resolve"; 2 | import path from "path"; 3 | 4 | const plugins = [ 5 | nodeResolve({ 6 | rootDir: path.join(process.cwd(), "../.."), 7 | moduleDirectories: ["node_modules", "packages"] 8 | }) 9 | ]; 10 | 11 | export default { 12 | input: "src/index.js", 13 | external: ["@babel/plugin-syntax-jsx", "@babel/helper-module-imports", "@babel/types", "html-entities", "validate-html-nesting"], 14 | output: { 15 | file: "index.js", 16 | format: "cjs", 17 | exports: "auto" 18 | }, 19 | plugins 20 | }; 21 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/PackageDocs.ts: -------------------------------------------------------------------------------- 1 | import { stc, type Children } from "@alloy-js/core"; 2 | import { Scope, SourceDirectory } from "@alloy-js/core/stc"; 3 | import { PackageDocContext } from "../contexts/package-docs.js"; 4 | 5 | export interface PackageDocsProps { 6 | name: string; 7 | children?: Children; 8 | } 9 | 10 | export function PackageDocs(props: PackageDocsProps) { 11 | return stc(PackageDocContext.Provider)({ 12 | value: { name: props.name }, 13 | }).children( 14 | SourceDirectory({ path: props.name }).children( 15 | Scope({ name: props.name }).children(props.children), 16 | ), 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /samples/python-example/src/components/Model.tsx: -------------------------------------------------------------------------------- 1 | import { For, refkey } from "@alloy-js/core"; 2 | import * as py from "@alloy-js/python"; 3 | import { RestApiModel } from "../schema.js"; 4 | import { ModelProperty } from "./index.js"; 5 | 6 | interface ModelProps { 7 | model: RestApiModel; 8 | } 9 | 10 | export function Model(props: ModelProps) { 11 | return ( 12 | 13 | 14 | {(prop) => } 15 | 16 | 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_hydratable_fixtures__/customElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 | 3 | ); 4 | 5 | const template2 = ( 6 | 12 | ); 13 | 14 | const template3 = ( 15 | 16 |
Title
17 |
18 | ); 19 | 20 | const template4 = ( 21 | <> 22 | 23 | 24 | ); 25 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_hydratable_fixtures__/customElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 | 3 | ); 4 | 5 | const template2 = ( 6 | 12 | ); 13 | 14 | const template3 = ( 15 | 16 |
Title
17 |
18 | ); 19 | 20 | const template4 = ( 21 | <> 22 | 23 | 24 | ); 25 | -------------------------------------------------------------------------------- /packages/core/src/context/member-declaration.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentContext, 3 | createNamedContext, 4 | useContext, 5 | } from "../context.js"; 6 | import type { OutputSymbol } from "../symbols/output-symbol.js"; 7 | 8 | /** 9 | * Provides the symbol for the member currently being declared. 10 | * 11 | * @see {@link DeclarationContext} for getting the symbol for the current non-member declaration. 12 | */ 13 | export const MemberDeclarationContext: ComponentContext = 14 | createNamedContext("MemberDeclaration"); 15 | 16 | export function useMemberDeclaration() { 17 | return useContext(MemberDeclarationContext); 18 | } 19 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/function/FunctionReturn.ts: -------------------------------------------------------------------------------- 1 | import type { ApiFunction } from "@microsoft/api-extractor-model"; 2 | import { Excerpt, MdxSection, TsDoc } from "../stc/index.js"; 3 | 4 | export interface FunctionReturnProps { 5 | fn: ApiFunction; 6 | } 7 | 8 | export function FunctionReturn(props: FunctionReturnProps) { 9 | return MdxSection({ title: "Returns" }).children( 10 | Excerpt({ excerpt: props.fn.returnTypeExcerpt, context: props.fn }), 11 | props.fn.tsdocComment && 12 | props.fn.tsdocComment.returnsBlock && 13 | TsDoc({ node: props.fn.tsdocComment.returnsBlock, context: props.fn }), 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /samples/client-emitter/src/components/Client.tsx: -------------------------------------------------------------------------------- 1 | import { Children, For, refkey } from "@alloy-js/core"; 2 | import * as ts from "@alloy-js/typescript"; 3 | import { useApi } from "../context/api.js"; 4 | import { ClientMethod } from "./ClientMethod.jsx"; 5 | 6 | export function Client(): Children { 7 | const schema = useApi().schema; 8 | const name = `${schema.name}Client`; 9 | 10 | return ( 11 | 12 | 13 | {(op) => } 14 | 15 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/go/src/scopes/function.ts: -------------------------------------------------------------------------------- 1 | import type { OutputSpace } from "@alloy-js/core"; 2 | import { GoLexicalScope } from "./lexical.js"; 3 | 4 | export class GoFunctionScope extends GoLexicalScope { 5 | public static readonly declarationSpaces = [ 6 | "local-variables", 7 | "parameters", 8 | "type-parameters", 9 | ]; 10 | 11 | get localVariables(): OutputSpace { 12 | return this.spaceFor("local-variables")!; 13 | } 14 | 15 | get parameters(): OutputSpace { 16 | return this.spaceFor("parameters")!; 17 | } 18 | 19 | get typeParameters(): OutputSpace { 20 | return this.spaceFor("type-parameters")!; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/java/src/components/Parameters.tsx: -------------------------------------------------------------------------------- 1 | import { Children, mapJoin } from "@alloy-js/core"; 2 | 3 | export interface ParametersProps { 4 | parameters?: Record; // Map parameter name to type 5 | } 6 | 7 | /** 8 | * Render a set of parameters for a method or constructor 9 | * 10 | * @param props - Takes record of parameter name to type 11 | */ 12 | export function Parameters(props: ParametersProps) { 13 | const { parameters = {} } = props; 14 | return mapJoin( 15 | () => Object.entries(parameters), 16 | ([name, type]) => { 17 | return [type, " ", name]; 18 | }, 19 | { joiner: ", " }, 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /packages/rollup-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 2 | // @ts-expect-error 3 | import alloyPreset from "@alloy-js/babel-preset"; 4 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 5 | // @ts-expect-error 6 | import typescriptPreset from "@babel/preset-typescript"; 7 | import { babel } from "@rollup/plugin-babel"; 8 | 9 | export default function alloyPlugin(): any { 10 | return babel({ 11 | inputSourceMap: true as any, 12 | sourceMaps: "both", 13 | babelHelpers: "bundled", 14 | extensions: [".ts", ".tsx"], 15 | presets: [typescriptPreset, [alloyPreset]], 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/function/FunctionDoc.ts: -------------------------------------------------------------------------------- 1 | import type { FunctionApi } from "../../build-json.js"; 2 | import { DocSourceFile, FunctionOverloadDoc } from "../stc/index.js"; 3 | 4 | export interface FunctionDocProps { 5 | fn: FunctionApi; 6 | } 7 | 8 | export function FunctionDoc(props: FunctionDocProps) { 9 | const title = props.fn.functions[0].displayName; 10 | 11 | return DocSourceFile({ title, declares: [props.fn.functions[0]] }).children( 12 | props.fn.functions.map((fn) => 13 | FunctionOverloadDoc({ 14 | fn, 15 | omitOverloadIndex: props.fn.functions.length === 1, 16 | }), 17 | ), 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/python/src/components/UnionTypeExpression.tsx: -------------------------------------------------------------------------------- 1 | import { Children, List } from "@alloy-js/core"; 2 | 3 | export interface UnionTypeExpressionProps { 4 | children: Children; 5 | } 6 | 7 | export function UnionTypeExpression(props: UnionTypeExpressionProps) { 8 | return ( 9 | 10 | ( 11 | 12 | 13 | 17 |
|{" "} 18 | 19 | } 20 | /> 21 |
22 | 23 | ) 24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /packages/csharp/src/scopes/method.ts: -------------------------------------------------------------------------------- 1 | import type { OutputSpace } from "@alloy-js/core"; 2 | import { CSharpLexicalScope } from "./lexical.js"; 3 | 4 | export class CSharpMethodScope extends CSharpLexicalScope { 5 | public static readonly declarationSpaces = [ 6 | "local-variables", 7 | "parameters", 8 | "type-parameters", 9 | ]; 10 | 11 | get localVariables(): OutputSpace { 12 | return this.spaceFor("local-variables")!; 13 | } 14 | 15 | get parameters(): OutputSpace { 16 | return this.spaceFor("parameters")!; 17 | } 18 | 19 | get typeParameters(): OutputSpace { 20 | return this.spaceFor("type-parameters")!; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/go/src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./doc/comment.js"; 2 | export * from "./function/function.js"; 3 | export * from "./ImportStatement.js"; 4 | export * from "./interface/declaration.js"; 5 | export * from "./ModuleDirectory.js"; 6 | export * from "./Name.js"; 7 | export * from "./parameters/parameters.js"; 8 | export * from "./parameters/typeparameters.jsx"; 9 | export * from "./pointer/pointer.js"; 10 | export * from "./Reference.js"; 11 | export * from "./SourceDirectory.js"; 12 | export * from "./SourceFile.js"; 13 | export * from "./struct/declaration.js"; 14 | export * from "./type/declaration.js"; 15 | export * from "./var/declaration.js"; 16 | -------------------------------------------------------------------------------- /packages/core/src/context/binder.ts: -------------------------------------------------------------------------------- 1 | import type { Binder } from "../binder.js"; 2 | import { 3 | type ComponentContext, 4 | createNamedContext, 5 | useContext, 6 | } from "../context.js"; 7 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 8 | import type { Output } from "../components/Output.js"; 9 | 10 | /** 11 | * The binder context provides the binder instance to all components. This 12 | * context is provided by the {@link Output | output component}. 13 | */ 14 | export const BinderContext: ComponentContext = 15 | createNamedContext("Binder"); 16 | 17 | export function useBinder() { 18 | return useContext(BinderContext); 19 | } 20 | -------------------------------------------------------------------------------- /packages/java/src/components/Value.tsx: -------------------------------------------------------------------------------- 1 | import { memo } from "@alloy-js/core"; 2 | 3 | export interface ValueProps { 4 | value?: unknown; 5 | } 6 | 7 | export function Value(props: ValueProps): any { 8 | return memo(() => { 9 | const value = props.value; 10 | 11 | if (typeof value === "undefined") { 12 | return "null"; 13 | } else if (typeof value === "number" || typeof value === "boolean") { 14 | return String(value); 15 | } else if (typeof value === "string") { 16 | return `"${value}"`; 17 | } else if (typeof value === "function") { 18 | // functions are inserted as-is. 19 | return value; 20 | } 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /packages/csharp/src/components/region/region.test.tsx: -------------------------------------------------------------------------------- 1 | import { Children } from "@alloy-js/core/jsx-runtime"; 2 | import { expect, it } from "vitest"; 3 | import { TestNamespace } from "../../../test/utils.jsx"; 4 | import { Region } from "./region.jsx"; 5 | 6 | const Wrapper = (props: { name: string; children: Children }) => ( 7 | 8 | {props.children} 9 | 10 | ); 11 | 12 | it("region test", () => { 13 | expect(// This is inside region) 14 | .toRenderTo(` 15 | #region Test Region 16 | // This is inside region 17 | #endregion 18 | `); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/function/FunctionSignature.ts: -------------------------------------------------------------------------------- 1 | import { code } from "@alloy-js/core"; 2 | import type { ApiFunction } from "@microsoft/api-extractor-model"; 3 | import { cleanExcerpt } from "../../utils.js"; 4 | import { Code, MdxParagraph } from "../stc/index.js"; 5 | 6 | export interface FunctionSignatureProps { 7 | fn: ApiFunction; 8 | } 9 | 10 | export function FunctionSignature(props: FunctionSignatureProps) { 11 | const c = code` 12 | import { ${props.fn.name} } from "${props.fn.getAssociatedPackage()?.name}"; 13 | 14 | ${cleanExcerpt(props.fn.excerpt.text)} 15 | `; 16 | 17 | return MdxParagraph().children(Code({ language: "ts" }).children(c)); 18 | } 19 | -------------------------------------------------------------------------------- /packages/core/test/symbols/symbol-table.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from "vitest"; 2 | import { createScope, createSymbol } from "./utils.js"; 3 | 4 | describe("OutputSymbol#moveTo", () => { 5 | it("moves the symbol to a new symbol table", () => { 6 | const scope = createScope("scope"); 7 | const [symbol] = createSymbol("sym", scope); 8 | expect(symbol.spaces).toEqual([scope.symbols]); 9 | const newScope = createScope("new-scope"); 10 | scope.symbols.moveTo(newScope.symbols); 11 | expect(scope.symbols.has(symbol)).toBe(false); 12 | expect(newScope.symbols.has(symbol)).toBe(true); 13 | expect(symbol.spaces).toEqual([newScope.symbols]); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/Summary.ts: -------------------------------------------------------------------------------- 1 | import type { ApiItem } from "@microsoft/api-extractor-model"; 2 | import type { DocComment } from "@microsoft/tsdoc"; 3 | import { MdxParagraph, TsDoc } from "./stc/index.js"; 4 | 5 | export interface SummaryProps { 6 | type?: ApiItem & { tsdocComment?: DocComment }; 7 | } 8 | 9 | export function Summary(props: SummaryProps) { 10 | if ( 11 | !props.type || 12 | !props.type.tsdocComment || 13 | !props.type.tsdocComment.summarySection 14 | ) 15 | return ""; 16 | 17 | return MdxParagraph().children( 18 | TsDoc({ 19 | node: props.type.tsdocComment.summarySection, 20 | context: props.type, 21 | }), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_fixtures__/simpleElements/output.js: -------------------------------------------------------------------------------- 1 | import { ssr as _$ssr } from "r-server"; 2 | var _tmpl$ = 3 | '

Welcome

', 4 | _tmpl$2 = "
", 5 | _tmpl$3 = "
", 6 | _tmpl$4 = 7 | "
"; 8 | const template = _$ssr(_tmpl$); 9 | const template2 = _$ssr(_tmpl$2); 10 | const template3 = _$ssr(_tmpl$3); 11 | const template4 = _$ssr(_tmpl$4); 12 | -------------------------------------------------------------------------------- /packages/docs/public/favicon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/context/ContextInterface.ts: -------------------------------------------------------------------------------- 1 | import type { ApiInterface } from "@microsoft/api-extractor-model"; 2 | import type { ContextApi } from "../../build-json.js"; 3 | import { InterfaceMembers, MdxSection } from "../stc/index.js"; 4 | 5 | export interface ContextInterfaceProps { 6 | context: ContextApi; 7 | } 8 | 9 | export function ContextInterface(props: ContextInterfaceProps) { 10 | return MdxSection({ title: "Context interface" }).children( 11 | typeof props.context.contextInterface === "string" ? 12 | props.context.contextInterface 13 | : InterfaceMembers({ 14 | iface: props.context.contextInterface as ApiInterface, 15 | }), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/java/src/components/ImportStatement.tsx: -------------------------------------------------------------------------------- 1 | import { mapJoin, memo } from "@alloy-js/core"; 2 | 3 | export interface ImportSymbol { 4 | package: string; 5 | name?: string; 6 | wildcard?: boolean; 7 | } 8 | 9 | export interface ImportStatementsProps { 10 | imports: ImportSymbol[]; 11 | } 12 | 13 | export function ImportStatements(props: ImportStatementsProps) { 14 | return memo(() => 15 | mapJoin( 16 | () => props.imports, 17 | (importProp) => () => , 18 | ), 19 | ); 20 | } 21 | 22 | export function ImportStatement(props: ImportSymbol) { 23 | return () => `import ${props.package}.${props.wildcard ? "*" : props.name};`; 24 | } 25 | -------------------------------------------------------------------------------- /samples/client-emitter/src/components/Model.tsx: -------------------------------------------------------------------------------- 1 | import { For, refkey } from "@alloy-js/core"; 2 | import * as ts from "@alloy-js/typescript"; 3 | import { RestApiModel } from "../schema.js"; 4 | import { ModelProperty } from "./ModelProperty.jsx"; 5 | interface ModelProps { 6 | model: RestApiModel; 7 | } 8 | export function Model(props: ModelProps) { 9 | return ( 10 | 15 | 16 | {(prop) => } 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/MdxSection.ts: -------------------------------------------------------------------------------- 1 | import type { Children } from "@alloy-js/core"; 2 | import { SectionContext, useSectionContext } from "../contexts/section.js"; 3 | import { MdxParagraph } from "./stc/index.js"; 4 | 5 | export interface MdxSectionProps { 6 | title: string; 7 | children?: Children; 8 | } 9 | 10 | export function MdxSection(props: MdxSectionProps) { 11 | const sectionContext = useSectionContext(); 12 | const level = sectionContext.level + 1; 13 | return [ 14 | MdxParagraph().children("#".repeat(level) + " " + props.title), 15 | SectionContext.ProviderStc({ value: { level } }).children( 16 | MdxParagraph().children(props.children), 17 | ), 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /api-extractor.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", 3 | "apiReport": { 4 | "enabled": false 5 | }, 6 | "dtsRollup": { 7 | "enabled": false 8 | }, 9 | "docModel": { 10 | "enabled": true, 11 | "apiJsonFilePath": "/temp/api.json" 12 | }, 13 | "mainEntryPointFilePath": "/dist/src/index.d.ts", 14 | 15 | "messages": { 16 | "extractorMessageReporting": { 17 | "ae-missing-release-tag": { 18 | "logLevel": "none" 19 | } 20 | }, 21 | "compilerMessageReporting": { 22 | "TS6307": { 23 | "logLevel": "none" 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/csharp/src/components/stc/index.ts: -------------------------------------------------------------------------------- 1 | import * as core from "@alloy-js/core"; 2 | import * as base from "../index.js"; 3 | 4 | export const ClassDeclaration = core.stc(base.ClassDeclaration); 5 | export const Constructor = core.stc(base.Constructor); 6 | export const Field = core.stc(base.Field); 7 | export const ClassMethod = core.stc(base.Method); 8 | export const EnumDeclaration = core.stc(base.EnumDeclaration); 9 | export const EnumMember = core.stc(base.EnumMember); 10 | export const Parameter = core.stc(base.Parameter); 11 | export const Parameters = core.stc(base.Parameters); 12 | export const UsingDirective = core.stc(base.Usings); 13 | export const StructDeclaration = core.stc(base.StructDeclaration); 14 | -------------------------------------------------------------------------------- /packages/msbuild/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "declaration": true, 6 | "outDir": "dist", 7 | "types": ["@alloy-js/core/testing/matchers"], 8 | "paths": { 9 | "#components/*": ["./src/components/*"], 10 | "#createLibrary": ["./src/create-library.ts"], 11 | "#builtins": ["./src/builtins.ts"] 12 | } 13 | }, 14 | "references": [{ "path": "../core" }], 15 | "include": [ 16 | "src/**/*.ts", 17 | "src/**/*.tsx", 18 | "test/**/*.ts", 19 | "test/**/*.tsx", 20 | "scripts/**/*.ts", 21 | "scripts/**/*.tsx" 22 | ], 23 | "exclude": ["node_modules", "dist"] 24 | } 25 | -------------------------------------------------------------------------------- /packages/typescript/src/components/FunctionCallExpression.tsx: -------------------------------------------------------------------------------- 1 | import { Children, For, Indent, Wrap } from "@alloy-js/core"; 2 | 3 | export interface FunctionCallExpressionProps { 4 | target: Children; 5 | args?: Children[]; 6 | } 7 | 8 | export function FunctionCallExpression(props: FunctionCallExpressionProps) { 9 | return ( 10 | 11 | {props.target}( 12 | 1} 14 | with={Indent} 15 | props={{ softline: true, trailingBreak: true }} 16 | > 17 | 18 | {(arg) => arg} 19 | 20 | 21 | ) 22 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/json/src/components/reference.tsx: -------------------------------------------------------------------------------- 1 | import { Refkey } from "@alloy-js/core"; 2 | import { ref } from "../symbols/index.js"; 3 | 4 | export interface ReferenceProps { 5 | /** 6 | * The refkey for the symbol to reference. 7 | */ 8 | refkey: Refkey; 9 | } 10 | 11 | /** 12 | * Emit a reference to a JSON value by its refkey. 13 | * 14 | * @remarks 15 | * 16 | * Note that when you place a refkey in a template, the refkey will be converted 17 | * into a reference automatically. Using this component directly is generally 18 | * not required or recommended. 19 | */ 20 | export function Reference(props: ReferenceProps) { 21 | const reference = ref(props.refkey); 22 | return <>"{reference}"; 23 | } 24 | -------------------------------------------------------------------------------- /packages/python/src/name-conflict-resolver.ts: -------------------------------------------------------------------------------- 1 | import { PythonOutputSymbol } from "./symbols/python-output-symbol.js"; 2 | 3 | export function pythonNameConflictResolver( 4 | _: string, 5 | symbols: PythonOutputSymbol[], 6 | ) { 7 | for (let i = 1; i < symbols.length; i++) { 8 | // Rename all but the first symbol to have a suffix of _2, _3, plus the scope name if available. 9 | const symbol = symbols[i] as unknown as { 10 | originalName: string; 11 | name: string; 12 | module?: string; 13 | }; 14 | symbol.name = 15 | symbol.originalName + 16 | "_" + 17 | (i + 1) + 18 | "_" + 19 | (symbols[i].aliasTarget?.scope?.name ?? symbol.module ?? ""); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/java/src/components/Variable.tsx: -------------------------------------------------------------------------------- 1 | import { Children, code, Namekey } from "@alloy-js/core"; 2 | import { useJavaNamePolicy } from "../name-policy.js"; 3 | import { ModifierProps, Modifiers } from "./Modifiers.jsx"; 4 | 5 | export interface VariableProps extends ModifierProps { 6 | type: Children; 7 | name: string | Namekey; 8 | value?: Children; 9 | } 10 | 11 | export function Variable(props: VariableProps) { 12 | const name = useJavaNamePolicy().getName( 13 | typeof props.name === "string" ? props.name : props.name.name, 14 | "variable", 15 | ); 16 | const modifiers = ; 17 | 18 | return code`${modifiers}${props.type} ${name}${props.value ? code` = ${props.value}` : ""}`; 19 | } 20 | -------------------------------------------------------------------------------- /packages/python/src/components/Reference.tsx: -------------------------------------------------------------------------------- 1 | import { computed, emitSymbol, Refkey } from "@alloy-js/core"; 2 | import { ref } from "../symbols/index.js"; 3 | 4 | export interface ReferenceProps { 5 | refkey: Refkey; 6 | } 7 | 8 | /** 9 | * A Python reference to a symbol, such as a variable, function, or class. 10 | * 11 | * @remarks 12 | * This component is used to render references to symbols in Python code. 13 | * It takes a `refkey` prop which is the key of the symbol to reference. 14 | */ 15 | export function Reference({ refkey }: ReferenceProps) { 16 | const reference = ref(refkey); 17 | const symbolRef = computed(() => reference()[1]); 18 | 19 | emitSymbol(symbolRef); 20 | return <>{reference()[0]}; 21 | } 22 | -------------------------------------------------------------------------------- /packages/python/src/components/StatementList.tsx: -------------------------------------------------------------------------------- 1 | import { Children, List } from "@alloy-js/core"; 2 | 3 | export interface StatementListProps { 4 | children: Children; 5 | } 6 | 7 | /** 8 | * A Python statement list, which is a list of statements that can be rendered 9 | * in a Python source file. 10 | * 11 | * @example 12 | * ```tsx 13 | * 14 | * 15 | * 16 | * 17 | * ``` 18 | * renders to 19 | * ```py 20 | * def test(): 21 | * pass 22 | * 23 | * x = 42 24 | * ``` 25 | */ 26 | export function StatementList(props: StatementListProps) { 27 | return {props.children}; 28 | } 29 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_fixtures__/simpleElements/output.js: -------------------------------------------------------------------------------- 1 | import { template as _$template } from "r-dom"; 2 | var _tmpl$ = /*#__PURE__*/ _$template( 3 | `

Welcome

` 4 | ), 5 | _tmpl$2 = /*#__PURE__*/ _$template(`
`), 6 | _tmpl$3 = /*#__PURE__*/ _$template(`
`), 7 | _tmpl$4 = /*#__PURE__*/ _$template( 8 | `
4 | 5 | 6 | 7 | 13 | 18 |
19 | ); 20 | -------------------------------------------------------------------------------- /packages/go/src/symbols/type-parameter.ts: -------------------------------------------------------------------------------- 1 | import { Children, Namekey, OutputSpace } from "@alloy-js/core"; 2 | import { GoSymbol, GoSymbolOptions } from "./go.js"; 3 | 4 | interface TypeParameterSymbolOptions extends GoSymbolOptions { 5 | constraint?: Children; 6 | } 7 | /** 8 | * A symbol for type parameters in Go. 9 | */ 10 | export class TypeParameterSymbol extends GoSymbol { 11 | public readonly symbolKind = "type-parameter"; 12 | 13 | constructor( 14 | name: string | Namekey, 15 | spaces: OutputSpace | undefined, 16 | options: TypeParameterSymbolOptions = {}, 17 | ) { 18 | super(name, spaces, options); 19 | this.#constraint = options.constraint ?? "any"; 20 | } 21 | 22 | #constraint: Children; 23 | get constraint(): Children { 24 | return this.#constraint; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/typescript/test/if-statement.test.tsx: -------------------------------------------------------------------------------- 1 | import { d } from "@alloy-js/core/testing"; 2 | import { expect, it } from "vitest"; 3 | import { 4 | ElseClause, 5 | ElseIfClause, 6 | IfStatement, 7 | } from "../src/components/IfStatement.jsx"; 8 | import { toSourceText } from "./utils.jsx"; 9 | 10 | it("works with blocks", () => { 11 | const text = toSourceText( 12 | <> 13 | // do thing 14 | // do another thing 15 | // do default thing 16 | , 17 | ); 18 | 19 | expect(text).toBe(d` 20 | if (x === 1) { 21 | // do thing 22 | } else if (x === 2) { 23 | // do another thing 24 | } else { 25 | // do default thing 26 | } 27 | `); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/core/test/children.test.tsx: -------------------------------------------------------------------------------- 1 | import { children, Children, printTree, renderTree } from "@alloy-js/core"; 2 | import { expect, it } from "vitest"; 3 | 4 | it("handles a single element", () => { 5 | function Foo(props: { children?: Children }) { 6 | return children(() => props.children); 7 | } 8 | 9 | const res = renderTree(a b c); 10 | expect(printTree(res)).toBe("a b c"); 11 | }); 12 | 13 | it("handles a multiple elements", () => { 14 | function Foo(props: { children?: Children }) { 15 | const c = children(() => props.children); 16 | return c; 17 | } 18 | 19 | function Bar() { 20 | return "Bar"; 21 | } 22 | 23 | const res = renderTree( 24 | 25 | 26 | 27 | , 28 | ); 29 | 30 | expect(printTree(res)).toBe(`BarBar`); 31 | }); 32 | -------------------------------------------------------------------------------- /packages/markdown/src/components/Frontmatter.tsx: -------------------------------------------------------------------------------- 1 | import { List } from "@alloy-js/core"; 2 | import { Children } from "@alloy-js/core/jsx-runtime"; 3 | import { stringify } from "yaml"; 4 | 5 | export interface FrontmatterProps { 6 | /** Js value to automatically serialize as yaml */ 7 | jsValue?: Record; 8 | children?: Children; 9 | } 10 | 11 | /** 12 | * Create a frontmatter block for markdown files. 13 | * 14 | * @example 15 | * 16 | * ```markdown 17 | * --- 18 | * title: "My Title" 19 | * --- 20 | * ``` 21 | */ 22 | export function Frontmatter(props: FrontmatterProps) { 23 | return ( 24 | 25 | {"---"} 26 | {props.jsValue ? 27 | stringify(props.jsValue).trim() 28 | : } 29 | {"---"} 30 | 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /packages/core/src/components/ReferenceOrContent.tsx: -------------------------------------------------------------------------------- 1 | import { computed } from "@vue/reactivity"; 2 | import { useContext } from "../context.js"; 3 | import { BinderContext } from "../context/binder.js"; 4 | import type { Refkey } from "../refkey.js"; 5 | import type { Children } from "../runtime/component.js"; 6 | 7 | export interface ReferenceOrContentProps { 8 | readonly refkey: Refkey; 9 | readonly children: Children; 10 | } 11 | 12 | export function ReferenceOrContent(props: ReferenceOrContentProps) { 13 | const binder = useContext(BinderContext); 14 | if (!binder) { 15 | throw new Error("Need binder context to create declarations"); 16 | } 17 | 18 | const sym = binder.getSymbolForRefkey(props.refkey); 19 | return computed(() => 20 | sym.value === undefined ? props.children : props.refkey, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /packages/markdown/src/components/Section.tsx: -------------------------------------------------------------------------------- 1 | import { List } from "@alloy-js/core"; 2 | import { Children } from "@alloy-js/core/jsx-runtime"; 3 | import { SectionContext, useSectionContext } from "../context/section.js"; 4 | import { Heading } from "./Heading.jsx"; 5 | 6 | export interface SectionProps { 7 | heading?: Children; 8 | children: Children; 9 | } 10 | 11 | export function Section(props: SectionProps) { 12 | const sectionContext = useSectionContext(); 13 | 14 | return ( 15 | 16 | {props.heading && {props.heading}} 17 | 20 | {props.children} 21 | 22 | 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/python/src/components/PythonBlock.tsx: -------------------------------------------------------------------------------- 1 | import { Block, Children } from "@alloy-js/core"; 2 | 3 | export interface PythonBlockProps { 4 | children: Children; 5 | opener?: string; 6 | } 7 | 8 | /** 9 | * A Python block component that can be used to render a block of Python code. 10 | * 11 | * @example 12 | * ```tsx 13 | * 14 | * 15 | * 16 | * 17 | * ``` 18 | * renders to 19 | * ```py 20 | * def my_function(): 21 | * x: int = None 22 | * y: str = None 23 | * ``` 24 | */ 25 | export function PythonBlock(props: PythonBlockProps) { 26 | return ( 27 | 28 | {props.children} 29 | 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/variable/VariableDoc.ts: -------------------------------------------------------------------------------- 1 | import type { VariableApi } from "../../build-json.js"; 2 | import { 3 | DocSourceFile, 4 | Examples, 5 | Excerpt, 6 | Remarks, 7 | SeeAlso, 8 | Summary, 9 | } from "../stc/index.js"; 10 | 11 | export interface VariableDocProps { 12 | variable: VariableApi; 13 | } 14 | 15 | export function VariableDoc(props: VariableDocProps) { 16 | const apiVariable = props.variable.variable; 17 | 18 | const title = props.variable.variable.displayName; 19 | 20 | return DocSourceFile({ title, declares: apiVariable }).children( 21 | Summary({ type: apiVariable }), 22 | Excerpt({ excerpt: apiVariable.excerpt, context: apiVariable }), 23 | Remarks({ type: apiVariable }), 24 | Examples({ type: apiVariable }), 25 | SeeAlso({ type: apiVariable }), 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/prepare-release-pr.yml: -------------------------------------------------------------------------------- 1 | name: Prepare Auto Release Branch 2 | 3 | # Disable as MS Org doesn't allow github action to create PR anymore. Can be re-added if a solution is found. 4 | on: 5 | push: 6 | branches: 7 | - main 8 | 9 | concurrency: ${{ github.workflow }}-${{ github.ref }} 10 | 11 | permissions: 12 | pull-requests: write 13 | contents: write 14 | 15 | jobs: 16 | release: 17 | name: Release 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Checkout Repo 21 | uses: actions/checkout@v2 22 | 23 | - uses: ./.github/actions/setup 24 | 25 | - run: pnpm install 26 | name: Install dependencies 27 | 28 | - name: Create release branch 29 | run: pnpm tsx ./eng/prepare-release-pr.ts 30 | env: 31 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 32 | -------------------------------------------------------------------------------- /samples/client-emitter/src/context/api.ts: -------------------------------------------------------------------------------- 1 | import { createContext, useContext } from "@alloy-js/core"; 2 | import { RestApi, RestApiModel, RestApiModelReference } from "../schema.js"; 3 | 4 | interface ApiContext { 5 | schema: RestApi; 6 | resolveReference: (ref: RestApiModelReference) => RestApiModel | undefined; 7 | } 8 | export const ApiContext = createContext(); 9 | 10 | export function useApi(): ApiContext { 11 | return useContext(ApiContext)!; 12 | } 13 | 14 | export function createApiContext(schema: RestApi): ApiContext { 15 | return { 16 | schema, 17 | resolveReference(node) { 18 | const model = schema.models.find((v) => v.name === node.ref); 19 | 20 | if (!model) { 21 | throw new Error(`Unresolved reference ${node.ref}`); 22 | } 23 | 24 | return model; 25 | }, 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /packages/babel-plugin-alloy/test/fixtures/real-world-sample/code.js: -------------------------------------------------------------------------------- 1 | function emit() { 2 | return ( 3 | 4 | 5 | 6 | This is a sample output project. 7 | 8 | 9 | 10 | await ("./package.json"); 11 | 12 | const foo = 1; 13 | 14 | 15 | 16 | 17 | const v = ; 18 | 19 | 20 | 21 | ) 22 | } -------------------------------------------------------------------------------- /packages/core/test/control-flow/show.test.tsx: -------------------------------------------------------------------------------- 1 | import "@alloy-js/core/testing"; 2 | import { ref } from "@vue/reactivity"; 3 | import { expect, it } from "vitest"; 4 | import { Show } from "../../src/components/Show.jsx"; 5 | import { printTree, renderTree } from "../../src/render.js"; 6 | 7 | it("selects the true branch", () => { 8 | const template = true; 9 | expect(template).toRenderTo(`true`); 10 | }); 11 | 12 | it("works with reactivity", () => { 13 | const count = ref(0); 14 | const template = ( 15 | 16 | even 17 | 18 | ); 19 | const tree = renderTree(template); 20 | expect(printTree(tree)).toBe(`even`); 21 | count.value++; 22 | expect(printTree(tree)).toBe(`odd`); 23 | count.value++; 24 | expect(printTree(tree)).toBe(`even`); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/java/src/components/ArgumentList.tsx: -------------------------------------------------------------------------------- 1 | import { Children, For, Indent } from "@alloy-js/core"; 2 | 3 | export interface ArgumentListProps { 4 | args?: Children[]; 5 | omitParensWhenEmpty?: boolean; 6 | } 7 | 8 | /** 9 | * A list of arguments to be passed to a function, constructor, enum, and so 10 | * forth. Includes parenthesis when arguments are passed, otherwise returns an 11 | * empty string. 12 | */ 13 | export function ArgumentList(props: ArgumentListProps) { 14 | if (props.omitParensWhenEmpty && (!props.args || props.args.length === 0)) { 15 | return ""; 16 | } 17 | 18 | return ( 19 | 20 | ( 21 | 22 | 23 | {(value) => value} 24 | 25 | 26 | ) 27 | 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /packages/core/test/reactivity/untrack.test.ts: -------------------------------------------------------------------------------- 1 | import { ref } from "@vue/reactivity"; 2 | import { expect, it } from "vitest"; 3 | import { memo, untrack } from "../../src/reactivity.js"; 4 | import { flushJobs } from "../../src/scheduler.js"; 5 | 6 | it("ignores signals for dependency tracking", () => { 7 | const signal = ref(0); 8 | 9 | const m = memo(() => { 10 | return untrack(() => signal.value); 11 | }); 12 | 13 | expect(m()).toBe(0); 14 | 15 | signal.value = 1; 16 | flushJobs(); 17 | 18 | expect(m()).toBe(0); 19 | }); 20 | 21 | it("doesn't affect signal changes", () => { 22 | const signal = ref(0); 23 | 24 | const m = memo(() => { 25 | return signal.value; 26 | }); 27 | 28 | expect(m()).toBe(0); 29 | 30 | untrack(() => { 31 | signal.value = 1; 32 | }); 33 | flushJobs(); 34 | 35 | expect(m()).toBe(1); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/context/ContextFactory.ts: -------------------------------------------------------------------------------- 1 | import { code } from "@alloy-js/core"; 2 | import type { ContextApi } from "../../build-json.js"; 3 | import { FunctionSignature, MdxSection, Summary } from "../stc/index.js"; 4 | 5 | export interface ContextFactoryProps { 6 | context: ContextApi; 7 | } 8 | 9 | export function ContextFactory(props: ContextFactoryProps) { 10 | const { contextFactory } = props.context; 11 | if (!contextFactory) return null; 12 | 13 | const section = MdxSection({ title: "Factory" }); 14 | 15 | const c = code` 16 | import { ${contextFactory.displayName} } from "@alloy-js/core"; 17 | 18 | const myContext = ${contextFactory.displayName}(); 19 | `; 20 | 21 | return section.children( 22 | FunctionSignature({ fn: contextFactory }), 23 | Summary({ type: contextFactory }), 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /packages/core/src/components/index.tsx: -------------------------------------------------------------------------------- 1 | export * from "./AppendFile.jsx"; 2 | export * from "./Block.js"; 3 | export * from "./CopyFile.jsx"; 4 | export * from "./Declaration.js"; 5 | export * from "./For.js"; 6 | export * from "./Indent.jsx"; 7 | export * from "./List.jsx"; 8 | export * from "./MemberDeclaration.jsx"; 9 | export * from "./MemberName.jsx"; 10 | export * from "./MemberScope.jsx"; 11 | export * from "./Name.jsx"; 12 | export * from "./Output.js"; 13 | export * from "./Prose.jsx"; 14 | export * from "./ReferenceOrContent.jsx"; 15 | export * from "./Scope.js"; 16 | export * from "./Show.jsx"; 17 | export * from "./SourceDirectory.js"; 18 | export * from "./SourceFile.js"; 19 | export * from "./StatementList.jsx"; 20 | export * from "./Switch.jsx"; 21 | export * from "./TemplateFile.jsx"; 22 | export * from "./UpdateFile.jsx"; 23 | export * from "./Wrap.jsx"; 24 | -------------------------------------------------------------------------------- /packages/typescript/test/block-scope.test.tsx: -------------------------------------------------------------------------------- 1 | import { d } from "@alloy-js/core/testing"; 2 | import { expect, it } from "vitest"; 3 | import { BlockScope } from "../src/components/BlockScope.jsx"; 4 | import { VarDeclaration } from "../src/index.js"; 5 | import { toSourceText } from "./utils.jsx"; 6 | 7 | it("creates a scope", () => { 8 | const text = toSourceText( 9 | <> 10 | ; 11 | 12 | ; 13 | 14 | , 15 | ); 16 | 17 | expect(text).toBe(d` 18 | const x = hi; 19 | { 20 | const x = hello; 21 | } 22 | `); 23 | }); 24 | 25 | it("renders an empty block properly", () => { 26 | const text = toSourceText(); 27 | 28 | expect(text).toBe("{}"); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/babel-preset-alloy/index.js: -------------------------------------------------------------------------------- 1 | import alloyTransform from "@alloy-js/babel-plugin"; 2 | import jsxTransform from "@alloy-js/babel-plugin-jsx-dom-expressions"; 3 | 4 | export default function (context, options = {}) { 5 | const defaultOptions = { 6 | alloyModuleName: "@alloy-js/core", 7 | moduleName: "@alloy-js/core/jsx-runtime", 8 | generate: "universal", 9 | wrapConditionals: true, 10 | preserveWhitespace: true, 11 | }; 12 | 13 | const plugins = [ 14 | [ 15 | alloyTransform, 16 | { 17 | alloyModuleName: 18 | options.alloyModuleName ?? defaultOptions.alloyModuleName, 19 | legacyWhitespace: 20 | options.legacyWhitespace ?? defaultOptions.legacyWhitespace, 21 | }, 22 | ], 23 | [jsxTransform, Object.assign(defaultOptions, options)], 24 | ]; 25 | 26 | return { plugins }; 27 | } 28 | -------------------------------------------------------------------------------- /packages/java/src/components/ObjectDeclaration.tsx: -------------------------------------------------------------------------------- 1 | import { Children, code } from "@alloy-js/core"; 2 | import { ArgumentList } from "./ArgumentList.jsx"; 3 | import { CommonDeclarationProps } from "./Declaration.js"; 4 | import { ModifierProps } from "./Modifiers.jsx"; 5 | import { Variable } from "./Variable.js"; 6 | 7 | export interface ObjectDeclarationProps 8 | extends CommonDeclarationProps, 9 | ModifierProps { 10 | type: Children; 11 | args?: Children[]; 12 | } 13 | 14 | /** 15 | * Shorthand to instantiate a new object. 16 | * Declares it with 'new' and passes arguments to the constructor of the object, if any 17 | */ 18 | export function ObjectDeclaration(props: ObjectDeclarationProps) { 19 | const args = ; 20 | const value = code`new ${props.type}${args}`; 21 | return ; 22 | } 23 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_hydratable_fixtures__/simpleElements/output.js: -------------------------------------------------------------------------------- 1 | import { template as _$template } from "r-dom"; 2 | import { getNextElement as _$getNextElement } from "r-dom"; 3 | var _tmpl$ = /*#__PURE__*/ _$template( 4 | `

Welcome

` 5 | ), 6 | _tmpl$2 = /*#__PURE__*/ _$template(`
`), 7 | _tmpl$3 = /*#__PURE__*/ _$template(`
`), 8 | _tmpl$4 = /*#__PURE__*/ _$template( 9 | `
' 6 | ], 7 | _tmpl$2 = ["
"], 8 | _tmpl$3 = ["
"], 9 | _tmpl$4 = [ 10 | "
" 12 | ]; 13 | const template = _$ssr(_tmpl$, _$ssrHydrationKey()); 14 | const template2 = _$ssr(_tmpl$2, _$ssrHydrationKey()); 15 | const template3 = _$ssr(_tmpl$3, _$ssrHydrationKey()); 16 | const template4 = _$ssr(_tmpl$4, _$ssrHydrationKey()); 17 | -------------------------------------------------------------------------------- /samples/client-emitter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@alloy-js/sample-client-emitter", 3 | "private": "true", 4 | "version": "1.0.0", 5 | "description": "", 6 | "main": "index.js", 7 | "scripts": { 8 | "build": "alloy build", 9 | "clean": "rimraf dist/ .temp/", 10 | "watch": "alloy build --watch" 11 | }, 12 | "keywords": [], 13 | "author": "brian.terlson@microsoft.com", 14 | "license": "MIT", 15 | "dependencies": { 16 | "@alloy-js/core": "workspace:~", 17 | "@alloy-js/typescript": "workspace:~", 18 | "@alloy-js/java": "workspace:~" 19 | }, 20 | "devDependencies": { 21 | "@alloy-js/cli": "workspace:~", 22 | "@alloy-js/rollup-plugin": "workspace:~", 23 | "@rollup/plugin-typescript": "catalog:", 24 | "@types/node": "catalog:", 25 | "concurrently": "catalog:", 26 | "typescript": "catalog:", 27 | "vitest": "catalog:" 28 | }, 29 | "type": "module" 30 | } 31 | -------------------------------------------------------------------------------- /packages/python/src/parameter-descriptor.ts: -------------------------------------------------------------------------------- 1 | import type { Children, Namekey, Refkey } from "@alloy-js/core"; 2 | 3 | /** 4 | * Information for a Python function parameter. 5 | */ 6 | export interface ParameterDescriptor { 7 | /** 8 | * The name of the parameter. 9 | */ 10 | readonly name: string | Namekey; 11 | 12 | /** 13 | * The type of the parameter. 14 | */ 15 | readonly type?: Children; 16 | 17 | /** 18 | * The refkey for this parameter. 19 | */ 20 | readonly refkey?: Refkey | Refkey[]; 21 | 22 | /** 23 | * Documentation for the parameter. 24 | */ 25 | readonly doc?: Children; 26 | 27 | /** 28 | * The default value of the parameter. 29 | */ 30 | readonly default?: Children; 31 | } 32 | 33 | export function isParameterDescriptor( 34 | param: unknown, 35 | ): param is ParameterDescriptor { 36 | return typeof param === "object" && param !== null && "name" in param; 37 | } 38 | -------------------------------------------------------------------------------- /.github/copilot-instructions.md: -------------------------------------------------------------------------------- 1 | ## Working with Alloy Jsx files 2 | 3 | This repository is built on alloy which use JSX to define components. This is NOT the same as React JSX, so you should not use React JSX syntax. 4 | 5 | - Alloy syntax 6 | - Base elements are to be imported from `@alloy-js/core` 7 | - A generic node is defined as `Children` 8 | - Use `<>` instead of `` 9 | - DO NOT use any html elements like `
`, ``, etc. Use Alloy components instead. 10 | - Use `code` string template function to render raw string content 11 | - Components should be structured as followed: 12 | - in a `components` folder in the package 13 | - file should use `kebab-case` for the file name 14 | - component should be named using `PascalCase` 15 | - if component needs props, an interface should be defined with the name `Props` 16 | - DO NOT destructure props in the component definition 17 | -------------------------------------------------------------------------------- /samples/python-example/src/context/api.ts: -------------------------------------------------------------------------------- 1 | import { createContext, useContext } from "@alloy-js/core"; 2 | import { RestApi, RestApiModel, RestApiModelReference } from "../schema.js"; 3 | 4 | // context interface 5 | export interface ApiContext { 6 | schema: RestApi; 7 | resolveReference: (ref: RestApiModelReference) => RestApiModel | undefined; 8 | } 9 | 10 | // context variable 11 | export const ApiContext = createContext(); 12 | 13 | // context accessor 14 | export function useApi(): ApiContext { 15 | return useContext(ApiContext)!; 16 | } 17 | 18 | export function createApiContext(schema: RestApi): ApiContext { 19 | return { 20 | schema, 21 | resolveReference(node) { 22 | const model = schema.models.find((v) => v.name === node.ref); 23 | 24 | if (!model) { 25 | throw new Error(`Unresolved reference ${node.ref}`); 26 | } 27 | 28 | return model; 29 | }, 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); 45 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); 45 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__universal_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); -------------------------------------------------------------------------------- /packages/java/src/components/Constructor.tsx: -------------------------------------------------------------------------------- 1 | import { Block } from "@alloy-js/core"; 2 | import { Children } from "@alloy-js/core/jsx-runtime"; 3 | import { ModifierProps, Modifiers } from "./Modifiers.jsx"; 4 | import { Name } from "./Name.js"; 5 | import { Parameters } from "./Parameters.js"; 6 | 7 | export interface ConstructorProps extends ModifierProps { 8 | name?: string; 9 | parameters?: Record; // Map of parameter name to type 10 | children?: Children; 11 | } 12 | 13 | /** 14 | * Declare a constructor, usually for a class or enum 15 | * If no name is provided, will try take name from class or enum declaration 16 | */ 17 | export function Constructor(props: ConstructorProps) { 18 | return ( 19 | <> 20 | 21 | {props.name ?? }( 22 | ){" "} 23 | {props.children} 24 | 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/commenter.yml: -------------------------------------------------------------------------------- 1 | name: Make Change Comment 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["Check Changes"] 6 | types: 7 | - completed 8 | 9 | permissions: 10 | pull-requests: write 11 | 12 | jobs: 13 | commenter: 14 | if: ${{ github.actor != 'dependabot[bot]' && !startsWith(github.head_ref, 'publish/') }} 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/download-artifact@v4 19 | with: 20 | name: comment 21 | run-id: ${{github.event.workflow_run.id }} 22 | github-token: ${{secrets.GITHUB_TOKEN}} 23 | - uses: ./.github/actions/setup 24 | 25 | - run: pnpm install 26 | name: Install dependencies 27 | 28 | - run: pnpm chronus-github-pr-commenter --comment-file comment.json 29 | env: 30 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 31 | name: Create/update comment 32 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dom_hydratable_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__dynamic_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); 45 | -------------------------------------------------------------------------------- /packages/babel-plugin-jsx-dom-expressions/test/__ssr_hydratable_fixtures__/simpleElements/code.js: -------------------------------------------------------------------------------- 1 | const template = ( 2 |
3 | 4 |

Welcome

5 | 6 | 7 | {/* Comment Node */} 8 |
9 | ); 10 | 11 | const template2 = ( 12 |
13 | 14 | 15 | 16 | 17 |
18 | ); 19 | 20 | const template3 = ( 21 |
22 |
23 | 24 | 25 |
26 |
27 |
28 |
29 | ); 30 | 31 | const template4 = ( 32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 42 |
43 |
44 | ); -------------------------------------------------------------------------------- /packages/java/src/name-policy.ts: -------------------------------------------------------------------------------- 1 | import { createNamePolicy, NamePolicy, useNamePolicy } from "@alloy-js/core"; 2 | import { camelCase, constantCase, pascalCase } from "change-case"; 3 | 4 | export type JavaElements = 5 | | "class" 6 | | "interface" 7 | | "enum" 8 | | "enum-member" 9 | | "function" 10 | | "parameter" 11 | | "constant" 12 | | "variable" 13 | | "method"; 14 | 15 | export function createJavaNamePolicy(): NamePolicy { 16 | return createNamePolicy((name, element) => { 17 | switch (element) { 18 | case "class": 19 | case "interface": 20 | case "enum": 21 | return pascalCase(name); 22 | case "enum-member": 23 | case "constant": 24 | return constantCase(name); 25 | default: 26 | return camelCase(name); 27 | } 28 | }); 29 | } 30 | 31 | export function useJavaNamePolicy(): NamePolicy { 32 | return useNamePolicy(); 33 | } 34 | -------------------------------------------------------------------------------- /packages/json/src/context/JsonFileContext.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentContext, 3 | createNamedContext, 4 | useContext, 5 | } from "@alloy-js/core"; 6 | import { JsonOutputSymbol } from "../symbols/json-symbol.js"; 7 | 8 | export interface JsonFileContext { 9 | /** The path of the current JSON file. May be different from the path on disk. */ 10 | path?: string; 11 | 12 | /** The URL of the current JSON file */ 13 | url?: string; 14 | 15 | /** The symbol for the value in this JSON file */ 16 | symbol: JsonOutputSymbol; 17 | } 18 | 19 | /** 20 | * Provides information about the current JSON source file. This context is used 21 | * to allow references between JSON files. 22 | */ 23 | export const JsonFileContext: ComponentContext = 24 | createNamedContext("JsonFile"); 25 | 26 | export function useJsonFileContext(): JsonFileContext | undefined { 27 | return useContext(JsonFileContext); 28 | } 29 | -------------------------------------------------------------------------------- /packages/docs/scripts/components/type/TypeDoc.ts: -------------------------------------------------------------------------------- 1 | import { ApiInterface, ApiItemKind } from "@microsoft/api-extractor-model"; 2 | import type { TypeApi } from "../../build-json.js"; 3 | import { 4 | DocSourceFile, 5 | Examples, 6 | Excerpt, 7 | Remarks, 8 | SeeAlso, 9 | Summary, 10 | TypeMembers, 11 | } from "../stc/index.js"; 12 | 13 | export interface TypeDocProps { 14 | type: TypeApi; 15 | } 16 | 17 | export function TypeDoc(props: TypeDocProps) { 18 | const apiType = props.type.type; 19 | const title = apiType.displayName; 20 | 21 | return DocSourceFile({ title, declares: [apiType] }).children( 22 | Summary({ type: apiType }), 23 | apiType.kind === ApiItemKind.TypeAlias ? 24 | Excerpt({ excerpt: apiType.excerpt, context: apiType }) 25 | : TypeMembers({ type: apiType as ApiInterface }), 26 | Remarks({ type: apiType }), 27 | Examples({ type: apiType }), 28 | SeeAlso({ type: apiType }), 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /packages/python/src/builtins/python.ts: -------------------------------------------------------------------------------- 1 | import { SymbolCreator } from "@alloy-js/core"; 2 | import { createModule } from "../create-module.js"; 3 | 4 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 5 | type dummy = SymbolCreator; 6 | 7 | export const abcModule = createModule({ 8 | name: "abc", 9 | descriptor: { 10 | ".": ["abstractmethod"], 11 | }, 12 | }); 13 | 14 | export const dataclassesModule = createModule({ 15 | name: "dataclasses", 16 | descriptor: { 17 | ".": ["dataclass", "KW_ONLY"], 18 | }, 19 | }); 20 | 21 | export const enumModule = createModule({ 22 | name: "enum", 23 | descriptor: { 24 | ".": ["auto", "Enum", "Flag", "IntEnum", "IntFlag", "StrEnum"], 25 | }, 26 | }); 27 | 28 | export const requestsModule = createModule({ 29 | name: "requests", 30 | descriptor: { 31 | ".": ["get", "post", "put", "delete", "patch", "head", "options"], 32 | models: ["Response", "Request"], 33 | }, 34 | }); 35 | -------------------------------------------------------------------------------- /test/performance/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "performance", 3 | "private": true, 4 | "version": "1.0.0", 5 | "description": "", 6 | "main": "index.js", 7 | "scripts": { 8 | "build": "alloy build", 9 | "bench": "pnpm run build && node dist/src/index.js" 10 | }, 11 | "devDependencies": { 12 | "@alloy-js/cli": "workspace:~", 13 | "@alloy-js/core": "workspace:~", 14 | "@alloy-js/csharp": "workspace:~", 15 | "@alloy-js/rollup-plugin": "workspace:~", 16 | "@alloy-js/typescript": "workspace:~", 17 | "@rollup/plugin-typescript": "catalog:", 18 | "@types/node": "catalog:", 19 | "cli-table3": "catalog:", 20 | "concurrently": "catalog:", 21 | "listr2": "^9.0.3", 22 | "typescript": "catalog:" 23 | }, 24 | "keywords": [], 25 | "author": "", 26 | "license": "ISC", 27 | "packageManager": "pnpm@10.13.1", 28 | "type": "module", 29 | "dependencies": { 30 | "picocolors": "catalog:" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/typescript/src/components/ExportStatement.tsx: -------------------------------------------------------------------------------- 1 | import { dirname, relative } from "pathe"; 2 | import { TSModuleScope, TSOutputSymbol } from "../symbols/index.js"; 3 | import { modulePath } from "../utils.js"; 4 | import { useSourceFile } from "./SourceFile.js"; 5 | 6 | export interface ExportStatementProps { 7 | star?: boolean; 8 | from?: TSModuleScope; 9 | } 10 | 11 | export function ExportStatement(props: ExportStatementProps) { 12 | if (props.star) { 13 | const module = useSourceFile(); 14 | const allSymbols = props.from!.getAllSymbols(); 15 | for (const symbol of allSymbols) { 16 | for (const refkey of symbol.refkeys) { 17 | module.scope.exportedSymbols.set(refkey, symbol as TSOutputSymbol); 18 | } 19 | } 20 | return ( 21 | <> 22 | export * from " 23 | {modulePath(relative(dirname(module.scope.name), props.from!.name))}"; 24 | 25 | ); 26 | } 27 | 28 | return ""; 29 | } 30 | -------------------------------------------------------------------------------- /packages/csharp/src/components/namespace/namespace-name.tsx: -------------------------------------------------------------------------------- 1 | import { useNamespaceContext } from "../../contexts/namespace.js"; 2 | import { NamespaceSymbol } from "../../symbols/namespace.js"; 3 | 4 | /** @internal */ 5 | export interface NamespaceNameProps { 6 | symbol: NamespaceSymbol; 7 | 8 | /** If it should print relative to the parent context */ 9 | relative?: boolean; 10 | } 11 | 12 | /** @internal */ 13 | export function NamespaceName(props: NamespaceNameProps) { 14 | const names = [props.symbol.name]; 15 | const parent = props.relative ? useNamespaceContext()?.symbol : undefined; 16 | 17 | let current = props.symbol.ownerSymbol; 18 | while (current) { 19 | if ( 20 | current === parent || 21 | !(current instanceof NamespaceSymbol) || 22 | current.isGlobal 23 | ) { 24 | break; 25 | } 26 | names.unshift(current.name); 27 | current = current.ownerSymbol; 28 | } 29 | 30 | return names.join("."); 31 | } 32 | -------------------------------------------------------------------------------- /packages/python/src/components/FunctionCallExpression.tsx: -------------------------------------------------------------------------------- 1 | import { Children, For, Indent, Wrap } from "@alloy-js/core"; 2 | 3 | export interface FunctionCallExpressionProps { 4 | target: Children; 5 | args?: Children[]; 6 | } 7 | 8 | /** 9 | * A Python function call expression. 10 | * 11 | * @example 12 | * ```tsx 13 | * 14 | * ``` 15 | * This will generate: 16 | * ```python 17 | * foo(arg1, arg2) 18 | * ``` 19 | */ 20 | export function FunctionCallExpression(props: FunctionCallExpressionProps) { 21 | return ( 22 | 23 | {props.target}( 24 | 1} 26 | with={Indent} 27 | props={{ softline: true, trailingBreak: true }} 28 | > 29 | 30 | {(arg) => arg} 31 | 32 | 33 | ) 34 | 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /samples/client-emitter/src/components/ModelProperty.tsx: -------------------------------------------------------------------------------- 1 | import { Children, refkey } from "@alloy-js/core"; 2 | import * as ts from "@alloy-js/typescript"; 3 | import { useApi } from "../context/api.js"; 4 | import { RestApiModelProperty } from "../schema.js"; 5 | import { Model } from "./Model.jsx"; 6 | 7 | interface ModelPropertyProps { 8 | property: RestApiModelProperty; 9 | } 10 | 11 | export function ModelProperty(props: ModelPropertyProps) { 12 | let memberType: Children; 13 | 14 | const apiType = props.property.type; 15 | 16 | if (typeof apiType === "object") { 17 | if ("ref" in apiType) { 18 | const apiContext = useApi(); 19 | const model = apiContext.resolveReference(apiType); 20 | memberType = refkey(model); 21 | } else { 22 | memberType = ; 23 | } 24 | } else { 25 | memberType = apiType; 26 | } 27 | 28 | return ; 29 | } 30 | --------------------------------------------------------------------------------