funkscript 0.0.0-stage → 0.2.4
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/LICENSE +21 -0
- package/README.md +204 -2
- package/dist/Widget.tsx +9 -0
- package/dist/ast/types.d.ts +513 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +5 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/ast/walk.d.ts +8 -0
- package/dist/ast/walk.d.ts.map +1 -0
- package/dist/ast/walk.js +23 -0
- package/dist/ast/walk.js.map +1 -0
- package/dist/cli/build-bun.d.ts +24 -0
- package/dist/cli/build-bun.d.ts.map +1 -0
- package/dist/cli/build-bun.js +190 -0
- package/dist/cli/build-bun.js.map +1 -0
- package/dist/cli/build-watch.d.ts +21 -0
- package/dist/cli/build-watch.d.ts.map +1 -0
- package/dist/cli/build-watch.js +244 -0
- package/dist/cli/build-watch.js.map +1 -0
- package/dist/cli/build.d.ts +4 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +338 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/check.d.ts +4 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +278 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/commands.d.ts +13 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +262 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/doc.d.ts +3 -0
- package/dist/cli/doc.d.ts.map +1 -0
- package/dist/cli/doc.js +71 -0
- package/dist/cli/doc.js.map +1 -0
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +121 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/emit.d.ts +4 -0
- package/dist/cli/emit.d.ts.map +1 -0
- package/dist/cli/emit.js +87 -0
- package/dist/cli/emit.js.map +1 -0
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +103 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fmt.d.ts +3 -0
- package/dist/cli/fmt.d.ts.map +1 -0
- package/dist/cli/fmt.js +146 -0
- package/dist/cli/fmt.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +186 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +412 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/io.d.ts +9 -0
- package/dist/cli/io.d.ts.map +1 -0
- package/dist/cli/io.js +113 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/output-collisions.d.ts +2 -0
- package/dist/cli/output-collisions.d.ts.map +1 -0
- package/dist/cli/output-collisions.js +39 -0
- package/dist/cli/output-collisions.js.map +1 -0
- package/dist/cli/pipeline-style.d.ts +3 -0
- package/dist/cli/pipeline-style.d.ts.map +1 -0
- package/dist/cli/pipeline-style.js +45 -0
- package/dist/cli/pipeline-style.js.map +1 -0
- package/dist/cli/repl.d.ts +37 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +334 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/run.d.ts +4 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +185 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +124 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/tsc.d.ts +3 -0
- package/dist/cli/tsc.d.ts.map +1 -0
- package/dist/cli/tsc.js +143 -0
- package/dist/cli/tsc.js.map +1 -0
- package/dist/cli/typecheck.d.ts +23 -0
- package/dist/cli/typecheck.d.ts.map +1 -0
- package/dist/cli/typecheck.js +65 -0
- package/dist/cli/typecheck.js.map +1 -0
- package/dist/compiler/ast-inspection.d.ts +18 -0
- package/dist/compiler/ast-inspection.d.ts.map +1 -0
- package/dist/compiler/ast-inspection.js +96 -0
- package/dist/compiler/ast-inspection.js.map +1 -0
- package/dist/compiler/boolean-operators.d.ts +8 -0
- package/dist/compiler/boolean-operators.d.ts.map +1 -0
- package/dist/compiler/boolean-operators.js +84 -0
- package/dist/compiler/boolean-operators.js.map +1 -0
- package/dist/compiler/check.d.ts +87 -0
- package/dist/compiler/check.d.ts.map +1 -0
- package/dist/compiler/check.js +1830 -0
- package/dist/compiler/check.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts +6 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +136 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/effect-mutation-rule.d.ts +4 -0
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -0
- package/dist/compiler/effect-mutation-rule.js +348 -0
- package/dist/compiler/effect-mutation-rule.js.map +1 -0
- package/dist/compiler/entry-rules.d.ts +5 -0
- package/dist/compiler/entry-rules.d.ts.map +1 -0
- package/dist/compiler/entry-rules.js +89 -0
- package/dist/compiler/entry-rules.js.map +1 -0
- package/dist/compiler/imported-record-functions.d.ts +4 -0
- package/dist/compiler/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/imported-record-functions.js +706 -0
- package/dist/compiler/imported-record-functions.js.map +1 -0
- package/dist/compiler/imported-schemas.d.ts +21 -0
- package/dist/compiler/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/imported-schemas.js +461 -0
- package/dist/compiler/imported-schemas.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts +23 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -0
- package/dist/compiler/incremental-build.js +90 -0
- package/dist/compiler/incremental-build.js.map +1 -0
- package/dist/compiler/incremental-dependencies.d.ts +7 -0
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -0
- package/dist/compiler/incremental-dependencies.js +190 -0
- package/dist/compiler/incremental-dependencies.js.map +1 -0
- package/dist/compiler/js-interop-nullability.d.ts +9 -0
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -0
- package/dist/compiler/js-interop-nullability.js +57 -0
- package/dist/compiler/js-interop-nullability.js.map +1 -0
- package/dist/compiler/module-resolution.d.ts +6 -0
- package/dist/compiler/module-resolution.d.ts.map +1 -0
- package/dist/compiler/module-resolution.js +44 -0
- package/dist/compiler/module-resolution.js.map +1 -0
- package/dist/compiler/modules/output-collisions.d.ts +2 -0
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -0
- package/dist/compiler/modules/output-collisions.js +39 -0
- package/dist/compiler/modules/output-collisions.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts +7 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -0
- package/dist/compiler/modules/output-plan.js +37 -0
- package/dist/compiler/modules/output-plan.js.map +1 -0
- package/dist/compiler/modules/resolution.d.ts +8 -0
- package/dist/compiler/modules/resolution.d.ts.map +1 -0
- package/dist/compiler/modules/resolution.js +48 -0
- package/dist/compiler/modules/resolution.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts +9 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -0
- package/dist/compiler/numeric-comparisons.js +153 -0
- package/dist/compiler/numeric-comparisons.js.map +1 -0
- package/dist/compiler/optional-arguments.d.ts +11 -0
- package/dist/compiler/optional-arguments.d.ts.map +1 -0
- package/dist/compiler/optional-arguments.js +246 -0
- package/dist/compiler/optional-arguments.js.map +1 -0
- package/dist/compiler/package-fingerprint.d.ts +7 -0
- package/dist/compiler/package-fingerprint.d.ts.map +1 -0
- package/dist/compiler/package-fingerprint.js +178 -0
- package/dist/compiler/package-fingerprint.js.map +1 -0
- package/dist/compiler/package-record-contracts.d.ts +5 -0
- package/dist/compiler/package-record-contracts.d.ts.map +1 -0
- package/dist/compiler/package-record-contracts.js +126 -0
- package/dist/compiler/package-record-contracts.js.map +1 -0
- package/dist/compiler/pipeline-companions.d.ts +18 -0
- package/dist/compiler/pipeline-companions.d.ts.map +1 -0
- package/dist/compiler/pipeline-companions.js +1042 -0
- package/dist/compiler/pipeline-companions.js.map +1 -0
- package/dist/compiler/pipelines/catalog.d.ts +15 -0
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -0
- package/dist/compiler/pipelines/catalog.js +55 -0
- package/dist/compiler/pipelines/catalog.js.map +1 -0
- package/dist/compiler/pipelines/companions.d.ts +18 -0
- package/dist/compiler/pipelines/companions.d.ts.map +1 -0
- package/dist/compiler/pipelines/companions.js +1042 -0
- package/dist/compiler/pipelines/companions.js.map +1 -0
- package/dist/compiler/pipelines/resolution.d.ts +38 -0
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -0
- package/dist/compiler/pipelines/resolution.js +571 -0
- package/dist/compiler/pipelines/resolution.js.map +1 -0
- package/dist/compiler/project-config.d.ts +28 -0
- package/dist/compiler/project-config.d.ts.map +1 -0
- package/dist/compiler/project-config.js +155 -0
- package/dist/compiler/project-config.js.map +1 -0
- package/dist/compiler/providers.d.ts +4 -0
- package/dist/compiler/providers.d.ts.map +1 -0
- package/dist/compiler/providers.js +101 -0
- package/dist/compiler/providers.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts +6 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -0
- package/dist/compiler/record-contracts.js +41 -0
- package/dist/compiler/record-contracts.js.map +1 -0
- package/dist/compiler/rules/control-flow.d.ts +10 -0
- package/dist/compiler/rules/control-flow.d.ts.map +1 -0
- package/dist/compiler/rules/control-flow.js +19 -0
- package/dist/compiler/rules/control-flow.js.map +1 -0
- package/dist/compiler/rules/diagnostic.d.ts +4 -0
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -0
- package/dist/compiler/rules/diagnostic.js +2 -0
- package/dist/compiler/rules/diagnostic.js.map +1 -0
- package/dist/compiler/rules/module-scope-refs.d.ts +5 -0
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -0
- package/dist/compiler/rules/module-scope-refs.js +47 -0
- package/dist/compiler/rules/module-scope-refs.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts +13 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -0
- package/dist/compiler/schemas/analysis.js +24 -0
- package/dist/compiler/schemas/analysis.js.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts +4 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.js +706 -0
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -0
- package/dist/compiler/schemas/imported-schemas.d.ts +21 -0
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-schemas.js +461 -0
- package/dist/compiler/schemas/imported-schemas.js.map +1 -0
- package/dist/compiler/source-map.d.ts +6 -0
- package/dist/compiler/source-map.d.ts.map +1 -0
- package/dist/compiler/source-map.js +127 -0
- package/dist/compiler/source-map.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts +33 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -0
- package/dist/compiler/typescript-context.js +200 -0
- package/dist/compiler/typescript-context.js.map +1 -0
- package/dist/compiler.d.ts +77 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +497 -0
- package/dist/compiler.js.map +1 -0
- package/dist/emitter/assemblyscript.d.ts +5 -0
- package/dist/emitter/assemblyscript.d.ts.map +1 -0
- package/dist/emitter/assemblyscript.js +979 -0
- package/dist/emitter/assemblyscript.js.map +1 -0
- package/dist/emitter/declarations.d.ts +46 -0
- package/dist/emitter/declarations.d.ts.map +1 -0
- package/dist/emitter/declarations.js +739 -0
- package/dist/emitter/declarations.js.map +1 -0
- package/dist/emitter/emitter.d.ts +165 -0
- package/dist/emitter/emitter.d.ts.map +1 -0
- package/dist/emitter/emitter.js +2448 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/emitter/imports.d.ts +6 -0
- package/dist/emitter/imports.d.ts.map +1 -0
- package/dist/emitter/imports.js +73 -0
- package/dist/emitter/imports.js.map +1 -0
- package/dist/emitter/indent.d.ts +3 -0
- package/dist/emitter/indent.d.ts.map +1 -0
- package/dist/emitter/indent.js +31 -0
- package/dist/emitter/indent.js.map +1 -0
- package/dist/emitter/jsx.d.ts +20 -0
- package/dist/emitter/jsx.d.ts.map +1 -0
- package/dist/emitter/jsx.js +82 -0
- package/dist/emitter/jsx.js.map +1 -0
- package/dist/emitter/local-bindings.d.ts +6 -0
- package/dist/emitter/local-bindings.d.ts.map +1 -0
- package/dist/emitter/local-bindings.js +32 -0
- package/dist/emitter/local-bindings.js.map +1 -0
- package/dist/emitter/match.d.ts +56 -0
- package/dist/emitter/match.d.ts.map +1 -0
- package/dist/emitter/match.js +1287 -0
- package/dist/emitter/match.js.map +1 -0
- package/dist/emitter/pipeline-catalog.d.ts +15 -0
- package/dist/emitter/pipeline-catalog.d.ts.map +1 -0
- package/dist/emitter/pipeline-catalog.js +55 -0
- package/dist/emitter/pipeline-catalog.js.map +1 -0
- package/dist/emitter/pipeline-resolution.d.ts +38 -0
- package/dist/emitter/pipeline-resolution.d.ts.map +1 -0
- package/dist/emitter/pipeline-resolution.js +571 -0
- package/dist/emitter/pipeline-resolution.js.map +1 -0
- package/dist/emitter/runtime-helpers.d.ts +10 -0
- package/dist/emitter/runtime-helpers.d.ts.map +1 -0
- package/dist/emitter/runtime-helpers.js +22 -0
- package/dist/emitter/runtime-helpers.js.map +1 -0
- package/dist/emitter/schemas.d.ts +36 -0
- package/dist/emitter/schemas.d.ts.map +1 -0
- package/dist/emitter/schemas.js +766 -0
- package/dist/emitter/schemas.js.map +1 -0
- package/dist/emitter/statements.d.ts +23 -0
- package/dist/emitter/statements.d.ts.map +1 -0
- package/dist/emitter/statements.js +216 -0
- package/dist/emitter/statements.js.map +1 -0
- package/dist/emitter/tagged-match.d.ts +23 -0
- package/dist/emitter/tagged-match.d.ts.map +1 -0
- package/dist/emitter/tagged-match.js +109 -0
- package/dist/emitter/tagged-match.js.map +1 -0
- package/dist/emitter/types.d.ts +22 -0
- package/dist/emitter/types.d.ts.map +1 -0
- package/dist/emitter/types.js +231 -0
- package/dist/emitter/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +98 -0
- package/dist/errors.js.map +1 -0
- package/dist/formatter/comments.d.ts +25 -0
- package/dist/formatter/comments.d.ts.map +1 -0
- package/dist/formatter/comments.js +283 -0
- package/dist/formatter/comments.js.map +1 -0
- package/dist/formatter/index.d.ts +71 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +1113 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/operator-precedence.d.ts +3 -0
- package/dist/formatter/operator-precedence.d.ts.map +1 -0
- package/dist/formatter/operator-precedence.js +27 -0
- package/dist/formatter/operator-precedence.js.map +1 -0
- package/dist/formatter/prettier.d.ts +7 -0
- package/dist/formatter/prettier.d.ts.map +1 -0
- package/dist/formatter/prettier.js +51 -0
- package/dist/formatter/prettier.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/interop/callback.d.ts +38 -0
- package/dist/interop/callback.d.ts.map +1 -0
- package/dist/interop/callback.js +130 -0
- package/dist/interop/callback.js.map +1 -0
- package/dist/interop/index.d.ts +6 -0
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +6 -0
- package/dist/interop/index.js.map +1 -0
- package/dist/interop/js.d.ts +16 -0
- package/dist/interop/js.d.ts.map +1 -0
- package/dist/interop/js.js +35 -0
- package/dist/interop/js.js.map +1 -0
- package/dist/interop/record.d.ts +9 -0
- package/dist/interop/record.d.ts.map +1 -0
- package/dist/interop/record.js +18 -0
- package/dist/interop/record.js.map +1 -0
- package/dist/interop/valibot.d.ts +9 -0
- package/dist/interop/valibot.d.ts.map +1 -0
- package/dist/interop/valibot.js +94 -0
- package/dist/interop/valibot.js.map +1 -0
- package/dist/interop/zod.d.ts +45 -0
- package/dist/interop/zod.d.ts.map +1 -0
- package/dist/interop/zod.js +143 -0
- package/dist/interop/zod.js.map +1 -0
- package/dist/lexer/lexer.d.ts +65 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +1335 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +96 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +150 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/lsp/code-action-worker.d.ts +2 -0
- package/dist/lsp/code-action-worker.d.ts.map +1 -0
- package/dist/lsp/code-action-worker.js +17 -0
- package/dist/lsp/code-action-worker.js.map +1 -0
- package/dist/lsp/completion.d.ts +11 -0
- package/dist/lsp/completion.d.ts.map +1 -0
- package/dist/lsp/completion.js +260 -0
- package/dist/lsp/completion.js.map +1 -0
- package/dist/lsp/definition.d.ts +42 -0
- package/dist/lsp/definition.d.ts.map +1 -0
- package/dist/lsp/definition.js +1074 -0
- package/dist/lsp/definition.js.map +1 -0
- package/dist/lsp/diagnostics-worker.d.ts +2 -0
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -0
- package/dist/lsp/diagnostics-worker.js +169 -0
- package/dist/lsp/diagnostics-worker.js.map +1 -0
- package/dist/lsp/docs.d.ts +37 -0
- package/dist/lsp/docs.d.ts.map +1 -0
- package/dist/lsp/docs.js +830 -0
- package/dist/lsp/docs.js.map +1 -0
- package/dist/lsp/error-channel.d.ts +3 -0
- package/dist/lsp/error-channel.d.ts.map +1 -0
- package/dist/lsp/error-channel.js +48 -0
- package/dist/lsp/error-channel.js.map +1 -0
- package/dist/lsp/hover.d.ts +5 -0
- package/dist/lsp/hover.d.ts.map +1 -0
- package/dist/lsp/hover.js +651 -0
- package/dist/lsp/hover.js.map +1 -0
- package/dist/lsp/imports.d.ts +5 -0
- package/dist/lsp/imports.d.ts.map +1 -0
- package/dist/lsp/imports.js +317 -0
- package/dist/lsp/imports.js.map +1 -0
- package/dist/lsp/index.d.ts +16 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +17 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/inlay-hints.d.ts +3 -0
- package/dist/lsp/inlay-hints.d.ts.map +1 -0
- package/dist/lsp/inlay-hints.js +236 -0
- package/dist/lsp/inlay-hints.js.map +1 -0
- package/dist/lsp/interop-rename.d.ts +26 -0
- package/dist/lsp/interop-rename.d.ts.map +1 -0
- package/dist/lsp/interop-rename.js +346 -0
- package/dist/lsp/interop-rename.js.map +1 -0
- package/dist/lsp/match-arms.d.ts +3 -0
- package/dist/lsp/match-arms.d.ts.map +1 -0
- package/dist/lsp/match-arms.js +341 -0
- package/dist/lsp/match-arms.js.map +1 -0
- package/dist/lsp/navigation.d.ts +23 -0
- package/dist/lsp/navigation.d.ts.map +1 -0
- package/dist/lsp/navigation.js +430 -0
- package/dist/lsp/navigation.js.map +1 -0
- package/dist/lsp/parsed-documents.d.ts +25 -0
- package/dist/lsp/parsed-documents.d.ts.map +1 -0
- package/dist/lsp/parsed-documents.js +47 -0
- package/dist/lsp/parsed-documents.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts +2 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -0
- package/dist/lsp/rename-worker.js +27 -0
- package/dist/lsp/rename-worker.js.map +1 -0
- package/dist/lsp/server.d.ts +78 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +1098 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts +4 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -0
- package/dist/lsp/thunk-pipeline.js +95 -0
- package/dist/lsp/thunk-pipeline.js.map +1 -0
- package/dist/lsp/validation.d.ts +8 -0
- package/dist/lsp/validation.d.ts.map +1 -0
- package/dist/lsp/validation.js +124 -0
- package/dist/lsp/validation.js.map +1 -0
- package/dist/lsp/workspace.d.ts +8 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +70 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/math.ts +1 -0
- package/dist/parser/declarations.d.ts +21 -0
- package/dist/parser/declarations.d.ts.map +1 -0
- package/dist/parser/declarations.js +626 -0
- package/dist/parser/declarations.js.map +1 -0
- package/dist/parser/errors.d.ts +9 -0
- package/dist/parser/errors.d.ts.map +1 -0
- package/dist/parser/errors.js +11 -0
- package/dist/parser/errors.js.map +1 -0
- package/dist/parser/index.d.ts +9 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +9 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/jsx.d.ts +5 -0
- package/dist/parser/jsx.d.ts.map +1 -0
- package/dist/parser/jsx.js +188 -0
- package/dist/parser/jsx.js.map +1 -0
- package/dist/parser/operator-expressions.d.ts +16 -0
- package/dist/parser/operator-expressions.d.ts.map +1 -0
- package/dist/parser/operator-expressions.js +146 -0
- package/dist/parser/operator-expressions.js.map +1 -0
- package/dist/parser/parser.d.ts +104 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +1216 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/patterns.d.ts +9 -0
- package/dist/parser/patterns.d.ts.map +1 -0
- package/dist/parser/patterns.js +292 -0
- package/dist/parser/patterns.js.map +1 -0
- package/dist/parser/pipeline-expressions.d.ts +10 -0
- package/dist/parser/pipeline-expressions.d.ts.map +1 -0
- package/dist/parser/pipeline-expressions.js +57 -0
- package/dist/parser/pipeline-expressions.js.map +1 -0
- package/dist/parser/scope.d.ts +17 -0
- package/dist/parser/scope.d.ts.map +1 -0
- package/dist/parser/scope.js +56 -0
- package/dist/parser/scope.js.map +1 -0
- package/dist/parser/statements.d.ts +13 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +737 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/types.d.ts +13 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +371 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/plugins/bun-preload.d.ts +4 -0
- package/dist/plugins/bun-preload.d.ts.map +1 -0
- package/dist/plugins/bun-preload.js +18 -0
- package/dist/plugins/bun-preload.js.map +1 -0
- package/dist/plugins/bun.d.ts +115 -0
- package/dist/plugins/bun.d.ts.map +1 -0
- package/dist/plugins/bun.js +240 -0
- package/dist/plugins/bun.js.map +1 -0
- package/dist/plugins/esbuild.d.ts +45 -0
- package/dist/plugins/esbuild.d.ts.map +1 -0
- package/dist/plugins/esbuild.js +184 -0
- package/dist/plugins/esbuild.js.map +1 -0
- package/dist/plugins/type-view.d.ts +30 -0
- package/dist/plugins/type-view.d.ts.map +1 -0
- package/dist/plugins/type-view.js +245 -0
- package/dist/plugins/type-view.js.map +1 -0
- package/dist/plugins/vite.d.ts +56 -0
- package/dist/plugins/vite.d.ts.map +1 -0
- package/dist/plugins/vite.js +182 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/service.ts +3 -0
- package/dist/service.ts.map +1 -0
- package/dist/testing/index.d.ts +24 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +56 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tooling/doc.d.ts +82 -0
- package/dist/tooling/doc.d.ts.map +1 -0
- package/dist/tooling/doc.js +624 -0
- package/dist/tooling/doc.js.map +1 -0
- package/dist/tooling/idiomatic.d.ts +20 -0
- package/dist/tooling/idiomatic.d.ts.map +1 -0
- package/dist/tooling/idiomatic.js +154 -0
- package/dist/tooling/idiomatic.js.map +1 -0
- package/dist/tooling/migrate.d.ts +62 -0
- package/dist/tooling/migrate.d.ts.map +1 -0
- package/dist/tooling/migrate.js +608 -0
- package/dist/tooling/migrate.js.map +1 -0
- package/dist/tooling/pipeline-style.d.ts +12 -0
- package/dist/tooling/pipeline-style.d.ts.map +1 -0
- package/dist/tooling/pipeline-style.js +208 -0
- package/dist/tooling/pipeline-style.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +25 -0
- package/dist/version.js.map +1 -0
- package/package.json +128 -4
- package/src/ast/types.ts +753 -0
- package/src/ast/walk.ts +35 -0
- package/src/cli/build-bun.ts +249 -0
- package/src/cli/build-watch.ts +299 -0
- package/src/cli/build.ts +450 -0
- package/src/cli/check.ts +342 -0
- package/src/cli/commands.ts +301 -0
- package/src/cli/doc.ts +81 -0
- package/src/cli/doctor.ts +173 -0
- package/src/cli/emit.ts +138 -0
- package/src/cli/explain.ts +127 -0
- package/src/cli/fmt.ts +170 -0
- package/src/cli/index.ts +227 -0
- package/src/cli/init.ts +491 -0
- package/src/cli/io.ts +150 -0
- package/src/cli/pipeline-style.ts +55 -0
- package/src/cli/repl.ts +443 -0
- package/src/cli/run.ts +238 -0
- package/src/cli/test.ts +148 -0
- package/src/cli/tsc.ts +207 -0
- package/src/cli/typecheck.ts +100 -0
- package/src/compiler/ast-inspection.ts +121 -0
- package/src/compiler/boolean-operators.ts +108 -0
- package/src/compiler/check.ts +2763 -0
- package/src/compiler/diagnostics.ts +179 -0
- package/src/compiler/effect-mutation-rule.ts +407 -0
- package/src/compiler/entry-rules.ts +116 -0
- package/src/compiler/incremental-build.ts +131 -0
- package/src/compiler/incremental-dependencies.ts +200 -0
- package/src/compiler/js-interop-nullability.ts +67 -0
- package/src/compiler/modules/output-collisions.ts +48 -0
- package/src/compiler/modules/output-plan.ts +46 -0
- package/src/compiler/modules/resolution.ts +56 -0
- package/src/compiler/numeric-comparisons.ts +213 -0
- package/src/compiler/optional-arguments.ts +335 -0
- package/src/compiler/package-fingerprint.ts +216 -0
- package/src/compiler/package-record-contracts.ts +156 -0
- package/src/compiler/pipelines/catalog.ts +1128 -0
- package/src/compiler/pipelines/companions.ts +1279 -0
- package/src/compiler/pipelines/resolution.ts +684 -0
- package/src/compiler/project-config.ts +221 -0
- package/src/compiler/record-contracts.ts +46 -0
- package/src/compiler/rules/control-flow.ts +57 -0
- package/src/compiler/rules/diagnostic.ts +11 -0
- package/src/compiler/rules/module-scope-refs.ts +63 -0
- package/src/compiler/schemas/analysis.ts +45 -0
- package/src/compiler/schemas/imported-record-functions.ts +984 -0
- package/src/compiler/schemas/imported-schemas.ts +761 -0
- package/src/compiler/source-map.ts +165 -0
- package/src/compiler/typescript-context.ts +250 -0
- package/src/compiler.ts +865 -0
- package/src/emitter/assemblyscript.ts +1220 -0
- package/src/emitter/declarations.ts +916 -0
- package/src/emitter/emitter.ts +3128 -0
- package/src/emitter/imports.ts +89 -0
- package/src/emitter/indent.ts +39 -0
- package/src/emitter/jsx.ts +122 -0
- package/src/emitter/local-bindings.ts +40 -0
- package/src/emitter/match.ts +1631 -0
- package/src/emitter/runtime-helpers.ts +31 -0
- package/src/emitter/schemas.ts +969 -0
- package/src/emitter/statements.ts +310 -0
- package/src/emitter/tagged-match.ts +171 -0
- package/src/emitter/types.ts +289 -0
- package/src/errors.ts +115 -0
- package/src/formatter/comments.ts +350 -0
- package/src/formatter/index.ts +1457 -0
- package/src/formatter/operator-precedence.ts +36 -0
- package/src/formatter/prettier.ts +61 -0
- package/src/index.ts +16 -0
- package/src/interop/callback.ts +188 -0
- package/src/interop/js.ts +66 -0
- package/src/interop/record.ts +36 -0
- package/src/interop/valibot.ts +141 -0
- package/src/interop/zod.ts +219 -0
- package/src/lexer/lexer.ts +1521 -0
- package/src/lexer/tokens.ts +174 -0
- package/src/lsp/code-action-worker.ts +31 -0
- package/src/lsp/completion.ts +343 -0
- package/src/lsp/definition.ts +1165 -0
- package/src/lsp/diagnostics-worker.ts +198 -0
- package/src/lsp/docs.ts +864 -0
- package/src/lsp/error-channel.ts +63 -0
- package/src/lsp/hover.ts +803 -0
- package/src/lsp/imports.ts +380 -0
- package/src/lsp/index.ts +55 -0
- package/src/lsp/inlay-hints.ts +308 -0
- package/src/lsp/interop-rename.ts +454 -0
- package/src/lsp/match-arms.ts +400 -0
- package/src/lsp/navigation.ts +553 -0
- package/src/lsp/parsed-documents.ts +64 -0
- package/src/lsp/rename-worker.ts +40 -0
- package/src/lsp/server.ts +1437 -0
- package/src/lsp/thunk-pipeline.ts +117 -0
- package/src/lsp/validation.ts +147 -0
- package/src/lsp/workspace.ts +74 -0
- package/src/parser/declarations.ts +808 -0
- package/src/parser/errors.ts +18 -0
- package/src/parser/jsx.ts +253 -0
- package/src/parser/operator-expressions.ts +170 -0
- package/src/parser/parser.ts +1565 -0
- package/src/parser/patterns.ts +342 -0
- package/src/parser/pipeline-expressions.ts +77 -0
- package/src/parser/scope.ts +69 -0
- package/src/parser/statements.ts +831 -0
- package/src/parser/types.ts +453 -0
- package/src/plugins/bun-preload.ts +25 -0
- package/src/plugins/bun.ts +448 -0
- package/src/plugins/esbuild.ts +308 -0
- package/src/plugins/type-view.ts +326 -0
- package/src/plugins/vite.ts +294 -0
- package/src/testing/index.ts +72 -0
- package/src/tooling/doc.ts +786 -0
- package/src/tooling/idiomatic.ts +202 -0
- package/src/tooling/pipeline-style.ts +248 -0
- package/src/version.ts +27 -0
package/src/compiler.ts
ADDED
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type { SourceMap } from "magic-string";
|
|
3
|
+
export type { SourceMap };
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
type BindingTarget,
|
|
8
|
+
type Pattern,
|
|
9
|
+
type Program,
|
|
10
|
+
type Span,
|
|
11
|
+
} from "./ast/types.js";
|
|
12
|
+
import { walkAst } from "./ast/walk.js";
|
|
13
|
+
import { collectImportedSchemaFacts } from "./compiler/schemas/analysis.js";
|
|
14
|
+
import { resolveImportedSchemas } from "./compiler/schemas/imported-schemas.js";
|
|
15
|
+
import { applyJsInteropNullability } from "./compiler/js-interop-nullability.js";
|
|
16
|
+
import { validateBooleanOperators } from "./compiler/boolean-operators.js";
|
|
17
|
+
import { validateNumericComparisons } from "./compiler/numeric-comparisons.js";
|
|
18
|
+
import { resolveOptionalArguments } from "./compiler/optional-arguments.js";
|
|
19
|
+
import { inferPipelineCompanions } from "./compiler/pipelines/companions.js";
|
|
20
|
+
import { isPathPolicyEnabled } from "./compiler/project-config.js";
|
|
21
|
+
import { generateSourceMap } from "./compiler/source-map.js";
|
|
22
|
+
import { TypeScriptCompilationContext } from "./compiler/typescript-context.js";
|
|
23
|
+
import { prepareAssemblyScript } from "./emitter/assemblyscript.js";
|
|
24
|
+
import { Emitter, type EmitterOptions } from "./emitter/emitter.js";
|
|
25
|
+
import { PIPELINE_COMPANION_CATALOG } from "./compiler/pipelines/catalog.js";
|
|
26
|
+
import { FunScriptError, toErrorMessage } from "./errors.js";
|
|
27
|
+
import { Lexer, type LexerError } from "./lexer/lexer.js";
|
|
28
|
+
import { Parser, type ParseError } from "./parser/parser.js";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
TYPE_FEST_DECLARATION,
|
|
32
|
+
TypeScriptCompilationContext,
|
|
33
|
+
} from "./compiler/typescript-context.js";
|
|
34
|
+
|
|
35
|
+
export interface CompileOptions {
|
|
36
|
+
sourcemap?: boolean;
|
|
37
|
+
/** Reject raw TypeScript escapes in FunkScript source. */
|
|
38
|
+
noTs?: boolean;
|
|
39
|
+
/** Reject authored references to globalThis. */
|
|
40
|
+
noGlobalThis?: boolean;
|
|
41
|
+
/** Enforce bare pipeline stages for known companions instead of redundant Module.method prefixes. */
|
|
42
|
+
barePipelines?: boolean;
|
|
43
|
+
/** Reject deeply nested destructuring patterns exceeding maxDestructureDepth (defaults to 2). */
|
|
44
|
+
noDeepDestructure?: boolean;
|
|
45
|
+
/** Directories governed by the noDeepDestructure policy, relative to policyRoot. */
|
|
46
|
+
noDeepDestructurePaths?: string[];
|
|
47
|
+
/** Maximum destructuring depth allowed (defaults to 2 when noDeepDestructure is active). */
|
|
48
|
+
maxDestructureDepth?: number;
|
|
49
|
+
/** Restrict authored source to Effect ecosystem imports and explicit Effect APIs. */
|
|
50
|
+
effectOnly?: boolean;
|
|
51
|
+
/** Directories governed by the Effect-only policy, relative to policyRoot. */
|
|
52
|
+
effectOnlyDirectories?: string[];
|
|
53
|
+
/** Allow unfinished typed holes ('???') during compilation (defaults to false; holes fail build by default). */
|
|
54
|
+
allowHoles?: boolean;
|
|
55
|
+
/** Allow early returns ('when (...) =>') during compilation (defaults to false). */
|
|
56
|
+
allowEarlyReturns?: boolean;
|
|
57
|
+
allowEarlyReturnsPaths?: string[];
|
|
58
|
+
policyRoot?: string;
|
|
59
|
+
outputFile?: string;
|
|
60
|
+
context?: TypeScriptCompilationContext;
|
|
61
|
+
/** In-memory source files, keyed by absolute path, for cross-module analysis. */
|
|
62
|
+
virtualSources?: ReadonlyMap<string, string>;
|
|
63
|
+
/** Return compiler pipeline metadata without emitting a TypeScript program. @internal */
|
|
64
|
+
pipelineAnalysisOnly?: boolean;
|
|
65
|
+
/** Absolute source path when the displayed filename is project-relative. */
|
|
66
|
+
sourcePath?: string;
|
|
67
|
+
/** Emit modular subpath imports (e.g. 'effect/Effect', 'effect/Option') instead of barrel imports from 'effect'. */
|
|
68
|
+
modularEffectImports?: boolean;
|
|
69
|
+
/** Preserve direct FunkScript specifiers for runtime loaders. @internal */
|
|
70
|
+
preserveFunImports?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CompileResult {
|
|
74
|
+
source: string;
|
|
75
|
+
ast: Program;
|
|
76
|
+
typescript: string;
|
|
77
|
+
targetExtension: string;
|
|
78
|
+
/** Type-directed pipeline stage resolution produced by the compiler pass. */
|
|
79
|
+
pipelineStageResolutions: ReadonlyMap<
|
|
80
|
+
number,
|
|
81
|
+
import("./emitter/emitter.js").StageResolution
|
|
82
|
+
>;
|
|
83
|
+
/** Inferred input companion for each pipeline stage offset. */
|
|
84
|
+
pipelineStageInputCompanions: ReadonlyMap<number, string>;
|
|
85
|
+
/** Qualified stages whose receiver type allows the equivalent bare form. */
|
|
86
|
+
barePipelineStageResolutions: ReadonlyMap<
|
|
87
|
+
number,
|
|
88
|
+
import("./emitter/emitter.js").StageResolution
|
|
89
|
+
>;
|
|
90
|
+
map?: SourceMap;
|
|
91
|
+
sourcemap?: SourceMap;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class CompilerError extends FunScriptError {
|
|
95
|
+
readonly _tag = "CompilerError";
|
|
96
|
+
constructor(
|
|
97
|
+
public readonly message: string,
|
|
98
|
+
public readonly error: LexerError | ParseError | Error,
|
|
99
|
+
source?: string,
|
|
100
|
+
) {
|
|
101
|
+
const span = "span" in error ? (error as { span?: Span }).span : undefined;
|
|
102
|
+
super(message, span, source);
|
|
103
|
+
this.name = "CompilerError";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Reject authored raw TypeScript escapes and banned legacy/unsafe types. */
|
|
108
|
+
function validateNoBannedTypes(ast: Program): void {
|
|
109
|
+
walkAst(ast, (node) => {
|
|
110
|
+
if (
|
|
111
|
+
(node.kind === "SchemaDeclaration" ||
|
|
112
|
+
node.kind === "ErrorDeclaration" ||
|
|
113
|
+
node.kind === "ServiceDeclaration") &&
|
|
114
|
+
(node.id as { name?: string })?.name === "JSNullish"
|
|
115
|
+
) {
|
|
116
|
+
throw new FunScriptError(
|
|
117
|
+
"'JSNullish' is a built-in interop type and cannot be redeclared",
|
|
118
|
+
node.span as Span | undefined,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (node.kind === "ImportDeclaration") {
|
|
122
|
+
const decl =
|
|
123
|
+
node as unknown as import("./ast/types.js").ImportDeclaration;
|
|
124
|
+
if (
|
|
125
|
+
decl.defaultBinding?.name === "JSNullish" ||
|
|
126
|
+
decl.namespaceBinding?.name === "JSNullish" ||
|
|
127
|
+
decl.specifiers.some(
|
|
128
|
+
(specifier) => specifier.local.name === "JSNullish",
|
|
129
|
+
)
|
|
130
|
+
) {
|
|
131
|
+
throw new FunScriptError(
|
|
132
|
+
"'JSNullish' is a built-in interop type and cannot be imported as a local name",
|
|
133
|
+
node.span as Span | undefined,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (node.kind === "TypeReferenceNode") {
|
|
138
|
+
const typeName = (node.name as { name?: string })?.name;
|
|
139
|
+
if (typeName === "Any") {
|
|
140
|
+
throw new FunScriptError(
|
|
141
|
+
"The 'Any' type is disabled in FunkScript; use 'Unknown' and decode with Schema, or specify a concrete type",
|
|
142
|
+
node.span as Span | undefined,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (typeName === "Unit") {
|
|
146
|
+
throw new FunScriptError(
|
|
147
|
+
"The 'Unit' type has been unified to 'Void' in FunkScript; use 'Void' instead",
|
|
148
|
+
node.span as Span | undefined,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (typeName === "Null") {
|
|
152
|
+
throw new FunScriptError(
|
|
153
|
+
"The 'Null' type is disabled in FunkScript; model absence using 'Option<T>' instead",
|
|
154
|
+
node.span as Span | undefined,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (typeName === "Undefined") {
|
|
158
|
+
throw new FunScriptError(
|
|
159
|
+
"The 'Undefined' type is disabled in FunkScript; model absence using 'Option<T>' instead",
|
|
160
|
+
node.span as Span | undefined,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Reject unfinished typed holes ('???') unless allowHoles is explicitly enabled. */
|
|
168
|
+
function validateNoHoles(ast: Program): void {
|
|
169
|
+
walkAst(ast, (node) => {
|
|
170
|
+
if (node.kind === "TypedHole") {
|
|
171
|
+
const label = (node as { label?: string }).label || "???";
|
|
172
|
+
throw new FunScriptError(
|
|
173
|
+
`Typed hole '${label}' is unfinished code. Implement this expression before building or type-checking.`,
|
|
174
|
+
node.span as Span | undefined,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Reject early returns ('when (...) =>') unless allowEarlyReturns is explicitly enabled. */
|
|
181
|
+
function validateNoEarlyReturns(ast: Program): void {
|
|
182
|
+
walkAst(ast, (node) => {
|
|
183
|
+
if (
|
|
184
|
+
node.kind === "WhenStatement" &&
|
|
185
|
+
(node as { isEarlyReturn?: boolean }).isEarlyReturn
|
|
186
|
+
) {
|
|
187
|
+
throw new FunScriptError(
|
|
188
|
+
"Early returns ('when (...) =>') are disabled by default; use 'match' for conditional branching or 'effect' blocks for sequential workflows, or enable 'allowEarlyReturns' in funscript.config.fun",
|
|
189
|
+
node.span as Span | undefined,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function validateNoTs(ast: Program): void {
|
|
196
|
+
walkAst(ast, (node) => {
|
|
197
|
+
if (
|
|
198
|
+
node.kind === "TsEscapeDeclaration" ||
|
|
199
|
+
node.kind === "TsEscapeExpression" ||
|
|
200
|
+
node.kind === "TsEscapeTypeNode"
|
|
201
|
+
) {
|
|
202
|
+
throw new FunScriptError(
|
|
203
|
+
"TypeScript escapes are disabled by --no-ts; write this code in FunkScript",
|
|
204
|
+
node.span as Span | undefined,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (node.kind === "AsDeclaration") {
|
|
208
|
+
throw new FunScriptError(
|
|
209
|
+
"AssemblyScript blocks are disabled by --no-ts; write this code in FunkScript",
|
|
210
|
+
node.span as Span | undefined,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Block globalThis references in authored AST, without matching property names or strings. */
|
|
217
|
+
function validateNoGlobalThis(ast: Program): void {
|
|
218
|
+
walkAst(ast, (node, parent, property) => {
|
|
219
|
+
if (
|
|
220
|
+
(node.kind === "MemberExpression" || node.kind === "IndexExpression") &&
|
|
221
|
+
["window", "self", "global"].includes(
|
|
222
|
+
(node.object as { name?: string } | undefined)?.name ?? "",
|
|
223
|
+
)
|
|
224
|
+
) {
|
|
225
|
+
const member =
|
|
226
|
+
node.kind === "MemberExpression"
|
|
227
|
+
? (node.property as { name?: string } | undefined)?.name
|
|
228
|
+
: (
|
|
229
|
+
node.index as
|
|
230
|
+
| {
|
|
231
|
+
kind?: string;
|
|
232
|
+
parts?: { kind?: string; value?: string }[];
|
|
233
|
+
}
|
|
234
|
+
| undefined
|
|
235
|
+
)?.kind === "StringLiteral"
|
|
236
|
+
? (
|
|
237
|
+
node.index as { parts?: { kind?: string; value?: string }[] }
|
|
238
|
+
).parts
|
|
239
|
+
?.map((part) =>
|
|
240
|
+
part.kind === "StringRawPart" ? (part.value ?? "") : "",
|
|
241
|
+
)
|
|
242
|
+
.join("")
|
|
243
|
+
: undefined;
|
|
244
|
+
if (member === "globalThis")
|
|
245
|
+
throw new FunScriptError(
|
|
246
|
+
"globalThis is disabled by project policy; use explicit FunkScript imports and interop",
|
|
247
|
+
node.span as Span | undefined,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
const isPropertyName =
|
|
251
|
+
(parent?.kind === "MemberExpression" && property === "property") ||
|
|
252
|
+
(parent?.kind === "FieldEntry" && property === "key") ||
|
|
253
|
+
(parent?.kind === "RecordTypeField" && property === "name") ||
|
|
254
|
+
(parent?.kind === "RecordFieldSchema" && property === "name") ||
|
|
255
|
+
(parent?.kind === "RecordPatternField" &&
|
|
256
|
+
property === "key" &&
|
|
257
|
+
Boolean((parent as { pattern?: unknown }).pattern));
|
|
258
|
+
if (
|
|
259
|
+
node.kind === "Identifier" &&
|
|
260
|
+
node.name === "globalThis" &&
|
|
261
|
+
!isPropertyName
|
|
262
|
+
) {
|
|
263
|
+
throw new FunScriptError(
|
|
264
|
+
"globalThis is disabled by project policy; use explicit FunkScript imports and interop",
|
|
265
|
+
node.span as Span | undefined,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Calculate the structural destructuring depth of a pattern or binding target. */
|
|
272
|
+
export function getPatternDepth(
|
|
273
|
+
pattern: Pattern | BindingTarget | undefined | null,
|
|
274
|
+
): number {
|
|
275
|
+
if (!pattern) return 0;
|
|
276
|
+
switch (pattern.kind) {
|
|
277
|
+
case "Identifier":
|
|
278
|
+
case "UpperIdentifier":
|
|
279
|
+
case "WildcardPattern":
|
|
280
|
+
case "LiteralPattern":
|
|
281
|
+
case "VariablePattern":
|
|
282
|
+
return 0;
|
|
283
|
+
case "RestPattern":
|
|
284
|
+
return getPatternDepth(pattern.argument);
|
|
285
|
+
case "OrPattern":
|
|
286
|
+
return pattern.patterns.reduce(
|
|
287
|
+
(max, p) => Math.max(max, getPatternDepth(p)),
|
|
288
|
+
0,
|
|
289
|
+
);
|
|
290
|
+
case "ArrayPattern": {
|
|
291
|
+
if (pattern.elements.length === 0) return 0;
|
|
292
|
+
let maxChild = 0;
|
|
293
|
+
for (const el of pattern.elements) {
|
|
294
|
+
if (el) maxChild = Math.max(maxChild, getPatternDepth(el));
|
|
295
|
+
}
|
|
296
|
+
return 1 + maxChild;
|
|
297
|
+
}
|
|
298
|
+
case "RecordPattern": {
|
|
299
|
+
if (pattern.fields.length === 0) return 0;
|
|
300
|
+
let maxChild = 0;
|
|
301
|
+
for (const field of pattern.fields) {
|
|
302
|
+
if (field.pattern) {
|
|
303
|
+
maxChild = Math.max(maxChild, getPatternDepth(field.pattern));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return 1 + maxChild;
|
|
307
|
+
}
|
|
308
|
+
case "ConstructorPattern": {
|
|
309
|
+
if (pattern.args.length === 0) return 0;
|
|
310
|
+
let maxChild = 0;
|
|
311
|
+
for (const arg of pattern.args) {
|
|
312
|
+
maxChild = Math.max(maxChild, getPatternDepth(arg));
|
|
313
|
+
}
|
|
314
|
+
return 1 + maxChild;
|
|
315
|
+
}
|
|
316
|
+
default:
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Block deeply nested destructuring patterns when noDeepDestructure or maxDestructureDepth is active. */
|
|
322
|
+
function validateMaxDestructureDepth(ast: Program, maxDepth: number): void {
|
|
323
|
+
const checkDepth = (
|
|
324
|
+
pattern: Pattern | BindingTarget | undefined | null,
|
|
325
|
+
span?: Span,
|
|
326
|
+
) => {
|
|
327
|
+
if (!pattern) return;
|
|
328
|
+
const depth = getPatternDepth(pattern);
|
|
329
|
+
if (depth > maxDepth) {
|
|
330
|
+
throw new FunScriptError(
|
|
331
|
+
`Destructuring depth of ${depth} exceeds the maximum allowed depth of ${maxDepth} (configured via 'maxDestructureDepth' / 'noDeepDestructure')`,
|
|
332
|
+
span ?? pattern.span,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
walkAst(ast, (node) => {
|
|
338
|
+
if (node.kind === "BindingDeclaration") {
|
|
339
|
+
checkDepth(node.id as BindingTarget, (node.id as BindingTarget).span);
|
|
340
|
+
} else if (node.kind === "Parameter") {
|
|
341
|
+
checkDepth(node.name as BindingTarget, (node.name as BindingTarget).span);
|
|
342
|
+
} else if (node.kind === "MatchArm") {
|
|
343
|
+
checkDepth(node.pattern as Pattern, (node.pattern as Pattern).span);
|
|
344
|
+
} else if (node.kind === "EffectBindStatement") {
|
|
345
|
+
checkDepth(node.id as BindingTarget, (node.id as BindingTarget).span);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Block redundant companion prefixes in pipeline stages when barePipelines policy is active. */
|
|
351
|
+
function validateBarePipelines(ast: Program): void {
|
|
352
|
+
walkAst(ast, (node) => {
|
|
353
|
+
if (node.kind === "PipelineExpression") {
|
|
354
|
+
const stage = node.right as
|
|
355
|
+
{ kind?: string; callee?: { kind?: string } } | undefined;
|
|
356
|
+
let target: {
|
|
357
|
+
object?: { kind?: string; name?: string };
|
|
358
|
+
property?: { kind?: string; name?: string };
|
|
359
|
+
span?: Span;
|
|
360
|
+
} | null = null;
|
|
361
|
+
if (stage?.kind === "MemberExpression") {
|
|
362
|
+
target = stage as {
|
|
363
|
+
object?: { kind?: string; name?: string };
|
|
364
|
+
property?: { kind?: string; name?: string };
|
|
365
|
+
span?: Span;
|
|
366
|
+
};
|
|
367
|
+
} else if (
|
|
368
|
+
stage?.kind === "CallExpression" &&
|
|
369
|
+
stage.callee?.kind === "MemberExpression"
|
|
370
|
+
) {
|
|
371
|
+
target = stage.callee as {
|
|
372
|
+
object?: { kind?: string; name?: string };
|
|
373
|
+
property?: { kind?: string; name?: string };
|
|
374
|
+
span?: Span;
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (
|
|
378
|
+
target &&
|
|
379
|
+
target.object?.kind === "UpperIdentifier" &&
|
|
380
|
+
target.property?.kind === "Identifier" &&
|
|
381
|
+
target.object.name &&
|
|
382
|
+
target.property.name
|
|
383
|
+
) {
|
|
384
|
+
const modName = target.object.name;
|
|
385
|
+
const methodName = target.property.name;
|
|
386
|
+
const catalogEntries = (
|
|
387
|
+
PIPELINE_COMPANION_CATALOG as Record<string, readonly string[]>
|
|
388
|
+
)[modName];
|
|
389
|
+
if (catalogEntries && catalogEntries.includes(methodName)) {
|
|
390
|
+
throw new FunScriptError(
|
|
391
|
+
`Redundant pipeline prefix '${modName}.${methodName}'. FunkScript infers the piped companion automatically; use '|> ${methodName}' instead to reduce noise`,
|
|
392
|
+
target.span,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** Conservative source-level Effect ecosystem boundary; this is not a purity proof. */
|
|
401
|
+
function validateEffectOnly(
|
|
402
|
+
ast: Program,
|
|
403
|
+
options?: CompileOptions,
|
|
404
|
+
filename = "<anonymous>",
|
|
405
|
+
): void {
|
|
406
|
+
const forbiddenGlobals = new Set([
|
|
407
|
+
"globalThis",
|
|
408
|
+
"global",
|
|
409
|
+
"window",
|
|
410
|
+
"self",
|
|
411
|
+
"process",
|
|
412
|
+
"console",
|
|
413
|
+
"fetch",
|
|
414
|
+
"require",
|
|
415
|
+
"eval",
|
|
416
|
+
"Function",
|
|
417
|
+
"Date",
|
|
418
|
+
"setTimeout",
|
|
419
|
+
"setInterval",
|
|
420
|
+
"clearTimeout",
|
|
421
|
+
"clearInterval",
|
|
422
|
+
"queueMicrotask",
|
|
423
|
+
"WebSocket",
|
|
424
|
+
"XMLHttpRequest",
|
|
425
|
+
"Bun",
|
|
426
|
+
"Deno",
|
|
427
|
+
]);
|
|
428
|
+
validateNoTs(ast);
|
|
429
|
+
walkAst(ast, (node, parent, property) => {
|
|
430
|
+
if (
|
|
431
|
+
node.kind === "ImportDeclaration" ||
|
|
432
|
+
node.kind === "ExportFromDeclaration"
|
|
433
|
+
) {
|
|
434
|
+
const parts =
|
|
435
|
+
(
|
|
436
|
+
node.source as
|
|
437
|
+
{ parts?: { kind?: string; value?: string }[] } | undefined
|
|
438
|
+
)?.parts ?? [];
|
|
439
|
+
const name = parts
|
|
440
|
+
.map((part) =>
|
|
441
|
+
part.kind === "StringRawPart" ? (part.value ?? "") : "",
|
|
442
|
+
)
|
|
443
|
+
.join("");
|
|
444
|
+
if (
|
|
445
|
+
!name.startsWith("./") &&
|
|
446
|
+
!name.startsWith("../") &&
|
|
447
|
+
name !== "effect" &&
|
|
448
|
+
!name.startsWith("effect/") &&
|
|
449
|
+
!name.startsWith("@effect/")
|
|
450
|
+
) {
|
|
451
|
+
throw new FunScriptError(
|
|
452
|
+
`Effect-only policy disallows import '${name}'; use an Effect ecosystem package or a local module`,
|
|
453
|
+
node.span as Span | undefined,
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
if (
|
|
457
|
+
(name.startsWith("./") || name.startsWith("../")) &&
|
|
458
|
+
options?.effectOnlyDirectories
|
|
459
|
+
) {
|
|
460
|
+
const root = options.policyRoot ?? process.cwd();
|
|
461
|
+
const source = options.sourcePath ?? filename;
|
|
462
|
+
const target = path.resolve(
|
|
463
|
+
path.dirname(path.resolve(root, source)),
|
|
464
|
+
name,
|
|
465
|
+
);
|
|
466
|
+
const stem = target.replace(/\.(?:js|jsx|ts|tsx|fun|funx)$/, "");
|
|
467
|
+
if (!isPathPolicyEnabled(options.effectOnlyDirectories, root, target)) {
|
|
468
|
+
throw new FunScriptError(
|
|
469
|
+
`Effect-only local import '${name}' must remain within an Effect-only directory`,
|
|
470
|
+
node.span as Span | undefined,
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
const nonFunSources = [
|
|
474
|
+
target,
|
|
475
|
+
`${stem}.js`,
|
|
476
|
+
`${stem}.jsx`,
|
|
477
|
+
`${stem}.ts`,
|
|
478
|
+
`${stem}.tsx`,
|
|
479
|
+
`${stem}.mjs`,
|
|
480
|
+
`${stem}.cjs`,
|
|
481
|
+
].filter((file) => /\.(?:[cm]?[jt]s|[jt]sx)$/i.test(file));
|
|
482
|
+
if (
|
|
483
|
+
nonFunSources.some(
|
|
484
|
+
(file) => fs.existsSync(file) || options.virtualSources?.has(file),
|
|
485
|
+
)
|
|
486
|
+
) {
|
|
487
|
+
throw new FunScriptError(
|
|
488
|
+
`Effect-only local import '${name}' resolves to a JavaScript or TypeScript file`,
|
|
489
|
+
node.span as Span | undefined,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
const funSources = [
|
|
493
|
+
target,
|
|
494
|
+
`${stem}.fun`,
|
|
495
|
+
`${stem}.funx`,
|
|
496
|
+
path.join(target, "index.fun"),
|
|
497
|
+
path.join(target, "index.funx"),
|
|
498
|
+
].filter((file) => /\.funx?$/.test(file));
|
|
499
|
+
const resolved = funSources.find(
|
|
500
|
+
(file) => fs.existsSync(file) || options.virtualSources?.has(file),
|
|
501
|
+
);
|
|
502
|
+
if (!resolved)
|
|
503
|
+
throw new FunScriptError(
|
|
504
|
+
`Effect-only local import '${name}' must resolve to a FunkScript source file`,
|
|
505
|
+
node.span as Span | undefined,
|
|
506
|
+
);
|
|
507
|
+
if (fs.existsSync(resolved)) {
|
|
508
|
+
const real = fs.realpathSync(resolved);
|
|
509
|
+
const realDirs = options.effectOnlyDirectories.map((directory) => {
|
|
510
|
+
const absolute = path.resolve(root, directory);
|
|
511
|
+
return fs.existsSync(absolute)
|
|
512
|
+
? fs.realpathSync(absolute)
|
|
513
|
+
: absolute;
|
|
514
|
+
});
|
|
515
|
+
if (
|
|
516
|
+
!/\.funx?$/.test(real) ||
|
|
517
|
+
!isPathPolicyEnabled(realDirs, root, real)
|
|
518
|
+
) {
|
|
519
|
+
throw new FunScriptError(
|
|
520
|
+
`Effect-only local import '${name}' must resolve to FunkScript inside an Effect-only directory`,
|
|
521
|
+
node.span as Span | undefined,
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (
|
|
528
|
+
node.kind === "JsExpression" ||
|
|
529
|
+
(node.kind === "BindingDeclaration" && node.isJs)
|
|
530
|
+
)
|
|
531
|
+
throw new FunScriptError(
|
|
532
|
+
"Effect-only policy disallows 'js' interop; use Effect ecosystem APIs",
|
|
533
|
+
node.span as Span | undefined,
|
|
534
|
+
);
|
|
535
|
+
if (node.kind === "SchemaDeclaration" && node.isTs)
|
|
536
|
+
throw new FunScriptError(
|
|
537
|
+
"Effect-only policy disallows TypeScript-derived schemas",
|
|
538
|
+
node.span as Span | undefined,
|
|
539
|
+
);
|
|
540
|
+
const isPropertyName =
|
|
541
|
+
(parent?.kind === "MemberExpression" && property === "property") ||
|
|
542
|
+
(parent?.kind === "FieldEntry" && property === "key") ||
|
|
543
|
+
(parent?.kind === "RecordTypeField" && property === "name") ||
|
|
544
|
+
(parent?.kind === "RecordFieldSchema" && property === "name") ||
|
|
545
|
+
(parent?.kind === "RecordPatternField" &&
|
|
546
|
+
property === "key" &&
|
|
547
|
+
Boolean((parent as { pattern?: unknown }).pattern));
|
|
548
|
+
if (
|
|
549
|
+
(node.kind === "Identifier" || node.kind === "UpperIdentifier") &&
|
|
550
|
+
forbiddenGlobals.has(node.name as string) &&
|
|
551
|
+
!isPropertyName
|
|
552
|
+
) {
|
|
553
|
+
throw new FunScriptError(
|
|
554
|
+
`Effect-only policy disallows '${String(node.name)}'; use an Effect ecosystem API`,
|
|
555
|
+
node.span as Span | undefined,
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Compiles FunkScript source code directly to TypeScript code as an Effect.
|
|
563
|
+
*/
|
|
564
|
+
export const compileString = (
|
|
565
|
+
source: string,
|
|
566
|
+
filename: string = "<anonymous>",
|
|
567
|
+
options?: CompileOptions,
|
|
568
|
+
): Effect.Effect<CompileResult, CompilerError> =>
|
|
569
|
+
Effect.flatMap(
|
|
570
|
+
/\bas[ \t]*\{/.test(source)
|
|
571
|
+
? Effect.flatMap(
|
|
572
|
+
Effect.try({
|
|
573
|
+
try: () => {
|
|
574
|
+
const ast = new Parser(
|
|
575
|
+
new Lexer(source, filename).tokenize(),
|
|
576
|
+
filename,
|
|
577
|
+
source,
|
|
578
|
+
).parse();
|
|
579
|
+
if (options?.effectOnly)
|
|
580
|
+
validateEffectOnly(ast, options, filename);
|
|
581
|
+
else if (options?.noTs) validateNoTs(ast);
|
|
582
|
+
return ast;
|
|
583
|
+
},
|
|
584
|
+
catch: (error: unknown) =>
|
|
585
|
+
new CompilerError(
|
|
586
|
+
toErrorMessage(error),
|
|
587
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
588
|
+
),
|
|
589
|
+
}),
|
|
590
|
+
(ast) => {
|
|
591
|
+
const blocks = ast.body.filter(
|
|
592
|
+
(decl) => decl.kind === "AsDeclaration",
|
|
593
|
+
);
|
|
594
|
+
return blocks.length === 0
|
|
595
|
+
? Effect.succeed(ast)
|
|
596
|
+
: Effect.tryPromise({
|
|
597
|
+
try: async () => {
|
|
598
|
+
for (const decl of blocks)
|
|
599
|
+
await prepareAssemblyScript(decl);
|
|
600
|
+
return ast;
|
|
601
|
+
},
|
|
602
|
+
catch: (error: unknown) =>
|
|
603
|
+
new CompilerError(
|
|
604
|
+
toErrorMessage(error),
|
|
605
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
606
|
+
),
|
|
607
|
+
});
|
|
608
|
+
},
|
|
609
|
+
)
|
|
610
|
+
: Effect.succeed(undefined),
|
|
611
|
+
(preparedAst) =>
|
|
612
|
+
Effect.try({
|
|
613
|
+
try: () => {
|
|
614
|
+
// Reuse the AST already parsed while preparing AssemblyScript blocks.
|
|
615
|
+
const ast =
|
|
616
|
+
preparedAst ??
|
|
617
|
+
new Parser(
|
|
618
|
+
new Lexer(source, filename).tokenize(),
|
|
619
|
+
filename,
|
|
620
|
+
source,
|
|
621
|
+
).parse();
|
|
622
|
+
|
|
623
|
+
validateNoBannedTypes(ast);
|
|
624
|
+
if (!options?.allowHoles) validateNoHoles(ast);
|
|
625
|
+
const allowEarlyReturns =
|
|
626
|
+
options?.allowEarlyReturns ||
|
|
627
|
+
isPathPolicyEnabled(
|
|
628
|
+
options?.allowEarlyReturnsPaths,
|
|
629
|
+
options?.policyRoot ?? process.cwd(),
|
|
630
|
+
filename,
|
|
631
|
+
);
|
|
632
|
+
if (!allowEarlyReturns) validateNoEarlyReturns(ast);
|
|
633
|
+
if (options?.effectOnly) validateEffectOnly(ast, options, filename);
|
|
634
|
+
else if (options?.noTs) validateNoTs(ast);
|
|
635
|
+
if (options?.noGlobalThis) validateNoGlobalThis(ast);
|
|
636
|
+
if (options?.barePipelines) validateBarePipelines(ast);
|
|
637
|
+
const isDeepDestructureRestricted =
|
|
638
|
+
options?.noDeepDestructure ||
|
|
639
|
+
isPathPolicyEnabled(
|
|
640
|
+
options?.noDeepDestructurePaths,
|
|
641
|
+
options?.policyRoot ?? process.cwd(),
|
|
642
|
+
filename,
|
|
643
|
+
);
|
|
644
|
+
const effectiveMaxDepth =
|
|
645
|
+
options?.maxDestructureDepth ??
|
|
646
|
+
(isDeepDestructureRestricted ? 2 : undefined);
|
|
647
|
+
if (effectiveMaxDepth !== undefined) {
|
|
648
|
+
validateMaxDestructureDepth(ast, effectiveMaxDepth);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// 3. Emit TypeScript
|
|
652
|
+
const context =
|
|
653
|
+
options?.context ??
|
|
654
|
+
new TypeScriptCompilationContext(options?.sourcePath ?? filename);
|
|
655
|
+
context.setFilename(options?.sourcePath ?? filename);
|
|
656
|
+
const {
|
|
657
|
+
importedRecordContracts,
|
|
658
|
+
importedIdentitySchemas,
|
|
659
|
+
importedGenericDataSchemas,
|
|
660
|
+
importedDataSchemas,
|
|
661
|
+
importedNullishSchemas,
|
|
662
|
+
importedTaggedUnionVariants,
|
|
663
|
+
importedRecordFunctions,
|
|
664
|
+
} = collectImportedSchemaFacts(
|
|
665
|
+
ast,
|
|
666
|
+
options?.sourcePath ?? filename,
|
|
667
|
+
context,
|
|
668
|
+
options?.virtualSources,
|
|
669
|
+
);
|
|
670
|
+
if (!options?.pipelineAnalysisOnly) {
|
|
671
|
+
validateNumericComparisons(
|
|
672
|
+
ast,
|
|
673
|
+
source,
|
|
674
|
+
context,
|
|
675
|
+
importedRecordFunctions,
|
|
676
|
+
importedRecordContracts,
|
|
677
|
+
importedGenericDataSchemas,
|
|
678
|
+
importedIdentitySchemas,
|
|
679
|
+
importedDataSchemas,
|
|
680
|
+
importedNullishSchemas,
|
|
681
|
+
importedTaggedUnionVariants,
|
|
682
|
+
);
|
|
683
|
+
validateBooleanOperators(
|
|
684
|
+
ast,
|
|
685
|
+
source,
|
|
686
|
+
context,
|
|
687
|
+
importedRecordFunctions,
|
|
688
|
+
importedRecordContracts,
|
|
689
|
+
importedGenericDataSchemas,
|
|
690
|
+
importedIdentitySchemas,
|
|
691
|
+
importedDataSchemas,
|
|
692
|
+
importedNullishSchemas,
|
|
693
|
+
importedTaggedUnionVariants,
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
const {
|
|
697
|
+
pipelineCompanions,
|
|
698
|
+
stageResolutions,
|
|
699
|
+
stageInputCompanions,
|
|
700
|
+
bareStageResolutions,
|
|
701
|
+
directCallResolutions,
|
|
702
|
+
constructorCalls,
|
|
703
|
+
} = inferPipelineCompanions(
|
|
704
|
+
ast,
|
|
705
|
+
context,
|
|
706
|
+
importedRecordFunctions,
|
|
707
|
+
importedRecordContracts,
|
|
708
|
+
importedGenericDataSchemas,
|
|
709
|
+
importedIdentitySchemas,
|
|
710
|
+
importedDataSchemas,
|
|
711
|
+
options?.pipelineAnalysisOnly,
|
|
712
|
+
importedNullishSchemas,
|
|
713
|
+
importedTaggedUnionVariants,
|
|
714
|
+
);
|
|
715
|
+
if (options?.pipelineAnalysisOnly) {
|
|
716
|
+
return {
|
|
717
|
+
source,
|
|
718
|
+
ast,
|
|
719
|
+
typescript: "",
|
|
720
|
+
targetExtension: filename.endsWith(".funx") ? ".tsx" : ".ts",
|
|
721
|
+
pipelineStageResolutions: stageResolutions,
|
|
722
|
+
pipelineStageInputCompanions: stageInputCompanions,
|
|
723
|
+
barePipelineStageResolutions: bareStageResolutions,
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const importedSchemas = resolveImportedSchemas(ast, context);
|
|
727
|
+
const emitterOptions: EmitterOptions = {
|
|
728
|
+
pipelineCompanions,
|
|
729
|
+
stageResolutions,
|
|
730
|
+
directCallResolutions,
|
|
731
|
+
constructorCalls,
|
|
732
|
+
importedSchemas,
|
|
733
|
+
importedRecordFunctions,
|
|
734
|
+
importedRecordContracts,
|
|
735
|
+
importedIdentitySchemas,
|
|
736
|
+
importedGenericDataSchemas,
|
|
737
|
+
importedDataSchemas,
|
|
738
|
+
importedNullishSchemas,
|
|
739
|
+
importedTaggedUnionVariants,
|
|
740
|
+
isJsx: filename.endsWith(".funx"),
|
|
741
|
+
modularEffectImports: options?.modularEffectImports,
|
|
742
|
+
preserveFunImports: options?.preserveFunImports,
|
|
743
|
+
context,
|
|
744
|
+
};
|
|
745
|
+
const optionalResolutions = resolveOptionalArguments(
|
|
746
|
+
ast,
|
|
747
|
+
context,
|
|
748
|
+
emitterOptions,
|
|
749
|
+
options?.sourcePath ?? filename,
|
|
750
|
+
options?.virtualSources,
|
|
751
|
+
);
|
|
752
|
+
emitterOptions.forwardOptionalArguments =
|
|
753
|
+
optionalResolutions.arguments;
|
|
754
|
+
emitterOptions.forwardNullArguments =
|
|
755
|
+
optionalResolutions.nullArguments;
|
|
756
|
+
emitterOptions.forwardOptionalProperties =
|
|
757
|
+
optionalResolutions.properties;
|
|
758
|
+
emitterOptions.forwardNullProperties =
|
|
759
|
+
optionalResolutions.nullProperties;
|
|
760
|
+
const emitter = new Emitter(ast, undefined, emitterOptions);
|
|
761
|
+
const emitted = applyJsInteropNullability(emitter.emit(), context);
|
|
762
|
+
const shebang = source.startsWith("#!")
|
|
763
|
+
? source.includes("\n")
|
|
764
|
+
? source.slice(0, source.indexOf("\n") + 1)
|
|
765
|
+
: `${source}\n`
|
|
766
|
+
: "";
|
|
767
|
+
const typescript = shebang ? shebang + emitted : emitted;
|
|
768
|
+
const targetExtension = filename.endsWith(".funx") ? ".tsx" : ".ts";
|
|
769
|
+
|
|
770
|
+
const map =
|
|
771
|
+
(options?.sourcemap ?? true)
|
|
772
|
+
? generateSourceMap(
|
|
773
|
+
source,
|
|
774
|
+
filename,
|
|
775
|
+
typescript,
|
|
776
|
+
ast,
|
|
777
|
+
emitterOptions,
|
|
778
|
+
options?.outputFile,
|
|
779
|
+
)
|
|
780
|
+
: undefined;
|
|
781
|
+
|
|
782
|
+
return {
|
|
783
|
+
source,
|
|
784
|
+
ast,
|
|
785
|
+
typescript,
|
|
786
|
+
targetExtension,
|
|
787
|
+
pipelineStageResolutions: stageResolutions,
|
|
788
|
+
pipelineStageInputCompanions: stageInputCompanions,
|
|
789
|
+
barePipelineStageResolutions: bareStageResolutions,
|
|
790
|
+
map,
|
|
791
|
+
sourcemap: map,
|
|
792
|
+
};
|
|
793
|
+
},
|
|
794
|
+
catch: (error: unknown) =>
|
|
795
|
+
new CompilerError(
|
|
796
|
+
toErrorMessage(error),
|
|
797
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
798
|
+
source,
|
|
799
|
+
),
|
|
800
|
+
}),
|
|
801
|
+
);
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Parses and checks a FunkScript source string.
|
|
805
|
+
*/
|
|
806
|
+
export const checkString = (
|
|
807
|
+
source: string,
|
|
808
|
+
filename: string = "<anonymous>",
|
|
809
|
+
options?: Pick<
|
|
810
|
+
CompileOptions,
|
|
811
|
+
| "noTs"
|
|
812
|
+
| "noGlobalThis"
|
|
813
|
+
| "barePipelines"
|
|
814
|
+
| "noDeepDestructure"
|
|
815
|
+
| "noDeepDestructurePaths"
|
|
816
|
+
| "maxDestructureDepth"
|
|
817
|
+
| "policyRoot"
|
|
818
|
+
| "effectOnly"
|
|
819
|
+
| "allowHoles"
|
|
820
|
+
| "allowEarlyReturns"
|
|
821
|
+
| "allowEarlyReturnsPaths"
|
|
822
|
+
>,
|
|
823
|
+
): Effect.Effect<Program, CompilerError> =>
|
|
824
|
+
Effect.try({
|
|
825
|
+
try: () => {
|
|
826
|
+
const lexer = new Lexer(source, filename);
|
|
827
|
+
const tokens = lexer.tokenize();
|
|
828
|
+
const parser = new Parser(tokens, filename, source);
|
|
829
|
+
const ast = parser.parse();
|
|
830
|
+
validateNoBannedTypes(ast);
|
|
831
|
+
if (!options?.allowHoles) validateNoHoles(ast);
|
|
832
|
+
const allowEarlyReturns =
|
|
833
|
+
options?.allowEarlyReturns ||
|
|
834
|
+
isPathPolicyEnabled(
|
|
835
|
+
options?.allowEarlyReturnsPaths,
|
|
836
|
+
options?.policyRoot ?? process.cwd(),
|
|
837
|
+
filename,
|
|
838
|
+
);
|
|
839
|
+
if (!allowEarlyReturns) validateNoEarlyReturns(ast);
|
|
840
|
+
if (options?.effectOnly) validateEffectOnly(ast, options, filename);
|
|
841
|
+
else if (options?.noTs) validateNoTs(ast);
|
|
842
|
+
if (options?.noGlobalThis) validateNoGlobalThis(ast);
|
|
843
|
+
if (options?.barePipelines) validateBarePipelines(ast);
|
|
844
|
+
const isDeepDestructureRestricted =
|
|
845
|
+
options?.noDeepDestructure ||
|
|
846
|
+
isPathPolicyEnabled(
|
|
847
|
+
options?.noDeepDestructurePaths,
|
|
848
|
+
options?.policyRoot ?? process.cwd(),
|
|
849
|
+
filename,
|
|
850
|
+
);
|
|
851
|
+
const effectiveMaxDepth =
|
|
852
|
+
options?.maxDestructureDepth ??
|
|
853
|
+
(isDeepDestructureRestricted ? 2 : undefined);
|
|
854
|
+
if (effectiveMaxDepth !== undefined) {
|
|
855
|
+
validateMaxDestructureDepth(ast, effectiveMaxDepth);
|
|
856
|
+
}
|
|
857
|
+
return ast;
|
|
858
|
+
},
|
|
859
|
+
catch: (error: unknown) =>
|
|
860
|
+
new CompilerError(
|
|
861
|
+
toErrorMessage(error),
|
|
862
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
863
|
+
source,
|
|
864
|
+
),
|
|
865
|
+
});
|