funkscript 0.2.4 → 0.2.7
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 +23 -5
- package/dist/ast/types.d.ts.map +1 -1
- package/dist/ast/types.js.map +1 -1
- package/dist/ast/walk.d.ts.map +1 -1
- package/dist/ast/walk.js.map +1 -1
- package/dist/cli/build-bun.d.ts.map +1 -1
- package/dist/cli/build-bun.js.map +1 -1
- package/dist/cli/build-watch.d.ts.map +1 -1
- package/dist/cli/build-watch.js +9 -27
- package/dist/cli/build-watch.js.map +1 -1
- package/dist/cli/build.d.ts +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +3 -58
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/check-policy.d.ts +9 -0
- package/dist/cli/check-policy.d.ts.map +1 -0
- package/dist/cli/check-policy.js +39 -0
- package/dist/cli/check-policy.js.map +1 -0
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +16 -30
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doc.d.ts.map +1 -1
- package/dist/cli/doc.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +5 -7
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/emit.d.ts +1 -1
- package/dist/cli/emit.d.ts.map +1 -1
- package/dist/cli/emit.js.map +1 -1
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/fmt.d.ts.map +1 -1
- package/dist/cli/fmt.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +66 -21
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/io.d.ts.map +1 -1
- package/dist/cli/io.js.map +1 -1
- package/dist/cli/pipeline-style.d.ts.map +1 -1
- package/dist/cli/pipeline-style.js.map +1 -1
- package/dist/cli/query.d.ts +3 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +152 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +2 -29
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/test.d.ts +1 -1
- package/dist/cli/test.d.ts.map +1 -1
- package/dist/cli/test.js.map +1 -1
- package/dist/cli/tsc.d.ts.map +1 -1
- package/dist/cli/tsc.js +6 -8
- package/dist/cli/tsc.js.map +1 -1
- package/dist/cli/typecheck.d.ts.map +1 -1
- package/dist/cli/typecheck.js.map +1 -1
- package/dist/compiler/ast-inspection.d.ts.map +1 -1
- package/dist/compiler/ast-inspection.js.map +1 -1
- package/dist/compiler/boolean-operators.d.ts.map +1 -1
- package/dist/compiler/boolean-operators.js +12 -2
- package/dist/compiler/boolean-operators.js.map +1 -1
- package/dist/compiler/check.d.ts.map +1 -1
- package/dist/compiler/check.js +113 -131
- package/dist/compiler/check.js.map +1 -1
- package/dist/compiler/diagnostics-json.d.ts +73 -0
- package/dist/compiler/diagnostics-json.d.ts.map +1 -0
- package/dist/compiler/diagnostics-json.js +957 -0
- package/dist/compiler/diagnostics-json.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -1
- package/dist/compiler/diagnostics.js.map +1 -1
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -1
- package/dist/compiler/effect-mutation-rule.js.map +1 -1
- package/dist/compiler/entry-rules.d.ts.map +1 -1
- package/dist/compiler/entry-rules.js.map +1 -1
- package/dist/compiler/escape-audit.d.ts +46 -0
- package/dist/compiler/escape-audit.d.ts.map +1 -0
- package/dist/compiler/escape-audit.js +682 -0
- package/dist/compiler/escape-audit.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -1
- package/dist/compiler/incremental-build.js.map +1 -1
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -1
- package/dist/compiler/incremental-dependencies.js.map +1 -1
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -1
- package/dist/compiler/js-interop-nullability.js.map +1 -1
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -1
- package/dist/compiler/modules/output-collisions.js.map +1 -1
- package/dist/compiler/modules/output-plan.d.ts.map +1 -1
- package/dist/compiler/modules/output-plan.js +10 -5
- package/dist/compiler/modules/output-plan.js.map +1 -1
- package/dist/compiler/modules/resolution.d.ts.map +1 -1
- package/dist/compiler/modules/resolution.js +2 -1
- package/dist/compiler/modules/resolution.js.map +1 -1
- package/dist/compiler/modules/source-files.d.ts +5 -0
- package/dist/compiler/modules/source-files.d.ts.map +1 -0
- package/dist/compiler/modules/source-files.js +13 -0
- package/dist/compiler/modules/source-files.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
- package/dist/compiler/numeric-comparisons.js +13 -7
- package/dist/compiler/numeric-comparisons.js.map +1 -1
- package/dist/compiler/optional-arguments.d.ts.map +1 -1
- package/dist/compiler/optional-arguments.js.map +1 -1
- package/dist/compiler/package-fingerprint.d.ts.map +1 -1
- package/dist/compiler/package-fingerprint.js.map +1 -1
- package/dist/compiler/package-record-contracts.d.ts.map +1 -1
- package/dist/compiler/package-record-contracts.js.map +1 -1
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -1
- package/dist/compiler/pipelines/catalog.js.map +1 -1
- package/dist/compiler/pipelines/companions.d.ts.map +1 -1
- package/dist/compiler/pipelines/companions.js.map +1 -1
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
- package/dist/compiler/pipelines/resolution.js +24 -23
- package/dist/compiler/pipelines/resolution.js.map +1 -1
- package/dist/compiler/project-config.d.ts.map +1 -1
- package/dist/compiler/project-config.js +29 -19
- package/dist/compiler/project-config.js.map +1 -1
- package/dist/compiler/query.d.ts +53 -0
- package/dist/compiler/query.d.ts.map +1 -0
- package/dist/compiler/query.js +781 -0
- package/dist/compiler/query.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -1
- package/dist/compiler/record-contracts.js.map +1 -1
- package/dist/compiler/rules/control-flow.d.ts.map +1 -1
- package/dist/compiler/rules/control-flow.js.map +1 -1
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -1
- package/dist/compiler/rules/diagnostic.js.map +1 -1
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -1
- package/dist/compiler/rules/module-scope-refs.js.map +1 -1
- package/dist/compiler/rules/resource-escape.d.ts +7 -0
- package/dist/compiler/rules/resource-escape.d.ts.map +1 -0
- package/dist/compiler/rules/resource-escape.js +146 -0
- package/dist/compiler/rules/resource-escape.js.map +1 -0
- package/dist/compiler/rules/resource-providers.d.ts +19 -0
- package/dist/compiler/rules/resource-providers.d.ts.map +1 -0
- package/dist/compiler/rules/resource-providers.js +222 -0
- package/dist/compiler/rules/resource-providers.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -1
- package/dist/compiler/schemas/analysis.js.map +1 -1
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -1
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -1
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -1
- package/dist/compiler/schemas/imported-schemas.js.map +1 -1
- package/dist/compiler/source-map.d.ts.map +1 -1
- package/dist/compiler/source-map.js +2 -7
- package/dist/compiler/source-map.js.map +1 -1
- package/dist/compiler/type-view-paths.d.ts +6 -0
- package/dist/compiler/type-view-paths.d.ts.map +1 -0
- package/dist/compiler/type-view-paths.js +12 -0
- package/dist/compiler/type-view-paths.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -1
- package/dist/compiler/typescript-context.js +5 -7
- package/dist/compiler/typescript-context.js.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js.map +1 -1
- package/dist/emitter/assemblyscript.d.ts.map +1 -1
- package/dist/emitter/assemblyscript.js +120 -136
- package/dist/emitter/assemblyscript.js.map +1 -1
- package/dist/emitter/declarations.d.ts.map +1 -1
- package/dist/emitter/declarations.js.map +1 -1
- package/dist/emitter/emitter.d.ts +3 -1
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +10 -1
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/imports.d.ts.map +1 -1
- package/dist/emitter/imports.js.map +1 -1
- package/dist/emitter/indent.d.ts.map +1 -1
- package/dist/emitter/indent.js.map +1 -1
- package/dist/emitter/jsx.d.ts.map +1 -1
- package/dist/emitter/jsx.js.map +1 -1
- package/dist/emitter/local-bindings.d.ts.map +1 -1
- package/dist/emitter/local-bindings.js.map +1 -1
- package/dist/emitter/match.d.ts.map +1 -1
- package/dist/emitter/match.js.map +1 -1
- package/dist/emitter/runtime-helpers.d.ts.map +1 -1
- package/dist/emitter/runtime-helpers.js.map +1 -1
- package/dist/emitter/schemas.d.ts.map +1 -1
- package/dist/emitter/schemas.js.map +1 -1
- package/dist/emitter/statements.d.ts +1 -0
- package/dist/emitter/statements.d.ts.map +1 -1
- package/dist/emitter/statements.js +1 -0
- package/dist/emitter/statements.js.map +1 -1
- package/dist/emitter/tagged-match.d.ts.map +1 -1
- package/dist/emitter/tagged-match.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/formatter/comments.d.ts.map +1 -1
- package/dist/formatter/comments.js +13 -0
- package/dist/formatter/comments.js.map +1 -1
- package/dist/formatter/index.d.ts +9 -0
- package/dist/formatter/index.d.ts.map +1 -1
- package/dist/formatter/index.js +215 -5
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/operator-precedence.d.ts.map +1 -1
- package/dist/formatter/operator-precedence.js.map +1 -1
- package/dist/formatter/prettier.d.ts.map +1 -1
- package/dist/formatter/prettier.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interop/callback.d.ts.map +1 -1
- package/dist/interop/callback.js.map +1 -1
- package/dist/interop/js.d.ts.map +1 -1
- package/dist/interop/js.js.map +1 -1
- package/dist/interop/record.d.ts.map +1 -1
- package/dist/interop/record.js.map +1 -1
- package/dist/interop/valibot.d.ts.map +1 -1
- package/dist/interop/valibot.js.map +1 -1
- package/dist/interop/zod.d.ts.map +1 -1
- package/dist/interop/zod.js.map +1 -1
- package/dist/lexer/lexer.d.ts +1 -0
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/lexer.js +26 -10
- package/dist/lexer/lexer.js.map +1 -1
- package/dist/lexer/tokens.d.ts.map +1 -1
- package/dist/lexer/tokens.js.map +1 -1
- package/dist/lsp/code-action-worker.d.ts.map +1 -1
- package/dist/lsp/code-action-worker.js.map +1 -1
- package/dist/lsp/completion.d.ts +25 -0
- package/dist/lsp/completion.d.ts.map +1 -1
- package/dist/lsp/completion.js +1114 -51
- package/dist/lsp/completion.js.map +1 -1
- package/dist/lsp/definition.d.ts +2 -0
- package/dist/lsp/definition.d.ts.map +1 -1
- package/dist/lsp/definition.js +52 -58
- package/dist/lsp/definition.js.map +1 -1
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -1
- package/dist/lsp/diagnostics-worker.js +1 -1
- package/dist/lsp/diagnostics-worker.js.map +1 -1
- package/dist/lsp/docs.d.ts +1 -1
- package/dist/lsp/docs.d.ts.map +1 -1
- package/dist/lsp/docs.js +4 -3
- package/dist/lsp/docs.js.map +1 -1
- package/dist/lsp/error-channel.d.ts.map +1 -1
- package/dist/lsp/error-channel.js.map +1 -1
- package/dist/lsp/hover.d.ts +5 -1
- package/dist/lsp/hover.d.ts.map +1 -1
- package/dist/lsp/hover.js +1016 -46
- package/dist/lsp/hover.js.map +1 -1
- package/dist/lsp/imports.d.ts +2 -0
- package/dist/lsp/imports.d.ts.map +1 -1
- package/dist/lsp/imports.js +45 -21
- package/dist/lsp/imports.js.map +1 -1
- package/dist/lsp/index.d.ts.map +1 -1
- package/dist/lsp/index.js.map +1 -1
- package/dist/lsp/inlay-hints.d.ts.map +1 -1
- package/dist/lsp/inlay-hints.js.map +1 -1
- package/dist/lsp/interop-rename.d.ts.map +1 -1
- package/dist/lsp/interop-rename.js.map +1 -1
- package/dist/lsp/match-arms.d.ts.map +1 -1
- package/dist/lsp/match-arms.js.map +1 -1
- package/dist/lsp/navigation.d.ts +1 -1
- package/dist/lsp/navigation.d.ts.map +1 -1
- package/dist/lsp/navigation.js +30 -12
- package/dist/lsp/navigation.js.map +1 -1
- package/dist/lsp/parsed-documents.d.ts.map +1 -1
- package/dist/lsp/parsed-documents.js.map +1 -1
- package/dist/lsp/range-format.d.ts +4 -0
- package/dist/lsp/range-format.d.ts.map +1 -0
- package/dist/lsp/range-format.js +88 -0
- package/dist/lsp/range-format.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -1
- package/dist/lsp/rename-worker.js.map +1 -1
- package/dist/lsp/schema-import-hover.d.ts +8 -0
- package/dist/lsp/schema-import-hover.d.ts.map +1 -0
- package/dist/lsp/schema-import-hover.js +52 -0
- package/dist/lsp/schema-import-hover.js.map +1 -0
- package/dist/lsp/server.d.ts +3 -1
- package/dist/lsp/server.d.ts.map +1 -1
- package/dist/lsp/server.js +73 -48
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/signature-help.d.ts +6 -0
- package/dist/lsp/signature-help.d.ts.map +1 -0
- package/dist/lsp/signature-help.js +183 -0
- package/dist/lsp/signature-help.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -1
- package/dist/lsp/thunk-pipeline.js.map +1 -1
- package/dist/lsp/validation.d.ts.map +1 -1
- package/dist/lsp/validation.js +3 -2
- package/dist/lsp/validation.js.map +1 -1
- package/dist/lsp/workspace.d.ts +3 -1
- package/dist/lsp/workspace.d.ts.map +1 -1
- package/dist/lsp/workspace.js +66 -10
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/parser/declarations.d.ts.map +1 -1
- package/dist/parser/declarations.js +22 -1
- package/dist/parser/declarations.js.map +1 -1
- package/dist/parser/errors.d.ts.map +1 -1
- package/dist/parser/errors.js.map +1 -1
- package/dist/parser/jsx.d.ts.map +1 -1
- package/dist/parser/jsx.js.map +1 -1
- package/dist/parser/operator-expressions.d.ts.map +1 -1
- package/dist/parser/operator-expressions.js.map +1 -1
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/patterns.d.ts.map +1 -1
- package/dist/parser/patterns.js.map +1 -1
- package/dist/parser/pipeline-expressions.d.ts.map +1 -1
- package/dist/parser/pipeline-expressions.js.map +1 -1
- package/dist/parser/scope.d.ts.map +1 -1
- package/dist/parser/scope.js.map +1 -1
- package/dist/parser/statements.d.ts.map +1 -1
- package/dist/parser/statements.js.map +1 -1
- package/dist/parser/types.d.ts.map +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/plugins/bun-preload.d.ts.map +1 -1
- package/dist/plugins/bun-preload.js.map +1 -1
- package/dist/plugins/bun.d.ts +2 -18
- package/dist/plugins/bun.d.ts.map +1 -1
- package/dist/plugins/bun.js +5 -30
- package/dist/plugins/bun.js.map +1 -1
- package/dist/plugins/esbuild.d.ts +1 -1
- package/dist/plugins/esbuild.d.ts.map +1 -1
- package/dist/plugins/esbuild.js +10 -36
- package/dist/plugins/esbuild.js.map +1 -1
- package/dist/plugins/server-boundary.d.ts +14 -0
- package/dist/plugins/server-boundary.d.ts.map +1 -0
- package/dist/plugins/server-boundary.js +25 -0
- package/dist/plugins/server-boundary.js.map +1 -0
- package/dist/plugins/type-view.d.ts.map +1 -1
- package/dist/plugins/type-view.js +5 -3
- package/dist/plugins/type-view.js.map +1 -1
- package/dist/plugins/vite.d.ts +2 -18
- package/dist/plugins/vite.d.ts.map +1 -1
- package/dist/plugins/vite.js +4 -29
- package/dist/plugins/vite.js.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/tooling/doc.d.ts.map +1 -1
- package/dist/tooling/doc.js.map +1 -1
- package/dist/tooling/idiomatic.d.ts.map +1 -1
- package/dist/tooling/idiomatic.js.map +1 -1
- package/dist/tooling/pipeline-style.d.ts.map +1 -1
- package/dist/tooling/pipeline-style.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +13 -6
- package/src/cli/build-watch.ts +10 -29
- package/src/cli/build.ts +9 -60
- package/src/cli/check-policy.ts +54 -0
- package/src/cli/check.ts +19 -31
- package/src/cli/commands.ts +13 -0
- package/src/cli/doctor.ts +10 -7
- package/src/cli/index.ts +3 -0
- package/src/cli/init.ts +66 -21
- package/src/cli/query.ts +191 -0
- package/src/cli/run.ts +5 -30
- package/src/cli/tsc.ts +10 -8
- package/src/compiler/boolean-operators.ts +11 -2
- package/src/compiler/check.ts +152 -180
- package/src/compiler/diagnostics-json.ts +1205 -0
- package/src/compiler/escape-audit.ts +913 -0
- package/src/compiler/modules/output-plan.ts +11 -9
- package/src/compiler/modules/resolution.ts +2 -1
- package/src/compiler/modules/source-files.ts +13 -0
- package/src/compiler/numeric-comparisons.ts +14 -8
- package/src/compiler/pipelines/resolution.ts +30 -26
- package/src/compiler/project-config.ts +30 -19
- package/src/compiler/query.ts +1177 -0
- package/src/compiler/rules/resource-escape.ts +223 -0
- package/src/compiler/rules/resource-providers.ts +293 -0
- package/src/compiler/source-map.ts +3 -7
- package/src/compiler/type-view-paths.ts +10 -0
- package/src/compiler/typescript-context.ts +6 -7
- package/src/emitter/assemblyscript.ts +101 -147
- package/src/emitter/emitter.ts +13 -1
- package/src/emitter/statements.ts +2 -0
- package/src/formatter/comments.ts +14 -0
- package/src/formatter/index.ts +299 -4
- package/src/index.ts +3 -0
- package/src/lexer/lexer.ts +39 -20
- package/src/lsp/completion.ts +1452 -66
- package/src/lsp/definition.ts +50 -58
- package/src/lsp/diagnostics-worker.ts +1 -4
- package/src/lsp/docs.ts +4 -3
- package/src/lsp/hover.ts +1465 -44
- package/src/lsp/imports.ts +75 -22
- package/src/lsp/navigation.ts +41 -22
- package/src/lsp/range-format.ts +102 -0
- package/src/lsp/schema-import-hover.ts +76 -0
- package/src/lsp/server.ts +99 -69
- package/src/lsp/signature-help.ts +226 -0
- package/src/lsp/validation.ts +3 -2
- package/src/lsp/workspace.ts +63 -9
- package/src/parser/declarations.ts +27 -1
- package/src/plugins/bun.ts +14 -66
- package/src/plugins/esbuild.ts +16 -55
- package/src/plugins/server-boundary.ts +41 -0
- package/src/plugins/type-view.ts +11 -3
- package/src/plugins/vite.ts +12 -62
- package/dist/Widget.tsx +0 -9
- package/dist/cli/output-collisions.d.ts +0 -2
- package/dist/cli/output-collisions.d.ts.map +0 -1
- package/dist/cli/output-collisions.js +0 -39
- package/dist/cli/output-collisions.js.map +0 -1
- package/dist/compiler/imported-record-functions.d.ts +0 -4
- package/dist/compiler/imported-record-functions.d.ts.map +0 -1
- package/dist/compiler/imported-record-functions.js +0 -706
- package/dist/compiler/imported-record-functions.js.map +0 -1
- package/dist/compiler/imported-schemas.d.ts +0 -21
- package/dist/compiler/imported-schemas.d.ts.map +0 -1
- package/dist/compiler/imported-schemas.js +0 -461
- package/dist/compiler/imported-schemas.js.map +0 -1
- package/dist/compiler/module-resolution.d.ts +0 -6
- package/dist/compiler/module-resolution.d.ts.map +0 -1
- package/dist/compiler/module-resolution.js +0 -44
- package/dist/compiler/module-resolution.js.map +0 -1
- package/dist/compiler/pipeline-companions.d.ts +0 -18
- package/dist/compiler/pipeline-companions.d.ts.map +0 -1
- package/dist/compiler/pipeline-companions.js +0 -1042
- package/dist/compiler/pipeline-companions.js.map +0 -1
- package/dist/compiler/providers.d.ts +0 -4
- package/dist/compiler/providers.d.ts.map +0 -1
- package/dist/compiler/providers.js +0 -101
- package/dist/compiler/providers.js.map +0 -1
- package/dist/emitter/pipeline-catalog.d.ts +0 -15
- package/dist/emitter/pipeline-catalog.d.ts.map +0 -1
- package/dist/emitter/pipeline-catalog.js +0 -55
- package/dist/emitter/pipeline-catalog.js.map +0 -1
- package/dist/emitter/pipeline-resolution.d.ts +0 -38
- package/dist/emitter/pipeline-resolution.d.ts.map +0 -1
- package/dist/emitter/pipeline-resolution.js +0 -571
- package/dist/emitter/pipeline-resolution.js.map +0 -1
- package/dist/interop/index.d.ts +0 -6
- package/dist/interop/index.d.ts.map +0 -1
- package/dist/interop/index.js +0 -6
- package/dist/interop/index.js.map +0 -1
- package/dist/math.ts +0 -1
- package/dist/parser/index.d.ts +0 -9
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/index.js +0 -9
- package/dist/parser/index.js.map +0 -1
- package/dist/service.ts +0 -3
- package/dist/service.ts.map +0 -1
- package/dist/tooling/migrate.d.ts +0 -62
- package/dist/tooling/migrate.d.ts.map +0 -1
- package/dist/tooling/migrate.js +0 -608
- package/dist/tooling/migrate.js.map +0 -1
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { compileString, CompilerError } from "../compiler.js";
|
|
6
|
+
import { toErrorMessage } from "../errors.js";
|
|
7
|
+
import { DEFAULT_COMPILER_OPTIONS } from "./check.js";
|
|
8
|
+
import { resolveFunModule } from "./modules/resolution.js";
|
|
9
|
+
import { JSX_INTRINSICS_DECLARATION, TS_RESET_DECLARATION, TYPE_FEST_DECLARATION, } from "./typescript-context.js";
|
|
10
|
+
function getCompilerOptions(cwd) {
|
|
11
|
+
let baseOptions = { ...DEFAULT_COMPILER_OPTIONS };
|
|
12
|
+
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, "tsconfig.json");
|
|
13
|
+
if (configPath) {
|
|
14
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
15
|
+
if (!configFile.error && configFile.config) {
|
|
16
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
17
|
+
baseOptions = { ...baseOptions, ...parsed.options };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
...baseOptions,
|
|
22
|
+
noEmit: true,
|
|
23
|
+
allowImportingTsExtensions: true,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function toVirtualTsPath(fullFunPath) {
|
|
27
|
+
const ext = fullFunPath.endsWith(".funx") ? ".tsx" : ".ts";
|
|
28
|
+
return `${fullFunPath}${ext}`;
|
|
29
|
+
}
|
|
30
|
+
function cleanTypeString(typeText) {
|
|
31
|
+
return typeText.replace(/\b([A-Z][A-Za-z0-9_]*)\$Class\b/g, "$1");
|
|
32
|
+
}
|
|
33
|
+
function formatType(checker, type, enclosingNode) {
|
|
34
|
+
return cleanTypeString(checker.typeToString(type, enclosingNode, ts.TypeFormatFlags.NoTruncation));
|
|
35
|
+
}
|
|
36
|
+
function extractStringLiteralValue(lit) {
|
|
37
|
+
const fromParts = lit.parts
|
|
38
|
+
.map((p) => (p.kind === "StringRawPart" ? p.value : ""))
|
|
39
|
+
.join("");
|
|
40
|
+
if (fromParts.length > 0)
|
|
41
|
+
return fromParts;
|
|
42
|
+
if ((lit.raw.startsWith('"') && lit.raw.endsWith('"')) ||
|
|
43
|
+
(lit.raw.startsWith("'") && lit.raw.endsWith("'"))) {
|
|
44
|
+
return lit.raw.slice(1, -1);
|
|
45
|
+
}
|
|
46
|
+
return lit.raw;
|
|
47
|
+
}
|
|
48
|
+
function collectImports(ast) {
|
|
49
|
+
const imports = [];
|
|
50
|
+
for (const item of ast.body) {
|
|
51
|
+
if (item.kind === "ImportDeclaration") {
|
|
52
|
+
imports.push(extractStringLiteralValue(item.source));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return imports;
|
|
56
|
+
}
|
|
57
|
+
function collectTopLevelDeclarations(ast) {
|
|
58
|
+
const entries = [];
|
|
59
|
+
for (const item of ast.body) {
|
|
60
|
+
if (item.kind === "ExportDeclaration") {
|
|
61
|
+
entries.push({ exported: true, decl: item.declaration });
|
|
62
|
+
}
|
|
63
|
+
else if (item.kind === "SchemaDeclaration" ||
|
|
64
|
+
item.kind === "ErrorDeclaration" ||
|
|
65
|
+
item.kind === "ServiceDeclaration" ||
|
|
66
|
+
item.kind === "BindingDeclaration") {
|
|
67
|
+
entries.push({ exported: false, decl: item });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return entries;
|
|
71
|
+
}
|
|
72
|
+
function collectBindingTargetLocations(target) {
|
|
73
|
+
switch (target.kind) {
|
|
74
|
+
case "Identifier":
|
|
75
|
+
case "UpperIdentifier":
|
|
76
|
+
return [{ name: target.name, span: target.span }];
|
|
77
|
+
case "VariablePattern":
|
|
78
|
+
return [{ name: target.name.name, span: target.name.span }];
|
|
79
|
+
case "RestPattern":
|
|
80
|
+
return collectBindingTargetLocations(target.argument);
|
|
81
|
+
case "RecordPattern":
|
|
82
|
+
return target.fields.flatMap((field) => field.pattern
|
|
83
|
+
? collectBindingTargetLocations(field.pattern)
|
|
84
|
+
: [{ name: field.key.name, span: field.key.span }]);
|
|
85
|
+
case "ArrayPattern":
|
|
86
|
+
return target.elements.flatMap((elem) => collectBindingTargetLocations(elem));
|
|
87
|
+
case "OrPattern":
|
|
88
|
+
return target.patterns.flatMap((part) => collectBindingTargetLocations(part));
|
|
89
|
+
case "WildcardPattern":
|
|
90
|
+
case "LiteralPattern":
|
|
91
|
+
case "ConstructorPattern":
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isEffectType(type, checker) {
|
|
96
|
+
const symbol = type.symbol ?? type.aliasSymbol;
|
|
97
|
+
if (!symbol || symbol.getName() !== "Effect") {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const typeArgs = checker.getTypeArguments(type);
|
|
101
|
+
if (typeArgs.length !== 3) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const decls = symbol.declarations;
|
|
105
|
+
if (!decls || decls.length === 0) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return decls.some((d) => {
|
|
109
|
+
const fileName = d.getSourceFile().fileName;
|
|
110
|
+
return fileName.includes("effect") || Boolean(type.getProperty("pipe"));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function collectUnionMembers(type, checker, enclosingNode) {
|
|
114
|
+
const out = [];
|
|
115
|
+
const seen = new Set();
|
|
116
|
+
const visit = (t) => {
|
|
117
|
+
if ((t.flags & ts.TypeFlags.Never) !== 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (t.isUnion()) {
|
|
121
|
+
for (const member of t.types) {
|
|
122
|
+
visit(member);
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const formatted = formatType(checker, t, enclosingNode);
|
|
127
|
+
if (formatted === "never" || seen.has(formatted)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
seen.add(formatted);
|
|
131
|
+
out.push(formatted);
|
|
132
|
+
};
|
|
133
|
+
visit(type);
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
function decomposeEffectType(type, checker, enclosingNode) {
|
|
137
|
+
if (isEffectType(type, checker)) {
|
|
138
|
+
const [successType, errorType, reqType] = checker.getTypeArguments(type);
|
|
139
|
+
return {
|
|
140
|
+
success: successType
|
|
141
|
+
? formatType(checker, successType, enclosingNode)
|
|
142
|
+
: "unknown",
|
|
143
|
+
error: errorType
|
|
144
|
+
? formatType(checker, errorType, enclosingNode)
|
|
145
|
+
: "never",
|
|
146
|
+
requirements: reqType
|
|
147
|
+
? collectUnionMembers(reqType, checker, enclosingNode)
|
|
148
|
+
: [],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const callSignatures = type.getCallSignatures();
|
|
152
|
+
if (callSignatures.length > 0 && type.getConstructSignatures().length === 0) {
|
|
153
|
+
const returnType = callSignatures[0].getReturnType();
|
|
154
|
+
if (isEffectType(returnType, checker)) {
|
|
155
|
+
return decomposeEffectType(returnType, checker, enclosingNode);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
function collectBindingNamesFromTsNode(nameNode, decl, variables) {
|
|
161
|
+
if (ts.isIdentifier(nameNode)) {
|
|
162
|
+
variables.set(nameNode.text, decl);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (const element of nameNode.elements) {
|
|
166
|
+
if (ts.isBindingElement(element)) {
|
|
167
|
+
collectBindingNamesFromTsNode(element.name, decl, variables);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function findTopLevelDeclarationsInTs(sourceFile) {
|
|
172
|
+
const variables = new Map();
|
|
173
|
+
const typeAliases = new Map();
|
|
174
|
+
const classes = new Map();
|
|
175
|
+
for (const stmt of sourceFile.statements) {
|
|
176
|
+
if (ts.isVariableStatement(stmt)) {
|
|
177
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
178
|
+
collectBindingNamesFromTsNode(decl.name, decl, variables);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (ts.isTypeAliasDeclaration(stmt)) {
|
|
182
|
+
typeAliases.set(stmt.name.text, stmt);
|
|
183
|
+
}
|
|
184
|
+
else if (ts.isClassDeclaration(stmt) && stmt.name) {
|
|
185
|
+
classes.set(stmt.name.text, stmt);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return { variables, typeAliases, classes };
|
|
189
|
+
}
|
|
190
|
+
function resolveSchemaSymbol(entry, funPath, checker, tsDecls) {
|
|
191
|
+
const name = entry.decl.id.name;
|
|
192
|
+
const kind = entry.decl.body.kind === "TypeSignatureSchema" ? "type" : "schema";
|
|
193
|
+
const typeAlias = tsDecls.typeAliases.get(name);
|
|
194
|
+
const varDecl = tsDecls.variables.get(name);
|
|
195
|
+
const node = typeAlias ?? varDecl;
|
|
196
|
+
let resolvedType;
|
|
197
|
+
if (typeAlias) {
|
|
198
|
+
resolvedType =
|
|
199
|
+
kind === "type"
|
|
200
|
+
? checker.getTypeFromTypeNode(typeAlias.type)
|
|
201
|
+
: checker.getTypeAtLocation(typeAlias);
|
|
202
|
+
}
|
|
203
|
+
else if (varDecl) {
|
|
204
|
+
resolvedType = checker.getTypeAtLocation(varDecl);
|
|
205
|
+
}
|
|
206
|
+
let typeStr = resolvedType
|
|
207
|
+
? formatType(checker, resolvedType, node)
|
|
208
|
+
: "unknown";
|
|
209
|
+
const effect = resolvedType && kind === "type"
|
|
210
|
+
? decomposeEffectType(resolvedType, checker, node)
|
|
211
|
+
: undefined;
|
|
212
|
+
if (kind === "type" && resolvedType && typeStr === name) {
|
|
213
|
+
if (effect) {
|
|
214
|
+
const reqs = effect.requirements.length > 0
|
|
215
|
+
? effect.requirements.join(" | ")
|
|
216
|
+
: "never";
|
|
217
|
+
typeStr = `Effect<${effect.success}, ${effect.error}, ${reqs}>`;
|
|
218
|
+
}
|
|
219
|
+
else if (resolvedType.getCallSignatures().length > 0 &&
|
|
220
|
+
resolvedType.getConstructSignatures().length === 0) {
|
|
221
|
+
typeStr = cleanTypeString(checker.signatureToString(resolvedType.getCallSignatures()[0], node, ts.TypeFormatFlags.NoTruncation |
|
|
222
|
+
ts.TypeFormatFlags.WriteArrowStyleSignature));
|
|
223
|
+
}
|
|
224
|
+
else if (typeAlias) {
|
|
225
|
+
typeStr = cleanTypeString(typeAlias.type.getText());
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
name,
|
|
230
|
+
kind,
|
|
231
|
+
exported: entry.exported,
|
|
232
|
+
file: funPath,
|
|
233
|
+
line: entry.decl.id.span.start.line,
|
|
234
|
+
column: entry.decl.id.span.start.column,
|
|
235
|
+
type: typeStr,
|
|
236
|
+
...(effect ? { effect } : {}),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function resolveErrorSymbol(entry, funPath, checker, tsDecls) {
|
|
240
|
+
const name = entry.decl.id.name;
|
|
241
|
+
const classDecl = tsDecls.classes.get(`${name}$Class`);
|
|
242
|
+
const typeAlias = tsDecls.typeAliases.get(name);
|
|
243
|
+
let typeStr = name;
|
|
244
|
+
if (classDecl) {
|
|
245
|
+
const classType = checker.getTypeAtLocation(classDecl);
|
|
246
|
+
const baseTypes = classType.getBaseTypes();
|
|
247
|
+
if (baseTypes && baseTypes.length > 0) {
|
|
248
|
+
typeStr = formatType(checker, baseTypes[0], classDecl);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
typeStr = formatType(checker, classType, classDecl);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else if (typeAlias) {
|
|
255
|
+
const aliasType = checker.getTypeAtLocation(typeAlias);
|
|
256
|
+
typeStr = formatType(checker, aliasType, typeAlias);
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
name,
|
|
260
|
+
kind: "error",
|
|
261
|
+
exported: entry.exported,
|
|
262
|
+
file: funPath,
|
|
263
|
+
line: entry.decl.id.span.start.line,
|
|
264
|
+
column: entry.decl.id.span.start.column,
|
|
265
|
+
type: typeStr,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function resolveServiceSymbol(entry, funPath, checker, tsDecls) {
|
|
269
|
+
const name = entry.decl.id.name;
|
|
270
|
+
const classDecl = tsDecls.classes.get(name);
|
|
271
|
+
let typeStr = name;
|
|
272
|
+
if (classDecl) {
|
|
273
|
+
const classType = checker.getTypeAtLocation(classDecl);
|
|
274
|
+
const baseTypes = classType.getBaseTypes();
|
|
275
|
+
if (baseTypes && baseTypes.length > 0) {
|
|
276
|
+
const shapeArgs = checker.getTypeArguments(baseTypes[0]);
|
|
277
|
+
if (shapeArgs.length >= 2) {
|
|
278
|
+
typeStr = formatType(checker, shapeArgs[1], classDecl);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
typeStr = formatType(checker, baseTypes[0], classDecl);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
typeStr = formatType(checker, classType, classDecl);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
name,
|
|
290
|
+
kind: "service",
|
|
291
|
+
exported: entry.exported,
|
|
292
|
+
file: funPath,
|
|
293
|
+
line: entry.decl.id.span.start.line,
|
|
294
|
+
column: entry.decl.id.span.start.column,
|
|
295
|
+
type: typeStr,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function resolveBindingSymbols(entry, funPath, checker, tsDecls) {
|
|
299
|
+
const targets = collectBindingTargetLocations(entry.decl.id);
|
|
300
|
+
const isSimpleTarget = entry.decl.id.kind === "Identifier" ||
|
|
301
|
+
entry.decl.id.kind === "UpperIdentifier";
|
|
302
|
+
return targets.map(({ name, span }) => {
|
|
303
|
+
const varDecl = tsDecls.variables.get(name);
|
|
304
|
+
let resolvedType;
|
|
305
|
+
if (varDecl) {
|
|
306
|
+
if (ts.isIdentifier(varDecl.name)) {
|
|
307
|
+
resolvedType = checker.getTypeAtLocation(varDecl);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const symbol = checker.getSymbolsInScope(varDecl, ts.SymbolFlags.BlockScopedVariable);
|
|
311
|
+
const match = symbol.find((sym) => sym.getName() === name);
|
|
312
|
+
if (match) {
|
|
313
|
+
resolvedType = checker.getTypeOfSymbolAtLocation(match, varDecl);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const isFuncFromAst = isSimpleTarget &&
|
|
318
|
+
(entry.decl.init.kind === "FunctionExpression" ||
|
|
319
|
+
entry.decl.typeAnnotation?.kind === "FunctionTypeNode");
|
|
320
|
+
const isFuncFromTs = resolvedType !== undefined &&
|
|
321
|
+
!isEffectType(resolvedType, checker) &&
|
|
322
|
+
resolvedType.getCallSignatures().length > 0 &&
|
|
323
|
+
resolvedType.getConstructSignatures().length === 0;
|
|
324
|
+
const kind = isFuncFromAst || isFuncFromTs ? "function" : "binding";
|
|
325
|
+
const typeStr = resolvedType
|
|
326
|
+
? formatType(checker, resolvedType, varDecl)
|
|
327
|
+
: "unknown";
|
|
328
|
+
const effect = resolvedType
|
|
329
|
+
? decomposeEffectType(resolvedType, checker, varDecl)
|
|
330
|
+
: undefined;
|
|
331
|
+
return {
|
|
332
|
+
name,
|
|
333
|
+
kind,
|
|
334
|
+
exported: entry.exported,
|
|
335
|
+
file: funPath,
|
|
336
|
+
line: span.start.line,
|
|
337
|
+
column: span.start.column,
|
|
338
|
+
type: typeStr,
|
|
339
|
+
...(effect ? { effect } : {}),
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function collectAstTypedHoles(ast) {
|
|
344
|
+
const holes = [];
|
|
345
|
+
const visited = new Set();
|
|
346
|
+
const walk = (node) => {
|
|
347
|
+
if (!node || typeof node !== "object")
|
|
348
|
+
return;
|
|
349
|
+
if (visited.has(node))
|
|
350
|
+
return;
|
|
351
|
+
visited.add(node);
|
|
352
|
+
if (Array.isArray(node)) {
|
|
353
|
+
for (const item of node)
|
|
354
|
+
walk(item);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const record = node;
|
|
358
|
+
if (record.kind === "TypedHole") {
|
|
359
|
+
holes.push(record);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
for (const [key, value] of Object.entries(record)) {
|
|
363
|
+
if (key === "span")
|
|
364
|
+
continue;
|
|
365
|
+
walk(value);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
walk(ast);
|
|
369
|
+
return holes;
|
|
370
|
+
}
|
|
371
|
+
function extractTypedHoleCallMessage(node) {
|
|
372
|
+
if (!ts.isCallExpression(node) || node.arguments.length !== 0) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
if (!ts.isParenthesizedExpression(node.expression)) {
|
|
376
|
+
return undefined;
|
|
377
|
+
}
|
|
378
|
+
const arrow = node.expression.expression;
|
|
379
|
+
if (!ts.isArrowFunction(arrow) || arrow.parameters.length !== 0) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
if (!ts.isBlock(arrow.body) || arrow.body.statements.length !== 1) {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
const stmt = arrow.body.statements[0];
|
|
386
|
+
if (!ts.isThrowStatement(stmt) || !stmt.expression) {
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
389
|
+
if (!ts.isNewExpression(stmt.expression)) {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
const ctor = stmt.expression.expression;
|
|
393
|
+
if (!ts.isIdentifier(ctor) || ctor.text !== "Error") {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
const args = stmt.expression.arguments;
|
|
397
|
+
if (!args || args.length !== 1 || !ts.isStringLiteral(args[0])) {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
const prefix = "Typed hole reached: ";
|
|
401
|
+
if (!args[0].text.startsWith(prefix)) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
return args[0].text.slice(prefix.length);
|
|
405
|
+
}
|
|
406
|
+
function collectTsHoleCalls(sourceFile) {
|
|
407
|
+
const matches = [];
|
|
408
|
+
const visit = (node) => {
|
|
409
|
+
const rawMessage = extractTypedHoleCallMessage(node);
|
|
410
|
+
if (rawMessage !== undefined) {
|
|
411
|
+
matches.push({ call: node, rawMessage });
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
ts.forEachChild(node, visit);
|
|
415
|
+
};
|
|
416
|
+
visit(sourceFile);
|
|
417
|
+
return matches;
|
|
418
|
+
}
|
|
419
|
+
function findEnclosingOuterFunctionReturnType(node, checker) {
|
|
420
|
+
let cur = node.parent;
|
|
421
|
+
while (cur) {
|
|
422
|
+
if (ts.isFunctionLike(cur) && cur.type) {
|
|
423
|
+
return checker.getTypeFromTypeNode(cur.type);
|
|
424
|
+
}
|
|
425
|
+
if (ts.isVariableDeclaration(cur) && cur.type) {
|
|
426
|
+
return checker.getTypeFromTypeNode(cur.type);
|
|
427
|
+
}
|
|
428
|
+
cur = cur.parent;
|
|
429
|
+
}
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
function unwrapEffectSuccessFromOuterCall(effectCall, checker) {
|
|
433
|
+
let outerCall = effectCall;
|
|
434
|
+
if (ts.isCallExpression(outerCall.parent) &&
|
|
435
|
+
outerCall.parent.expression.getText().endsWith("Effect.scoped")) {
|
|
436
|
+
outerCall = outerCall.parent;
|
|
437
|
+
}
|
|
438
|
+
const contextual = checker.getContextualType(outerCall);
|
|
439
|
+
const candidate = contextual ?? findEnclosingOuterFunctionReturnType(outerCall, checker);
|
|
440
|
+
if (candidate && isEffectType(candidate, checker)) {
|
|
441
|
+
const args = checker.getTypeArguments(candidate);
|
|
442
|
+
return args[0];
|
|
443
|
+
}
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
function unwrapEffectSuccessIfReturnInEffectGen(holeCall, checker) {
|
|
447
|
+
if (ts.isArrowFunction(holeCall.parent)) {
|
|
448
|
+
const parentCall = holeCall.parent.parent;
|
|
449
|
+
if (ts.isCallExpression(parentCall) &&
|
|
450
|
+
parentCall.expression.getText().endsWith("Effect.map")) {
|
|
451
|
+
return unwrapEffectSuccessFromOuterCall(parentCall, checker);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (!ts.isReturnStatement(holeCall.parent)) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
let genFn = holeCall.parent.parent;
|
|
458
|
+
while (genFn && !ts.isFunctionLike(genFn)) {
|
|
459
|
+
genFn = genFn.parent;
|
|
460
|
+
}
|
|
461
|
+
if (!genFn || !ts.isCallExpression(genFn.parent)) {
|
|
462
|
+
return undefined;
|
|
463
|
+
}
|
|
464
|
+
const effectCall = genFn.parent;
|
|
465
|
+
const calleeText = effectCall.expression.getText();
|
|
466
|
+
if (!calleeText.endsWith("Effect.gen") &&
|
|
467
|
+
calleeText !== "gen" &&
|
|
468
|
+
!calleeText.endsWith("Effect.map")) {
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
return unwrapEffectSuccessFromOuterCall(effectCall, checker);
|
|
472
|
+
}
|
|
473
|
+
function unwrapMatchChainExpectedType(holeCall, checker) {
|
|
474
|
+
if (!ts.isArrowFunction(holeCall.parent)) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
const armArrow = holeCall.parent;
|
|
478
|
+
if (!ts.isCallExpression(armArrow.parent)) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
let chainCall = armArrow.parent;
|
|
482
|
+
while (ts.isPropertyAccessExpression(chainCall.parent) &&
|
|
483
|
+
ts.isCallExpression(chainCall.parent.parent)) {
|
|
484
|
+
chainCall = chainCall.parent.parent;
|
|
485
|
+
}
|
|
486
|
+
const chainCtx = checker.getContextualType(chainCall);
|
|
487
|
+
if (chainCtx && (chainCtx.flags & ts.TypeFlags.Never) === 0) {
|
|
488
|
+
return chainCtx;
|
|
489
|
+
}
|
|
490
|
+
if (ts.isReturnStatement(chainCall.parent)) {
|
|
491
|
+
return findEnclosingOuterFunctionReturnType(chainCall, checker);
|
|
492
|
+
}
|
|
493
|
+
return undefined;
|
|
494
|
+
}
|
|
495
|
+
function resolveHoleExpectedType(holeCall, checker) {
|
|
496
|
+
const contextual = checker.getContextualType(holeCall);
|
|
497
|
+
if (contextual && (contextual.flags & ts.TypeFlags.Never) === 0) {
|
|
498
|
+
return formatType(checker, contextual, holeCall);
|
|
499
|
+
}
|
|
500
|
+
const effectSuccess = unwrapEffectSuccessIfReturnInEffectGen(holeCall, checker);
|
|
501
|
+
if (effectSuccess && (effectSuccess.flags & ts.TypeFlags.Never) === 0) {
|
|
502
|
+
return formatType(checker, effectSuccess, holeCall);
|
|
503
|
+
}
|
|
504
|
+
const matchType = unwrapMatchChainExpectedType(holeCall, checker);
|
|
505
|
+
if (matchType && (matchType.flags & ts.TypeFlags.Never) === 0) {
|
|
506
|
+
return formatType(checker, matchType, holeCall);
|
|
507
|
+
}
|
|
508
|
+
return undefined;
|
|
509
|
+
}
|
|
510
|
+
function resolveFileHoles(ast, funPath, sourceFile, checker) {
|
|
511
|
+
const astHoles = collectAstTypedHoles(ast);
|
|
512
|
+
if (astHoles.length === 0) {
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
const tsHoles = collectTsHoleCalls(sourceFile);
|
|
516
|
+
const usedTsIndices = new Set();
|
|
517
|
+
const queriedHoles = [];
|
|
518
|
+
for (const astHole of astHoles) {
|
|
519
|
+
const targetMsg = astHole.label || "???";
|
|
520
|
+
let matchedIdx = tsHoles.findIndex((h, idx) => !usedTsIndices.has(idx) && h.rawMessage === targetMsg);
|
|
521
|
+
if (matchedIdx === -1) {
|
|
522
|
+
matchedIdx = tsHoles.findIndex((_, idx) => !usedTsIndices.has(idx));
|
|
523
|
+
}
|
|
524
|
+
let expectedType;
|
|
525
|
+
if (matchedIdx !== -1) {
|
|
526
|
+
usedTsIndices.add(matchedIdx);
|
|
527
|
+
expectedType = resolveHoleExpectedType(tsHoles[matchedIdx].call, checker);
|
|
528
|
+
}
|
|
529
|
+
queriedHoles.push({
|
|
530
|
+
file: funPath,
|
|
531
|
+
line: astHole.span.start.line,
|
|
532
|
+
column: astHole.span.start.column,
|
|
533
|
+
...(astHole.label !== undefined ? { message: astHole.label } : {}),
|
|
534
|
+
...(expectedType !== undefined ? { expectedType } : {}),
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
return queriedHoles;
|
|
538
|
+
}
|
|
539
|
+
function inspectCompiledFile(compiled, program, checker, symbolFilter) {
|
|
540
|
+
const sourceFile = program.getSourceFile(compiled.virtualTsPath);
|
|
541
|
+
const imports = collectImports(compiled.ast);
|
|
542
|
+
const declEntries = collectTopLevelDeclarations(compiled.ast);
|
|
543
|
+
let symbols = [];
|
|
544
|
+
let holes = [];
|
|
545
|
+
if (sourceFile) {
|
|
546
|
+
const tsDecls = findTopLevelDeclarationsInTs(sourceFile);
|
|
547
|
+
for (const entry of declEntries) {
|
|
548
|
+
switch (entry.decl.kind) {
|
|
549
|
+
case "SchemaDeclaration":
|
|
550
|
+
symbols.push(resolveSchemaSymbol(entry, compiled.funPath, checker, tsDecls));
|
|
551
|
+
break;
|
|
552
|
+
case "ErrorDeclaration":
|
|
553
|
+
symbols.push(resolveErrorSymbol(entry, compiled.funPath, checker, tsDecls));
|
|
554
|
+
break;
|
|
555
|
+
case "ServiceDeclaration":
|
|
556
|
+
symbols.push(resolveServiceSymbol(entry, compiled.funPath, checker, tsDecls));
|
|
557
|
+
break;
|
|
558
|
+
case "BindingDeclaration":
|
|
559
|
+
symbols.push(...resolveBindingSymbols(entry, compiled.funPath, checker, tsDecls));
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
holes = resolveFileHoles(compiled.ast, compiled.funPath, sourceFile, checker);
|
|
564
|
+
}
|
|
565
|
+
if (symbolFilter) {
|
|
566
|
+
symbols = symbols.filter((s) => s.name === symbolFilter);
|
|
567
|
+
}
|
|
568
|
+
return {
|
|
569
|
+
file: compiled.funPath,
|
|
570
|
+
imports,
|
|
571
|
+
symbols,
|
|
572
|
+
holes,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Queries semantic type, Effect channel, and typed-hole information for virtual FunkScript files.
|
|
577
|
+
*/
|
|
578
|
+
export const queryVirtualFiles = (virtualInputFiles, options) => Effect.tryPromise({
|
|
579
|
+
try: async () => {
|
|
580
|
+
const cwd = options?.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
581
|
+
const compilerOptions = getCompilerOptions(cwd);
|
|
582
|
+
const virtualTsFiles = new Map();
|
|
583
|
+
const compiledFiles = [];
|
|
584
|
+
const virtualSources = new Map(Object.entries(virtualInputFiles).map(([file, content]) => [
|
|
585
|
+
path.resolve(cwd, file),
|
|
586
|
+
content,
|
|
587
|
+
]));
|
|
588
|
+
for (const [filePath, source] of Object.entries(virtualInputFiles)) {
|
|
589
|
+
const fullFunPath = path.isAbsolute(filePath)
|
|
590
|
+
? path.normalize(filePath)
|
|
591
|
+
: path.normalize(path.join(cwd, filePath));
|
|
592
|
+
const virtualTsPath = toVirtualTsPath(fullFunPath);
|
|
593
|
+
let compiled;
|
|
594
|
+
try {
|
|
595
|
+
compiled = await Effect.runPromise(compileString(source, filePath, {
|
|
596
|
+
sourcemap: false,
|
|
597
|
+
allowHoles: true,
|
|
598
|
+
preserveFunImports: true,
|
|
599
|
+
sourcePath: fullFunPath,
|
|
600
|
+
virtualSources,
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
catch (err) {
|
|
604
|
+
const compErr = err instanceof CompilerError
|
|
605
|
+
? err
|
|
606
|
+
: new CompilerError(toErrorMessage(err), err instanceof Error ? err : new Error(toErrorMessage(err)));
|
|
607
|
+
throw new Error(`Failed to compile '${filePath}': ${compErr.message}`);
|
|
608
|
+
}
|
|
609
|
+
virtualTsFiles.set(virtualTsPath, compiled.typescript);
|
|
610
|
+
compiledFiles.push({
|
|
611
|
+
funPath: filePath,
|
|
612
|
+
virtualTsPath,
|
|
613
|
+
ast: compiled.ast,
|
|
614
|
+
typescript: compiled.typescript,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
const hasTsx = Array.from(virtualTsFiles.keys()).some((fileName) => fileName.endsWith(".tsx"));
|
|
618
|
+
const hasJsxIntrinsicTypes = Array.from(virtualTsFiles.values()).some((src) => /namespace\s+JSX[\s\S]*?IntrinsicElements/.test(src));
|
|
619
|
+
if (hasTsx && !hasJsxIntrinsicTypes) {
|
|
620
|
+
const jsxTypesPath = path.join(cwd, "__funscript_jsx_intrinsics__.d.ts");
|
|
621
|
+
virtualTsFiles.set(jsxTypesPath, JSX_INTRINSICS_DECLARATION);
|
|
622
|
+
}
|
|
623
|
+
virtualTsFiles.set(path.join(cwd, "__funscript_ts_reset__.d.ts"), TS_RESET_DECLARATION);
|
|
624
|
+
virtualTsFiles.set(path.join(cwd, "__funscript_type_fest__.d.ts"), TYPE_FEST_DECLARATION);
|
|
625
|
+
const files = [];
|
|
626
|
+
if (compiledFiles.length > 0) {
|
|
627
|
+
const defaultHost = ts.createCompilerHost(compilerOptions);
|
|
628
|
+
const resolveVirtualContent = (fileName) => {
|
|
629
|
+
const norm = path.normalize(fileName);
|
|
630
|
+
const direct = virtualTsFiles.get(norm);
|
|
631
|
+
if (direct !== undefined)
|
|
632
|
+
return direct;
|
|
633
|
+
if (virtualTsFiles.has(norm + ".ts"))
|
|
634
|
+
return virtualTsFiles.get(norm + ".ts");
|
|
635
|
+
if (virtualTsFiles.has(norm + ".tsx"))
|
|
636
|
+
return virtualTsFiles.get(norm + ".tsx");
|
|
637
|
+
if (norm.endsWith(".js") &&
|
|
638
|
+
virtualTsFiles.has(norm.slice(0, -3) + ".ts")) {
|
|
639
|
+
return virtualTsFiles.get(norm.slice(0, -3) + ".ts");
|
|
640
|
+
}
|
|
641
|
+
if (norm.endsWith(".jsx") &&
|
|
642
|
+
virtualTsFiles.has(norm.slice(0, -4) + ".tsx")) {
|
|
643
|
+
return virtualTsFiles.get(norm.slice(0, -4) + ".tsx");
|
|
644
|
+
}
|
|
645
|
+
if (path.basename(fileName) === "__funscript_type_fest__.d.ts") {
|
|
646
|
+
return TYPE_FEST_DECLARATION;
|
|
647
|
+
}
|
|
648
|
+
if (path.basename(fileName) === "__funscript_ts_reset__.d.ts") {
|
|
649
|
+
return TS_RESET_DECLARATION;
|
|
650
|
+
}
|
|
651
|
+
if (path.basename(fileName) === "__funscript_jsx_intrinsics__.d.ts") {
|
|
652
|
+
return JSX_INTRINSICS_DECLARATION;
|
|
653
|
+
}
|
|
654
|
+
return undefined;
|
|
655
|
+
};
|
|
656
|
+
const host = {
|
|
657
|
+
...defaultHost,
|
|
658
|
+
getSourceFile: (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
659
|
+
const content = resolveVirtualContent(fileName);
|
|
660
|
+
if (content !== undefined) {
|
|
661
|
+
return ts.createSourceFile(fileName, content, languageVersion, true);
|
|
662
|
+
}
|
|
663
|
+
return defaultHost.getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
664
|
+
},
|
|
665
|
+
fileExists: (fileName) => {
|
|
666
|
+
if (resolveVirtualContent(fileName) !== undefined)
|
|
667
|
+
return true;
|
|
668
|
+
return defaultHost.fileExists(fileName);
|
|
669
|
+
},
|
|
670
|
+
readFile: (fileName) => {
|
|
671
|
+
const content = resolveVirtualContent(fileName);
|
|
672
|
+
if (content !== undefined)
|
|
673
|
+
return content;
|
|
674
|
+
return defaultHost.readFile(fileName);
|
|
675
|
+
},
|
|
676
|
+
writeFile: () => { },
|
|
677
|
+
};
|
|
678
|
+
host.resolveModuleNames = (names, containingFile) => names.map((name) => {
|
|
679
|
+
if (/^\.{1,2}\//.test(name)) {
|
|
680
|
+
if (name.endsWith(".js")) {
|
|
681
|
+
const regular = ts.resolveModuleName(name, containingFile, compilerOptions, defaultHost).resolvedModule;
|
|
682
|
+
if (regular)
|
|
683
|
+
return regular;
|
|
684
|
+
}
|
|
685
|
+
const source = resolveFunModule(containingFile, name, (file) => /\.funx?$/.test(file) &&
|
|
686
|
+
virtualTsFiles.has(file + (file.endsWith(".funx") ? ".tsx" : ".ts")), { directories: true });
|
|
687
|
+
if (source) {
|
|
688
|
+
return {
|
|
689
|
+
resolvedFileName: source + (source.endsWith(".funx") ? ".tsx" : ".ts"),
|
|
690
|
+
extension: source.endsWith(".funx")
|
|
691
|
+
? ts.Extension.Tsx
|
|
692
|
+
: ts.Extension.Ts,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
if (/\.funx?$/.test(name))
|
|
696
|
+
return undefined;
|
|
697
|
+
}
|
|
698
|
+
return ts.resolveModuleName(name, containingFile, compilerOptions, host).resolvedModule;
|
|
699
|
+
});
|
|
700
|
+
const program = ts.createProgram({
|
|
701
|
+
rootNames: Array.from(virtualTsFiles.keys()),
|
|
702
|
+
options: compilerOptions,
|
|
703
|
+
host,
|
|
704
|
+
});
|
|
705
|
+
const checker = program.getTypeChecker();
|
|
706
|
+
for (const compiled of compiledFiles) {
|
|
707
|
+
files.push(inspectCompiledFile(compiled, program, checker, options?.symbol));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
schemaVersion: 1,
|
|
712
|
+
files,
|
|
713
|
+
};
|
|
714
|
+
},
|
|
715
|
+
catch: (error) => error instanceof Error
|
|
716
|
+
? error
|
|
717
|
+
: new Error(`Query failed: ${toErrorMessage(error)}`),
|
|
718
|
+
});
|
|
719
|
+
/**
|
|
720
|
+
* Reads FunkScript files from disk and queries their semantic information.
|
|
721
|
+
*/
|
|
722
|
+
export const queryFiles = (files, options) => Effect.gen(function* () {
|
|
723
|
+
const cwd = options?.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
724
|
+
const virtualFiles = {};
|
|
725
|
+
for (const filePath of files) {
|
|
726
|
+
const fullPath = path.isAbsolute(filePath)
|
|
727
|
+
? filePath
|
|
728
|
+
: path.resolve(cwd, filePath);
|
|
729
|
+
const content = yield* Effect.tryPromise({
|
|
730
|
+
try: () => fs.readFile(fullPath, "utf-8"),
|
|
731
|
+
catch: (err) => new Error(`Failed to read file '${filePath}': ${toErrorMessage(err)}`),
|
|
732
|
+
});
|
|
733
|
+
virtualFiles[filePath] = content;
|
|
734
|
+
}
|
|
735
|
+
return yield* queryVirtualFiles(virtualFiles, options);
|
|
736
|
+
});
|
|
737
|
+
/**
|
|
738
|
+
* Formats a QueryReport as JSON or human-readable semantic inspection output.
|
|
739
|
+
*/
|
|
740
|
+
export function formatQueryReport(report, options) {
|
|
741
|
+
if (options?.json) {
|
|
742
|
+
return JSON.stringify(report, null, 2);
|
|
743
|
+
}
|
|
744
|
+
if (report.files.length === 0) {
|
|
745
|
+
return "No files queried.";
|
|
746
|
+
}
|
|
747
|
+
const sections = [];
|
|
748
|
+
for (const fileReport of report.files) {
|
|
749
|
+
const lines = [`File: ${fileReport.file}`];
|
|
750
|
+
if (fileReport.imports.length > 0) {
|
|
751
|
+
lines.push(` Imports: ${fileReport.imports.join(", ")}`);
|
|
752
|
+
}
|
|
753
|
+
if (fileReport.symbols.length === 0) {
|
|
754
|
+
lines.push(" Symbols: (none)");
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
lines.push(` Symbols (${fileReport.symbols.length}):`);
|
|
758
|
+
for (const sym of fileReport.symbols) {
|
|
759
|
+
const exp = sym.exported ? "export " : "";
|
|
760
|
+
lines.push(` ${exp}${sym.kind} ${sym.name}: ${sym.type} (${sym.file}:${sym.line}:${sym.column})`);
|
|
761
|
+
if (sym.effect) {
|
|
762
|
+
const reqs = sym.effect.requirements.length > 0
|
|
763
|
+
? sym.effect.requirements.join(" | ")
|
|
764
|
+
: "never";
|
|
765
|
+
lines.push(` effect: success=${sym.effect.success}, error=${sym.effect.error}, requirements=${reqs}`);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
if (fileReport.holes.length > 0) {
|
|
770
|
+
lines.push(` Holes (${fileReport.holes.length}):`);
|
|
771
|
+
for (const hole of fileReport.holes) {
|
|
772
|
+
const label = hole.message ? ` "${hole.message}"` : "";
|
|
773
|
+
const expected = hole.expectedType ?? "unknown";
|
|
774
|
+
lines.push(` ???${label} -> expected ${expected} (${hole.file}:${hole.line}:${hole.column})`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
sections.push(lines.join("\n"));
|
|
778
|
+
}
|
|
779
|
+
return sections.join("\n\n");
|
|
780
|
+
}
|
|
781
|
+
//# sourceMappingURL=query.js.map
|