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.
- package/README.md +4 -4
- package/cmd/goscript/cmd_compile.go +0 -3
- package/cmd/goscript/deps.go +11 -0
- package/compiler/analysis.go +259 -55
- package/compiler/assignment.go +2 -2
- package/compiler/builtin_test.go +1 -1
- package/compiler/compiler.go +201 -49
- package/compiler/compiler_test.go +53 -0
- package/compiler/composite-lit.go +32 -8
- package/compiler/decl.go +6 -6
- package/compiler/expr-call.go +83 -0
- package/compiler/expr.go +1 -1
- package/compiler/protobuf.go +557 -0
- package/compiler/spec-struct.go +4 -0
- package/compiler/spec-value.go +11 -3
- package/compiler/spec.go +18 -1
- package/compiler/stmt-assign.go +35 -0
- package/compiler/type-assert.go +87 -0
- package/compiler/type.go +5 -2
- package/dist/gs/builtin/builtin.d.ts +19 -1
- package/dist/gs/builtin/builtin.js +85 -5
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +1 -1
- package/dist/gs/builtin/slice.js +59 -26
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/cmp/index.js.map +1 -1
- package/dist/gs/context/context.d.ts +1 -1
- package/dist/gs/context/context.js +20 -11
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +7 -0
- package/dist/gs/errors/errors.js +190 -0
- package/dist/gs/errors/errors.js.map +1 -0
- package/dist/gs/errors/index.d.ts +1 -0
- package/dist/gs/errors/index.js +2 -0
- package/dist/gs/errors/index.js.map +1 -0
- package/dist/gs/internal/goarch/index.js +1 -1
- package/dist/gs/internal/goarch/index.js.map +1 -1
- package/dist/gs/io/index.d.ts +1 -0
- package/dist/gs/io/index.js +2 -0
- package/dist/gs/io/index.js.map +1 -0
- package/dist/gs/io/io.d.ts +107 -0
- package/dist/gs/io/io.js +385 -0
- package/dist/gs/io/io.js.map +1 -0
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/math/bits/index.js +34 -32
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +1 -0
- package/dist/gs/runtime/runtime.js +15 -18
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +1 -1
- package/dist/gs/slices/slices.js +1 -1
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +18 -0
- package/dist/gs/strings/builder.js +205 -0
- package/dist/gs/strings/builder.js.map +1 -0
- package/dist/gs/strings/clone.d.ts +1 -0
- package/dist/gs/strings/clone.js +16 -0
- package/dist/gs/strings/clone.js.map +1 -0
- package/dist/gs/strings/compare.d.ts +1 -0
- package/dist/gs/strings/compare.js +14 -0
- package/dist/gs/strings/compare.js.map +1 -0
- package/dist/gs/strings/index.d.ts +2 -0
- package/dist/gs/strings/index.js +3 -0
- package/dist/gs/strings/index.js.map +1 -0
- package/dist/gs/strings/iter.d.ts +8 -0
- package/dist/gs/strings/iter.js +160 -0
- package/dist/gs/strings/iter.js.map +1 -0
- package/dist/gs/strings/reader.d.ts +34 -0
- package/dist/gs/strings/reader.js +418 -0
- package/dist/gs/strings/reader.js.map +1 -0
- package/dist/gs/strings/replace.d.ts +106 -0
- package/dist/gs/strings/replace.js +1136 -0
- package/dist/gs/strings/replace.js.map +1 -0
- package/dist/gs/strings/search.d.ts +24 -0
- package/dist/gs/strings/search.js +169 -0
- package/dist/gs/strings/search.js.map +1 -0
- package/dist/gs/strings/strings.d.ts +47 -0
- package/dist/gs/strings/strings.js +418 -0
- package/dist/gs/strings/strings.js.map +1 -0
- package/dist/gs/stringslite/index.d.ts +1 -0
- package/dist/gs/stringslite/index.js +2 -0
- package/dist/gs/stringslite/index.js.map +1 -0
- package/dist/gs/stringslite/strings.d.ts +11 -0
- package/dist/gs/stringslite/strings.js +67 -0
- package/dist/gs/stringslite/strings.js.map +1 -0
- package/dist/gs/sync/index.d.ts +1 -0
- package/dist/gs/sync/index.js +2 -0
- package/dist/gs/sync/index.js.map +1 -0
- package/dist/gs/sync/sync.d.ts +79 -0
- package/dist/gs/sync/sync.js +392 -0
- package/dist/gs/sync/sync.js.map +1 -0
- package/dist/gs/time/time.js +7 -7
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/index.d.ts +1 -0
- package/dist/gs/unicode/index.js +2 -0
- package/dist/gs/unicode/index.js.map +1 -0
- package/dist/gs/unicode/unicode.d.ts +105 -0
- package/dist/gs/unicode/unicode.js +332 -0
- package/dist/gs/unicode/unicode.js.map +1 -0
- package/dist/gs/unicode/utf8/index.d.ts +1 -0
- package/dist/gs/unicode/utf8/index.js +3 -0
- package/dist/gs/unicode/utf8/index.js.map +1 -0
- package/dist/gs/unicode/utf8/utf8.d.ts +20 -0
- package/dist/gs/unicode/utf8/utf8.js +196 -0
- package/dist/gs/unicode/utf8/utf8.js.map +1 -0
- package/dist/gs/unsafe/index.d.ts +1 -0
- package/dist/gs/unsafe/index.js +2 -0
- package/dist/gs/unsafe/index.js.map +1 -0
- package/dist/gs/unsafe/unsafe.d.ts +11 -0
- package/dist/gs/unsafe/unsafe.js +44 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -0
- package/go.mod +2 -1
- package/go.sum +6 -2
- package/gs/README.md +6 -0
- package/gs/builtin/builtin.ts +158 -0
- package/gs/builtin/channel.ts +683 -0
- package/gs/builtin/defer.ts +58 -0
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/io.ts +22 -0
- package/gs/builtin/map.ts +50 -0
- package/gs/builtin/slice.ts +1030 -0
- package/gs/builtin/type.ts +1106 -0
- package/gs/builtin/varRef.ts +25 -0
- package/gs/cmp/godoc.txt +8 -0
- package/gs/cmp/index.ts +29 -0
- package/gs/context/context.ts +401 -0
- package/gs/context/godoc.txt +69 -0
- package/gs/context/index.ts +1 -0
- package/gs/errors/errors.ts +223 -0
- package/gs/errors/godoc.txt +63 -0
- package/gs/errors/index.ts +1 -0
- package/gs/internal/goarch/godoc.txt +39 -0
- package/gs/internal/goarch/index.ts +18 -0
- package/gs/io/godoc.txt +61 -0
- package/gs/io/index.ts +1 -0
- package/gs/io/io.go +75 -0
- package/gs/io/io.ts +546 -0
- package/gs/iter/godoc.txt +203 -0
- package/gs/iter/index.ts +1 -0
- package/gs/iter/iter.ts +117 -0
- package/gs/math/bits/index.ts +356 -0
- package/gs/math/godoc.txt +76 -0
- package/gs/runtime/godoc.txt +331 -0
- package/gs/runtime/index.ts +1 -0
- package/gs/runtime/runtime.ts +178 -0
- package/gs/slices/godoc.txt +44 -0
- package/gs/slices/index.ts +1 -0
- package/gs/slices/slices.ts +22 -0
- package/gs/strings/builder.test.ts +121 -0
- package/gs/strings/builder.ts +223 -0
- package/gs/strings/clone.test.ts +43 -0
- package/gs/strings/clone.ts +17 -0
- package/gs/strings/compare.test.ts +84 -0
- package/gs/strings/compare.ts +13 -0
- package/gs/strings/godoc.txt +66 -0
- package/gs/strings/index.ts +2 -0
- package/gs/strings/iter.test.ts +343 -0
- package/gs/strings/iter.ts +171 -0
- package/gs/strings/reader.test.ts +243 -0
- package/gs/strings/reader.ts +451 -0
- package/gs/strings/replace.test.ts +181 -0
- package/gs/strings/replace.ts +1310 -0
- package/gs/strings/search.test.ts +214 -0
- package/gs/strings/search.ts +213 -0
- package/gs/strings/strings.test.ts +477 -0
- package/gs/strings/strings.ts +510 -0
- package/gs/stringslite/godoc.txt +17 -0
- package/gs/stringslite/index.ts +1 -0
- package/gs/stringslite/strings.ts +82 -0
- package/gs/sync/godoc.txt +21 -0
- package/gs/sync/index.ts +1 -0
- package/gs/sync/sync.go +64 -0
- package/gs/sync/sync.ts +449 -0
- package/gs/time/godoc.md +116 -0
- package/gs/time/godoc.txt +116 -0
- package/gs/time/index.ts +1 -0
- package/gs/time/time.ts +272 -0
- package/gs/unicode/godoc.txt +52 -0
- package/gs/unicode/index.ts +1 -0
- package/gs/unicode/unicode.go +38 -0
- package/gs/unicode/unicode.ts +418 -0
- package/gs/unicode/utf8/godoc.txt +22 -0
- package/gs/unicode/utf8/index.ts +2 -0
- package/gs/unicode/utf8/utf8.ts +227 -0
- package/gs/unsafe/godoc.txt +19 -0
- package/gs/unsafe/index.ts +1 -0
- package/gs/unsafe/unsafe.test.ts +68 -0
- package/gs/unsafe/unsafe.ts +77 -0
- 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.
|
|
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
|
-
"
|
|
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",
|