goscript 0.0.25 → 0.0.28

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.
Files changed (190) hide show
  1. package/README.md +4 -4
  2. package/cmd/goscript/cmd_compile.go +0 -3
  3. package/cmd/goscript/deps.go +11 -0
  4. package/compiler/analysis.go +259 -55
  5. package/compiler/assignment.go +2 -2
  6. package/compiler/builtin_test.go +1 -1
  7. package/compiler/compiler.go +201 -49
  8. package/compiler/compiler_test.go +53 -0
  9. package/compiler/composite-lit.go +32 -8
  10. package/compiler/decl.go +6 -6
  11. package/compiler/expr-call.go +83 -0
  12. package/compiler/expr.go +1 -1
  13. package/compiler/protobuf.go +557 -0
  14. package/compiler/spec-struct.go +4 -0
  15. package/compiler/spec-value.go +11 -3
  16. package/compiler/spec.go +18 -1
  17. package/compiler/stmt-assign.go +35 -0
  18. package/compiler/type-assert.go +87 -0
  19. package/compiler/type.go +5 -2
  20. package/dist/gs/builtin/builtin.d.ts +19 -1
  21. package/dist/gs/builtin/builtin.js +85 -5
  22. package/dist/gs/builtin/builtin.js.map +1 -1
  23. package/dist/gs/builtin/channel.js.map +1 -1
  24. package/dist/gs/builtin/slice.d.ts +1 -1
  25. package/dist/gs/builtin/slice.js +59 -26
  26. package/dist/gs/builtin/slice.js.map +1 -1
  27. package/dist/gs/cmp/index.js.map +1 -1
  28. package/dist/gs/context/context.d.ts +1 -1
  29. package/dist/gs/context/context.js +20 -11
  30. package/dist/gs/context/context.js.map +1 -1
  31. package/dist/gs/errors/errors.d.ts +7 -0
  32. package/dist/gs/errors/errors.js +190 -0
  33. package/dist/gs/errors/errors.js.map +1 -0
  34. package/dist/gs/errors/index.d.ts +1 -0
  35. package/dist/gs/errors/index.js +2 -0
  36. package/dist/gs/errors/index.js.map +1 -0
  37. package/dist/gs/internal/goarch/index.js +1 -1
  38. package/dist/gs/internal/goarch/index.js.map +1 -1
  39. package/dist/gs/io/index.d.ts +1 -0
  40. package/dist/gs/io/index.js +2 -0
  41. package/dist/gs/io/index.js.map +1 -0
  42. package/dist/gs/io/io.d.ts +107 -0
  43. package/dist/gs/io/io.js +385 -0
  44. package/dist/gs/io/io.js.map +1 -0
  45. package/dist/gs/iter/iter.js.map +1 -1
  46. package/dist/gs/math/bits/index.js +34 -32
  47. package/dist/gs/math/bits/index.js.map +1 -1
  48. package/dist/gs/runtime/runtime.d.ts +1 -0
  49. package/dist/gs/runtime/runtime.js +15 -18
  50. package/dist/gs/runtime/runtime.js.map +1 -1
  51. package/dist/gs/slices/slices.d.ts +1 -1
  52. package/dist/gs/slices/slices.js +1 -1
  53. package/dist/gs/slices/slices.js.map +1 -1
  54. package/dist/gs/strings/builder.d.ts +18 -0
  55. package/dist/gs/strings/builder.js +205 -0
  56. package/dist/gs/strings/builder.js.map +1 -0
  57. package/dist/gs/strings/clone.d.ts +1 -0
  58. package/dist/gs/strings/clone.js +16 -0
  59. package/dist/gs/strings/clone.js.map +1 -0
  60. package/dist/gs/strings/compare.d.ts +1 -0
  61. package/dist/gs/strings/compare.js +14 -0
  62. package/dist/gs/strings/compare.js.map +1 -0
  63. package/dist/gs/strings/index.d.ts +2 -0
  64. package/dist/gs/strings/index.js +3 -0
  65. package/dist/gs/strings/index.js.map +1 -0
  66. package/dist/gs/strings/iter.d.ts +8 -0
  67. package/dist/gs/strings/iter.js +160 -0
  68. package/dist/gs/strings/iter.js.map +1 -0
  69. package/dist/gs/strings/reader.d.ts +34 -0
  70. package/dist/gs/strings/reader.js +418 -0
  71. package/dist/gs/strings/reader.js.map +1 -0
  72. package/dist/gs/strings/replace.d.ts +106 -0
  73. package/dist/gs/strings/replace.js +1136 -0
  74. package/dist/gs/strings/replace.js.map +1 -0
  75. package/dist/gs/strings/search.d.ts +24 -0
  76. package/dist/gs/strings/search.js +169 -0
  77. package/dist/gs/strings/search.js.map +1 -0
  78. package/dist/gs/strings/strings.d.ts +47 -0
  79. package/dist/gs/strings/strings.js +418 -0
  80. package/dist/gs/strings/strings.js.map +1 -0
  81. package/dist/gs/stringslite/index.d.ts +1 -0
  82. package/dist/gs/stringslite/index.js +2 -0
  83. package/dist/gs/stringslite/index.js.map +1 -0
  84. package/dist/gs/stringslite/strings.d.ts +11 -0
  85. package/dist/gs/stringslite/strings.js +67 -0
  86. package/dist/gs/stringslite/strings.js.map +1 -0
  87. package/dist/gs/sync/index.d.ts +1 -0
  88. package/dist/gs/sync/index.js +2 -0
  89. package/dist/gs/sync/index.js.map +1 -0
  90. package/dist/gs/sync/sync.d.ts +79 -0
  91. package/dist/gs/sync/sync.js +392 -0
  92. package/dist/gs/sync/sync.js.map +1 -0
  93. package/dist/gs/time/time.js +7 -7
  94. package/dist/gs/time/time.js.map +1 -1
  95. package/dist/gs/unicode/index.d.ts +1 -0
  96. package/dist/gs/unicode/index.js +2 -0
  97. package/dist/gs/unicode/index.js.map +1 -0
  98. package/dist/gs/unicode/unicode.d.ts +105 -0
  99. package/dist/gs/unicode/unicode.js +332 -0
  100. package/dist/gs/unicode/unicode.js.map +1 -0
  101. package/dist/gs/unicode/utf8/index.d.ts +1 -0
  102. package/dist/gs/unicode/utf8/index.js +3 -0
  103. package/dist/gs/unicode/utf8/index.js.map +1 -0
  104. package/dist/gs/unicode/utf8/utf8.d.ts +20 -0
  105. package/dist/gs/unicode/utf8/utf8.js +196 -0
  106. package/dist/gs/unicode/utf8/utf8.js.map +1 -0
  107. package/dist/gs/unsafe/index.d.ts +1 -0
  108. package/dist/gs/unsafe/index.js +2 -0
  109. package/dist/gs/unsafe/index.js.map +1 -0
  110. package/dist/gs/unsafe/unsafe.d.ts +11 -0
  111. package/dist/gs/unsafe/unsafe.js +44 -0
  112. package/dist/gs/unsafe/unsafe.js.map +1 -0
  113. package/go.mod +2 -1
  114. package/go.sum +6 -2
  115. package/gs/README.md +6 -0
  116. package/gs/builtin/builtin.ts +158 -0
  117. package/gs/builtin/channel.ts +683 -0
  118. package/gs/builtin/defer.ts +58 -0
  119. package/gs/builtin/index.ts +1 -0
  120. package/gs/builtin/io.ts +22 -0
  121. package/gs/builtin/map.ts +50 -0
  122. package/gs/builtin/slice.ts +1030 -0
  123. package/gs/builtin/type.ts +1106 -0
  124. package/gs/builtin/varRef.ts +25 -0
  125. package/gs/cmp/godoc.txt +8 -0
  126. package/gs/cmp/index.ts +29 -0
  127. package/gs/context/context.ts +401 -0
  128. package/gs/context/godoc.txt +69 -0
  129. package/gs/context/index.ts +1 -0
  130. package/gs/errors/errors.ts +223 -0
  131. package/gs/errors/godoc.txt +63 -0
  132. package/gs/errors/index.ts +1 -0
  133. package/gs/internal/goarch/godoc.txt +39 -0
  134. package/gs/internal/goarch/index.ts +18 -0
  135. package/gs/io/godoc.txt +61 -0
  136. package/gs/io/index.ts +1 -0
  137. package/gs/io/io.go +75 -0
  138. package/gs/io/io.ts +546 -0
  139. package/gs/iter/godoc.txt +203 -0
  140. package/gs/iter/index.ts +1 -0
  141. package/gs/iter/iter.ts +117 -0
  142. package/gs/math/bits/index.ts +356 -0
  143. package/gs/math/godoc.txt +76 -0
  144. package/gs/runtime/godoc.txt +331 -0
  145. package/gs/runtime/index.ts +1 -0
  146. package/gs/runtime/runtime.ts +178 -0
  147. package/gs/slices/godoc.txt +44 -0
  148. package/gs/slices/index.ts +1 -0
  149. package/gs/slices/slices.ts +22 -0
  150. package/gs/strings/builder.test.ts +121 -0
  151. package/gs/strings/builder.ts +223 -0
  152. package/gs/strings/clone.test.ts +43 -0
  153. package/gs/strings/clone.ts +17 -0
  154. package/gs/strings/compare.test.ts +84 -0
  155. package/gs/strings/compare.ts +13 -0
  156. package/gs/strings/godoc.txt +66 -0
  157. package/gs/strings/index.ts +2 -0
  158. package/gs/strings/iter.test.ts +343 -0
  159. package/gs/strings/iter.ts +171 -0
  160. package/gs/strings/reader.test.ts +243 -0
  161. package/gs/strings/reader.ts +451 -0
  162. package/gs/strings/replace.test.ts +181 -0
  163. package/gs/strings/replace.ts +1310 -0
  164. package/gs/strings/search.test.ts +214 -0
  165. package/gs/strings/search.ts +213 -0
  166. package/gs/strings/strings.test.ts +477 -0
  167. package/gs/strings/strings.ts +510 -0
  168. package/gs/stringslite/godoc.txt +17 -0
  169. package/gs/stringslite/index.ts +1 -0
  170. package/gs/stringslite/strings.ts +82 -0
  171. package/gs/sync/godoc.txt +21 -0
  172. package/gs/sync/index.ts +1 -0
  173. package/gs/sync/sync.go +64 -0
  174. package/gs/sync/sync.ts +449 -0
  175. package/gs/time/godoc.md +116 -0
  176. package/gs/time/godoc.txt +116 -0
  177. package/gs/time/index.ts +1 -0
  178. package/gs/time/time.ts +272 -0
  179. package/gs/unicode/godoc.txt +52 -0
  180. package/gs/unicode/index.ts +1 -0
  181. package/gs/unicode/unicode.go +38 -0
  182. package/gs/unicode/unicode.ts +418 -0
  183. package/gs/unicode/utf8/godoc.txt +22 -0
  184. package/gs/unicode/utf8/index.ts +2 -0
  185. package/gs/unicode/utf8/utf8.ts +227 -0
  186. package/gs/unsafe/godoc.txt +19 -0
  187. package/gs/unsafe/index.ts +1 -0
  188. package/gs/unsafe/unsafe.test.ts +68 -0
  189. package/gs/unsafe/unsafe.ts +77 -0
  190. package/package.json +6 -4
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import * as unsafe from './unsafe.js'
3
+
4
+ describe('unsafe package', () => {
5
+ it('should throw error for Alignof', () => {
6
+ expect(() => unsafe.Alignof({})).toThrow(
7
+ 'unsafe.Alignof is not supported in JavaScript/TypeScript',
8
+ )
9
+ })
10
+
11
+ it('should throw error for Offsetof', () => {
12
+ expect(() => unsafe.Offsetof({})).toThrow(
13
+ 'unsafe.Offsetof is not supported in JavaScript/TypeScript',
14
+ )
15
+ })
16
+
17
+ it('should throw error for Sizeof', () => {
18
+ expect(() => unsafe.Sizeof({})).toThrow(
19
+ 'unsafe.Sizeof is not supported in JavaScript/TypeScript',
20
+ )
21
+ })
22
+
23
+ it('should throw error for Add', () => {
24
+ expect(() => unsafe.Add(null, 1)).toThrow(
25
+ 'unsafe.Add is not supported in JavaScript/TypeScript',
26
+ )
27
+ })
28
+
29
+ it('should throw error for Slice', () => {
30
+ expect(() => unsafe.Slice(null, 1)).toThrow(
31
+ 'unsafe.Slice is not supported in JavaScript/TypeScript',
32
+ )
33
+ })
34
+
35
+ it('should throw error for SliceData', () => {
36
+ expect(() => unsafe.SliceData([])).toThrow(
37
+ 'unsafe.SliceData is not supported in JavaScript/TypeScript',
38
+ )
39
+ })
40
+
41
+ it('should throw error for String', () => {
42
+ expect(() => unsafe.String(null, 1)).toThrow(
43
+ 'unsafe.String is not supported in JavaScript/TypeScript',
44
+ )
45
+ })
46
+
47
+ it('should throw error for StringData', () => {
48
+ expect(() => unsafe.StringData('test')).toThrow(
49
+ 'unsafe.StringData is not supported in JavaScript/TypeScript',
50
+ )
51
+ })
52
+
53
+ it('should export IntegerType as number type', () => {
54
+ // IntegerType is just a type alias, so we can't test it directly
55
+ // But we can verify it's exported and can be used as a type
56
+ const value: unsafe.IntegerType = 42
57
+ expect(typeof value).toBe('number')
58
+ })
59
+
60
+ it('should export ArbitraryType and Pointer types', () => {
61
+ // These are type aliases, so we can't test them directly
62
+ // But we can verify they can be used as types
63
+ const arbitrary: unsafe.ArbitraryType = 'anything'
64
+ const pointer: unsafe.Pointer = null
65
+ expect(arbitrary).toBe('anything')
66
+ expect(pointer).toBe(null)
67
+ })
68
+ })
@@ -0,0 +1,77 @@
1
+ // Package unsafe provides facilities for low-level programming including operations
2
+ // that violate the type system. Most operations are not supported in JavaScript/TypeScript
3
+ // and will throw errors when used.
4
+
5
+ // ArbitraryType is a shorthand for an arbitrary Go type; it is not a real type
6
+ export type ArbitraryType = any
7
+
8
+ // Pointer is a pointer type but a Pointer value may not be dereferenced
9
+ export type Pointer = any
10
+
11
+ // IntegerType is a shorthand for an integer type; it is not a real type
12
+ // This is the only type from unsafe that can be meaningfully implemented in JavaScript
13
+ export type IntegerType = number
14
+
15
+ // Alignof returns the alignment of the (type of the) variable in bytes
16
+ // This operation is not meaningful in JavaScript/TypeScript
17
+ export function Alignof(variable: ArbitraryType): number {
18
+ throw new Error(
19
+ 'unsafe.Alignof is not supported in JavaScript/TypeScript: memory alignment is not a meaningful concept in JavaScript',
20
+ )
21
+ }
22
+
23
+ // Offsetof returns the field offset in bytes relative to the struct's address
24
+ // This operation is not meaningful in JavaScript/TypeScript
25
+ export function Offsetof(selector: ArbitraryType): number {
26
+ throw new Error(
27
+ 'unsafe.Offsetof is not supported in JavaScript/TypeScript: memory layout and field offsets are not meaningful concepts in JavaScript',
28
+ )
29
+ }
30
+
31
+ // Sizeof returns the size of the (type of the) variable in bytes
32
+ // This operation is not meaningful in JavaScript/TypeScript
33
+ export function Sizeof(variable: ArbitraryType): number {
34
+ throw new Error(
35
+ 'unsafe.Sizeof is not supported in JavaScript/TypeScript: memory size is not a meaningful concept in JavaScript',
36
+ )
37
+ }
38
+
39
+ // Add adds len to ptr and returns the updated pointer
40
+ // Pointer arithmetic is not supported in JavaScript/TypeScript
41
+ export function Add(ptr: Pointer, len: IntegerType): Pointer {
42
+ throw new Error(
43
+ 'unsafe.Add is not supported in JavaScript/TypeScript: pointer arithmetic is not available in JavaScript',
44
+ )
45
+ }
46
+
47
+ // Slice returns a slice whose underlying array starts at ptr
48
+ // This operation is not meaningful in JavaScript/TypeScript
49
+ export function Slice(ptr: Pointer, len: IntegerType): any[] {
50
+ throw new Error(
51
+ 'unsafe.Slice is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
52
+ )
53
+ }
54
+
55
+ // SliceData returns a pointer to the underlying array of the slice
56
+ // This operation is not meaningful in JavaScript/TypeScript
57
+ export function SliceData(slice: any[]): Pointer {
58
+ throw new Error(
59
+ 'unsafe.SliceData is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
60
+ )
61
+ }
62
+
63
+ // String returns a string value whose underlying bytes start at ptr
64
+ // This operation is not meaningful in JavaScript/TypeScript
65
+ export function String(ptr: Pointer, len: IntegerType): string {
66
+ throw new Error(
67
+ 'unsafe.String is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
68
+ )
69
+ }
70
+
71
+ // StringData returns a pointer to the underlying bytes of the str
72
+ // This operation is not meaningful in JavaScript/TypeScript
73
+ export function StringData(str: string): Pointer {
74
+ throw new Error(
75
+ 'unsafe.StringData is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
76
+ )
77
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goscript",
3
3
  "description": "Go to TypeScript transpiler",
4
- "version": "0.0.25",
4
+ "version": "0.0.28",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",
@@ -42,13 +42,14 @@
42
42
  }
