@barefootjs/go-template 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Go Template test renderer
3
+ *
4
+ * Compiles JSX source with GoTemplateAdapter and renders to HTML via `go run`.
5
+ * Used by adapter-tests conformance runner.
6
+ */
7
+ import type { TemplateAdapter } from '@barefootjs/jsx';
8
+ export declare class GoNotAvailableError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ export interface RenderOptions {
12
+ /** JSX source code */
13
+ source: string;
14
+ /** Template adapter to use */
15
+ adapter: TemplateAdapter;
16
+ /** Props to inject (optional) */
17
+ props?: Record<string, unknown>;
18
+ /** Additional component files (filename → source) */
19
+ components?: Record<string, string>;
20
+ }
21
+ export declare function renderGoTemplateComponent(options: RenderOptions): Promise<string>;
22
+ //# sourceMappingURL=test-render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-render.d.ts","sourceRoot":"","sources":["../src/test-render.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,iBAAiB,CAAA;AAOnE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAgCD,MAAM,WAAW,aAAa;IAC5B,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,8BAA8B;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACpC;AAED,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAmNvF"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@barefootjs/go-template",
3
+ "version": "0.1.0",
4
+ "description": "Go html/template adapter for BarefootJS - generates Go template files from IR",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./adapter": {
14
+ "types": "./dist/adapter/index.d.ts",
15
+ "import": "./dist/adapter/index.js"
16
+ },
17
+ "./test-render": {
18
+ "bun": "./src/test-render.ts"
19
+ },
20
+ "./build": {
21
+ "types": "./dist/build.d.ts",
22
+ "import": "./dist/build.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src"
28
+ ],
29
+ "scripts": {
30
+ "build": "bun run build:js && bun run build:types",
31
+ "build:js": "bun build ./src/index.ts ./src/adapter/index.ts ./src/build.ts --root ./src --outdir ./dist --format esm --external @barefootjs/jsx --external @barefootjs/shared --external typescript",
32
+ "build:types": "tsgo --emitDeclarationOnly --outDir ./dist",
33
+ "test": "bun test",
34
+ "clean": "rm -rf dist",
35
+ "prepack": "node ../../scripts/swap-publish-config.mjs pack",
36
+ "postpack": "node ../../scripts/swap-publish-config.mjs unpack"
37
+ },
38
+ "keywords": [
39
+ "go",
40
+ "template",
41
+ "barefoot",
42
+ "ssr"
43
+ ],
44
+ "author": "kobaken <kentafly88@gmail.com>",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/piconic-ai/barefootjs",
49
+ "directory": "packages/adapter-go-template"
50
+ },
51
+ "peerDependencies": {
52
+ "@barefootjs/jsx": "workspace:*",
53
+ "typescript": "^5.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@barefootjs/adapter-tests": "workspace:*",
57
+ "@barefootjs/jsx": "workspace:*"
58
+ }
59
+ }
@@ -0,0 +1,65 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { deduplicateGoTypes } from '../build'
3
+
4
+ describe('deduplicateGoTypes', () => {
5
+ test('deduplicates NewXxxProps with single-line doc comment', () => {
6
+ const input = [
7
+ '// NewFooProps creates FooProps from FooInput.',
8
+ 'func NewFooProps(in FooInput) FooProps {',
9
+ '\treturn FooProps{}',
10
+ '}',
11
+ '',
12
+ '// NewFooProps creates FooProps from FooInput.',
13
+ 'func NewFooProps(in FooInput) FooProps {',
14
+ '\tscopeID := in.ScopeID',
15
+ '\treturn FooProps{ScopeID: scopeID}',
16
+ '}',
17
+ ].join('\n')
18
+
19
+ const result = deduplicateGoTypes(input)
20
+ const matches = result.match(/func NewFooProps/g)
21
+ expect(matches).toHaveLength(1)
22
+ expect(result).toContain('ScopeID')
23
+ })
24
+
25
+ test('deduplicates NewXxxProps with multi-line doc comment', () => {
26
+ const input = [
27
+ '// NewBarProps creates BarProps from BarInput.',
28
+ '//',
29
+ '// NOTE: `Items` is populated by the route handler.',
30
+ 'func NewBarProps(in BarInput) BarProps {',
31
+ '\treturn BarProps{}',
32
+ '}',
33
+ '',
34
+ '// NewBarProps creates BarProps from BarInput.',
35
+ '//',
36
+ '// NOTE: `Items` is populated by the route handler.',
37
+ 'func NewBarProps(in BarInput) BarProps {',
38
+ '\tscopeID := in.ScopeID',
39
+ '\treturn BarProps{ScopeID: scopeID}',
40
+ '}',
41
+ ].join('\n')
42
+
43
+ const result = deduplicateGoTypes(input)
44
+ const matches = result.match(/func NewBarProps/g)
45
+ expect(matches).toHaveLength(1)
46
+ expect(result).toContain('ScopeID')
47
+ })
48
+
49
+ test('preserves multi-line doc comment in output', () => {
50
+ const input = [
51
+ '// NewBazProps creates BazProps from BazInput.',
52
+ '//',
53
+ '// NOTE: `Children` is populated by the route handler, not by',
54
+ '// NewBazProps — the SSR template iterates over it.',
55
+ 'func NewBazProps(in BazInput) BazProps {',
56
+ '\tscopeID := in.ScopeID',
57
+ '\treturn BazProps{ScopeID: scopeID}',
58
+ '}',
59
+ ].join('\n')
60
+
61
+ const result = deduplicateGoTypes(input)
62
+ expect(result).toContain('NOTE: `Children` is populated by the route handler')
63
+ expect(result).toContain('func NewBazProps')
64
+ })
65
+ })