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,223 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import {
|
|
3
|
+
asRecord,
|
|
4
|
+
astChild,
|
|
5
|
+
astChildren,
|
|
6
|
+
astName,
|
|
7
|
+
collectPatternVars,
|
|
8
|
+
isAstNode,
|
|
9
|
+
type AstInspectNode,
|
|
10
|
+
} from "../ast-inspection.js";
|
|
11
|
+
|
|
12
|
+
/** Find resources flowing into a block's result, including through aliases and closures. */
|
|
13
|
+
export function findResourceEscape(
|
|
14
|
+
effectBlock: AstInspectNode,
|
|
15
|
+
finalExpr: AstInspectNode,
|
|
16
|
+
followsAcquire: (expr: AstInspectNode, seen: Set<string>) => boolean,
|
|
17
|
+
isIndependentProperty: (expr: AstInspectNode) => boolean,
|
|
18
|
+
): AstInspectNode | undefined {
|
|
19
|
+
const resolveReturned = (
|
|
20
|
+
name: string | undefined,
|
|
21
|
+
seen: Set<string>,
|
|
22
|
+
): AstInspectNode | undefined => {
|
|
23
|
+
if (!name || seen.has(name)) return undefined;
|
|
24
|
+
const stmts = astChildren(effectBlock, "body");
|
|
25
|
+
const bind = stmts.find(
|
|
26
|
+
(stmt) =>
|
|
27
|
+
stmt.kind === "EffectBindStatement" &&
|
|
28
|
+
astName(astChild(stmt, "id")) === name,
|
|
29
|
+
);
|
|
30
|
+
if (bind) return bind;
|
|
31
|
+
const alias = stmts.find(
|
|
32
|
+
(stmt) =>
|
|
33
|
+
stmt.kind === "BindingDeclaration" &&
|
|
34
|
+
astName(astChild(stmt, "id")) === name,
|
|
35
|
+
);
|
|
36
|
+
const init = astChild(alias, "init");
|
|
37
|
+
return init?.kind === "Identifier"
|
|
38
|
+
? resolveReturned(astName(init), new Set([...seen, name]))
|
|
39
|
+
: undefined;
|
|
40
|
+
};
|
|
41
|
+
const findEscapedResource = (
|
|
42
|
+
expr: AstInspectNode | null,
|
|
43
|
+
hidden: Set<string>,
|
|
44
|
+
seen: Set<string>,
|
|
45
|
+
inClosure: boolean,
|
|
46
|
+
matched: ReadonlyMap<string, AstInspectNode> = new Map(),
|
|
47
|
+
): AstInspectNode | undefined => {
|
|
48
|
+
if (!expr) return undefined;
|
|
49
|
+
if (
|
|
50
|
+
expr.kind === "StringLiteral" ||
|
|
51
|
+
expr.kind === "TemplateLiteral" ||
|
|
52
|
+
expr.kind === "NumberLiteral" ||
|
|
53
|
+
expr.kind === "BooleanLiteral"
|
|
54
|
+
)
|
|
55
|
+
return undefined;
|
|
56
|
+
if (expr.kind === "Identifier") {
|
|
57
|
+
const name = astName(expr);
|
|
58
|
+
if (!name || seen.has(name)) return undefined;
|
|
59
|
+
if (matched.has(name)) return matched.get(name);
|
|
60
|
+
if (hidden.has(name)) return undefined;
|
|
61
|
+
const bind = resolveReturned(name, new Set());
|
|
62
|
+
const source = astChild(bind, "effect");
|
|
63
|
+
if (source && followsAcquire(source, new Set())) return source;
|
|
64
|
+
const local = astChildren(effectBlock, "body").find(
|
|
65
|
+
(stmt) =>
|
|
66
|
+
stmt.kind === "BindingDeclaration" &&
|
|
67
|
+
astName(astChild(stmt, "id")) === name,
|
|
68
|
+
);
|
|
69
|
+
return findEscapedResource(
|
|
70
|
+
astChild(local, "init"),
|
|
71
|
+
hidden,
|
|
72
|
+
new Set([...seen, name]),
|
|
73
|
+
inClosure,
|
|
74
|
+
matched,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (expr.kind === "MemberExpression" || expr.kind === "IndexExpression") {
|
|
78
|
+
return inClosure || !isIndependentProperty(expr)
|
|
79
|
+
? findEscapedResource(
|
|
80
|
+
astChild(expr, "object"),
|
|
81
|
+
hidden,
|
|
82
|
+
seen,
|
|
83
|
+
true,
|
|
84
|
+
matched,
|
|
85
|
+
)
|
|
86
|
+
: undefined;
|
|
87
|
+
}
|
|
88
|
+
if (expr.kind === "MatchExpression") {
|
|
89
|
+
const subject = findEscapedResource(
|
|
90
|
+
astChild(expr, "scrutinee"),
|
|
91
|
+
hidden,
|
|
92
|
+
seen,
|
|
93
|
+
false,
|
|
94
|
+
matched,
|
|
95
|
+
);
|
|
96
|
+
for (const arm of astChildren(expr, "arms")) {
|
|
97
|
+
const nestedHidden = new Set(hidden);
|
|
98
|
+
const nestedMatched = new Map(matched);
|
|
99
|
+
for (const name of collectPatternVars(astChild(arm, "pattern"))) {
|
|
100
|
+
nestedHidden.add(name);
|
|
101
|
+
if (subject) nestedMatched.set(name, subject);
|
|
102
|
+
else nestedMatched.delete(name);
|
|
103
|
+
}
|
|
104
|
+
const found = findEscapedResource(
|
|
105
|
+
astChild(arm, "body"),
|
|
106
|
+
nestedHidden,
|
|
107
|
+
seen,
|
|
108
|
+
inClosure,
|
|
109
|
+
nestedMatched,
|
|
110
|
+
);
|
|
111
|
+
if (found) return found;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (expr.kind === "FunctionExpression") {
|
|
116
|
+
const nestedHidden = new Set(hidden);
|
|
117
|
+
const nestedMatched = new Map(matched);
|
|
118
|
+
for (const param of astChildren(expr, "params")) {
|
|
119
|
+
for (const name of collectPatternVars(astChild(param, "name"))) {
|
|
120
|
+
nestedHidden.add(name);
|
|
121
|
+
nestedMatched.delete(name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const body = astChild(expr, "body");
|
|
125
|
+
if (body?.kind === "BlockStatement") {
|
|
126
|
+
for (const stmt of astChildren(body, "statements")) {
|
|
127
|
+
if (stmt.kind === "BindingDeclaration") {
|
|
128
|
+
for (const name of collectPatternVars(astChild(stmt, "id"))) {
|
|
129
|
+
nestedHidden.add(name);
|
|
130
|
+
nestedMatched.delete(name);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return findEscapedResource(body, nestedHidden, seen, true, nestedMatched);
|
|
136
|
+
}
|
|
137
|
+
if (expr.kind === "FieldEntry" || expr.kind === "DotPathEntry")
|
|
138
|
+
return findEscapedResource(
|
|
139
|
+
astChild(expr, "value"),
|
|
140
|
+
hidden,
|
|
141
|
+
seen,
|
|
142
|
+
inClosure,
|
|
143
|
+
matched,
|
|
144
|
+
);
|
|
145
|
+
if (expr.kind === "ShorthandEntry")
|
|
146
|
+
return findEscapedResource(
|
|
147
|
+
astChild(expr, "key"),
|
|
148
|
+
hidden,
|
|
149
|
+
seen,
|
|
150
|
+
inClosure,
|
|
151
|
+
matched,
|
|
152
|
+
);
|
|
153
|
+
for (const [key, value] of Object.entries(asRecord(expr))) {
|
|
154
|
+
if (key === "span" || key === "typeAnnotation") continue;
|
|
155
|
+
const children = Array.isArray(value) ? value : [value];
|
|
156
|
+
for (const child of children) {
|
|
157
|
+
if (!isAstNode(child)) continue;
|
|
158
|
+
const found = findEscapedResource(
|
|
159
|
+
child,
|
|
160
|
+
hidden,
|
|
161
|
+
seen,
|
|
162
|
+
inClosure,
|
|
163
|
+
matched,
|
|
164
|
+
);
|
|
165
|
+
if (found) return found;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
};
|
|
170
|
+
return findEscapedResource(finalExpr, new Set(), new Set(), false);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Check a scoped result using TypeScript types to recognize independent values. */
|
|
174
|
+
export function findScopedResourceEscape(
|
|
175
|
+
effectBlock: AstInspectNode,
|
|
176
|
+
finalExpr: AstInspectNode,
|
|
177
|
+
sourceFile: ts.SourceFile,
|
|
178
|
+
checker: ts.TypeChecker,
|
|
179
|
+
followsAcquire: (expr: AstInspectNode, seen: Set<string>) => boolean,
|
|
180
|
+
): AstInspectNode | undefined {
|
|
181
|
+
const isIndependentProperty = (expr: AstInspectNode): boolean => {
|
|
182
|
+
if (expr.kind !== "MemberExpression") return false;
|
|
183
|
+
const object = astName(astChild(expr, "object"));
|
|
184
|
+
const property = astName(astChild(expr, "property"));
|
|
185
|
+
if (!object || !property) return false;
|
|
186
|
+
const isPrimitive = (type: ts.Type): boolean =>
|
|
187
|
+
type.isUnion()
|
|
188
|
+
? type.types.every(isPrimitive)
|
|
189
|
+
: !!(
|
|
190
|
+
type.flags &
|
|
191
|
+
(ts.TypeFlags.StringLike |
|
|
192
|
+
ts.TypeFlags.NumberLike |
|
|
193
|
+
ts.TypeFlags.BooleanLike |
|
|
194
|
+
ts.TypeFlags.BigIntLike |
|
|
195
|
+
ts.TypeFlags.ESSymbolLike |
|
|
196
|
+
ts.TypeFlags.Null |
|
|
197
|
+
ts.TypeFlags.Undefined)
|
|
198
|
+
);
|
|
199
|
+
let found = false;
|
|
200
|
+
let independent = true;
|
|
201
|
+
const visit = (candidate: ts.Node): void => {
|
|
202
|
+
if (
|
|
203
|
+
ts.isPropertyAccessExpression(candidate) &&
|
|
204
|
+
ts.isIdentifier(candidate.expression) &&
|
|
205
|
+
candidate.expression.text === object &&
|
|
206
|
+
candidate.name.text === property
|
|
207
|
+
) {
|
|
208
|
+
found = true;
|
|
209
|
+
if (!isPrimitive(checker.getTypeAtLocation(candidate)))
|
|
210
|
+
independent = false;
|
|
211
|
+
}
|
|
212
|
+
ts.forEachChild(candidate, visit);
|
|
213
|
+
};
|
|
214
|
+
visit(sourceFile);
|
|
215
|
+
return found && independent;
|
|
216
|
+
};
|
|
217
|
+
return findResourceEscape(
|
|
218
|
+
effectBlock,
|
|
219
|
+
finalExpr,
|
|
220
|
+
followsAcquire,
|
|
221
|
+
isIndependentProperty,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import type { Program } from "../../ast/types.js";
|
|
3
|
+
import { FunScriptError, isFileNotFoundError } from "../../errors.js";
|
|
4
|
+
import { Lexer } from "../../lexer/lexer.js";
|
|
5
|
+
import { Parser } from "../../parser/parser.js";
|
|
6
|
+
import {
|
|
7
|
+
astBool,
|
|
8
|
+
astChild,
|
|
9
|
+
astChildren,
|
|
10
|
+
astName,
|
|
11
|
+
collectPatternVars,
|
|
12
|
+
getMemberNames,
|
|
13
|
+
type AstInspectNode,
|
|
14
|
+
} from "../ast-inspection.js";
|
|
15
|
+
import { resolveFunModule } from "../modules/resolution.js";
|
|
16
|
+
import { findResourceEscape } from "./resource-escape.js";
|
|
17
|
+
|
|
18
|
+
const scopedEffectProviders = new Set([
|
|
19
|
+
"acquireRelease",
|
|
20
|
+
"makeSpanScoped",
|
|
21
|
+
"forkScoped",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function effectImportNames(program: Program | undefined) {
|
|
25
|
+
const effect = new Set(["Effect"]);
|
|
26
|
+
const scope = new Set(["Scope"]);
|
|
27
|
+
const acquire = new Set(["acquireRelease"]);
|
|
28
|
+
const finalizer = new Set(["addFinalizer"]);
|
|
29
|
+
for (const item of program?.body ?? []) {
|
|
30
|
+
if (item.kind !== "ImportDeclaration" || item.isTypeOnly) continue;
|
|
31
|
+
const source = item.source.parts
|
|
32
|
+
.map((part) => (part.kind === "StringRawPart" ? part.value : ""))
|
|
33
|
+
.join("");
|
|
34
|
+
if (source === "effect") {
|
|
35
|
+
for (const spec of item.specifiers) {
|
|
36
|
+
if (spec.isTypeOnly) continue;
|
|
37
|
+
if (spec.imported.name === "Effect") effect.add(spec.local.name);
|
|
38
|
+
if (spec.imported.name === "Scope") scope.add(spec.local.name);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (source === "effect/Effect" || source === "effect/Scope") {
|
|
42
|
+
if (item.namespaceBinding)
|
|
43
|
+
(source === "effect/Effect" ? effect : scope).add(
|
|
44
|
+
item.namespaceBinding.name,
|
|
45
|
+
);
|
|
46
|
+
for (const spec of item.specifiers) {
|
|
47
|
+
if (spec.isTypeOnly) continue;
|
|
48
|
+
if (
|
|
49
|
+
source === "effect/Effect" &&
|
|
50
|
+
scopedEffectProviders.has(spec.imported.name)
|
|
51
|
+
)
|
|
52
|
+
acquire.add(spec.local.name);
|
|
53
|
+
if (spec.imported.name === "addFinalizer")
|
|
54
|
+
finalizer.add(spec.local.name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const item of program?.body ?? []) {
|
|
59
|
+
const declaration =
|
|
60
|
+
item.kind === "ExportDeclaration" ? item.declaration : item;
|
|
61
|
+
if (
|
|
62
|
+
declaration.kind !== "BindingDeclaration" ||
|
|
63
|
+
declaration.id.kind !== "Identifier"
|
|
64
|
+
)
|
|
65
|
+
continue;
|
|
66
|
+
effect.delete(declaration.id.name);
|
|
67
|
+
scope.delete(declaration.id.name);
|
|
68
|
+
acquire.delete(declaration.id.name);
|
|
69
|
+
finalizer.delete(declaration.id.name);
|
|
70
|
+
}
|
|
71
|
+
return { effect, scope, acquire, finalizer };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type Ref = { target: string; name: string };
|
|
75
|
+
type Module = {
|
|
76
|
+
file: string;
|
|
77
|
+
ast: Program;
|
|
78
|
+
bindings: Map<string, AstInspectNode>;
|
|
79
|
+
named: Map<string, Ref>;
|
|
80
|
+
namespaces: Map<string, string>;
|
|
81
|
+
imports: ReturnType<typeof effectImportNames>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Resolve resource acquisition through inspected FunkScript modules only. */
|
|
85
|
+
export function createResourceProviderResolver(options: {
|
|
86
|
+
rootFile: string;
|
|
87
|
+
rootAst: Program;
|
|
88
|
+
rootBindings: Map<string, AstInspectNode>;
|
|
89
|
+
rootImports: ReturnType<typeof effectImportNames>;
|
|
90
|
+
shadowed: ReadonlySet<string>;
|
|
91
|
+
sources: ReadonlyMap<string, string>;
|
|
92
|
+
programs: ReadonlyMap<string, Program>;
|
|
93
|
+
}): (expr: AstInspectNode, seen: Set<string>) => boolean {
|
|
94
|
+
const modules = new Map<string, Module>();
|
|
95
|
+
const resolveTarget = (file: string, specifier: string) =>
|
|
96
|
+
resolveFunModule(
|
|
97
|
+
file,
|
|
98
|
+
specifier,
|
|
99
|
+
(name) => options.sources.has(name) || fs.existsSync(name),
|
|
100
|
+
{ directories: true },
|
|
101
|
+
);
|
|
102
|
+
const moduleFor = (file: string, ast?: Program): Module | undefined => {
|
|
103
|
+
const cached = modules.get(file);
|
|
104
|
+
if (cached) return cached;
|
|
105
|
+
if (!ast) {
|
|
106
|
+
ast = options.programs.get(file);
|
|
107
|
+
if (!ast) {
|
|
108
|
+
try {
|
|
109
|
+
const source =
|
|
110
|
+
options.sources.get(file) ?? fs.readFileSync(file, "utf8");
|
|
111
|
+
ast = new Parser(
|
|
112
|
+
new Lexer(source, file).tokenize(),
|
|
113
|
+
file,
|
|
114
|
+
source,
|
|
115
|
+
).parse();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!(error instanceof FunScriptError) && !isFileNotFoundError(error))
|
|
118
|
+
throw error;
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const root = file === options.rootFile;
|
|
124
|
+
const context: Module = {
|
|
125
|
+
file,
|
|
126
|
+
ast,
|
|
127
|
+
bindings: root ? options.rootBindings : new Map<string, AstInspectNode>(),
|
|
128
|
+
imports: root ? options.rootImports : effectImportNames(ast),
|
|
129
|
+
named: new Map(),
|
|
130
|
+
namespaces: new Map(),
|
|
131
|
+
};
|
|
132
|
+
modules.set(file, context);
|
|
133
|
+
for (const entry of ast.body) {
|
|
134
|
+
const binding =
|
|
135
|
+
entry.kind === "ExportDeclaration" ? entry.declaration : entry;
|
|
136
|
+
if (
|
|
137
|
+
!root &&
|
|
138
|
+
binding.kind === "BindingDeclaration" &&
|
|
139
|
+
binding.id.kind === "Identifier"
|
|
140
|
+
)
|
|
141
|
+
context.bindings.set(binding.id.name, binding.init);
|
|
142
|
+
if (entry.kind !== "ImportDeclaration" || entry.isTypeOnly) continue;
|
|
143
|
+
const specifier = entry.source.parts
|
|
144
|
+
.map((part) => (part.kind === "StringRawPart" ? part.value : ""))
|
|
145
|
+
.join("");
|
|
146
|
+
const target = resolveTarget(file, specifier);
|
|
147
|
+
if (!target) continue;
|
|
148
|
+
if (
|
|
149
|
+
entry.namespaceBinding &&
|
|
150
|
+
!(root && options.shadowed.has(entry.namespaceBinding.name))
|
|
151
|
+
)
|
|
152
|
+
context.namespaces.set(entry.namespaceBinding.name, target);
|
|
153
|
+
for (const spec of entry.specifiers) {
|
|
154
|
+
if (
|
|
155
|
+
!spec.isTypeOnly &&
|
|
156
|
+
!(root && options.shadowed.has(spec.local.name))
|
|
157
|
+
)
|
|
158
|
+
context.named.set(spec.local.name, {
|
|
159
|
+
target,
|
|
160
|
+
name: spec.imported.name,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return context;
|
|
165
|
+
};
|
|
166
|
+
const root = moduleFor(options.rootFile, options.rootAst)!;
|
|
167
|
+
const exported = (
|
|
168
|
+
file: string,
|
|
169
|
+
name: string,
|
|
170
|
+
seen: Set<string>,
|
|
171
|
+
): { expression: AstInspectNode; context: Module } | undefined => {
|
|
172
|
+
const key = `export:${file}:${name}`;
|
|
173
|
+
if (seen.has(key)) return undefined;
|
|
174
|
+
const nextSeen = new Set([...seen, key]);
|
|
175
|
+
const context = moduleFor(file);
|
|
176
|
+
if (!context) return undefined;
|
|
177
|
+
for (const entry of context.ast.body) {
|
|
178
|
+
if (
|
|
179
|
+
entry.kind === "ExportDeclaration" &&
|
|
180
|
+
entry.declaration.kind === "BindingDeclaration" &&
|
|
181
|
+
entry.declaration.id.kind === "Identifier" &&
|
|
182
|
+
entry.declaration.id.name === name
|
|
183
|
+
)
|
|
184
|
+
return { expression: entry.declaration.init, context };
|
|
185
|
+
if (entry.kind === "ExportFromDeclaration" && !entry.isTypeOnly) {
|
|
186
|
+
const spec = entry.specifiers.find(
|
|
187
|
+
(item) => !item.isTypeOnly && item.local.name === name,
|
|
188
|
+
);
|
|
189
|
+
if (!spec) continue;
|
|
190
|
+
const source = entry.source.parts
|
|
191
|
+
.map((part) => (part.kind === "StringRawPart" ? part.value : ""))
|
|
192
|
+
.join("");
|
|
193
|
+
const target = resolveTarget(file, source);
|
|
194
|
+
if (target) return exported(target, spec.imported.name, nextSeen);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
};
|
|
199
|
+
// Function parameters shadow names only in their own module. Keep graph
|
|
200
|
+
// cycle markers when following an import, but not lexical shadowing names.
|
|
201
|
+
const acrossModule = (seen: Set<string>) =>
|
|
202
|
+
new Set(
|
|
203
|
+
[...seen].filter(
|
|
204
|
+
(key) =>
|
|
205
|
+
key.startsWith("binding:") ||
|
|
206
|
+
key.startsWith("namespace:") ||
|
|
207
|
+
key.startsWith("export:"),
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
const follows = (
|
|
211
|
+
expr: AstInspectNode | null,
|
|
212
|
+
seen: Set<string>,
|
|
213
|
+
context: Module,
|
|
214
|
+
): boolean => {
|
|
215
|
+
if (!expr) return false;
|
|
216
|
+
if (expr.kind === "Identifier") {
|
|
217
|
+
const name = astName(expr);
|
|
218
|
+
if (!name || seen.has(name)) return false;
|
|
219
|
+
const key = `binding:${context.file}:${name}`;
|
|
220
|
+
if (seen.has(key)) return false;
|
|
221
|
+
const nextSeen = new Set([...seen, key]);
|
|
222
|
+
const local = context.bindings.get(name);
|
|
223
|
+
if (local) return follows(local, nextSeen, context);
|
|
224
|
+
const imported = context.named.get(name);
|
|
225
|
+
const target =
|
|
226
|
+
imported && exported(imported.target, imported.name, nextSeen);
|
|
227
|
+
return target
|
|
228
|
+
? follows(target.expression, acrossModule(nextSeen), target.context)
|
|
229
|
+
: false;
|
|
230
|
+
}
|
|
231
|
+
if (expr.kind === "FunctionExpression") {
|
|
232
|
+
const nestedSeen = new Set(seen);
|
|
233
|
+
for (const param of astChildren(expr, "params"))
|
|
234
|
+
for (const name of collectPatternVars(astChild(param, "name")))
|
|
235
|
+
nestedSeen.add(name);
|
|
236
|
+
return follows(astChild(expr, "body"), nestedSeen, context);
|
|
237
|
+
}
|
|
238
|
+
if (expr.kind === "BlockStatement")
|
|
239
|
+
return follows(astChild(expr, "finalExpression"), seen, context);
|
|
240
|
+
if (expr.kind === "EffectBlockExpression" && astBool(expr, "unscoped")) {
|
|
241
|
+
const result = astChild(expr, "finalExpression");
|
|
242
|
+
return !!(
|
|
243
|
+
result &&
|
|
244
|
+
findResourceEscape(
|
|
245
|
+
expr,
|
|
246
|
+
result,
|
|
247
|
+
(source, localSeen) =>
|
|
248
|
+
follows(source, new Set([...seen, ...localSeen]), context),
|
|
249
|
+
() => true,
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (expr.kind === "CallExpression") {
|
|
254
|
+
const callee = astChild(expr, "callee");
|
|
255
|
+
const member = getMemberNames(callee);
|
|
256
|
+
const name = astName(callee);
|
|
257
|
+
if (
|
|
258
|
+
(member?.object &&
|
|
259
|
+
!seen.has(member.object) &&
|
|
260
|
+
context.imports.effect.has(member.object) &&
|
|
261
|
+
!!member.property &&
|
|
262
|
+
scopedEffectProviders.has(member.property)) ||
|
|
263
|
+
(callee?.kind === "Identifier" &&
|
|
264
|
+
name &&
|
|
265
|
+
!seen.has(name) &&
|
|
266
|
+
context.imports.acquire.has(name))
|
|
267
|
+
)
|
|
268
|
+
return true;
|
|
269
|
+
if (callee?.kind === "Identifier") return follows(callee, seen, context);
|
|
270
|
+
if (
|
|
271
|
+
member?.object &&
|
|
272
|
+
member.property &&
|
|
273
|
+
!seen.has(member.object) &&
|
|
274
|
+
!context.bindings.has(member.object)
|
|
275
|
+
) {
|
|
276
|
+
const key = `namespace:${context.file}:${member.object}.${member.property}`;
|
|
277
|
+
if (seen.has(key)) return false;
|
|
278
|
+
const nextSeen = new Set([...seen, key]);
|
|
279
|
+
const namespace = context.namespaces.get(member.object);
|
|
280
|
+
const target =
|
|
281
|
+
namespace && exported(namespace, member.property, nextSeen);
|
|
282
|
+
if (target)
|
|
283
|
+
return follows(
|
|
284
|
+
target.expression,
|
|
285
|
+
acrossModule(nextSeen),
|
|
286
|
+
target.context,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
291
|
+
};
|
|
292
|
+
return (expr, seen) => follows(expr, seen, root);
|
|
293
|
+
}
|
|
@@ -2,6 +2,7 @@ import MagicString, { Bundle, type SourceMap } from "magic-string";
|
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import type { Program } from "../ast/types.js";
|
|
4
4
|
import { Emitter, type EmitterOptions } from "../emitter/emitter.js";
|
|
5
|
+
import { funSourceToTypeScriptFile } from "./modules/source-files.js";
|
|
5
6
|
|
|
6
7
|
/** Map generated TypeScript back to declarations in the original source. */
|
|
7
8
|
export function generateSourceMap(
|
|
@@ -12,13 +13,8 @@ export function generateSourceMap(
|
|
|
12
13
|
emitterOptions: EmitterOptions,
|
|
13
14
|
outputFile?: string,
|
|
14
15
|
): SourceMap {
|
|
15
|
-
const outTarget =
|
|
16
|
-
|
|
17
|
-
: filename.endsWith(".funx")
|
|
18
|
-
? `${filename.slice(0, -5)}.tsx`
|
|
19
|
-
: filename.endsWith(".fun")
|
|
20
|
-
? `${filename.slice(0, -4)}.ts`
|
|
21
|
-
: `${filename}.ts`;
|
|
16
|
+
const outTarget =
|
|
17
|
+
outputFile || funSourceToTypeScriptFile(filename) || `${filename}.ts`;
|
|
22
18
|
|
|
23
19
|
const s = new MagicString(source);
|
|
24
20
|
const movedImports: Array<{
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Default location and manifest shared by the type-view writer and readers. */
|
|
2
|
+
export const DEFAULT_TYPE_VIEW_DIR = ".funscript/types";
|
|
3
|
+
export const TYPE_VIEW_MANIFEST = ".funscript-type-view.json";
|
|
4
|
+
|
|
5
|
+
/** Read source names from the current manifest or its legacy array format. */
|
|
6
|
+
export function typeViewManifestSources(manifest: unknown): unknown[] {
|
|
7
|
+
if (Array.isArray(manifest)) return manifest;
|
|
8
|
+
if (manifest && typeof manifest === "object") return Object.keys(manifest);
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { isFileNotFoundError } from "../errors.js";
|
|
5
|
+
import { funSourceToTypeScriptFile } from "./modules/source-files.js";
|
|
5
6
|
|
|
6
7
|
// Declaration files are immutable for the lifetime of a process in the common
|
|
7
8
|
// case. Share parsed ASTs between compilation contexts, while checking file
|
|
@@ -174,13 +175,11 @@ export class TypeScriptCompilationContext {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
setFilename(filename: string, reuseProgram = false): void {
|
|
177
|
-
const nextFile =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
? filename
|
|
181
|
-
: filename.
|
|
182
|
-
? filename
|
|
183
|
-
: filename + ".ts";
|
|
178
|
+
const nextFile =
|
|
179
|
+
funSourceToTypeScriptFile(filename) ??
|
|
180
|
+
(filename.endsWith(".ts") || filename.endsWith(".tsx")
|
|
181
|
+
? filename
|
|
182
|
+
: `${filename}.ts`);
|
|
184
183
|
if (this.virtualFile && this.virtualFile !== nextFile && !reuseProgram)
|
|
185
184
|
this.program = undefined;
|
|
186
185
|
// Directory tooling can opt into using the old Program as an incremental
|