43
43
  },
44
44
  "scripts": {
45
- "build": "tsc -p tsconfig.build.json",
45
+ "build": "npm run build:updategover && tsc -p tsconfig.build.json",
46
+ "build:updategover": "node -e \"const fs = require('fs'); const { execSync } = require('child_process'); const goVersion = execSync('go mod edit -json', { encoding: 'utf8' }); const goData = JSON.parse(goVersion); const version = goData.Go; const runtimePath = 'gs/runtime/runtime.ts'; const content = fs.readFileSync(runtimePath, 'utf8'); const updatedContent = content.replace(/export const GOVERSION = 'go[^']*'/, \\`export const GOVERSION = 'go\\${version}'\\`); fs.writeFileSync(runtimePath, updatedContent);\"",
46
47
  "prepublishOnly": "npm run build",
47
48
  "example": "cd ./example/simple && bash run.bash",
48
49
  "test": "npm run test:go && npm run test:js",
49
50
  "test:go": "go test -v ./...",
50
51
  "test:js": "npm run typecheck && vitest run",
51
- "typecheck": "tsgo --noEmit",
52
+ "typecheck": "tsgo --noEmit -p tsconfig.build.json",
52
53
  "format": "npm run format:go && npm run format:js && npm run format:config",
53
54
  "format:config": "prettier --write tsconfig.json package.json",
54
55
  "format:go": "gofumpt -w .",
@@ -70,7 +71,7 @@
70
71
  "dist",
71
72
  "cmd",
72
73
  "compiler",
73
- "builtin",
74
+ "gs",
74
75
  "!compliance",
75
76
  "go.mod",
76
77
  "go.sum",
@@ -82,6 +83,7 @@
82
83
  "./{src,builtin,example}/**/(*.ts|*.tsx|*.html|*.css|*.scss)": "prettier --config .prettierrc.yaml --write"
83
84
  },
84
85
  "devDependencies": {
86
+ "@aptre/protobuf-es-lite": "^0.4.9",
85
87
  "@eslint/js": "^9.25.1",
86
88
  "@types/node": "^22.15.18",
87
89
  "@typescript-eslint/eslint-plugin": "^8.31.0",