goscript 0.0.14 → 0.0.16
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 +154 -40
- package/builtin/builtin.ts +1168 -178
- package/compiler/analysis.go +726 -0
- package/compiler/compiler.go +5701 -4
- package/compiler/compiler_test.go +104 -0
- package/compiler/config.go +3 -3
- package/compiler/config_test.go +89 -0
- package/compiler/output.go +26 -0
- package/compiler/write-type-spec.go +506 -0
- package/compiler/writer.go +11 -0
- package/dist/builtin/builtin.d.ts +204 -67
- package/dist/builtin/builtin.js +845 -144
- package/dist/builtin/builtin.js.map +1 -1
- package/go.mod +4 -5
- package/go.sum +6 -11
- package/package.json +4 -3
- package/compiler/compile.go +0 -190
- package/compiler/compile_comment.go +0 -41
- package/compiler/compile_decls.go +0 -84
- package/compiler/compile_expr.go +0 -1022
- package/compiler/compile_field.go +0 -110
- package/compiler/compile_spec.go +0 -566
- package/compiler/compile_stmt.go +0 -1616
- package/compiler/context.go +0 -9
- package/compiler/file_compiler.go +0 -80
- package/compiler/output_path.go +0 -31
- package/compiler/pkg_compiler.go +0 -72
- package/compiler/types/tokens.go +0 -66
- package/compiler/types/types.go +0 -46
- package/dist/compliance/tests/array_literal/array_literal.gs.d.ts +0 -1
- package/dist/compliance/tests/array_literal/array_literal.gs.js +0 -15
- package/dist/compliance/tests/array_literal/array_literal.gs.js.map +0 -1
- package/dist/compliance/tests/async_basic/async_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/async_basic/async_basic.gs.js +0 -24
- package/dist/compliance/tests/async_basic/async_basic.gs.js.map +0 -1
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js +0 -82
- package/dist/compliance/tests/async_defer_statement/async_defer_statement.gs.js.map +0 -1
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.d.ts +0 -1
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js +0 -16
- package/dist/compliance/tests/basic_arithmetic/basic_arithmetic.gs.js.map +0 -1
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.d.ts +0 -1
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js +0 -14
- package/dist/compliance/tests/boolean_logic/boolean_logic.gs.js.map +0 -1
- package/dist/compliance/tests/channel_basic/channel_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/channel_basic/channel_basic.gs.js +0 -14
- package/dist/compliance/tests/channel_basic/channel_basic.gs.js.map +0 -1
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js +0 -27
- package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/constants/constants.gs.d.ts +0 -1
- package/dist/compliance/tests/constants/constants.gs.js +0 -16
- package/dist/compliance/tests/constants/constants.gs.js.map +0 -1
- package/dist/compliance/tests/copy_independence/copy_independence.gs.d.ts +0 -1
- package/dist/compliance/tests/copy_independence/copy_independence.gs.js +0 -33
- package/dist/compliance/tests/copy_independence/copy_independence.gs.js.map +0 -1
- package/dist/compliance/tests/defer_statement/defer_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/defer_statement/defer_statement.gs.js +0 -75
- package/dist/compliance/tests/defer_statement/defer_statement.gs.js.map +0 -1
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js +0 -37
- package/dist/compliance/tests/embedded_interface_assertion/embedded_interface_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.d.ts +0 -1
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js +0 -29
- package/dist/compliance/tests/flag_bitwise_op/flag_bitwise_op.gs.js.map +0 -1
- package/dist/compliance/tests/float64/float64.gs.d.ts +0 -1
- package/dist/compliance/tests/float64/float64.gs.js +0 -24
- package/dist/compliance/tests/float64/float64.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js +0 -10
- package/dist/compliance/tests/for_loop_basic/for_loop_basic.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js +0 -11
- package/dist/compliance/tests/for_loop_condition_only/for_loop_condition_only.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_condition_only/main.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_condition_only/main.gs.js +0 -10
- package/dist/compliance/tests/for_loop_condition_only/main.gs.js.map +0 -1
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.d.ts +0 -1
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js +0 -14
- package/dist/compliance/tests/for_loop_infinite/for_loop_infinite.gs.js.map +0 -1
- package/dist/compliance/tests/for_range/for_range.gs.d.ts +0 -1
- package/dist/compliance/tests/for_range/for_range.gs.js +0 -39
- package/dist/compliance/tests/for_range/for_range.gs.js.map +0 -1
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.d.ts +0 -1
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js +0 -15
- package/dist/compliance/tests/for_range_index_use/for_range_index_use.gs.js.map +0 -1
- package/dist/compliance/tests/func_literal/func_literal.gs.d.ts +0 -1
- package/dist/compliance/tests/func_literal/func_literal.gs.js +0 -10
- package/dist/compliance/tests/func_literal/func_literal.gs.js.map +0 -1
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.d.ts +0 -12
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js +0 -30
- package/dist/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/if_statement/if_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/if_statement/if_statement.gs.js +0 -13
- package/dist/compliance/tests/if_statement/if_statement.gs.js.map +0 -1
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js +0 -12
- package/dist/compliance/tests/interface_method_comments/interface_method_comments.gs.js.map +0 -1
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js +0 -34
- package/dist/compliance/tests/interface_multi_param_return/interface_multi_param_return.gs.js.map +0 -1
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js +0 -32
- package/dist/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js +0 -40
- package/dist/compliance/tests/interface_type_assertion/interface_type_assertion.gs.js.map +0 -1
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.d.ts +0 -1
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js +0 -51
- package/dist/compliance/tests/interface_type_assertion_signature_mismatch/interface_type_assertion_signature_mismatch.gs.js.map +0 -1
- package/dist/compliance/tests/map_support/map_support.gs.d.ts +0 -1
- package/dist/compliance/tests/map_support/map_support.gs.js +0 -88
- package/dist/compliance/tests/map_support/map_support.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js +0 -24
- package/dist/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js +0 -33
- package/dist/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js +0 -22
- package/dist/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.js.map +0 -1
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.d.ts +0 -1
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js +0 -33
- package/dist/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.js.map +0 -1
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.d.ts +0 -1
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js +0 -17
- package/dist/compliance/tests/multiple_return_values/multiple_return_values.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js +0 -29
- package/dist/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js +0 -27
- package/dist/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js +0 -22
- package/dist/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.js.map +0 -1
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.d.ts +0 -1
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js +0 -20
- package/dist/compliance/tests/pointer_initialization/pointer_initialization.gs.js.map +0 -1
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.d.ts +0 -1
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js +0 -28
- package/dist/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.js.map +0 -1
- package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.d.ts +0 -1
- package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.js +0 -30
- package/dist/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.js.map +0 -1
- package/dist/compliance/tests/select_statement/select_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/select_statement/select_statement.gs.js +0 -207
- package/dist/compliance/tests/select_statement/select_statement.gs.js.map +0 -1
- package/dist/compliance/tests/simple/simple.gs.d.ts +0 -1
- package/dist/compliance/tests/simple/simple.gs.js +0 -6
- package/dist/compliance/tests/simple/simple.gs.js.map +0 -1
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.d.ts +0 -1
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js +0 -24
- package/dist/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.js.map +0 -1
- package/dist/compliance/tests/slices/slices.gs.d.ts +0 -1
- package/dist/compliance/tests/slices/slices.gs.js +0 -294
- package/dist/compliance/tests/slices/slices.gs.js.map +0 -1
- package/dist/compliance/tests/string_conversion/string_conversion.gs.d.ts +0 -1
- package/dist/compliance/tests/string_conversion/string_conversion.gs.js +0 -41
- package/dist/compliance/tests/string_conversion/string_conversion.gs.js.map +0 -1
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.d.ts +0 -1
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js +0 -17
- package/dist/compliance/tests/string_rune_conversion/string_rune_conversion.gs.js.map +0 -1
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js +0 -48
- package/dist/compliance/tests/struct_embedding/struct_embedding.gs.js.map +0 -1
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js +0 -19
- package/dist/compliance/tests/struct_field_access/struct_field_access.gs.js.map +0 -1
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js +0 -26
- package/dist/compliance/tests/struct_pointer_interface_fields/struct_pointer_interface_fields.gs.js.map +0 -1
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.d.ts +0 -1
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js +0 -30
- package/dist/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.js.map +0 -1
- package/dist/compliance/tests/switch_statement/switch_statement.gs.d.ts +0 -1
- package/dist/compliance/tests/switch_statement/switch_statement.gs.js +0 -76
- package/dist/compliance/tests/switch_statement/switch_statement.gs.js.map +0 -1
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.d.ts +0 -1
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js +0 -31
- package/dist/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.js.map +0 -1
package/compiler/context.go
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
package compiler
|
|
2
|
-
|
|
3
|
-
// CompilerContext is the context for the compiler.
|
|
4
|
-
type CompilerContext struct {
|
|
5
|
-
// GoPackage is the name of the go package to compile
|
|
6
|
-
GoPackage string
|
|
7
|
-
// ComputedTsPackage is the path to the typescript package for this Go package.
|
|
8
|
-
ComputedTsPackage string
|
|
9
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
package compiler
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"fmt"
|
|
6
|
-
"go/ast"
|
|
7
|
-
"os"
|
|
8
|
-
"path/filepath"
|
|
9
|
-
|
|
10
|
-
"golang.org/x/tools/go/packages"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
// fileImport is an import in a file.
|
|
14
|
-
type fileImport struct {
|
|
15
|
-
importPath string
|
|
16
|
-
importVars map[string]struct{}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// FileCompiler is the root compiler for a file.
|
|
20
|
-
type FileCompiler struct {
|
|
21
|
-
compilerConfig *Config
|
|
22
|
-
codeWriter *TSCodeWriter
|
|
23
|
-
pkg *packages.Package
|
|
24
|
-
ast *ast.File
|
|
25
|
-
fullPath string
|
|
26
|
-
|
|
27
|
-
imports map[string]fileImport
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// NewFileCompiler builds a new FileCompiler
|
|
31
|
-
func NewFileCompiler(
|
|
32
|
-
compilerConf *Config,
|
|
33
|
-
pkg *packages.Package,
|
|
34
|
-
astFile *ast.File,
|
|
35
|
-
fullPath string,
|
|
36
|
-
) (*FileCompiler, error) {
|
|
37
|
-
return &FileCompiler{
|
|
38
|
-
compilerConfig: compilerConf,
|
|
39
|
-
pkg: pkg,
|
|
40
|
-
ast: astFile,
|
|
41
|
-
fullPath: fullPath,
|
|
42
|
-
|
|
43
|
-
imports: make(map[string]fileImport),
|
|
44
|
-
}, nil
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Compile compiles a file.
|
|
48
|
-
func (c *FileCompiler) Compile(ctx context.Context) error {
|
|
49
|
-
f := c.ast
|
|
50
|
-
|
|
51
|
-
pkgPath := c.pkg.PkgPath
|
|
52
|
-
outputFilePath := TranslateGoFilePathToTypescriptFilePath(pkgPath, filepath.Base(c.fullPath))
|
|
53
|
-
outputFilePathAbs := filepath.Join(c.compilerConfig.OutputPathRoot, outputFilePath)
|
|
54
|
-
|
|
55
|
-
if err := os.MkdirAll(filepath.Dir(outputFilePathAbs), 0o755); err != nil {
|
|
56
|
-
return err
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
of, err := os.OpenFile(outputFilePathAbs, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
|
|
60
|
-
if err != nil {
|
|
61
|
-
return err
|
|
62
|
-
}
|
|
63
|
-
defer of.Close() //nolint:errcheck
|
|
64
|
-
|
|
65
|
-
c.codeWriter = NewTSCodeWriter(of)
|
|
66
|
-
// Create comment map
|
|
67
|
-
cmap := ast.NewCommentMap(c.pkg.Fset, f, f.Comments)
|
|
68
|
-
// Pass comment map to compiler
|
|
69
|
-
goWriter := NewGoToTSCompiler(c.codeWriter, c.pkg, cmap)
|
|
70
|
-
|
|
71
|
-
// Add import for the goscript runtime using namespace import and alias
|
|
72
|
-
c.codeWriter.WriteLine("import * as goscript from \"@goscript/builtin\";")
|
|
73
|
-
c.codeWriter.WriteLine("") // Add a newline after the import
|
|
74
|
-
|
|
75
|
-
if err := goWriter.WriteDecls(f.Decls); err != nil {
|
|
76
|
-
return fmt.Errorf("failed to write declarations: %w", err)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return nil
|
|
80
|
-
}
|
package/compiler/output_path.go
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
package compiler
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"path/filepath"
|
|
6
|
-
"strings"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
var typeScriptGoStubPrefix = "@ts/"
|
|
10
|
-
|
|
11
|
-
// translateGoPathToTypescriptPath translates a go package import path to a typescript import path.
|
|
12
|
-
func translateGoPathToTypescriptPath(goImportPath string) string {
|
|
13
|
-
if strings.HasPrefix(goImportPath, typeScriptGoStubPrefix) {
|
|
14
|
-
return goImportPath[len(typeScriptGoStubPrefix):]
|
|
15
|
-
}
|
|
16
|
-
return fmt.Sprintf("@goscript/%s", goImportPath)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// packageNameFromGoPath attempts to determine the package name from the last segment of the go path.
|
|
20
|
-
func packageNameFromGoPath(goPkgPath string) string {
|
|
21
|
-
pts := strings.Split(goPkgPath, "/")
|
|
22
|
-
return pts[len(pts)-1]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// TranslateGoFilePathToTypescriptFilePath converts the go package path and typescript filename to output path within the typescript output dir
|
|
26
|
-
func TranslateGoFilePathToTypescriptFilePath(goPkgPath, goCodeFilename string) string {
|
|
27
|
-
op := translateGoPathToTypescriptPath(goPkgPath)
|
|
28
|
-
baseFilename := goCodeFilename[:len(goCodeFilename)-3]
|
|
29
|
-
baseFilename = fmt.Sprintf("%s.gs.ts", baseFilename)
|
|
30
|
-
return filepath.Join(op, baseFilename)
|
|
31
|
-
}
|
package/compiler/pkg_compiler.go
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
package compiler
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"go/ast"
|
|
6
|
-
"os"
|
|
7
|
-
"path/filepath"
|
|
8
|
-
|
|
9
|
-
"github.com/sirupsen/logrus"
|
|
10
|
-
"golang.org/x/tools/go/packages"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
// PackageCompiler compiles an entire package.
|
|
14
|
-
type PackageCompiler struct {
|
|
15
|
-
le *logrus.Entry
|
|
16
|
-
compilerConf *Config
|
|
17
|
-
outputPath string
|
|
18
|
-
pkg *packages.Package
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// NewPackageCompiler builds a new PackageCompiler.
|
|
22
|
-
func NewPackageCompiler(
|
|
23
|
-
le *logrus.Entry,
|
|
24
|
-
compilerConf *Config,
|
|
25
|
-
pkg *packages.Package,
|
|
26
|
-
) (*PackageCompiler, error) {
|
|
27
|
-
res := &PackageCompiler{
|
|
28
|
-
le: le,
|
|
29
|
-
pkg: pkg,
|
|
30
|
-
compilerConf: compilerConf,
|
|
31
|
-
outputPath: ComputeModulePath(compilerConf.OutputPathRoot, pkg.PkgPath),
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return res, nil
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Compile compiles the package.
|
|
38
|
-
func (c *PackageCompiler) Compile(ctx context.Context) error {
|
|
39
|
-
wd := c.compilerConf.Dir
|
|
40
|
-
if wd == "" {
|
|
41
|
-
var err error
|
|
42
|
-
wd, err = os.Getwd()
|
|
43
|
-
if err != nil {
|
|
44
|
-
return err
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Compile the files in the package one at a time
|
|
49
|
-
for i, f := range c.pkg.Syntax {
|
|
50
|
-
fileName := c.pkg.CompiledGoFiles[i]
|
|
51
|
-
relWdFileName, err := filepath.Rel(wd, fileName)
|
|
52
|
-
if err != nil {
|
|
53
|
-
return err
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
c.le.WithField("file", relWdFileName).Debug("compiling file")
|
|
57
|
-
if err := c.CompileFile(ctx, fileName, f); err != nil {
|
|
58
|
-
return err
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return nil
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// CompileFile compiles a file.
|
|
66
|
-
func (p *PackageCompiler) CompileFile(ctx context.Context, name string, syntax *ast.File) error {
|
|
67
|
-
fileCompiler, err := NewFileCompiler(p.compilerConf, p.pkg, syntax, name)
|
|
68
|
-
if err != nil {
|
|
69
|
-
return err
|
|
70
|
-
}
|
|
71
|
-
return fileCompiler.Compile(ctx)
|
|
72
|
-
}
|
package/compiler/types/tokens.go
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package types
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"go/token"
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
var tokenMap = map[token.Token]string{
|
|
8
|
-
token.ADD: "+",
|
|
9
|
-
token.SUB: "-",
|
|
10
|
-
token.MUL: "*",
|
|
11
|
-
token.QUO: "/",
|
|
12
|
-
token.REM: "%",
|
|
13
|
-
token.AND: "&",
|
|
14
|
-
token.OR: "|",
|
|
15
|
-
token.XOR: "^",
|
|
16
|
-
token.SHL: "<<",
|
|
17
|
-
token.SHR: ">>",
|
|
18
|
-
|
|
19
|
-
token.ADD_ASSIGN: "+=",
|
|
20
|
-
token.SUB_ASSIGN: "-=",
|
|
21
|
-
token.MUL_ASSIGN: "*=",
|
|
22
|
-
token.QUO_ASSIGN: "/=",
|
|
23
|
-
token.REM_ASSIGN: "%=",
|
|
24
|
-
|
|
25
|
-
token.AND_ASSIGN: "&=",
|
|
26
|
-
token.OR_ASSIGN: "|=",
|
|
27
|
-
token.XOR_ASSIGN: "^=", // TODO: check if this works
|
|
28
|
-
token.SHL_ASSIGN: "<<=",
|
|
29
|
-
token.SHR_ASSIGN: ">>=",
|
|
30
|
-
token.AND_NOT_ASSIGN: "&^=",
|
|
31
|
-
|
|
32
|
-
token.LAND: "&&",
|
|
33
|
-
token.LOR: "||",
|
|
34
|
-
// token.ARROW: ""
|
|
35
|
-
token.INC: "++",
|
|
36
|
-
token.DEC: "--",
|
|
37
|
-
token.EQL: "==",
|
|
38
|
-
token.LSS: "<",
|
|
39
|
-
token.GTR: ">",
|
|
40
|
-
token.ASSIGN: "=",
|
|
41
|
-
token.NOT: "!",
|
|
42
|
-
|
|
43
|
-
token.NEQ: "!=",
|
|
44
|
-
token.LEQ: "<=",
|
|
45
|
-
token.GEQ: ">=",
|
|
46
|
-
token.DEFINE: "=", // :=
|
|
47
|
-
token.ELLIPSIS: "...", // TODO
|
|
48
|
-
|
|
49
|
-
token.LPAREN: "(",
|
|
50
|
-
token.LBRACK: "[",
|
|
51
|
-
token.LBRACE: "{",
|
|
52
|
-
token.COMMA: ",",
|
|
53
|
-
token.PERIOD: ".",
|
|
54
|
-
|
|
55
|
-
token.RPAREN: ")",
|
|
56
|
-
token.RBRACK: "]",
|
|
57
|
-
token.RBRACE: "}",
|
|
58
|
-
token.SEMICOLON: ";",
|
|
59
|
-
token.COLON: ":",
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// TokenToTs looks up the typescript version of a token.
|
|
63
|
-
func TokenToTs(tok token.Token) (string, bool) {
|
|
64
|
-
t, ok := tokenMap[tok]
|
|
65
|
-
return t, ok
|
|
66
|
-
}
|
package/compiler/types/types.go
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
package types
|
|
2
|
-
|
|
3
|
-
// goToTypescriptPrimitives maps Go primitive types to their TypeScript equivalents.
|
|
4
|
-
//
|
|
5
|
-
// Assumptions:
|
|
6
|
-
// - Target environment is similar to GOOS=js GOARCH=wasm, where `int` and `uint` are 32 bits.
|
|
7
|
-
// - 32-bit Go integers fit safely within the JS/TypeScript `number` type.
|
|
8
|
-
// - 64-bit integers (`int64`, `uint64`) require TypeScript `bigint` (ES2020+).
|
|
9
|
-
// - Only primitive types are handled here. Composite types (pointers, slices, maps, structs, etc.)
|
|
10
|
-
// are not handled by this mapping.
|
|
11
|
-
var goToTypescriptPrimitives = map[string]string{
|
|
12
|
-
// Boolean
|
|
13
|
-
"bool": "boolean",
|
|
14
|
-
|
|
15
|
-
// Strings
|
|
16
|
-
"string": "string",
|
|
17
|
-
|
|
18
|
-
// Signed Integers
|
|
19
|
-
"int": "number",
|
|
20
|
-
"int8": "number",
|
|
21
|
-
"int16": "number",
|
|
22
|
-
"int32": "number",
|
|
23
|
-
"rune": "number", // alias for int32
|
|
24
|
-
"int64": "bigint", // Requires TypeScript target >= ES2020
|
|
25
|
-
|
|
26
|
-
// Unsigned Integers
|
|
27
|
-
"uint": "number",
|
|
28
|
-
"uint8": "number", // byte is an alias for uint8
|
|
29
|
-
"byte": "number",
|
|
30
|
-
"uint16": "number",
|
|
31
|
-
"uint32": "number",
|
|
32
|
-
"uint64": "bigint", // Requires TypeScript target >= ES2020
|
|
33
|
-
|
|
34
|
-
// Floating Point Numbers
|
|
35
|
-
"float32": "number",
|
|
36
|
-
"float64": "number",
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// GoBuiltinToTypescript returns the TypeScript equivalent of a Go primitive type name.
|
|
40
|
-
// Returns the TypeScript type and true if found, or an empty string and false otherwise.
|
|
41
|
-
//
|
|
42
|
-
// Only primitive types listed in goToTypescriptPrimitives are handled.
|
|
43
|
-
func GoBuiltinToTypescript(typeName string) (string, bool) {
|
|
44
|
-
val, ok := goToTypescriptPrimitives[typeName]
|
|
45
|
-
return val, ok
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Generated file based on array_literal.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
export async function main() {
|
|
4
|
-
// Test basic array literal
|
|
5
|
-
//nolint:staticcheck
|
|
6
|
-
let a = [1, 2, 3];
|
|
7
|
-
console.log(a[0], a[1], a[2]);
|
|
8
|
-
// Test array literal with inferred length
|
|
9
|
-
let b = ["hello", "world"];
|
|
10
|
-
console.log(b[0], b[1]);
|
|
11
|
-
// Test array literal with specific element initialization
|
|
12
|
-
let c = [0, 10, 0, 30, 0];
|
|
13
|
-
console.log(c[0], c[1], c[2], c[3], c[4]);
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=array_literal.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array_literal.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/array_literal/array_literal.gs.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,yDAAyD;AAIzD,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,2BAA2B;IAC3B,oBAAoB;IACpB,IAAI,CAAC,GAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE7B,0CAA0C;IAC1C,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC1B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAEvB,0DAA0D;IAC1D,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IACzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Generated file based on async_basic.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
import * as goscript from "@goscript/builtin";
|
|
4
|
-
// This function receives from a channel, making it async.
|
|
5
|
-
async function receiveFromChan(ch) {
|
|
6
|
-
let val = await ch.receive(); // This operation makes the function async
|
|
7
|
-
return val;
|
|
8
|
-
}
|
|
9
|
-
// This function calls an async function, making it async too.
|
|
10
|
-
async function caller(ch) {
|
|
11
|
-
// We expect this call to be awaited in TypeScript
|
|
12
|
-
let result = await receiveFromChan(ch);
|
|
13
|
-
return result + 1;
|
|
14
|
-
}
|
|
15
|
-
export async function main() {
|
|
16
|
-
// Create a buffered channel
|
|
17
|
-
let myChan = goscript.makeChannel(1, 0);
|
|
18
|
-
await myChan.send(10);
|
|
19
|
-
// Call the async caller function
|
|
20
|
-
let finalResult = await caller(myChan);
|
|
21
|
-
console.log(finalResult); // Expected output: 11
|
|
22
|
-
myChan.close();
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=async_basic.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_basic.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/async_basic/async_basic.gs.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,yDAAyD;AAEzD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C,0DAA0D;AAC1D,KAAK,UAAU,eAAe,CAAC,EAA4B;IAC1D,IAAI,GAAG,GAAG,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA,CAAC,0CAA0C;IACvE,OAAO,GAAG,CAAA;AACX,CAAC;AAED,8DAA8D;AAC9D,KAAK,UAAU,MAAM,CAAC,EAA4B;IACjD,kDAAkD;IAClD,IAAI,MAAM,GAAG,MAAM,eAAe,CAAC,EAAE,CAAC,CAAA;IACtC,OAAO,MAAM,GAAG,CAAC,CAAA;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,4BAA4B;IAC5B,IAAI,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAS,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/C,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAErB,iCAAiC;IACjC,IAAI,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;IACtC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA,CAAC,sBAAsB;IAE/C,MAAM,CAAC,KAAK,EAAE,CAAA;AACf,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Generated file based on async_defer_statement.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
4
|
-
if (value !== null && value !== void 0) {
|
|
5
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
6
|
-
var dispose, inner;
|
|
7
|
-
if (async) {
|
|
8
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
9
|
-
dispose = value[Symbol.asyncDispose];
|
|
10
|
-
}
|
|
11
|
-
if (dispose === void 0) {
|
|
12
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
13
|
-
dispose = value[Symbol.dispose];
|
|
14
|
-
if (async) inner = dispose;
|
|
15
|
-
}
|
|
16
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
17
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
18
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
19
|
-
}
|
|
20
|
-
else if (async) {
|
|
21
|
-
env.stack.push({ async: true });
|
|
22
|
-
}
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
26
|
-
return function (env) {
|
|
27
|
-
function fail(e) {
|
|
28
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
29
|
-
env.hasError = true;
|
|
30
|
-
}
|
|
31
|
-
var r, s = 0;
|
|
32
|
-
function next() {
|
|
33
|
-
while (r = env.stack.pop()) {
|
|
34
|
-
try {
|
|
35
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
36
|
-
if (r.dispose) {
|
|
37
|
-
var result = r.dispose.call(r.value);
|
|
38
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
39
|
-
}
|
|
40
|
-
else s |= 1;
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
fail(e);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
47
|
-
if (env.hasError) throw env.error;
|
|
48
|
-
}
|
|
49
|
-
return next();
|
|
50
|
-
};
|
|
51
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
52
|
-
var e = new Error(message);
|
|
53
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
54
|
-
});
|
|
55
|
-
import * as goscript from "@goscript/builtin";
|
|
56
|
-
export async function main() {
|
|
57
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
58
|
-
try {
|
|
59
|
-
const __defer = __addDisposableResource(env_1, new goscript.AsyncDisposableStack(), true);
|
|
60
|
-
let ch = goscript.makeChannel(1, false);
|
|
61
|
-
// Wait for signal from main
|
|
62
|
-
__defer.defer(async () => {
|
|
63
|
-
console.log("deferred start");
|
|
64
|
-
await ch.receive();
|
|
65
|
-
console.log("deferred end");
|
|
66
|
-
});
|
|
67
|
-
console.log("main start");
|
|
68
|
-
console.log("main signaling defer");
|
|
69
|
-
await ch.send(true);
|
|
70
|
-
console.log("main end");
|
|
71
|
-
}
|
|
72
|
-
catch (e_1) {
|
|
73
|
-
env_1.error = e_1;
|
|
74
|
-
env_1.hasError = true;
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
const result_1 = __disposeResources(env_1);
|
|
78
|
-
if (result_1)
|
|
79
|
-
await result_1;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=async_defer_statement.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_defer_statement.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/async_defer_statement/async_defer_statement.gs.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,yDAAyD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,IAAI;;;QACzB,MAAY,OAAO,kCAAG,IAAI,QAAQ,CAAC,oBAAoB,EAAE,OAAA,CAAC;QAC1D,IAAI,EAAE,GAAG,QAAQ,CAAC,WAAW,CAAU,CAAC,EAAE,KAAK,CAAC,CAAA;QAEhD,4BAA4B;QAC5B,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;YACxB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;YAC7B,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA;YAClB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;QACnC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;;;;;;;;;;;CACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Generated file based on basic_arithmetic.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
export async function main() {
|
|
4
|
-
// === Basic Arithmetic ===
|
|
5
|
-
let add = 2 + 3;
|
|
6
|
-
let sub = 10 - 4;
|
|
7
|
-
let mul = 6 * 7;
|
|
8
|
-
let div = 20 / 5;
|
|
9
|
-
let mod = 17 % 3;
|
|
10
|
-
console.log("Addition: Expected: 5, Actual:", add);
|
|
11
|
-
console.log("Subtraction: Expected: 6, Actual:", sub);
|
|
12
|
-
console.log("Multiplication: Expected: 42, Actual:", mul);
|
|
13
|
-
console.log("Division: Expected: 4, Actual:", div);
|
|
14
|
-
console.log("Modulus: Expected: 2, Actual:", mod);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=basic_arithmetic.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basic_arithmetic.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/basic_arithmetic/basic_arithmetic.gs.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,yDAAyD;AAIzD,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,2BAA2B;IAC3B,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,CAAA;IAChB,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,CAAA;IAChB,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;IAClD,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAA;IACrD,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAA;IACzD,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;IAClD,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Generated file based on boolean_logic.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
export async function main() {
|
|
4
|
-
// === Boolean Logic ===
|
|
5
|
-
let a = true;
|
|
6
|
-
let b = false;
|
|
7
|
-
let and = a && b;
|
|
8
|
-
let or = a || b;
|
|
9
|
-
let notA = !a;
|
|
10
|
-
console.log("AND: Expected: false, Actual:", and);
|
|
11
|
-
console.log("OR: Expected: true, Actual:", or);
|
|
12
|
-
console.log("NOT: Expected: false, Actual:", notA);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=boolean_logic.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"boolean_logic.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/boolean_logic/boolean_logic.gs.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,yDAAyD;AAIzD,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,wBAAwB;IACxB,IAAI,CAAC,GAAG,IAAI,CAAA;IACZ,IAAI,CAAC,GAAG,KAAK,CAAA;IACb,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,IAAI,IAAI,GAAG,CAAC,CAAC,CAAA;IACb,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,EAAE,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Generated file based on channel_basic.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
import * as goscript from "@goscript/builtin";
|
|
4
|
-
export async function main() {
|
|
5
|
-
let messages = goscript.makeChannel(0, "");
|
|
6
|
-
queueMicrotask(async () => {
|
|
7
|
-
{
|
|
8
|
-
await messages.send("ping");
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
let msg = await messages.receive();
|
|
12
|
-
console.log(msg);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=channel_basic.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"channel_basic.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/channel_basic/channel_basic.gs.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,yDAAyD;AAEzD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,IAAI,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAS,CAAC,EAAE,EAAE,CAAC,CAAA;IAElD,cAAc,CAAC,KAAK,IAAI,EAAE;QACzB,CAAC;YACA,MAAM,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;IACF,CAAC,CAAC,CAAA;IAEF,IAAI,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAA;IAClC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACjB,CAAC"}
|
package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Generated file based on composite_literal_assignment.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
import * as goscript from "@goscript/builtin";
|
|
4
|
-
class MyStruct {
|
|
5
|
-
MyInt = 0;
|
|
6
|
-
MyString = "";
|
|
7
|
-
//nolint:unused
|
|
8
|
-
myBool = false;
|
|
9
|
-
constructor(init) { if (init)
|
|
10
|
-
Object.assign(this, init); }
|
|
11
|
-
clone() { return Object.assign(Object.create(MyStruct.prototype), this); }
|
|
12
|
-
// Register this type with the runtime type system
|
|
13
|
-
static __typeInfo = goscript.registerType('MyStruct', goscript.TypeKind.Struct, new MyStruct(), new Set([]), MyStruct);
|
|
14
|
-
}
|
|
15
|
-
export async function main() {
|
|
16
|
-
// === Composite Literal Assignment (Value Copy) ===
|
|
17
|
-
// Creating a struct directly using a composite literal.
|
|
18
|
-
let structLiteral = new MyStruct({ MyString: "composite literal" });
|
|
19
|
-
// Assigning it creates another independent copy.
|
|
20
|
-
let structLiteralCopy = structLiteral.clone();
|
|
21
|
-
structLiteralCopy.MyString = "modified composite literal copy";
|
|
22
|
-
// Expected: "composite literal"
|
|
23
|
-
console.log("Original struct literal: Expected: composite literal, Actual: " + structLiteral.MyString);
|
|
24
|
-
// Expected: "modified composite literal copy"
|
|
25
|
-
console.log("Modified struct literal copy: Expected: modified composite literal copy, Actual: " + structLiteralCopy.MyString);
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=composite_literal_assignment.gs.js.map
|
package/dist/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"composite_literal_assignment.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,yDAAyD;AAEzD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C,MAAM,QAAQ;IACN,KAAK,GAAW,CAAC,CAAC;IAClB,QAAQ,GAAW,EAAE,CAAC;IAC7B,eAAe;IACP,MAAM,GAAY,KAAK,CAAC;IAEhC,YAAY,IAAwB,IAAI,IAAI,IAAI;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC,CAAC,CAAC;IAC9E,KAAK,KAAe,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvG,kDAAkD;IAClD,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,YAAY,CACvC,UAAU,EACV,QAAQ,CAAC,QAAQ,CAAC,MAAM,EACxB,IAAI,QAAQ,EAAE,EACd,IAAI,GAAG,CAAC,EAAE,CAAC,EACX,QAAQ,CACT,CAAC;;AAGH,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,oDAAoD;IACpD,wDAAwD;IACxD,IAAI,aAAa,GAAG,IAAI,QAAQ,CAAC,EAAC,QAAQ,EAAE,mBAAmB,EAAC,CAAC,CAAA;IACjE,iDAAiD;IACjD,IAAI,iBAAiB,GAAG,aAAa,CAAC,KAAK,EAAE,CAAA;IAC7C,iBAAiB,CAAC,QAAQ,GAAG,iCAAiC,CAAA;IAC9D,gCAAgC;IAChC,OAAO,CAAC,GAAG,CAAC,gEAAgE,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtG,8CAA8C;IAC9C,OAAO,CAAC,GAAG,CAAC,mFAAmF,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AAC9H,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Generated file based on constants.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
let Pi = 3.14;
|
|
4
|
-
let Truth = false;
|
|
5
|
-
// TODO: Handle large integer constants and bit shifts exceeding JS number limits.
|
|
6
|
-
// Big = 1 << 60
|
|
7
|
-
// Small = Big >> 59 // Commented out as it depends on Big
|
|
8
|
-
let Greeting = "Hello, Constants!";
|
|
9
|
-
export async function main() {
|
|
10
|
-
console.log(Pi);
|
|
11
|
-
console.log(Truth);
|
|
12
|
-
// println(Big) // Commented out until large integer handling is implemented
|
|
13
|
-
// println(Small) // Commented out as it depends on Big
|
|
14
|
-
console.log(Greeting);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=constants.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/constants/constants.gs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,yDAAyD;AAIzD,IAAI,EAAE,GAAG,IAAI,CAAC;AAEd,IAAI,KAAK,GAAG,KAAK,CAAC;AAElB,kFAAkF;AAClF,qBAAqB;AACrB,6DAA6D;AAC7D,IAAI,QAAQ,GAAG,mBAAmB,CAAC;AAEnC,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,4EAA4E;IAC5E,uDAAuD;IACvD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACtB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Generated file based on copy_independence.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
import * as goscript from "@goscript/builtin";
|
|
4
|
-
class MyStruct {
|
|
5
|
-
MyInt = 0;
|
|
6
|
-
MyString = "";
|
|
7
|
-
constructor(init) { if (init)
|
|
8
|
-
Object.assign(this, init); }
|
|
9
|
-
clone() { return Object.assign(Object.create(MyStruct.prototype), this); }
|
|
10
|
-
// Register this type with the runtime type system
|
|
11
|
-
static __typeInfo = goscript.registerType('MyStruct', goscript.TypeKind.Struct, new MyStruct(), new Set([]), MyStruct);
|
|
12
|
-
}
|
|
13
|
-
export async function main() {
|
|
14
|
-
// Setup from previous steps (simplified for this test)
|
|
15
|
-
let structPointer = new MyStruct({ MyInt: 4, MyString: "hello world" });
|
|
16
|
-
let dereferencedStructCopy = structPointer.clone();
|
|
17
|
-
dereferencedStructCopy.MyString = "original dereferenced copy modified";
|
|
18
|
-
let valueCopy1 = dereferencedStructCopy.clone();
|
|
19
|
-
valueCopy1.MyString = "value copy 1";
|
|
20
|
-
let valueCopy2 = dereferencedStructCopy.clone();
|
|
21
|
-
valueCopy2.MyString = "value copy 2";
|
|
22
|
-
let pointerCopy = structPointer;
|
|
23
|
-
// === Verifying Copy Independence ===
|
|
24
|
-
// Expected: "hello world"
|
|
25
|
-
console.log("pointerCopy (points to original structPointer): Expected: hello world, Actual: " + pointerCopy.MyString);
|
|
26
|
-
// Expected: "original dereferenced copy modified"
|
|
27
|
-
console.log("dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: " + dereferencedStructCopy.MyString);
|
|
28
|
-
// Expected: "value copy 1"
|
|
29
|
-
console.log("valueCopy1: Expected: value copy 1, Actual: " + valueCopy1.MyString);
|
|
30
|
-
// Expected: "value copy 2"
|
|
31
|
-
console.log("valueCopy2: Expected: value copy 2, Actual: " + valueCopy2.MyString);
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=copy_independence.gs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"copy_independence.gs.js","sourceRoot":"","sources":["../../../../compliance/tests/copy_independence/copy_independence.gs.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,yDAAyD;AAEzD,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAE9C,MAAM,QAAQ;IACN,KAAK,GAAW,CAAC,CAAC;IAClB,QAAQ,GAAW,EAAE,CAAC;IAE7B,YAAY,IAAwB,IAAI,IAAI,IAAI;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC,CAAC,CAAC;IAC9E,KAAK,KAAe,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvG,kDAAkD;IAClD,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,YAAY,CACvC,UAAU,EACV,QAAQ,CAAC,QAAQ,CAAC,MAAM,EACxB,IAAI,QAAQ,EAAE,EACd,IAAI,GAAG,CAAC,EAAE,CAAC,EACX,QAAQ,CACT,CAAC;;AAGH,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,uDAAuD;IACvD,IAAI,aAAa,GAAG,IAAI,QAAQ,CAAC,EAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAC,CAAC,CAAA;IACrE,IAAI,sBAAsB,GAAG,aAAa,CAAC,KAAK,EAAE,CAAA;IAClD,sBAAsB,CAAC,QAAQ,GAAG,qCAAqC,CAAA;IACvE,IAAI,UAAU,GAAG,sBAAsB,CAAC,KAAK,EAAE,CAAA;IAC/C,UAAU,CAAC,QAAQ,GAAG,cAAc,CAAA;IACpC,IAAI,UAAU,GAAG,sBAAsB,CAAC,KAAK,EAAE,CAAA;IAC/C,UAAU,CAAC,QAAQ,GAAG,cAAc,CAAA;IACpC,IAAI,WAAW,GAAG,aAAa,CAAA;IAE/B,sCAAsC;IACtC,0BAA0B;IAC1B,OAAO,CAAC,GAAG,CAAC,iFAAiF,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;IACrH,kDAAkD;IAClD,OAAO,CAAC,GAAG,CAAC,mHAAmH,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAA;IAClK,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,8CAA8C,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IACjF,2BAA2B;IAC3B,OAAO,CAAC,GAAG,CAAC,8CAA8C,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): Promise<void>;
|