funkscript 0.2.4 → 0.2.6
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 +5 -3
- 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.map +1 -1
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- 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 +4 -2
- 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 +0 -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/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.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 +5 -3
- 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 +95 -103
- package/dist/compiler/check.js.map +1 -1
- 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/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.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 +3 -0
- package/dist/compiler/modules/source-files.d.ts.map +1 -0
- package/dist/compiler/modules/source-files.js +5 -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.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.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/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.map +1 -1
- package/dist/compiler/type-view-paths.d.ts +4 -0
- package/dist/compiler/type-view-paths.d.ts.map +1 -0
- package/dist/compiler/type-view-paths.js +4 -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.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.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.map +1 -1
- package/dist/formatter/index.js +57 -3
- 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.map +1 -1
- 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.map +1 -1
- package/dist/lsp/completion.js.map +1 -1
- package/dist/lsp/definition.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/lsp/hover.js +16 -5
- package/dist/lsp/hover.js.map +1 -1
- package/dist/lsp/imports.d.ts.map +1 -1
- package/dist/lsp/imports.js +10 -1
- 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.map +1 -1
- 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/rename-worker.d.ts.map +1 -1
- package/dist/lsp/rename-worker.js.map +1 -1
- package/dist/lsp/server.d.ts +2 -1
- package/dist/lsp/server.d.ts.map +1 -1
- package/dist/lsp/server.js +20 -0
- 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.map +1 -1
- 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.map +1 -1
- package/dist/plugins/bun.js.map +1 -1
- package/dist/plugins/esbuild.d.ts.map +1 -1
- package/dist/plugins/esbuild.js.map +1 -1
- 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.map +1 -1
- 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 +6 -3
- package/src/cli/doctor.ts +8 -2
- package/src/cli/init.ts +66 -21
- package/src/cli/tsc.ts +8 -3
- package/src/compiler/boolean-operators.ts +11 -2
- package/src/compiler/check.ts +124 -132
- package/src/compiler/modules/resolution.ts +2 -1
- package/src/compiler/modules/source-files.ts +4 -0
- package/src/compiler/project-config.ts +30 -19
- package/src/compiler/rules/resource-escape.ts +223 -0
- package/src/compiler/rules/resource-providers.ts +293 -0
- package/src/compiler/type-view-paths.ts +3 -0
- 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 +70 -2
- package/src/lexer/lexer.ts +39 -20
- package/src/lsp/diagnostics-worker.ts +1 -4
- package/src/lsp/docs.ts +4 -3
- package/src/lsp/hover.ts +23 -4
- package/src/lsp/imports.ts +20 -1
- package/src/lsp/server.ts +30 -0
- package/src/lsp/signature-help.ts +226 -0
- package/src/lsp/validation.ts +3 -2
- package/src/parser/declarations.ts +27 -1
- package/src/plugins/type-view.ts +11 -3
- 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
package/dist/service.ts
DELETED
package/dist/service.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.ts","sources":["/tmp/opencode/test-sourcemap-1795428398636/service.fun"],"sourcesContent":["export val = 42\n"],"names":[],"mappings":"AAAA;"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Span } from "../ast/types.js";
|
|
2
|
-
export type MigrationDiagnosticKind = "ambiguous-effect-return" | "ambiguous-trailing-binding" | "ambiguous-empty-block" | "ambiguous-missing-return" | "parse-error" | "lexer-error";
|
|
3
|
-
export type MigrationDiagnosticSeverity = "error" | "warning" | "info";
|
|
4
|
-
export interface MigrationDiagnostic {
|
|
5
|
-
kind: MigrationDiagnosticKind;
|
|
6
|
-
severity: MigrationDiagnosticSeverity;
|
|
7
|
-
message: string;
|
|
8
|
-
span?: Span;
|
|
9
|
-
filename?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface MigrationChange {
|
|
12
|
-
kind: "explicit-return";
|
|
13
|
-
span: Span;
|
|
14
|
-
original: string;
|
|
15
|
-
replacement: string;
|
|
16
|
-
description: string;
|
|
17
|
-
offset: number;
|
|
18
|
-
}
|
|
19
|
-
export interface MigrateOptions {
|
|
20
|
-
filename?: string;
|
|
21
|
-
/** If true, returns proposed changes and diagnostics without modifying code. Default false */
|
|
22
|
-
dryRun?: boolean;
|
|
23
|
-
/** If false, does not apply any edits if any ambiguous constructs are detected. Default true */
|
|
24
|
-
allowPartial?: boolean;
|
|
25
|
-
/** If true, also migrates trailing match expressions to explicit '=> match'. Default false */
|
|
26
|
-
migrateTrailingMatch?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface MigrationResult {
|
|
29
|
-
/** The resulting source code (transformed if changes were applied, or original) */
|
|
30
|
-
code: string;
|
|
31
|
-
/** True if any transformations were applied to the code */
|
|
32
|
-
changed: boolean;
|
|
33
|
-
/** List of changes applied (or proposed if dryRun: true) */
|
|
34
|
-
changes: MigrationChange[];
|
|
35
|
-
/** List of ambiguous constructs or errors reported */
|
|
36
|
-
diagnostics: MigrationDiagnostic[];
|
|
37
|
-
/** True if migration succeeded with zero fatal errors */
|
|
38
|
-
success: boolean;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Parses source code, identifies legacy syntax patterns (e.g. block functions
|
|
42
|
-
* without explicit => returns), applies safe transformations, and reports
|
|
43
|
-
* ambiguous constructs without modifying them.
|
|
44
|
-
*/
|
|
45
|
-
export declare function migrateSource(source: string, options?: MigrateOptions): MigrationResult;
|
|
46
|
-
/**
|
|
47
|
-
* Migrates a file on disk.
|
|
48
|
-
*/
|
|
49
|
-
export declare function migrateFile(filePath: string, options?: MigrateOptions & {
|
|
50
|
-
write?: boolean;
|
|
51
|
-
}): Promise<MigrationResult>;
|
|
52
|
-
/**
|
|
53
|
-
* Migrates multiple files on disk.
|
|
54
|
-
*/
|
|
55
|
-
export declare function migrateFiles(filePaths: string[], options?: MigrateOptions & {
|
|
56
|
-
write?: boolean;
|
|
57
|
-
}): Promise<Map<string, MigrationResult>>;
|
|
58
|
-
/**
|
|
59
|
-
* Formats a human-readable migration summary report.
|
|
60
|
-
*/
|
|
61
|
-
export declare function formatMigrationReport(result: MigrationResult): string;
|
|
62
|
-
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/tooling/migrate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAWL,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,uBAAuB,GAC/B,yBAAyB,GACzB,4BAA4B,GAC5B,uBAAuB,GACvB,0BAA0B,GAC1B,aAAa,GACb,aAAa,CAAC;AAElB,MAAM,MAAM,2BAA2B,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,QAAQ,EAAE,2BAA2B,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gGAAgG;IAChG,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,8FAA8F;IAC9F,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,sDAAsD;IACtD,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB,GAC3B,eAAe,CA8KjB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACjD,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,GAAE,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACjD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAOvC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CA0BrE"}
|
package/dist/tooling/migrate.js
DELETED
|
@@ -1,608 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { Lexer } from "../lexer/lexer.js";
|
|
4
|
-
import { Parser } from "../parser/parser.js";
|
|
5
|
-
/**
|
|
6
|
-
* Parses source code, identifies legacy syntax patterns (e.g. block functions
|
|
7
|
-
* without explicit => returns), applies safe transformations, and reports
|
|
8
|
-
* ambiguous constructs without modifying them.
|
|
9
|
-
*/
|
|
10
|
-
export function migrateSource(source, options = {}) {
|
|
11
|
-
const filename = options.filename ?? "<anonymous>";
|
|
12
|
-
const allowPartial = options.allowPartial ?? true;
|
|
13
|
-
const dryRun = options.dryRun ?? false;
|
|
14
|
-
const diagnostics = [];
|
|
15
|
-
const changes = [];
|
|
16
|
-
// Step 1: Tokenize
|
|
17
|
-
const lexer = new Lexer(source, filename);
|
|
18
|
-
let tokens;
|
|
19
|
-
try {
|
|
20
|
-
tokens = lexer.tokenize();
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
return {
|
|
24
|
-
code: source,
|
|
25
|
-
changed: false,
|
|
26
|
-
changes: [],
|
|
27
|
-
diagnostics: [
|
|
28
|
-
{
|
|
29
|
-
kind: "lexer-error",
|
|
30
|
-
severity: "error",
|
|
31
|
-
message: err.message,
|
|
32
|
-
span: err.span,
|
|
33
|
-
filename,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
success: false,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
// Step 2: Parse allowing legacy return patterns
|
|
40
|
-
const parser = new Parser(tokens, filename, source, {
|
|
41
|
-
allowLegacyReturns: true,
|
|
42
|
-
throwOnError: false,
|
|
43
|
-
});
|
|
44
|
-
let ast;
|
|
45
|
-
try {
|
|
46
|
-
ast = parser.parse({ allowLegacyReturns: true, throwOnError: false });
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
return {
|
|
50
|
-
code: source,
|
|
51
|
-
changed: false,
|
|
52
|
-
changes: [],
|
|
53
|
-
diagnostics: [
|
|
54
|
-
{
|
|
55
|
-
kind: "parse-error",
|
|
56
|
-
severity: "error",
|
|
57
|
-
message: err.message,
|
|
58
|
-
span: err.span,
|
|
59
|
-
filename,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
success: false,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
// Check for fatal parser diagnostics (other than legacy returns)
|
|
66
|
-
const parseErrors = parser.getDiagnostics();
|
|
67
|
-
if (parseErrors.length > 0) {
|
|
68
|
-
for (const err of parseErrors) {
|
|
69
|
-
diagnostics.push({
|
|
70
|
-
kind: "parse-error",
|
|
71
|
-
severity: "error",
|
|
72
|
-
message: err.message,
|
|
73
|
-
span: err.span,
|
|
74
|
-
filename,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
code: source,
|
|
79
|
-
changed: false,
|
|
80
|
-
changes: [],
|
|
81
|
-
diagnostics,
|
|
82
|
-
success: false,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// Step 3: Traverse AST to identify candidates and ambiguous constructs
|
|
86
|
-
traverseAST(ast, source, options, changes, diagnostics, filename);
|
|
87
|
-
// If allowPartial is false and there are ambiguous constructs, do not modify
|
|
88
|
-
const hasAmbiguous = diagnostics.some((d) => d.kind.startsWith("ambiguous"));
|
|
89
|
-
if (!allowPartial && hasAmbiguous) {
|
|
90
|
-
return {
|
|
91
|
-
code: source,
|
|
92
|
-
changed: false,
|
|
93
|
-
changes: dryRun ? changes : [],
|
|
94
|
-
diagnostics,
|
|
95
|
-
success: false,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
// If dry-run mode, return proposed changes without modifying code
|
|
99
|
-
if (dryRun) {
|
|
100
|
-
return {
|
|
101
|
-
code: source,
|
|
102
|
-
changed: changes.length > 0,
|
|
103
|
-
changes,
|
|
104
|
-
diagnostics,
|
|
105
|
-
success: true,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
// Step 4: Apply safe text edits in reverse offset order
|
|
109
|
-
if (changes.length === 0) {
|
|
110
|
-
return {
|
|
111
|
-
code: source,
|
|
112
|
-
changed: false,
|
|
113
|
-
changes: [],
|
|
114
|
-
diagnostics,
|
|
115
|
-
success: true,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
// Deduplicate and sort changes descending by offset
|
|
119
|
-
const seenOffsets = new Set();
|
|
120
|
-
const uniqueChanges = changes.filter((c) => {
|
|
121
|
-
if (seenOffsets.has(c.offset))
|
|
122
|
-
return false;
|
|
123
|
-
seenOffsets.add(c.offset);
|
|
124
|
-
return true;
|
|
125
|
-
});
|
|
126
|
-
uniqueChanges.sort((a, b) => b.offset - a.offset);
|
|
127
|
-
let newCode = source;
|
|
128
|
-
for (const change of uniqueChanges) {
|
|
129
|
-
const before = newCode.slice(0, change.offset);
|
|
130
|
-
const after = newCode.slice(change.offset);
|
|
131
|
-
newCode = before + "=> " + after;
|
|
132
|
-
}
|
|
133
|
-
// Step 5: Verify transformed syntax. Ambiguous legacy blocks are deliberately
|
|
134
|
-
// left untouched, so validate those files in legacy mode while strict-parsing
|
|
135
|
-
// fully migrated files.
|
|
136
|
-
try {
|
|
137
|
-
const verifyLexer = new Lexer(newCode, filename);
|
|
138
|
-
const verifyTokens = verifyLexer.tokenize();
|
|
139
|
-
const hasAmbiguous = diagnostics.some((d) => d.kind.startsWith("ambiguous"));
|
|
140
|
-
const verifyParser = new Parser(verifyTokens, filename, newCode, {
|
|
141
|
-
allowLegacyReturns: hasAmbiguous,
|
|
142
|
-
throwOnError: true,
|
|
143
|
-
});
|
|
144
|
-
verifyParser.parse({
|
|
145
|
-
allowLegacyReturns: hasAmbiguous,
|
|
146
|
-
throwOnError: true,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
return {
|
|
151
|
-
code: source,
|
|
152
|
-
changed: false,
|
|
153
|
-
changes: [],
|
|
154
|
-
diagnostics: [
|
|
155
|
-
...diagnostics,
|
|
156
|
-
{
|
|
157
|
-
kind: "parse-error",
|
|
158
|
-
severity: "error",
|
|
159
|
-
message: `Migration verification failed: ${err.message}`,
|
|
160
|
-
span: err.span,
|
|
161
|
-
filename,
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
success: false,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
code: newCode,
|
|
169
|
-
changed: true,
|
|
170
|
-
changes: uniqueChanges,
|
|
171
|
-
diagnostics,
|
|
172
|
-
success: true,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Migrates a file on disk.
|
|
177
|
-
*/
|
|
178
|
-
export async function migrateFile(filePath, options = {}) {
|
|
179
|
-
const fullPath = path.resolve(filePath);
|
|
180
|
-
const source = await fs.readFile(fullPath, "utf-8");
|
|
181
|
-
const result = migrateSource(source, { ...options, filename: fullPath });
|
|
182
|
-
if (options.write && result.changed && result.success) {
|
|
183
|
-
await fs.writeFile(fullPath, result.code, "utf-8");
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Migrates multiple files on disk.
|
|
189
|
-
*/
|
|
190
|
-
export async function migrateFiles(filePaths, options = {}) {
|
|
191
|
-
const results = new Map();
|
|
192
|
-
for (const filePath of filePaths) {
|
|
193
|
-
const result = await migrateFile(filePath, options);
|
|
194
|
-
results.set(filePath, result);
|
|
195
|
-
}
|
|
196
|
-
return results;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Formats a human-readable migration summary report.
|
|
200
|
-
*/
|
|
201
|
-
export function formatMigrationReport(result) {
|
|
202
|
-
const lines = [];
|
|
203
|
-
if (result.changed) {
|
|
204
|
-
lines.push(`Applied ${result.changes.length} safe transformation(s):`);
|
|
205
|
-
for (const change of result.changes) {
|
|
206
|
-
lines.push(` - ${change.description}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
lines.push("No code transformations applied.");
|
|
211
|
-
}
|
|
212
|
-
if (result.diagnostics.length > 0) {
|
|
213
|
-
lines.push(`\nReported ${result.diagnostics.length} diagnostic(s) / ambiguous construct(s):`);
|
|
214
|
-
for (const diag of result.diagnostics) {
|
|
215
|
-
const loc = diag.span
|
|
216
|
-
? `[line ${diag.span.start.line}, col ${diag.span.start.column}]`
|
|
217
|
-
: "";
|
|
218
|
-
lines.push(` - [${diag.severity.toUpperCase()}] ${diag.kind} ${loc}: ${diag.message}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return lines.join("\n");
|
|
222
|
-
}
|
|
223
|
-
// --- AST Traversal & Analysis ---
|
|
224
|
-
function traverseAST(ast, source, options, changes, diagnostics, filename) {
|
|
225
|
-
for (const decl of ast.body) {
|
|
226
|
-
visitTopLevelDeclaration(decl, source, options, changes, diagnostics, filename);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function visitTopLevelDeclaration(decl, source, options, changes, diagnostics, filename) {
|
|
230
|
-
switch (decl.kind) {
|
|
231
|
-
case "ExportDeclaration":
|
|
232
|
-
if (decl.declaration) {
|
|
233
|
-
visitTopLevelDeclaration(decl.declaration, source, options, changes, diagnostics, filename);
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
case "ExportDefaultDeclaration":
|
|
237
|
-
if (decl.expression) {
|
|
238
|
-
visitExpression(decl.expression, source, options, changes, diagnostics, filename);
|
|
239
|
-
}
|
|
240
|
-
break;
|
|
241
|
-
case "BindingDeclaration":
|
|
242
|
-
if (decl.init) {
|
|
243
|
-
visitExpression(decl.init, source, options, changes, diagnostics, filename);
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
case "WhenStatement":
|
|
247
|
-
visitWhenStatement(decl, source, options, changes, diagnostics, filename);
|
|
248
|
-
break;
|
|
249
|
-
case "ServiceDeclaration":
|
|
250
|
-
// Service members declare signatures only
|
|
251
|
-
break;
|
|
252
|
-
case "SchemaDeclaration":
|
|
253
|
-
if (decl.body?.kind === "RecordSchema") {
|
|
254
|
-
for (const field of decl.body.fields) {
|
|
255
|
-
if (field.defaultValue) {
|
|
256
|
-
visitExpression(field.defaultValue, source, options, changes, diagnostics, filename);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
else if (decl.body?.kind === "RefinementSchema") {
|
|
261
|
-
if (decl.body.refinement) {
|
|
262
|
-
visitExpression(decl.body.refinement, source, options, changes, diagnostics, filename);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
break;
|
|
266
|
-
default:
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function visitExpression(expr, source, options, changes, diagnostics, filename) {
|
|
271
|
-
if (!expr)
|
|
272
|
-
return;
|
|
273
|
-
switch (expr.kind) {
|
|
274
|
-
case "FunctionExpression":
|
|
275
|
-
// Empty braces in a function body are parsed as an empty record by the
|
|
276
|
-
// language parser, while legacy function-block syntax used the same text.
|
|
277
|
-
// Keep this ambiguous form unchanged instead of treating it as a value.
|
|
278
|
-
if (expr.body.kind === "RecordExpression" &&
|
|
279
|
-
expr.body.entries.length === 0 &&
|
|
280
|
-
source
|
|
281
|
-
.slice(expr.body.span.start.offset, expr.body.span.end.offset)
|
|
282
|
-
.trim() === "{}") {
|
|
283
|
-
diagnostics.push({
|
|
284
|
-
kind: "ambiguous-empty-block",
|
|
285
|
-
severity: "warning",
|
|
286
|
-
message: "Empty braces in a function body are ambiguous; cannot infer whether this is an empty block or an empty record.",
|
|
287
|
-
span: expr.body.span,
|
|
288
|
-
filename,
|
|
289
|
-
});
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
handleFunctionExpression(expr, source, options, changes, diagnostics, filename);
|
|
293
|
-
break;
|
|
294
|
-
case "EffectBlockExpression":
|
|
295
|
-
handleEffectBlockExpression(expr, source, options, changes, diagnostics, filename);
|
|
296
|
-
break;
|
|
297
|
-
case "MutBlockExpression":
|
|
298
|
-
// mut (draft) => { ... } modifies draft and does not return explicit values
|
|
299
|
-
if (expr.body?.kind === "BlockStatement") {
|
|
300
|
-
for (const stmt of expr.body.statements) {
|
|
301
|
-
visitStatement(stmt, source, options, changes, diagnostics, filename);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
else if (expr.body) {
|
|
305
|
-
visitExpression(expr.body, source, options, changes, diagnostics, filename);
|
|
306
|
-
}
|
|
307
|
-
break;
|
|
308
|
-
case "MatchExpression":
|
|
309
|
-
if (expr.scrutinee) {
|
|
310
|
-
visitExpression(expr.scrutinee, source, options, changes, diagnostics, filename);
|
|
311
|
-
}
|
|
312
|
-
for (const arm of expr.arms) {
|
|
313
|
-
if (arm.guard) {
|
|
314
|
-
visitExpression(arm.guard, source, options, changes, diagnostics, filename);
|
|
315
|
-
}
|
|
316
|
-
if (arm.body?.kind === "BlockStatement") {
|
|
317
|
-
for (const stmt of arm.body.statements) {
|
|
318
|
-
visitStatement(stmt, source, options, changes, diagnostics, filename);
|
|
319
|
-
}
|
|
320
|
-
if (arm.body.finalExpression) {
|
|
321
|
-
visitExpression(arm.body.finalExpression, source, options, changes, diagnostics, filename);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
else if (arm.body) {
|
|
325
|
-
visitExpression(arm.body, source, options, changes, diagnostics, filename);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
break;
|
|
329
|
-
case "PipelineExpression":
|
|
330
|
-
visitExpression(expr.left, source, options, changes, diagnostics, filename);
|
|
331
|
-
visitExpression(expr.right, source, options, changes, diagnostics, filename);
|
|
332
|
-
break;
|
|
333
|
-
case "BinaryExpression":
|
|
334
|
-
visitExpression(expr.left, source, options, changes, diagnostics, filename);
|
|
335
|
-
visitExpression(expr.right, source, options, changes, diagnostics, filename);
|
|
336
|
-
break;
|
|
337
|
-
case "UnaryExpression":
|
|
338
|
-
visitExpression(expr.argument, source, options, changes, diagnostics, filename);
|
|
339
|
-
break;
|
|
340
|
-
case "CallExpression":
|
|
341
|
-
visitExpression(expr.callee, source, options, changes, diagnostics, filename);
|
|
342
|
-
for (const arg of expr.args) {
|
|
343
|
-
visitExpression(arg, source, options, changes, diagnostics, filename);
|
|
344
|
-
}
|
|
345
|
-
break;
|
|
346
|
-
case "MemberExpression":
|
|
347
|
-
visitExpression(expr.object, source, options, changes, diagnostics, filename);
|
|
348
|
-
break;
|
|
349
|
-
case "IndexExpression":
|
|
350
|
-
visitExpression(expr.object, source, options, changes, diagnostics, filename);
|
|
351
|
-
visitExpression(expr.index, source, options, changes, diagnostics, filename);
|
|
352
|
-
break;
|
|
353
|
-
case "ArrayExpression":
|
|
354
|
-
for (const elem of expr.elements) {
|
|
355
|
-
visitExpression(elem, source, options, changes, diagnostics, filename);
|
|
356
|
-
}
|
|
357
|
-
break;
|
|
358
|
-
case "SpreadElement":
|
|
359
|
-
visitExpression(expr.argument, source, options, changes, diagnostics, filename);
|
|
360
|
-
break;
|
|
361
|
-
case "RecordExpression":
|
|
362
|
-
for (const entry of expr.entries) {
|
|
363
|
-
if ("value" in entry && entry.value) {
|
|
364
|
-
visitExpression(entry.value, source, options, changes, diagnostics, filename);
|
|
365
|
-
}
|
|
366
|
-
else if (entry.kind === "SpreadEntry" && entry.argument) {
|
|
367
|
-
visitExpression(entry.argument, source, options, changes, diagnostics, filename);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
break;
|
|
371
|
-
case "JSXElement":
|
|
372
|
-
for (const child of expr.children) {
|
|
373
|
-
visitJSXChild(child, source, options, changes, diagnostics, filename);
|
|
374
|
-
}
|
|
375
|
-
for (const attr of expr.openingElement.attributes) {
|
|
376
|
-
if (attr.kind === "JSXSpreadAttribute") {
|
|
377
|
-
visitExpression(attr.argument, source, options, changes, diagnostics, filename);
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
if (attr.value && "expression" in attr.value && attr.value.expression) {
|
|
381
|
-
visitExpression(attr.value.expression, source, options, changes, diagnostics, filename);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
break;
|
|
385
|
-
case "JSXSelfClosingElement":
|
|
386
|
-
for (const attr of expr.attributes) {
|
|
387
|
-
if (attr.kind === "JSXSpreadAttribute") {
|
|
388
|
-
visitExpression(attr.argument, source, options, changes, diagnostics, filename);
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (attr.value && "expression" in attr.value && attr.value.expression) {
|
|
392
|
-
visitExpression(attr.value.expression, source, options, changes, diagnostics, filename);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
break;
|
|
396
|
-
case "StringLiteral":
|
|
397
|
-
for (const part of expr.parts) {
|
|
398
|
-
if (part.kind === "StringInterpolationPart" && part.expression) {
|
|
399
|
-
visitExpression(part.expression, source, options, changes, diagnostics, filename);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
break;
|
|
403
|
-
case "JsExpression":
|
|
404
|
-
if (expr.expression) {
|
|
405
|
-
visitExpression(expr.expression, source, options, changes, diagnostics, filename);
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
default:
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
function visitJSXChild(child, source, options, changes, diagnostics, filename) {
|
|
413
|
-
if (child.kind === "JSXExpressionContainer" && child.expression) {
|
|
414
|
-
visitExpression(child.expression, source, options, changes, diagnostics, filename);
|
|
415
|
-
}
|
|
416
|
-
else if (child.kind === "JSXElement") {
|
|
417
|
-
visitExpression(child, source, options, changes, diagnostics, filename);
|
|
418
|
-
}
|
|
419
|
-
else if (child.kind === "JSXSelfClosingElement") {
|
|
420
|
-
visitExpression(child, source, options, changes, diagnostics, filename);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function handleFunctionExpression(fn, source, options, changes, diagnostics, filename) {
|
|
424
|
-
if (fn.body.kind !== "BlockStatement") {
|
|
425
|
-
// Concise expression body (e.g. (a, b) => a + b) - already compliant
|
|
426
|
-
visitExpression(fn.body, source, options, changes, diagnostics, filename);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
const block = fn.body;
|
|
430
|
-
// The legacy parser represents an empty indented block with a synthetic
|
|
431
|
-
// `_error` final expression; it is not source text and cannot be migrated.
|
|
432
|
-
if (block.statements.length === 0 &&
|
|
433
|
-
block.finalExpression?.kind === "Identifier" &&
|
|
434
|
-
block.finalExpression.name === "_error") {
|
|
435
|
-
diagnostics.push({
|
|
436
|
-
kind: "ambiguous-empty-block",
|
|
437
|
-
severity: "warning",
|
|
438
|
-
message: "Function block is empty; cannot infer explicit return value.",
|
|
439
|
-
span: block.span,
|
|
440
|
-
filename,
|
|
441
|
-
});
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
// Visit inner statements and nested expressions
|
|
445
|
-
for (const stmt of block.statements) {
|
|
446
|
-
visitStatement(stmt, source, options, changes, diagnostics, filename);
|
|
447
|
-
}
|
|
448
|
-
if (block.finalExpression) {
|
|
449
|
-
visitExpression(block.finalExpression, source, options, changes, diagnostics, filename);
|
|
450
|
-
}
|
|
451
|
-
// Check function block termination
|
|
452
|
-
const lastStmt = block.statements.at(-1);
|
|
453
|
-
// 1. Compliant: Ends in an explicit ReturnStatement (=> returnValue)
|
|
454
|
-
if (lastStmt?.kind === "ReturnStatement") {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
// 2. Ambiguous: Trailing binding declaration
|
|
458
|
-
const isTrailingBinding = (lastStmt?.kind === "BindingDeclaration" && lastStmt.isTrailingBinding) ||
|
|
459
|
-
(!block.finalExpression && lastStmt?.kind === "BindingDeclaration") ||
|
|
460
|
-
(block.finalExpression &&
|
|
461
|
-
lastStmt?.kind === "BindingDeclaration" &&
|
|
462
|
-
lastStmt.id === block.finalExpression);
|
|
463
|
-
if (isTrailingBinding) {
|
|
464
|
-
const bind = lastStmt;
|
|
465
|
-
diagnostics.push({
|
|
466
|
-
kind: "ambiguous-trailing-binding",
|
|
467
|
-
severity: "warning",
|
|
468
|
-
message: `Function block ends with variable declaration '${"name" in bind.id ? bind.id.name : ""}'. Safe automated migration cannot assume this was intended as the return value.`,
|
|
469
|
-
span: bind.span,
|
|
470
|
-
filename,
|
|
471
|
-
});
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
// 3. Ambiguous: Empty block or statement-only block without return
|
|
475
|
-
if (!block.finalExpression) {
|
|
476
|
-
if (block.statements.length === 0) {
|
|
477
|
-
diagnostics.push({
|
|
478
|
-
kind: "ambiguous-empty-block",
|
|
479
|
-
severity: "warning",
|
|
480
|
-
message: "Function block is empty; cannot infer explicit return value.",
|
|
481
|
-
span: block.span,
|
|
482
|
-
filename,
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
diagnostics.push({
|
|
487
|
-
kind: "ambiguous-missing-return",
|
|
488
|
-
severity: "warning",
|
|
489
|
-
message: "Function block does not end with an expression; cannot infer explicit return value.",
|
|
490
|
-
span: block.span,
|
|
491
|
-
filename,
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
// 4. Trailing MatchExpression
|
|
497
|
-
if (block.finalExpression.kind === "MatchExpression") {
|
|
498
|
-
if (options.migrateTrailingMatch) {
|
|
499
|
-
addExplicitReturnChange(block.finalExpression, source, changes);
|
|
500
|
-
}
|
|
501
|
-
// Otherwise compliant under current parser exemption
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
// 5. Trailing EffectBlockExpression
|
|
505
|
-
if (block.finalExpression.kind === "EffectBlockExpression") {
|
|
506
|
-
// Compliant at function block level; the effect block itself is validated separately
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
// 6. Safe candidate: legacy bare expression at the end of function block!
|
|
510
|
-
addExplicitReturnChange(block.finalExpression, source, changes);
|
|
511
|
-
}
|
|
512
|
-
function handleEffectBlockExpression(expr, source, options, changes, diagnostics, filename) {
|
|
513
|
-
// Check if this effect block ended with an ambiguous bare return
|
|
514
|
-
if (expr.legacyReturnKind !== undefined) {
|
|
515
|
-
diagnostics.push({
|
|
516
|
-
kind: "ambiguous-effect-return",
|
|
517
|
-
severity: "warning",
|
|
518
|
-
message: "Effect block ends with a bare expression without explicit '=>' return or '<-' bind. Safe migration cannot determine whether the effect should be yielded or returned as a value.",
|
|
519
|
-
span: expr.finalExpression?.span ?? expr.span,
|
|
520
|
-
filename,
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
// Visit effect statements
|
|
524
|
-
for (const stmt of expr.body) {
|
|
525
|
-
if ("effect" in stmt && stmt.effect) {
|
|
526
|
-
visitExpression(stmt.effect, source, options, changes, diagnostics, filename);
|
|
527
|
-
}
|
|
528
|
-
if ("init" in stmt && stmt.init) {
|
|
529
|
-
visitExpression(stmt.init, source, options, changes, diagnostics, filename);
|
|
530
|
-
}
|
|
531
|
-
if ("value" in stmt && stmt.value) {
|
|
532
|
-
visitExpression(stmt.value, source, options, changes, diagnostics, filename);
|
|
533
|
-
}
|
|
534
|
-
if ("condition" in stmt && stmt.condition) {
|
|
535
|
-
visitExpression(stmt.condition, source, options, changes, diagnostics, filename);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
if (expr.finalExpression && expr.legacyReturnKind !== "missing") {
|
|
539
|
-
visitExpression(expr.finalExpression, source, options, changes, diagnostics, filename);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function visitStatement(stmt, source, options, changes, diagnostics, filename) {
|
|
543
|
-
switch (stmt.kind) {
|
|
544
|
-
case "BindingDeclaration":
|
|
545
|
-
if (stmt.init) {
|
|
546
|
-
visitExpression(stmt.init, source, options, changes, diagnostics, filename);
|
|
547
|
-
}
|
|
548
|
-
break;
|
|
549
|
-
case "AssignmentStatement":
|
|
550
|
-
if (stmt.value) {
|
|
551
|
-
visitExpression(stmt.value, source, options, changes, diagnostics, filename);
|
|
552
|
-
}
|
|
553
|
-
break;
|
|
554
|
-
case "ExpressionStatement":
|
|
555
|
-
if (stmt.expression) {
|
|
556
|
-
visitExpression(stmt.expression, source, options, changes, diagnostics, filename);
|
|
557
|
-
}
|
|
558
|
-
break;
|
|
559
|
-
case "ReturnStatement":
|
|
560
|
-
if (stmt.argument) {
|
|
561
|
-
visitExpression(stmt.argument, source, options, changes, diagnostics, filename);
|
|
562
|
-
}
|
|
563
|
-
break;
|
|
564
|
-
case "WhenStatement":
|
|
565
|
-
visitWhenStatement(stmt, source, options, changes, diagnostics, filename);
|
|
566
|
-
break;
|
|
567
|
-
default:
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
function visitWhenStatement(when, source, options, changes, diagnostics, filename) {
|
|
572
|
-
if (when.condition) {
|
|
573
|
-
visitExpression(when.condition, source, options, changes, diagnostics, filename);
|
|
574
|
-
}
|
|
575
|
-
if (when.consequent) {
|
|
576
|
-
if (when.consequent.kind === "BlockStatement") {
|
|
577
|
-
// when blocks do not use explicit returns
|
|
578
|
-
for (const stmt of when.consequent.statements) {
|
|
579
|
-
visitStatement(stmt, source, options, changes, diagnostics, filename);
|
|
580
|
-
}
|
|
581
|
-
if (when.consequent.finalExpression) {
|
|
582
|
-
visitExpression(when.consequent.finalExpression, source, options, changes, diagnostics, filename);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
else {
|
|
586
|
-
visitExpression(when.consequent, source, options, changes, diagnostics, filename);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
function addExplicitReturnChange(expr, source, changes) {
|
|
591
|
-
const startOffset = expr.span.start.offset;
|
|
592
|
-
const endOffset = expr.span.end.offset;
|
|
593
|
-
const original = source.slice(startOffset, endOffset);
|
|
594
|
-
// Safety check: ensure not already preceded by '=>'
|
|
595
|
-
const prefixSlice = source.slice(Math.max(0, startOffset - 4), startOffset);
|
|
596
|
-
if (prefixSlice.includes("=>")) {
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
changes.push({
|
|
600
|
-
kind: "explicit-return",
|
|
601
|
-
span: expr.span,
|
|
602
|
-
original,
|
|
603
|
-
replacement: `=> ${original}`,
|
|
604
|
-
description: `Add explicit '=>' return before expression at line ${expr.span.start.line}, col ${expr.span.start.column}`,
|
|
605
|
-
offset: startOffset,
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
//# sourceMappingURL=migrate.js.map
|