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,913 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type {
|
|
5
|
+
BindingDeclaration,
|
|
6
|
+
BindingTarget,
|
|
7
|
+
BlockStatement,
|
|
8
|
+
EffectStatement,
|
|
9
|
+
Expression,
|
|
10
|
+
FunctionBody,
|
|
11
|
+
JSXAttribute,
|
|
12
|
+
JSXChild,
|
|
13
|
+
MatchArm,
|
|
14
|
+
Pattern,
|
|
15
|
+
Program,
|
|
16
|
+
SchemaBody,
|
|
17
|
+
Span,
|
|
18
|
+
Statement,
|
|
19
|
+
TopLevelDeclaration,
|
|
20
|
+
TypeNode,
|
|
21
|
+
} from "../ast/types.js";
|
|
22
|
+
import { Lexer } from "../lexer/lexer.js";
|
|
23
|
+
import { Parser } from "../parser/parser.js";
|
|
24
|
+
|
|
25
|
+
export type EscapeHatchKind =
|
|
26
|
+
"raw-ts" | "js-interop" | "wildcard-match" | "typed-hole";
|
|
27
|
+
|
|
28
|
+
export interface EscapeHatchFinding {
|
|
29
|
+
kind: EscapeHatchKind;
|
|
30
|
+
file: string;
|
|
31
|
+
line: number;
|
|
32
|
+
column: number;
|
|
33
|
+
declaration?: string;
|
|
34
|
+
snippet: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface EscapeAuditCounts {
|
|
38
|
+
rawTs: number;
|
|
39
|
+
jsInterop: number;
|
|
40
|
+
wildcardMatch: number;
|
|
41
|
+
typedHole: number;
|
|
42
|
+
total: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface EscapeAuditFileReport {
|
|
46
|
+
file: string;
|
|
47
|
+
counts: EscapeAuditCounts;
|
|
48
|
+
findings: EscapeHatchFinding[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface EscapeAuditReport {
|
|
52
|
+
schemaVersion: 1;
|
|
53
|
+
counts: EscapeAuditCounts;
|
|
54
|
+
files: EscapeAuditFileReport[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const MAX_SNIPPET_LENGTH = 120;
|
|
58
|
+
|
|
59
|
+
function emptyCounts(): EscapeAuditCounts {
|
|
60
|
+
return {
|
|
61
|
+
rawTs: 0,
|
|
62
|
+
jsInterop: 0,
|
|
63
|
+
wildcardMatch: 0,
|
|
64
|
+
typedHole: 0,
|
|
65
|
+
total: 0,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function incrementCounts(
|
|
70
|
+
counts: EscapeAuditCounts,
|
|
71
|
+
kind: EscapeHatchKind,
|
|
72
|
+
): void {
|
|
73
|
+
counts.total += 1;
|
|
74
|
+
switch (kind) {
|
|
75
|
+
case "raw-ts":
|
|
76
|
+
counts.rawTs += 1;
|
|
77
|
+
break;
|
|
78
|
+
case "js-interop":
|
|
79
|
+
counts.jsInterop += 1;
|
|
80
|
+
break;
|
|
81
|
+
case "wildcard-match":
|
|
82
|
+
counts.wildcardMatch += 1;
|
|
83
|
+
break;
|
|
84
|
+
case "typed-hole":
|
|
85
|
+
counts.typedHole += 1;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function mergeCounts(
|
|
91
|
+
target: EscapeAuditCounts,
|
|
92
|
+
addition: EscapeAuditCounts,
|
|
93
|
+
): void {
|
|
94
|
+
target.rawTs += addition.rawTs;
|
|
95
|
+
target.jsInterop += addition.jsInterop;
|
|
96
|
+
target.wildcardMatch += addition.wildcardMatch;
|
|
97
|
+
target.typedHole += addition.typedHole;
|
|
98
|
+
target.total += addition.total;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function truncateSnippet(text: string): string {
|
|
102
|
+
const normalized = text.trim();
|
|
103
|
+
if (normalized.length <= MAX_SNIPPET_LENGTH) {
|
|
104
|
+
return normalized;
|
|
105
|
+
}
|
|
106
|
+
return `${normalized.slice(0, MAX_SNIPPET_LENGTH - 3)}...`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function extractLineSnippet(sourceLines: string[], span: Span): string {
|
|
110
|
+
const lineText = sourceLines[span.start.line - 1] ?? "";
|
|
111
|
+
return truncateSnippet(lineText);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function extractSpanSnippet(
|
|
115
|
+
source: string,
|
|
116
|
+
sourceLines: string[],
|
|
117
|
+
span: Span,
|
|
118
|
+
fallback: string,
|
|
119
|
+
): string {
|
|
120
|
+
const start = span.start.offset;
|
|
121
|
+
const end = span.end.offset;
|
|
122
|
+
if (start >= 0 && end > start && end <= source.length) {
|
|
123
|
+
const raw = source.slice(start, end);
|
|
124
|
+
const firstLine = raw.split(/\r?\n/)[0]?.trim() ?? "";
|
|
125
|
+
if (firstLine.length > 0) {
|
|
126
|
+
return truncateSnippet(firstLine);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const lineText = extractLineSnippet(sourceLines, span);
|
|
130
|
+
return lineText.length > 0 ? lineText : truncateSnippet(fallback);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isWildcardArmPattern(pattern: Pattern): boolean {
|
|
134
|
+
if (pattern.kind === "WildcardPattern") {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (pattern.kind === "OrPattern") {
|
|
138
|
+
return pattern.patterns.some((part) => isWildcardArmPattern(part));
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function collectBindingTargetNames(target: BindingTarget | Pattern): string[] {
|
|
144
|
+
switch (target.kind) {
|
|
145
|
+
case "Identifier":
|
|
146
|
+
case "UpperIdentifier":
|
|
147
|
+
return [target.name];
|
|
148
|
+
case "VariablePattern":
|
|
149
|
+
return [target.name.name];
|
|
150
|
+
case "RestPattern":
|
|
151
|
+
return collectBindingTargetNames(target.argument);
|
|
152
|
+
case "RecordPattern":
|
|
153
|
+
return target.fields.flatMap((field) =>
|
|
154
|
+
field.pattern
|
|
155
|
+
? collectBindingTargetNames(field.pattern)
|
|
156
|
+
: [field.key.name],
|
|
157
|
+
);
|
|
158
|
+
case "ArrayPattern":
|
|
159
|
+
return target.elements.flatMap((elem) => collectBindingTargetNames(elem));
|
|
160
|
+
case "OrPattern":
|
|
161
|
+
return target.patterns.flatMap((part) => collectBindingTargetNames(part));
|
|
162
|
+
case "WildcardPattern":
|
|
163
|
+
case "LiteralPattern":
|
|
164
|
+
case "ConstructorPattern":
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function formatBindingDeclarationName(
|
|
170
|
+
target: BindingTarget,
|
|
171
|
+
): string | undefined {
|
|
172
|
+
if (target.kind === "Identifier" || target.kind === "UpperIdentifier") {
|
|
173
|
+
return target.name;
|
|
174
|
+
}
|
|
175
|
+
const names = collectBindingTargetNames(target);
|
|
176
|
+
return names.length > 0 ? names.join(", ") : undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
class EscapeAuditVisitor {
|
|
180
|
+
public readonly findings: EscapeHatchFinding[] = [];
|
|
181
|
+
private readonly sourceLines: string[];
|
|
182
|
+
|
|
183
|
+
constructor(
|
|
184
|
+
private readonly source: string,
|
|
185
|
+
private readonly filename: string,
|
|
186
|
+
) {
|
|
187
|
+
this.sourceLines = source.split(/\r?\n/);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public visitProgram(program: Program): void {
|
|
191
|
+
for (const decl of program.body) {
|
|
192
|
+
this.visitTopLevelDeclaration(decl, undefined);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private addFinding(
|
|
197
|
+
kind: EscapeHatchKind,
|
|
198
|
+
span: Span,
|
|
199
|
+
declaration: string | undefined,
|
|
200
|
+
snippet: string,
|
|
201
|
+
): void {
|
|
202
|
+
const finding: EscapeHatchFinding = {
|
|
203
|
+
kind,
|
|
204
|
+
file: this.filename,
|
|
205
|
+
line: span.start.line,
|
|
206
|
+
column: span.start.column,
|
|
207
|
+
snippet,
|
|
208
|
+
};
|
|
209
|
+
if (declaration !== undefined) {
|
|
210
|
+
finding.declaration = declaration;
|
|
211
|
+
}
|
|
212
|
+
this.findings.push(finding);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private visitTopLevelDeclaration(
|
|
216
|
+
decl: TopLevelDeclaration,
|
|
217
|
+
declaration: string | undefined,
|
|
218
|
+
): void {
|
|
219
|
+
switch (decl.kind) {
|
|
220
|
+
case "ImportDeclaration":
|
|
221
|
+
case "ExportFromDeclaration":
|
|
222
|
+
case "AsDeclaration":
|
|
223
|
+
return;
|
|
224
|
+
case "ExportDeclaration":
|
|
225
|
+
this.visitTopLevelDeclaration(decl.declaration, declaration);
|
|
226
|
+
return;
|
|
227
|
+
case "ExportDefaultDeclaration":
|
|
228
|
+
this.visitExpression(decl.expression, declaration);
|
|
229
|
+
return;
|
|
230
|
+
case "TsEscapeDeclaration":
|
|
231
|
+
this.addFinding(
|
|
232
|
+
"raw-ts",
|
|
233
|
+
decl.span,
|
|
234
|
+
declaration,
|
|
235
|
+
extractSpanSnippet(
|
|
236
|
+
this.source,
|
|
237
|
+
this.sourceLines,
|
|
238
|
+
decl.span,
|
|
239
|
+
`ts { ${decl.code.trim()} }`,
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
return;
|
|
243
|
+
case "SchemaDeclaration": {
|
|
244
|
+
const declName = decl.id.name;
|
|
245
|
+
this.visitSchemaBody(decl.body, declName);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
case "ErrorDeclaration": {
|
|
249
|
+
const declName = decl.id.name;
|
|
250
|
+
for (const field of decl.fields) {
|
|
251
|
+
this.visitTypeNode(field.typeAnnotation, declName);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
case "ServiceDeclaration": {
|
|
256
|
+
const declName = decl.id.name;
|
|
257
|
+
for (const member of decl.members) {
|
|
258
|
+
this.visitTypeNode(member.signature, declName);
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
case "BindingDeclaration":
|
|
263
|
+
this.visitBindingDeclaration(decl, declaration);
|
|
264
|
+
return;
|
|
265
|
+
case "WhenStatement":
|
|
266
|
+
this.visitExpression(decl.condition, declaration);
|
|
267
|
+
this.visitFunctionBody(decl.consequent, declaration);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private visitBindingDeclaration(
|
|
273
|
+
decl: BindingDeclaration,
|
|
274
|
+
enclosingDeclaration: string | undefined,
|
|
275
|
+
): void {
|
|
276
|
+
const declName =
|
|
277
|
+
formatBindingDeclarationName(decl.id) ?? enclosingDeclaration;
|
|
278
|
+
if (decl.isJs) {
|
|
279
|
+
this.addFinding(
|
|
280
|
+
"js-interop",
|
|
281
|
+
decl.span,
|
|
282
|
+
declName,
|
|
283
|
+
extractLineSnippet(this.sourceLines, decl.span) ||
|
|
284
|
+
`js ${declName ?? "..."}`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
if (decl.typeAnnotation) {
|
|
288
|
+
this.visitTypeNode(decl.typeAnnotation, declName);
|
|
289
|
+
}
|
|
290
|
+
this.visitExpression(decl.init, declName);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private visitSchemaBody(body: SchemaBody, declaration: string): void {
|
|
294
|
+
switch (body.kind) {
|
|
295
|
+
case "RecordSchema":
|
|
296
|
+
for (const field of body.fields) {
|
|
297
|
+
this.visitTypeNode(field.typeAnnotation, declaration);
|
|
298
|
+
if (field.refinement) {
|
|
299
|
+
this.visitExpression(field.refinement, declaration);
|
|
300
|
+
}
|
|
301
|
+
if (field.defaultValue) {
|
|
302
|
+
this.visitExpression(field.defaultValue, declaration);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
case "TaggedUnionSchema":
|
|
307
|
+
for (const variant of body.variants) {
|
|
308
|
+
for (const field of variant.fields) {
|
|
309
|
+
this.visitTypeNode(field.typeAnnotation, declaration);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
case "StructuralUnionSchema":
|
|
314
|
+
for (const member of body.members) {
|
|
315
|
+
this.visitTypeNode(member, declaration);
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
case "RefinementSchema":
|
|
319
|
+
this.visitTypeNode(body.baseType, declaration);
|
|
320
|
+
this.visitExpression(body.refinement, declaration);
|
|
321
|
+
return;
|
|
322
|
+
case "TypeSignatureSchema":
|
|
323
|
+
this.visitTypeNode(body.signature, declaration);
|
|
324
|
+
return;
|
|
325
|
+
case "TsDerivedSchema":
|
|
326
|
+
this.visitTypeNode(body.targetType, declaration);
|
|
327
|
+
return;
|
|
328
|
+
case "ImportedTsSchema":
|
|
329
|
+
this.visitTypeNode(body.typeNode, declaration);
|
|
330
|
+
for (const arg of body.typeArgs) {
|
|
331
|
+
this.visitTypeNode(arg, declaration);
|
|
332
|
+
}
|
|
333
|
+
for (const arg of body.typeArguments) {
|
|
334
|
+
this.visitTypeNode(arg, declaration);
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private visitTypeNode(node: TypeNode, declaration: string | undefined): void {
|
|
341
|
+
switch (node.kind) {
|
|
342
|
+
case "TsEscapeTypeNode":
|
|
343
|
+
this.addFinding(
|
|
344
|
+
"raw-ts",
|
|
345
|
+
node.span,
|
|
346
|
+
declaration,
|
|
347
|
+
extractSpanSnippet(
|
|
348
|
+
this.source,
|
|
349
|
+
this.sourceLines,
|
|
350
|
+
node.span,
|
|
351
|
+
`ts { ${node.code.trim()} }`,
|
|
352
|
+
),
|
|
353
|
+
);
|
|
354
|
+
return;
|
|
355
|
+
case "TypeReferenceNode":
|
|
356
|
+
case "QualifiedTypeReferenceNode":
|
|
357
|
+
if (node.typeArgs) {
|
|
358
|
+
for (const arg of node.typeArgs) {
|
|
359
|
+
this.visitTypeNode(arg, declaration);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
case "FunctionTypeNode":
|
|
364
|
+
if (node.typeParams) {
|
|
365
|
+
for (const tp of node.typeParams) {
|
|
366
|
+
if (tp.constraint) {
|
|
367
|
+
this.visitTypeNode(tp.constraint, declaration);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
for (const param of node.params) {
|
|
372
|
+
if (param.typeAnnotation) {
|
|
373
|
+
this.visitTypeNode(param.typeAnnotation, declaration);
|
|
374
|
+
}
|
|
375
|
+
if (param.defaultValue) {
|
|
376
|
+
this.visitExpression(param.defaultValue, declaration);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
this.visitTypeNode(node.returnType, declaration);
|
|
380
|
+
return;
|
|
381
|
+
case "EffectTypeNode":
|
|
382
|
+
this.visitTypeNode(node.success, declaration);
|
|
383
|
+
if (node.error) {
|
|
384
|
+
this.visitTypeNode(node.error, declaration);
|
|
385
|
+
}
|
|
386
|
+
if (node.requirements) {
|
|
387
|
+
this.visitTypeNode(node.requirements, declaration);
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
case "RecordTypeNode":
|
|
391
|
+
for (const field of node.fields) {
|
|
392
|
+
this.visitTypeNode(field.typeAnnotation, declaration);
|
|
393
|
+
if (field.defaultValue) {
|
|
394
|
+
this.visitExpression(field.defaultValue, declaration);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
case "ArrayTypeNode":
|
|
399
|
+
this.visitTypeNode(node.elementType, declaration);
|
|
400
|
+
return;
|
|
401
|
+
case "UnionTypeNode":
|
|
402
|
+
case "IntersectionTypeNode":
|
|
403
|
+
for (const member of node.types) {
|
|
404
|
+
this.visitTypeNode(member, declaration);
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
case "TypeQueryNode":
|
|
408
|
+
this.visitExpression(node.expr, declaration);
|
|
409
|
+
return;
|
|
410
|
+
case "IndexedAccessTypeNode":
|
|
411
|
+
this.visitTypeNode(node.objectType, declaration);
|
|
412
|
+
this.visitTypeNode(node.indexType, declaration);
|
|
413
|
+
return;
|
|
414
|
+
case "ParenthesizedTypeNode":
|
|
415
|
+
this.visitTypeNode(node.typeNode, declaration);
|
|
416
|
+
return;
|
|
417
|
+
case "LiteralTypeNode":
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
private visitFunctionBody(
|
|
423
|
+
body: FunctionBody,
|
|
424
|
+
declaration: string | undefined,
|
|
425
|
+
): void {
|
|
426
|
+
if (body.kind === "BlockStatement") {
|
|
427
|
+
this.visitBlockStatement(body, declaration);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
this.visitExpression(body, declaration);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private visitBlockStatement(
|
|
434
|
+
block: BlockStatement,
|
|
435
|
+
declaration: string | undefined,
|
|
436
|
+
): void {
|
|
437
|
+
for (const stmt of block.statements) {
|
|
438
|
+
this.visitStatement(stmt, declaration);
|
|
439
|
+
}
|
|
440
|
+
if (block.finalExpression) {
|
|
441
|
+
this.visitExpression(block.finalExpression, declaration);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
private visitStatement(
|
|
446
|
+
stmt: Statement,
|
|
447
|
+
declaration: string | undefined,
|
|
448
|
+
): void {
|
|
449
|
+
switch (stmt.kind) {
|
|
450
|
+
case "BindingDeclaration":
|
|
451
|
+
this.visitBindingDeclaration(stmt, declaration);
|
|
452
|
+
return;
|
|
453
|
+
case "AssignmentStatement":
|
|
454
|
+
if (stmt.target.kind === "IndexExpression") {
|
|
455
|
+
this.visitExpression(stmt.target, declaration);
|
|
456
|
+
}
|
|
457
|
+
this.visitExpression(stmt.value, declaration);
|
|
458
|
+
return;
|
|
459
|
+
case "ExpressionStatement":
|
|
460
|
+
this.visitExpression(stmt.expression, declaration);
|
|
461
|
+
return;
|
|
462
|
+
case "ReturnStatement":
|
|
463
|
+
this.visitExpression(stmt.argument, declaration);
|
|
464
|
+
return;
|
|
465
|
+
case "WhenStatement":
|
|
466
|
+
this.visitExpression(stmt.condition, declaration);
|
|
467
|
+
this.visitFunctionBody(stmt.consequent, declaration);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private visitEffectStatement(
|
|
473
|
+
stmt: EffectStatement,
|
|
474
|
+
declaration: string | undefined,
|
|
475
|
+
): void {
|
|
476
|
+
switch (stmt.kind) {
|
|
477
|
+
case "EffectBindStatement":
|
|
478
|
+
this.visitExpression(stmt.effect, declaration);
|
|
479
|
+
return;
|
|
480
|
+
case "EffectDiscardStatement":
|
|
481
|
+
this.visitExpression(stmt.effect, declaration);
|
|
482
|
+
return;
|
|
483
|
+
case "EffectControlFlowStatement":
|
|
484
|
+
this.visitExpression(stmt.statement, declaration);
|
|
485
|
+
return;
|
|
486
|
+
case "BindingDeclaration":
|
|
487
|
+
case "AssignmentStatement":
|
|
488
|
+
case "WhenStatement":
|
|
489
|
+
this.visitStatement(stmt, declaration);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private visitMatchArm(arm: MatchArm, declaration: string | undefined): void {
|
|
495
|
+
if (isWildcardArmPattern(arm.pattern)) {
|
|
496
|
+
this.addFinding(
|
|
497
|
+
"wildcard-match",
|
|
498
|
+
arm.span,
|
|
499
|
+
declaration,
|
|
500
|
+
extractSpanSnippet(
|
|
501
|
+
this.source,
|
|
502
|
+
this.sourceLines,
|
|
503
|
+
arm.span,
|
|
504
|
+
"| _ => ...",
|
|
505
|
+
),
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
this.visitPattern(arm.pattern, declaration);
|
|
509
|
+
if (arm.guard) {
|
|
510
|
+
this.visitExpression(arm.guard, declaration);
|
|
511
|
+
}
|
|
512
|
+
this.visitFunctionBody(arm.body, declaration);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private visitPattern(
|
|
516
|
+
pattern: Pattern,
|
|
517
|
+
declaration: string | undefined,
|
|
518
|
+
): void {
|
|
519
|
+
switch (pattern.kind) {
|
|
520
|
+
case "WildcardPattern":
|
|
521
|
+
case "VariablePattern":
|
|
522
|
+
return;
|
|
523
|
+
case "LiteralPattern": {
|
|
524
|
+
const rawExpr = (pattern.literal as { rawExpr?: Expression }).rawExpr;
|
|
525
|
+
if (rawExpr) {
|
|
526
|
+
this.visitExpression(rawExpr, declaration);
|
|
527
|
+
} else if (pattern.literal.kind === "StringLiteral") {
|
|
528
|
+
for (const part of pattern.literal.parts) {
|
|
529
|
+
if (part.kind === "StringInterpolationPart") {
|
|
530
|
+
this.visitExpression(part.expression, declaration);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
case "ConstructorPattern":
|
|
537
|
+
for (const arg of pattern.args) {
|
|
538
|
+
this.visitPattern(arg, declaration);
|
|
539
|
+
}
|
|
540
|
+
return;
|
|
541
|
+
case "RecordPattern":
|
|
542
|
+
for (const field of pattern.fields) {
|
|
543
|
+
if (field.pattern) {
|
|
544
|
+
this.visitPattern(field.pattern, declaration);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return;
|
|
548
|
+
case "ArrayPattern":
|
|
549
|
+
for (const elem of pattern.elements) {
|
|
550
|
+
this.visitPattern(elem, declaration);
|
|
551
|
+
}
|
|
552
|
+
return;
|
|
553
|
+
case "RestPattern":
|
|
554
|
+
this.visitPattern(pattern.argument, declaration);
|
|
555
|
+
return;
|
|
556
|
+
case "OrPattern":
|
|
557
|
+
for (const part of pattern.patterns) {
|
|
558
|
+
this.visitPattern(part, declaration);
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private visitJsxChild(
|
|
565
|
+
child: JSXChild,
|
|
566
|
+
declaration: string | undefined,
|
|
567
|
+
): void {
|
|
568
|
+
switch (child.kind) {
|
|
569
|
+
case "JSXText":
|
|
570
|
+
return;
|
|
571
|
+
case "JSXExpressionContainer":
|
|
572
|
+
this.visitExpression(child.expression, declaration);
|
|
573
|
+
return;
|
|
574
|
+
case "JSXElement":
|
|
575
|
+
case "JSXSelfClosingElement":
|
|
576
|
+
this.visitExpression(child, declaration);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
private visitExpression(
|
|
582
|
+
expr: Expression,
|
|
583
|
+
declaration: string | undefined,
|
|
584
|
+
): void {
|
|
585
|
+
switch (expr.kind) {
|
|
586
|
+
case "NumberLiteral":
|
|
587
|
+
case "Identifier":
|
|
588
|
+
case "UpperIdentifier":
|
|
589
|
+
case "Placeholder":
|
|
590
|
+
return;
|
|
591
|
+
case "BooleanLiteral":
|
|
592
|
+
if (expr.rawExpr) {
|
|
593
|
+
this.visitExpression(expr.rawExpr, declaration);
|
|
594
|
+
}
|
|
595
|
+
return;
|
|
596
|
+
case "StringLiteral":
|
|
597
|
+
case "TemplateLiteral":
|
|
598
|
+
for (const part of expr.parts) {
|
|
599
|
+
if (part.kind === "StringInterpolationPart") {
|
|
600
|
+
this.visitExpression(part.expression, declaration);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return;
|
|
604
|
+
case "TaggedTemplateExpression":
|
|
605
|
+
this.visitExpression(expr.tag, declaration);
|
|
606
|
+
if (expr.typeArguments) {
|
|
607
|
+
for (const typeArg of expr.typeArguments) {
|
|
608
|
+
this.visitTypeNode(typeArg, declaration);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
this.visitExpression(expr.template, declaration);
|
|
612
|
+
return;
|
|
613
|
+
case "SpreadElement":
|
|
614
|
+
this.visitExpression(expr.argument, declaration);
|
|
615
|
+
return;
|
|
616
|
+
case "TypedHole":
|
|
617
|
+
this.addFinding(
|
|
618
|
+
"typed-hole",
|
|
619
|
+
expr.span,
|
|
620
|
+
declaration,
|
|
621
|
+
extractSpanSnippet(
|
|
622
|
+
this.source,
|
|
623
|
+
this.sourceLines,
|
|
624
|
+
expr.span,
|
|
625
|
+
expr.label ? `??? "${expr.label}"` : "???",
|
|
626
|
+
),
|
|
627
|
+
);
|
|
628
|
+
return;
|
|
629
|
+
case "TsEscapeExpression":
|
|
630
|
+
this.addFinding(
|
|
631
|
+
"raw-ts",
|
|
632
|
+
expr.span,
|
|
633
|
+
declaration,
|
|
634
|
+
extractSpanSnippet(
|
|
635
|
+
this.source,
|
|
636
|
+
this.sourceLines,
|
|
637
|
+
expr.span,
|
|
638
|
+
`ts { ${expr.code.trim()} }`,
|
|
639
|
+
),
|
|
640
|
+
);
|
|
641
|
+
return;
|
|
642
|
+
case "JsExpression":
|
|
643
|
+
this.addFinding(
|
|
644
|
+
"js-interop",
|
|
645
|
+
expr.span,
|
|
646
|
+
declaration,
|
|
647
|
+
extractSpanSnippet(
|
|
648
|
+
this.source,
|
|
649
|
+
this.sourceLines,
|
|
650
|
+
expr.span,
|
|
651
|
+
"js ...",
|
|
652
|
+
),
|
|
653
|
+
);
|
|
654
|
+
this.visitExpression(expr.expression, declaration);
|
|
655
|
+
return;
|
|
656
|
+
case "PipelineExpression":
|
|
657
|
+
this.visitExpression(expr.left, declaration);
|
|
658
|
+
if (expr.right.kind === "Identifier" && expr.right.name === "js") {
|
|
659
|
+
const snippet =
|
|
660
|
+
expr.span.start.line === expr.right.span.start.line
|
|
661
|
+
? extractSpanSnippet(
|
|
662
|
+
this.source,
|
|
663
|
+
this.sourceLines,
|
|
664
|
+
expr.span,
|
|
665
|
+
"|> js",
|
|
666
|
+
)
|
|
667
|
+
: extractLineSnippet(this.sourceLines, expr.right.span) ||
|
|
668
|
+
"|> js";
|
|
669
|
+
this.addFinding("js-interop", expr.right.span, declaration, snippet);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
this.visitExpression(expr.right, declaration);
|
|
673
|
+
return;
|
|
674
|
+
case "BinaryExpression":
|
|
675
|
+
this.visitExpression(expr.left, declaration);
|
|
676
|
+
this.visitExpression(expr.right, declaration);
|
|
677
|
+
return;
|
|
678
|
+
case "UnaryExpression":
|
|
679
|
+
this.visitExpression(expr.argument, declaration);
|
|
680
|
+
return;
|
|
681
|
+
case "CallExpression":
|
|
682
|
+
this.visitExpression(expr.callee, declaration);
|
|
683
|
+
for (const arg of expr.args) {
|
|
684
|
+
this.visitExpression(arg, declaration);
|
|
685
|
+
}
|
|
686
|
+
return;
|
|
687
|
+
case "MemberExpression":
|
|
688
|
+
this.visitExpression(expr.object, declaration);
|
|
689
|
+
return;
|
|
690
|
+
case "IndexExpression":
|
|
691
|
+
this.visitExpression(expr.object, declaration);
|
|
692
|
+
this.visitExpression(expr.index, declaration);
|
|
693
|
+
return;
|
|
694
|
+
case "RecordExpression":
|
|
695
|
+
for (const entry of expr.entries) {
|
|
696
|
+
if (entry.kind === "SpreadEntry") {
|
|
697
|
+
this.visitExpression(entry.argument, declaration);
|
|
698
|
+
} else if (
|
|
699
|
+
entry.kind === "FieldEntry" ||
|
|
700
|
+
entry.kind === "DotPathEntry"
|
|
701
|
+
) {
|
|
702
|
+
this.visitExpression(entry.value, declaration);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return;
|
|
706
|
+
case "ArrayExpression":
|
|
707
|
+
for (const elem of expr.elements) {
|
|
708
|
+
this.visitExpression(elem, declaration);
|
|
709
|
+
}
|
|
710
|
+
return;
|
|
711
|
+
case "FunctionExpression":
|
|
712
|
+
if (expr.typeParams) {
|
|
713
|
+
for (const tp of expr.typeParams) {
|
|
714
|
+
if (tp.constraint) {
|
|
715
|
+
this.visitTypeNode(tp.constraint, declaration);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
for (const param of expr.params) {
|
|
720
|
+
if (param.typeAnnotation) {
|
|
721
|
+
this.visitTypeNode(param.typeAnnotation, declaration);
|
|
722
|
+
}
|
|
723
|
+
if (param.defaultValue) {
|
|
724
|
+
this.visitExpression(param.defaultValue, declaration);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (expr.returnType) {
|
|
728
|
+
this.visitTypeNode(expr.returnType, declaration);
|
|
729
|
+
}
|
|
730
|
+
this.visitFunctionBody(expr.body, declaration);
|
|
731
|
+
return;
|
|
732
|
+
case "MutBlockExpression":
|
|
733
|
+
this.visitFunctionBody(expr.body, declaration);
|
|
734
|
+
return;
|
|
735
|
+
case "MatchExpression":
|
|
736
|
+
if (expr.scrutinee) {
|
|
737
|
+
this.visitExpression(expr.scrutinee, declaration);
|
|
738
|
+
}
|
|
739
|
+
for (const arm of expr.arms) {
|
|
740
|
+
this.visitMatchArm(arm, declaration);
|
|
741
|
+
}
|
|
742
|
+
return;
|
|
743
|
+
case "EffectBlockExpression":
|
|
744
|
+
for (const stmt of expr.body) {
|
|
745
|
+
this.visitEffectStatement(stmt, declaration);
|
|
746
|
+
}
|
|
747
|
+
this.visitExpression(expr.finalExpression, declaration);
|
|
748
|
+
return;
|
|
749
|
+
case "ParBlockExpression":
|
|
750
|
+
if (expr.concurrency) {
|
|
751
|
+
this.visitExpression(expr.concurrency, declaration);
|
|
752
|
+
}
|
|
753
|
+
for (const stmt of expr.body) {
|
|
754
|
+
this.visitEffectStatement(stmt, declaration);
|
|
755
|
+
}
|
|
756
|
+
this.visitExpression(expr.finalExpression, declaration);
|
|
757
|
+
return;
|
|
758
|
+
case "JSXSelfClosingElement":
|
|
759
|
+
if (expr.name.kind === "MemberExpression") {
|
|
760
|
+
this.visitExpression(expr.name, declaration);
|
|
761
|
+
}
|
|
762
|
+
this.visitJsxAttributes(expr.attributes, declaration);
|
|
763
|
+
return;
|
|
764
|
+
case "JSXElement":
|
|
765
|
+
if (expr.openingElement.name.kind === "MemberExpression") {
|
|
766
|
+
this.visitExpression(expr.openingElement.name, declaration);
|
|
767
|
+
}
|
|
768
|
+
this.visitJsxAttributes(expr.openingElement.attributes, declaration);
|
|
769
|
+
for (const child of expr.children) {
|
|
770
|
+
this.visitJsxChild(child, declaration);
|
|
771
|
+
}
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
private visitJsxAttributes(
|
|
777
|
+
attributes: JSXAttribute[],
|
|
778
|
+
declaration: string | undefined,
|
|
779
|
+
): void {
|
|
780
|
+
for (const attr of attributes) {
|
|
781
|
+
if (attr.kind === "JSXSpreadAttribute") {
|
|
782
|
+
this.visitExpression(attr.argument, declaration);
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
if (attr.value) {
|
|
786
|
+
if (attr.value.kind === "JSXExpressionContainer") {
|
|
787
|
+
this.visitExpression(attr.value.expression, declaration);
|
|
788
|
+
} else {
|
|
789
|
+
this.visitExpression(attr.value, declaration);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Audits a single FunkScript source string for AST-level escape hatches.
|
|
798
|
+
*/
|
|
799
|
+
export function auditEscapeHatches(
|
|
800
|
+
source: string,
|
|
801
|
+
filename: string = "<anonymous>",
|
|
802
|
+
): EscapeAuditFileReport {
|
|
803
|
+
const lexer = new Lexer(source, filename);
|
|
804
|
+
const tokens = lexer.tokenize();
|
|
805
|
+
const parser = new Parser(tokens, filename, source);
|
|
806
|
+
const ast = parser.parse();
|
|
807
|
+
|
|
808
|
+
const visitor = new EscapeAuditVisitor(source, filename);
|
|
809
|
+
visitor.visitProgram(ast);
|
|
810
|
+
|
|
811
|
+
const findings = visitor.findings.sort(
|
|
812
|
+
(a, b) => a.line - b.line || a.column - b.column,
|
|
813
|
+
);
|
|
814
|
+
const counts = emptyCounts();
|
|
815
|
+
for (const finding of findings) {
|
|
816
|
+
incrementCounts(counts, finding.kind);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
return {
|
|
820
|
+
file: filename,
|
|
821
|
+
counts,
|
|
822
|
+
findings,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Audits a map of virtual FunkScript files and aggregates counts into a report.
|
|
828
|
+
*/
|
|
829
|
+
export function auditEscapeHatchesVirtualFiles(
|
|
830
|
+
virtualInputFiles: Record<string, string>,
|
|
831
|
+
): EscapeAuditReport {
|
|
832
|
+
const counts = emptyCounts();
|
|
833
|
+
const files: EscapeAuditFileReport[] = [];
|
|
834
|
+
|
|
835
|
+
for (const [file, source] of Object.entries(virtualInputFiles)) {
|
|
836
|
+
const fileReport = auditEscapeHatches(source, file);
|
|
837
|
+
files.push(fileReport);
|
|
838
|
+
mergeCounts(counts, fileReport.counts);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
return {
|
|
842
|
+
schemaVersion: 1,
|
|
843
|
+
counts,
|
|
844
|
+
files,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Reads and audits FunkScript files on disk as an Effect.
|
|
850
|
+
*/
|
|
851
|
+
export function auditEscapeHatchesFiles(
|
|
852
|
+
files: string[],
|
|
853
|
+
): Effect.Effect<EscapeAuditReport, Error> {
|
|
854
|
+
return Effect.gen(function* () {
|
|
855
|
+
const virtualFiles: Record<string, string> = {};
|
|
856
|
+
|
|
857
|
+
for (const filePath of files) {
|
|
858
|
+
const fullPath = path.isAbsolute(filePath)
|
|
859
|
+
? filePath
|
|
860
|
+
: path.resolve(process.cwd(), filePath);
|
|
861
|
+
const content = yield* Effect.tryPromise({
|
|
862
|
+
try: () => fs.readFile(fullPath, "utf-8"),
|
|
863
|
+
catch: (err: unknown) =>
|
|
864
|
+
new Error(
|
|
865
|
+
`Failed to read file '${filePath}': ${err instanceof Error ? err.message : String(err)}`,
|
|
866
|
+
),
|
|
867
|
+
});
|
|
868
|
+
virtualFiles[filePath] = content;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
return yield* Effect.try({
|
|
872
|
+
try: () => auditEscapeHatchesVirtualFiles(virtualFiles),
|
|
873
|
+
catch: (err: unknown) =>
|
|
874
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Formats an escape-hatch audit report as human-readable text or JSON.
|
|
881
|
+
*/
|
|
882
|
+
export function formatEscapeAudit(
|
|
883
|
+
report: EscapeAuditReport,
|
|
884
|
+
options?: { json?: boolean },
|
|
885
|
+
): string {
|
|
886
|
+
if (options?.json) {
|
|
887
|
+
return JSON.stringify(report, null, 2);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
const lines: string[] = [];
|
|
891
|
+
const allFindings = report.files.flatMap((f) => f.findings);
|
|
892
|
+
|
|
893
|
+
if (allFindings.length === 0) {
|
|
894
|
+
lines.push(
|
|
895
|
+
`No escape hatches found across ${report.files.length} file(s).`,
|
|
896
|
+
);
|
|
897
|
+
} else {
|
|
898
|
+
for (const finding of allFindings) {
|
|
899
|
+
const declPart = finding.declaration ? ` (${finding.declaration})` : "";
|
|
900
|
+
lines.push(
|
|
901
|
+
`${finding.file}:${finding.line}:${finding.column} [${finding.kind}]${declPart}: ${finding.snippet}`,
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
lines.push("");
|
|
905
|
+
lines.push(
|
|
906
|
+
`Summary: ${report.counts.total} escape hatch(es) across ${report.files.length} file(s) ` +
|
|
907
|
+
`(raw-ts: ${report.counts.rawTs}, js-interop: ${report.counts.jsInterop}, ` +
|
|
908
|
+
`wildcard-match: ${report.counts.wildcardMatch}, typed-hole: ${report.counts.typedHole})`,
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
return lines.join("\n");
|
|
913
|
+
}
|