@aster-cloud/aster-lang-ts 1.0.37 → 1.2.0
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/CHANGELOG.md +68 -0
- package/README.md +13 -7
- package/dist/scripts/aster.js +10 -5
- package/dist/scripts/aster.js.map +1 -1
- package/dist/scripts/core-ir-json.js +8 -3
- package/dist/scripts/core-ir-json.js.map +1 -1
- package/dist/scripts/emit-classfiles.js +3 -2
- package/dist/scripts/emit-classfiles.js.map +1 -1
- package/dist/scripts/emit-core.js +8 -5
- package/dist/scripts/emit-core.js.map +1 -1
- package/dist/scripts/generate-casefold.d.ts +2 -0
- package/dist/scripts/generate-casefold.d.ts.map +1 -0
- package/dist/scripts/generate-casefold.js +34 -0
- package/dist/scripts/generate-casefold.js.map +1 -0
- package/dist/scripts/generate-diagnostic-overlays.d.ts +29 -0
- package/dist/scripts/generate-diagnostic-overlays.d.ts.map +1 -0
- package/dist/scripts/generate-diagnostic-overlays.js +90 -0
- package/dist/scripts/generate-diagnostic-overlays.js.map +1 -0
- package/dist/scripts/golden.js +45 -20
- package/dist/scripts/golden.js.map +1 -1
- package/dist/scripts/perf-benchmark.js +1 -0
- package/dist/scripts/perf-benchmark.js.map +1 -1
- package/dist/scripts/profile-medium-project.js +1 -1
- package/dist/scripts/profile-medium-project.js.map +1 -1
- package/dist/scripts/repl.js +3 -8
- package/dist/scripts/repl.js.map +1 -1
- package/dist/scripts/typecheck-cli.js +10 -9
- package/dist/scripts/typecheck-cli.js.map +1 -1
- package/dist/scripts/update-eff-violation-expected.js +6 -6
- package/dist/scripts/update-eff-violation-expected.js.map +1 -1
- package/dist/scripts/verify-capabilities.js +3 -6
- package/dist/scripts/verify-capabilities.js.map +1 -1
- package/dist/scripts/verify-lexicon-sync.js +26 -0
- package/dist/scripts/verify-lexicon-sync.js.map +1 -1
- package/dist/src/ai/validator.d.ts +1 -1
- package/dist/src/ai/validator.d.ts.map +1 -1
- package/dist/src/ai/validator.js +12 -12
- package/dist/src/ai/validator.js.map +1 -1
- package/dist/src/ast/ast.d.ts +2 -0
- package/dist/src/ast/ast.d.ts.map +1 -1
- package/dist/src/ast/ast.js +6 -0
- package/dist/src/ast/ast.js.map +1 -1
- package/dist/src/ast/type-nodes.d.ts +25 -0
- package/dist/src/ast/type-nodes.d.ts.map +1 -0
- package/dist/src/ast/type-nodes.js +56 -0
- package/dist/src/ast/type-nodes.js.map +1 -0
- package/dist/src/browser.d.ts +27 -10
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +44 -55
- package/dist/src/browser.js.map +1 -1
- package/dist/src/cli/policy-converter.js +5 -9
- package/dist/src/cli/policy-converter.js.map +1 -1
- package/dist/src/cnl-printer.d.ts.map +1 -1
- package/dist/src/cnl-printer.js +10 -9
- package/dist/src/cnl-printer.js.map +1 -1
- package/dist/src/compile-pipeline.d.ts +48 -0
- package/dist/src/compile-pipeline.d.ts.map +1 -0
- package/dist/src/compile-pipeline.js +89 -0
- package/dist/src/compile-pipeline.js.map +1 -0
- package/dist/src/config/lexicons/diagnostic-messages.d.ts +7 -5
- package/dist/src/config/lexicons/diagnostic-messages.d.ts.map +1 -1
- package/dist/src/config/lexicons/diagnostic-messages.js +17 -105
- package/dist/src/config/lexicons/diagnostic-messages.js.map +1 -1
- package/dist/src/config/lexicons/diagnostic-overlays.generated.d.ts +9 -0
- package/dist/src/config/lexicons/diagnostic-overlays.generated.d.ts.map +1 -0
- package/dist/src/config/lexicons/diagnostic-overlays.generated.js +615 -0
- package/dist/src/config/lexicons/diagnostic-overlays.generated.js.map +1 -0
- package/dist/src/config/lexicons/identifiers/casefold-table.generated.d.ts +9 -0
- package/dist/src/config/lexicons/identifiers/casefold-table.generated.d.ts.map +1 -0
- package/dist/src/config/lexicons/identifiers/casefold-table.generated.js +1467 -0
- package/dist/src/config/lexicons/identifiers/casefold-table.generated.js.map +1 -0
- package/dist/src/config/lexicons/identifiers/casefold.d.ts +7 -0
- package/dist/src/config/lexicons/identifiers/casefold.d.ts.map +1 -0
- package/dist/src/config/lexicons/identifiers/casefold.js +37 -0
- package/dist/src/config/lexicons/identifiers/casefold.js.map +1 -0
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.de-DE.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.de-DE.js +8 -0
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.de-DE.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.en-US.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.en-US.js +8 -0
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.en-US.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.zh-CN.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.zh-CN.js +8 -0
- package/dist/src/config/lexicons/identifiers/domains/finance.loan.zh-CN.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.de-DE.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.de-DE.js +6 -0
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.de-DE.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.en-US.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.en-US.js +6 -0
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.en-US.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.zh-CN.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.zh-CN.js +6 -0
- package/dist/src/config/lexicons/identifiers/domains/insurance.auto.zh-CN.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/index.d.ts +7 -9
- package/dist/src/config/lexicons/identifiers/index.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/index.js +8 -9
- package/dist/src/config/lexicons/identifiers/index.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/registry.d.ts +11 -5
- package/dist/src/config/lexicons/identifiers/registry.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/registry.js +20 -14
- package/dist/src/config/lexicons/identifiers/registry.js.map +1 -1
- package/dist/src/config/lexicons/identifiers/scopes.d.ts +52 -0
- package/dist/src/config/lexicons/identifiers/scopes.d.ts.map +1 -0
- package/dist/src/config/lexicons/identifiers/scopes.js +166 -0
- package/dist/src/config/lexicons/identifiers/scopes.js.map +1 -0
- package/dist/src/config/lexicons/identifiers/types.d.ts +15 -29
- package/dist/src/config/lexicons/identifiers/types.d.ts.map +1 -1
- package/dist/src/config/lexicons/identifiers/types.js +91 -101
- package/dist/src/config/lexicons/identifiers/types.js.map +1 -1
- package/dist/src/config/lexicons/lsp-ui-texts.d.ts +7 -0
- package/dist/src/config/lexicons/lsp-ui-texts.d.ts.map +1 -1
- package/dist/src/config/lexicons/lsp-ui-texts.js +12 -0
- package/dist/src/config/lexicons/lsp-ui-texts.js.map +1 -1
- package/dist/src/config/semantic.d.ts +5 -0
- package/dist/src/config/semantic.d.ts.map +1 -1
- package/dist/src/config/semantic.js +12 -0
- package/dist/src/config/semantic.js.map +1 -1
- package/dist/src/core/core_ir.d.ts +2 -0
- package/dist/src/core/core_ir.d.ts.map +1 -1
- package/dist/src/core/core_ir.js +6 -0
- package/dist/src/core/core_ir.js.map +1 -1
- package/dist/src/core/inferred_fields.d.ts +10 -0
- package/dist/src/core/inferred_fields.d.ts.map +1 -1
- package/dist/src/core/inferred_fields.js +9 -0
- package/dist/src/core/inferred_fields.js.map +1 -1
- package/dist/src/core/interpreter.d.ts.map +1 -1
- package/dist/src/core/interpreter.js +12 -10
- package/dist/src/core/interpreter.js.map +1 -1
- package/dist/src/core/resolution-mark.d.ts +28 -0
- package/dist/src/core/resolution-mark.d.ts.map +1 -0
- package/dist/src/core/resolution-mark.js +19 -0
- package/dist/src/core/resolution-mark.js.map +1 -0
- package/dist/src/core/resolve-typed-references.d.ts +36 -0
- package/dist/src/core/resolve-typed-references.d.ts.map +1 -0
- package/dist/src/core/resolve-typed-references.js +703 -0
- package/dist/src/core/resolve-typed-references.js.map +1 -0
- package/dist/src/diagnostics/error_codes.d.ts +11 -1
- package/dist/src/diagnostics/error_codes.d.ts.map +1 -1
- package/dist/src/diagnostics/error_codes.js +80 -0
- package/dist/src/diagnostics/error_codes.js.map +1 -1
- package/dist/src/frontend/canonicalizer.d.ts +8 -13
- package/dist/src/frontend/canonicalizer.d.ts.map +1 -1
- package/dist/src/frontend/canonicalizer.js +19 -48
- package/dist/src/frontend/canonicalizer.js.map +1 -1
- package/dist/src/frontend/resolution-choice.d.ts +34 -0
- package/dist/src/frontend/resolution-choice.d.ts.map +1 -0
- package/dist/src/frontend/resolution-choice.js +69 -0
- package/dist/src/frontend/resolution-choice.js.map +1 -0
- package/dist/src/frontend/resolution-context.d.ts +28 -0
- package/dist/src/frontend/resolution-context.d.ts.map +1 -0
- package/dist/src/frontend/resolution-context.js +7 -0
- package/dist/src/frontend/resolution-context.js.map +1 -0
- package/dist/src/frontend/resolve-declarations.d.ts +13 -0
- package/dist/src/frontend/resolve-declarations.d.ts.map +1 -0
- package/dist/src/frontend/resolve-declarations.js +595 -0
- package/dist/src/frontend/resolve-declarations.js.map +1 -0
- package/dist/src/frontend/resolve-policy-types.d.ts +54 -0
- package/dist/src/frontend/resolve-policy-types.d.ts.map +1 -0
- package/dist/src/frontend/resolve-policy-types.js +71 -0
- package/dist/src/frontend/resolve-policy-types.js.map +1 -0
- package/dist/src/index.d.ts +14 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/lower_to_core.d.ts +2 -16
- package/dist/src/lower_to_core.d.ts.map +1 -1
- package/dist/src/lower_to_core.js +105 -44
- package/dist/src/lower_to_core.js.map +1 -1
- package/dist/src/lsp/canonicalize-options.d.ts +8 -11
- package/dist/src/lsp/canonicalize-options.d.ts.map +1 -1
- package/dist/src/lsp/canonicalize-options.js +8 -8
- package/dist/src/lsp/canonicalize-options.js.map +1 -1
- package/dist/src/lsp/completion.d.ts +55 -5
- package/dist/src/lsp/completion.d.ts.map +1 -1
- package/dist/src/lsp/completion.js +149 -0
- package/dist/src/lsp/completion.js.map +1 -1
- package/dist/src/lsp/diagnostics.d.ts +2 -0
- package/dist/src/lsp/diagnostics.d.ts.map +1 -1
- package/dist/src/lsp/diagnostics.js +84 -73
- package/dist/src/lsp/diagnostics.js.map +1 -1
- package/dist/src/lsp/navigation/definition.d.ts +2 -1
- package/dist/src/lsp/navigation/definition.d.ts.map +1 -1
- package/dist/src/lsp/navigation/definition.js +35 -1
- package/dist/src/lsp/navigation/definition.js.map +1 -1
- package/dist/src/lsp/navigation/hover.d.ts +12 -5
- package/dist/src/lsp/navigation/hover.d.ts.map +1 -1
- package/dist/src/lsp/navigation/hover.js +136 -90
- package/dist/src/lsp/navigation/hover.js.map +1 -1
- package/dist/src/lsp/parse-document.d.ts +4 -1
- package/dist/src/lsp/parse-document.d.ts.map +1 -1
- package/dist/src/lsp/parse-document.js +20 -17
- package/dist/src/lsp/parse-document.js.map +1 -1
- package/dist/src/lsp/resolution.d.ts +40 -0
- package/dist/src/lsp/resolution.d.ts.map +1 -0
- package/dist/src/lsp/resolution.js +179 -0
- package/dist/src/lsp/resolution.js.map +1 -0
- package/dist/src/lsp/server.js +3 -1
- package/dist/src/lsp/server.js.map +1 -1
- package/dist/src/lsp/source-positions.d.ts +2 -8
- package/dist/src/lsp/source-positions.d.ts.map +1 -1
- package/dist/src/lsp/source-positions.js +4 -16
- package/dist/src/lsp/source-positions.js.map +1 -1
- package/dist/src/mapping/pipeline.js +3 -2
- package/dist/src/mapping/pipeline.js.map +1 -1
- package/dist/src/mapping/review-queue.d.ts.map +1 -1
- package/dist/src/mapping/review-queue.js +3 -2
- package/dist/src/mapping/review-queue.js.map +1 -1
- package/dist/src/parser/context.d.ts +3 -1
- package/dist/src/parser/context.d.ts.map +1 -1
- package/dist/src/parser/context.js +1 -0
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/decl-parser.d.ts.map +1 -1
- package/dist/src/parser/decl-parser.js +7 -5
- package/dist/src/parser/decl-parser.js.map +1 -1
- package/dist/src/parser/expr-stmt-parser.d.ts.map +1 -1
- package/dist/src/parser/expr-stmt-parser.js +2 -16
- package/dist/src/parser/expr-stmt-parser.js.map +1 -1
- package/dist/src/parser/type-parser.d.ts.map +1 -1
- package/dist/src/parser/type-parser.js +42 -0
- package/dist/src/parser/type-parser.js.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/parser.js +6 -1
- package/dist/src/parser.js.map +1 -1
- package/dist/src/typecheck/diagnostics.d.ts +10 -0
- package/dist/src/typecheck/diagnostics.d.ts.map +1 -1
- package/dist/src/typecheck/diagnostics.js +27 -0
- package/dist/src/typecheck/diagnostics.js.map +1 -1
- package/dist/src/typecheck/expression.d.ts.map +1 -1
- package/dist/src/typecheck/expression.js +13 -0
- package/dist/src/typecheck/expression.js.map +1 -1
- package/dist/src/typecheck/generics.d.ts +5 -0
- package/dist/src/typecheck/generics.d.ts.map +1 -1
- package/dist/src/typecheck/generics.js +15 -8
- package/dist/src/typecheck/generics.js.map +1 -1
- package/dist/src/types.d.ts +59 -13
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/version.d.ts +18 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +18 -0
- package/dist/src/version.js.map +1 -0
- package/dist/test/integration/builtin-enum-vocabulary.test.d.ts +2 -0
- package/dist/test/integration/builtin-enum-vocabulary.test.d.ts.map +1 -0
- package/dist/test/integration/builtin-enum-vocabulary.test.js +51 -0
- package/dist/test/integration/builtin-enum-vocabulary.test.js.map +1 -0
- package/dist/test/integration/lsp/lsp-rename-safety.test.js +0 -13
- package/dist/test/integration/lsp/lsp-rename-safety.test.js.map +1 -1
- package/dist/test/integration/name-resolution-entrypoints.test.d.ts +2 -0
- package/dist/test/integration/name-resolution-entrypoints.test.d.ts.map +1 -0
- package/dist/test/integration/name-resolution-entrypoints.test.js +109 -0
- package/dist/test/integration/name-resolution-entrypoints.test.js.map +1 -0
- package/dist/test/integration/scripts/typecheck-cli-repl.test.d.ts +2 -0
- package/dist/test/integration/scripts/typecheck-cli-repl.test.d.ts.map +1 -0
- package/dist/test/integration/scripts/typecheck-cli-repl.test.js +133 -0
- package/dist/test/integration/scripts/typecheck-cli-repl.test.js.map +1 -0
- package/dist/test/integration/vocabulary-resolution.test.d.ts +2 -0
- package/dist/test/integration/vocabulary-resolution.test.d.ts.map +1 -0
- package/dist/test/integration/vocabulary-resolution.test.js +291 -0
- package/dist/test/integration/vocabulary-resolution.test.js.map +1 -0
- package/dist/test/property/property.test.js +2 -1
- package/dist/test/property/property.test.js.map +1 -1
- package/dist/test/unit/canonicalizer/canonicalizer.test.js +7 -79
- package/dist/test/unit/canonicalizer/canonicalizer.test.js.map +1 -1
- package/dist/test/unit/config/lexicons/identifiers/identifier-mapping.test.js +134 -31
- package/dist/test/unit/config/lexicons/identifiers/identifier-mapping.test.js.map +1 -1
- package/dist/test/unit/config/lexicons/identifiers/literal-macro.test.js +16 -18
- package/dist/test/unit/config/lexicons/identifiers/literal-macro.test.js.map +1 -1
- package/dist/test/unit/core/resolve-typed-references.test.d.ts +2 -0
- package/dist/test/unit/core/resolve-typed-references.test.d.ts.map +1 -0
- package/dist/test/unit/core/resolve-typed-references.test.js +600 -0
- package/dist/test/unit/core/resolve-typed-references.test.js.map +1 -0
- package/dist/test/unit/diagnostics/diagnostic-overlays.test.d.ts +2 -0
- package/dist/test/unit/diagnostics/diagnostic-overlays.test.d.ts.map +1 -0
- package/dist/test/unit/diagnostics/diagnostic-overlays.test.js +156 -0
- package/dist/test/unit/diagnostics/diagnostic-overlays.test.js.map +1 -0
- package/dist/test/unit/diagnostics/resolution-codes.test.d.ts +6 -0
- package/dist/test/unit/diagnostics/resolution-codes.test.d.ts.map +1 -0
- package/dist/test/unit/diagnostics/resolution-codes.test.js +96 -0
- package/dist/test/unit/diagnostics/resolution-codes.test.js.map +1 -0
- package/dist/test/unit/formatter-corpus-roundtrip.test.js +5 -0
- package/dist/test/unit/formatter-corpus-roundtrip.test.js.map +1 -1
- package/dist/test/unit/formatter-roundtrip.test.js +84 -0
- package/dist/test/unit/formatter-roundtrip.test.js.map +1 -1
- package/dist/test/unit/frontend/resolve-declarations.test.d.ts +2 -0
- package/dist/test/unit/frontend/resolve-declarations.test.d.ts.map +1 -0
- package/dist/test/unit/frontend/resolve-declarations.test.js +459 -0
- package/dist/test/unit/frontend/resolve-declarations.test.js.map +1 -0
- package/dist/test/unit/identifiers/casefold.test.d.ts +2 -0
- package/dist/test/unit/identifiers/casefold.test.d.ts.map +1 -0
- package/dist/test/unit/identifiers/casefold.test.js +77 -0
- package/dist/test/unit/identifiers/casefold.test.js.map +1 -0
- package/dist/test/unit/identifiers/scopes.test.d.ts +2 -0
- package/dist/test/unit/identifiers/scopes.test.d.ts.map +1 -0
- package/dist/test/unit/identifiers/scopes.test.js +109 -0
- package/dist/test/unit/identifiers/scopes.test.js.map +1 -0
- package/dist/test/unit/lambda-capture-parity.test.js +12 -5
- package/dist/test/unit/lambda-capture-parity.test.js.map +1 -1
- package/dist/test/unit/lsp/lsp-locale-fixes.test.js +10 -11
- package/dist/test/unit/lsp/lsp-locale-fixes.test.js.map +1 -1
- package/dist/test/unit/lsp/parse-document.test.js +42 -0
- package/dist/test/unit/lsp/parse-document.test.js.map +1 -1
- package/dist/test/unit/lsp/resolution-completion.test.d.ts +2 -0
- package/dist/test/unit/lsp/resolution-completion.test.d.ts.map +1 -0
- package/dist/test/unit/lsp/resolution-completion.test.js +132 -0
- package/dist/test/unit/lsp/resolution-completion.test.js.map +1 -0
- package/dist/test/unit/lsp/resolution-definition.test.d.ts +2 -0
- package/dist/test/unit/lsp/resolution-definition.test.d.ts.map +1 -0
- package/dist/test/unit/lsp/resolution-definition.test.js +75 -0
- package/dist/test/unit/lsp/resolution-definition.test.js.map +1 -0
- package/dist/test/unit/lsp/resolution-diagnostics.test.d.ts +2 -0
- package/dist/test/unit/lsp/resolution-diagnostics.test.d.ts.map +1 -0
- package/dist/test/unit/lsp/resolution-diagnostics.test.js +88 -0
- package/dist/test/unit/lsp/resolution-diagnostics.test.js.map +1 -0
- package/dist/test/unit/lsp/resolution-fixture.d.ts +32 -0
- package/dist/test/unit/lsp/resolution-fixture.d.ts.map +1 -0
- package/dist/test/unit/lsp/resolution-fixture.js +69 -0
- package/dist/test/unit/lsp/resolution-fixture.js.map +1 -0
- package/dist/test/unit/lsp/resolution-hover.test.d.ts +2 -0
- package/dist/test/unit/lsp/resolution-hover.test.d.ts.map +1 -0
- package/dist/test/unit/lsp/resolution-hover.test.js +107 -0
- package/dist/test/unit/lsp/resolution-hover.test.js.map +1 -0
- package/dist/test/unit/lsp/tenant-vocabulary.test.js +21 -47
- package/dist/test/unit/lsp/tenant-vocabulary.test.js.map +1 -1
- package/dist/test/unit/parser/func-type.test.d.ts +2 -0
- package/dist/test/unit/parser/func-type.test.d.ts.map +1 -0
- package/dist/test/unit/parser/func-type.test.js +161 -0
- package/dist/test/unit/parser/func-type.test.js.map +1 -0
- package/dist/test/unit/parser/parser.test.js +33 -0
- package/dist/test/unit/parser/parser.test.js.map +1 -1
- package/dist/test/unit/public-api-checked-entries.test.d.ts +2 -0
- package/dist/test/unit/public-api-checked-entries.test.d.ts.map +1 -0
- package/dist/test/unit/public-api-checked-entries.test.js +28 -0
- package/dist/test/unit/public-api-checked-entries.test.js.map +1 -0
- package/dist/test/unit/typecheck/qualified-enum-member.test.d.ts +2 -0
- package/dist/test/unit/typecheck/qualified-enum-member.test.d.ts.map +1 -0
- package/dist/test/unit/typecheck/qualified-enum-member.test.js +73 -0
- package/dist/test/unit/typecheck/qualified-enum-member.test.js.map +1 -0
- package/dist/test/unit/version.test.d.ts +9 -0
- package/dist/test/unit/version.test.d.ts.map +1 -0
- package/dist/test/unit/version.test.js +34 -0
- package/dist/test/unit/version.test.js.map +1 -0
- package/package.json +2 -1
- package/dist/src/config/lexicons/identifiers/examples/canonicalizer-integration.d.ts +0 -47
- package/dist/src/config/lexicons/identifiers/examples/canonicalizer-integration.d.ts.map +0 -1
- package/dist/src/config/lexicons/identifiers/examples/canonicalizer-integration.js +0 -142
- package/dist/src/config/lexicons/identifiers/examples/canonicalizer-integration.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DomainVocabulary } from '../config/lexicons/identifiers/types.js';
|
|
2
|
+
import type { Diagnostic } from '../diagnostics/diagnostics.js';
|
|
3
|
+
import type { Core, TypecheckDiagnostic } from '../types.js';
|
|
4
|
+
/** 规范类型引用(与 Core IR 的类型节点同形) */
|
|
5
|
+
export type TypeRef = Core.Type;
|
|
6
|
+
export interface PolicyTypes {
|
|
7
|
+
structs: Array<{
|
|
8
|
+
canonical: string;
|
|
9
|
+
written: string;
|
|
10
|
+
fields: Array<{
|
|
11
|
+
canonical: string;
|
|
12
|
+
written: string;
|
|
13
|
+
type: TypeRef;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
enums: Array<{
|
|
17
|
+
canonical: string;
|
|
18
|
+
written: string;
|
|
19
|
+
members: Array<{
|
|
20
|
+
canonical: string;
|
|
21
|
+
written: string;
|
|
22
|
+
}>;
|
|
23
|
+
}>;
|
|
24
|
+
functions: Array<{
|
|
25
|
+
canonical: string;
|
|
26
|
+
written: string;
|
|
27
|
+
params: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
type: TypeRef;
|
|
30
|
+
}>;
|
|
31
|
+
returnType?: TypeRef;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/** 解析诊断(语法)与名称解析诊断(E8xx / W8xx) */
|
|
35
|
+
export type PolicyTypesDiagnostic = Diagnostic | TypecheckDiagnostic;
|
|
36
|
+
export interface ResolvePolicyTypesOptions {
|
|
37
|
+
/** 源码的 CNL 语言(lexicon id,如 de-DE) */
|
|
38
|
+
locale: string;
|
|
39
|
+
vocabulary?: DomainVocabulary;
|
|
40
|
+
/** 关键词别名(ADR 0022),按语义 token 种类并入 lexicon,只影响解析 */
|
|
41
|
+
aliasSet?: Record<string, string[]>;
|
|
42
|
+
}
|
|
43
|
+
export type ResolvePolicyTypesResult = {
|
|
44
|
+
ok: true;
|
|
45
|
+
types: PolicyTypes;
|
|
46
|
+
} | {
|
|
47
|
+
ok: false;
|
|
48
|
+
diagnostics: PolicyTypesDiagnostic[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 解析策略源码中的类型声明。语法错误或任一 E8xx 时返回 ok:false 与诊断;W8xx 不影响结果。
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolvePolicyTypes(source: string, opts: ResolvePolicyTypesOptions): ResolvePolicyTypesResult;
|
|
54
|
+
//# sourceMappingURL=resolve-policy-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-policy-types.d.ts","sourceRoot":"","sources":["../../../src/frontend/resolve-policy-types.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAIhE,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE7D,gCAAgC;AAChC,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;AAEhC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,KAAK,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;KACtE,CAAC,CAAC;IACH,KAAK,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,KAAK,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAC7G,SAAS,EAAE,KAAK,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;QAC/C,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC,CAAC;CACJ;AAED,mCAAmC;AACnC,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,mBAAmB,CAAC;AAErE,MAAM,WAAW,yBAAyB;IACxC,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACrC;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAChC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,qBAAqB,EAAE,CAAA;CAAE,CAAC;AAyCxD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,GAAG,wBAAwB,CAa5G"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module frontend/resolve-policy-types
|
|
3
|
+
*
|
|
4
|
+
* 为执行输入映射提取策略的已解析类型(ADR 0051 §8):只跑解析 + R1 + lower + R2,不做类型检查。
|
|
5
|
+
* 每个声明同时给出规范名与源码原写法,供调用方把用户按策略写法提交的输入映射到规范 IR。
|
|
6
|
+
*/
|
|
7
|
+
import { LexiconRegistry, initializeAllBundledLexicons } from '../config/lexicons/index.js';
|
|
8
|
+
import { buildVocabularyScopes } from '../config/lexicons/identifiers/scopes.js';
|
|
9
|
+
import { DiagnosticError } from '../diagnostics/diagnostics.js';
|
|
10
|
+
import { hasErrors, parseSource, resolveAndLower } from '../compile-pipeline.js';
|
|
11
|
+
function lexiconFor(locale, aliasSet) {
|
|
12
|
+
initializeAllBundledLexicons();
|
|
13
|
+
const base = LexiconRegistry.get(locale);
|
|
14
|
+
if (!base)
|
|
15
|
+
throw new Error(`未注册的 locale:${locale}`);
|
|
16
|
+
if (!aliasSet || Object.keys(aliasSet).length === 0)
|
|
17
|
+
return base;
|
|
18
|
+
return { ...base, aliases: { ...base.aliases, ...aliasSet } };
|
|
19
|
+
}
|
|
20
|
+
/** 类型引用只保留结构,去掉源码位置(origin 中的写法与位置不属于类型身份)。 */
|
|
21
|
+
function typeRef(t) {
|
|
22
|
+
return JSON.parse(JSON.stringify(t, (k, v) => (k === 'origin' ? undefined : v)));
|
|
23
|
+
}
|
|
24
|
+
const writtenOf = (resolved, fallback) => resolved?.written ?? fallback;
|
|
25
|
+
function collect(ast, core) {
|
|
26
|
+
const types = { structs: [], enums: [], functions: [] };
|
|
27
|
+
// lower 与 R2 都逐个映射声明,AST 与 Core 的声明下标一一对应
|
|
28
|
+
core.decls.forEach((d, i) => {
|
|
29
|
+
const src = ast.decls[i];
|
|
30
|
+
if (d.kind === 'Data' && src.kind === 'Data') {
|
|
31
|
+
const fields = d.fields.map((f, j) => ({
|
|
32
|
+
canonical: f.name,
|
|
33
|
+
written: writtenOf(src.fields[j]?.resolved, f.name),
|
|
34
|
+
type: typeRef(f.type),
|
|
35
|
+
}));
|
|
36
|
+
types.structs.push({ canonical: d.name, written: writtenOf(src.resolved, d.name), fields });
|
|
37
|
+
}
|
|
38
|
+
else if (d.kind === 'Enum' && src.kind === 'Enum') {
|
|
39
|
+
const members = d.variants.map((v, j) => ({ canonical: v, written: writtenOf(src.resolvedVariants?.[j], v) }));
|
|
40
|
+
types.enums.push({ canonical: d.name, written: writtenOf(src.resolved, d.name), members });
|
|
41
|
+
}
|
|
42
|
+
else if (d.kind === 'Func' && src.kind === 'Func') {
|
|
43
|
+
const params = d.params.map((p) => ({ name: p.name, type: typeRef(p.type) }));
|
|
44
|
+
const returnType = d.retTypeInferred ? {} : { returnType: typeRef(d.ret) };
|
|
45
|
+
types.functions.push({ canonical: d.name, written: writtenOf(src.resolved, d.name), params, ...returnType });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return types;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 解析策略源码中的类型声明。语法错误或任一 E8xx 时返回 ok:false 与诊断;W8xx 不影响结果。
|
|
52
|
+
*/
|
|
53
|
+
export function resolvePolicyTypes(source, opts) {
|
|
54
|
+
const lexicon = lexiconFor(opts.locale, opts.aliasSet);
|
|
55
|
+
const scopes = opts.vocabulary ? buildVocabularyScopes(opts.vocabulary) : undefined;
|
|
56
|
+
try {
|
|
57
|
+
const parsed = parseSource(source, lexicon, scopes);
|
|
58
|
+
if (hasErrors(parsed.diagnostics))
|
|
59
|
+
return { ok: false, diagnostics: [...parsed.diagnostics] };
|
|
60
|
+
const resolved = resolveAndLower(parsed.ast, scopes);
|
|
61
|
+
if (hasErrors(resolved.diagnostics))
|
|
62
|
+
return { ok: false, diagnostics: [...resolved.diagnostics] };
|
|
63
|
+
return { ok: true, types: collect(resolved.ast, resolved.core) };
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (err instanceof DiagnosticError)
|
|
67
|
+
return { ok: false, diagnostics: [err.diagnostic] };
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=resolve-policy-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-policy-types.js","sourceRoot":"","sources":["../../../src/frontend/resolve-policy-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AAE,MAAM,CAAC,CAAC;QACpD,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9F,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IACnE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,eAAe;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACxF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -8,26 +8,32 @@
|
|
|
8
8
|
*
|
|
9
9
|
* **编译管道**:
|
|
10
10
|
* ```
|
|
11
|
-
* CNL 源代码 → canonicalize → lex → parse → AST → lowerModule → Core IR → typecheck → JVM
|
|
11
|
+
* CNL 源代码 → canonicalize → lex → parse → AST → R1 名称解析 → lowerModule → R2 名称解析 → Core IR → typecheck → JVM
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
14
|
* @example 基础用法
|
|
15
15
|
* ```typescript
|
|
16
|
-
* import {
|
|
16
|
+
* import { parseSource, resolveAndLowerChecked } from '@aster-cloud/aster-lang-ts';
|
|
17
17
|
*
|
|
18
18
|
* const src = `Module app. Rule id, produce Int: Return 1.`;
|
|
19
|
-
* const
|
|
20
|
-
* const
|
|
21
|
-
* const ast = parse(tokens); // 语法分析
|
|
22
|
-
* const core = lowerModule(ast); // 降级到 Core IR
|
|
19
|
+
* const { ast } = parseSource(src); // 规范化 + 词法 + 语法分析
|
|
20
|
+
* const { core } = resolveAndLowerChecked(ast); // R1 → lower → R2;任一 E8xx 抛出 NameResolutionError
|
|
23
21
|
* console.log(core);
|
|
24
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* 公开 API 只提供带名称解析检查的出口(resolveAndLowerChecked / compile / resolvePolicyTypes):
|
|
25
|
+
* 未经 R1/R2 的原始 lower 与不抛错的 resolveAndLower 是内部实现,可能产出含本地化名的 Core。
|
|
25
26
|
*/
|
|
26
27
|
export { canonicalize } from './frontend/canonicalizer.js';
|
|
27
28
|
export { lex } from './frontend/lexer.js';
|
|
28
29
|
export { parse, parseWithLexicon } from './parser.js';
|
|
29
30
|
export type { ParseResult } from './parser.js';
|
|
30
|
-
export {
|
|
31
|
+
export { parseSource, resolveAndLowerChecked, NameResolutionError } from './compile-pipeline.js';
|
|
32
|
+
export type { ParsedSource, ResolvedCore } from './compile-pipeline.js';
|
|
33
|
+
export { buildVocabularyScopes, canonicalScopesJson, foldKey, VocabularyScopeError, } from './config/lexicons/identifiers/index.js';
|
|
34
|
+
export type { Candidate, DomainVocabulary, IdentifierMapping, VocabularyScopes, VocabularyScopeErrorCode, } from './config/lexicons/identifiers/index.js';
|
|
35
|
+
export { resolvePolicyTypes } from './frontend/resolve-policy-types.js';
|
|
36
|
+
export type { PolicyTypes, PolicyTypesDiagnostic, ResolvePolicyTypesOptions, ResolvePolicyTypesResult, TypeRef, } from './frontend/resolve-policy-types.js';
|
|
31
37
|
export { createKeywordTranslator, buildKeywordTranslationIndex, buildFullTranslationIndex, translateTokens, translateTokensWithMarkers, translateToken, needsKeywordTranslation, } from './frontend/keyword-translator.js';
|
|
32
38
|
export type { KeywordTranslationIndex, MarkerKeywordIndex, TranslationIndexResult, } from './frontend/keyword-translator.js';
|
|
33
39
|
export { Core, Effect } from './core/core_ir.js';
|
|
@@ -41,6 +47,7 @@ export { CONTROLS_REGISTRY } from './governance/controls-registry.data.js';
|
|
|
41
47
|
export type { ControlsRegistryData, LocalizedTitle } from './governance/controls-registry.data.js';
|
|
42
48
|
export { generateFieldValue, generateInputValues, getFieldValueHint, } from './parser/input-generator.js';
|
|
43
49
|
export type { TypeKind, FieldInfo, ParameterInfo, } from './parser/input-generator.js';
|
|
50
|
+
export { RESOLVER_VERSION, CASEFOLD_VERSION, CORE_IR_ABI } from './version.js';
|
|
44
51
|
export type * from './types.js';
|
|
45
52
|
export { runSemanticBridge } from './mapping/pipeline.js';
|
|
46
53
|
export type { BridgeResult, VerifiedCandidate } from './mapping/pipeline.js';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjG,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGxE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,OAAO,EACP,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAChD,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,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OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACrF,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EACrE,cAAc,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACtG,YAAY,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -8,26 +8,31 @@
|
|
|
8
8
|
*
|
|
9
9
|
* **编译管道**:
|
|
10
10
|
* ```
|
|
11
|
-
* CNL 源代码 → canonicalize → lex → parse → AST → lowerModule → Core IR → typecheck → JVM
|
|
11
|
+
* CNL 源代码 → canonicalize → lex → parse → AST → R1 名称解析 → lowerModule → R2 名称解析 → Core IR → typecheck → JVM
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
14
|
* @example 基础用法
|
|
15
15
|
* ```typescript
|
|
16
|
-
* import {
|
|
16
|
+
* import { parseSource, resolveAndLowerChecked } from '@aster-cloud/aster-lang-ts';
|
|
17
17
|
*
|
|
18
18
|
* const src = `Module app. Rule id, produce Int: Return 1.`;
|
|
19
|
-
* const
|
|
20
|
-
* const
|
|
21
|
-
* const ast = parse(tokens); // 语法分析
|
|
22
|
-
* const core = lowerModule(ast); // 降级到 Core IR
|
|
19
|
+
* const { ast } = parseSource(src); // 规范化 + 词法 + 语法分析
|
|
20
|
+
* const { core } = resolveAndLowerChecked(ast); // R1 → lower → R2;任一 E8xx 抛出 NameResolutionError
|
|
23
21
|
* console.log(core);
|
|
24
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* 公开 API 只提供带名称解析检查的出口(resolveAndLowerChecked / compile / resolvePolicyTypes):
|
|
25
|
+
* 未经 R1/R2 的原始 lower 与不抛错的 resolveAndLower 是内部实现,可能产出含本地化名的 Core。
|
|
25
26
|
*/
|
|
26
27
|
// 编译器管道函数
|
|
27
28
|
export { canonicalize } from './frontend/canonicalizer.js';
|
|
28
29
|
export { lex } from './frontend/lexer.js';
|
|
29
30
|
export { parse, parseWithLexicon } from './parser.js';
|
|
30
|
-
|
|
31
|
+
// 名称解析接入后的前端(ADR 0051):parse → R1 → lower → R2;只导出带检查的出口
|
|
32
|
+
export { parseSource, resolveAndLowerChecked, NameResolutionError } from './compile-pipeline.js';
|
|
33
|
+
// 领域词汇按位置解析(ADR 0051)
|
|
34
|
+
export { buildVocabularyScopes, canonicalScopesJson, foldKey, VocabularyScopeError, } from './config/lexicons/identifiers/index.js';
|
|
35
|
+
export { resolvePolicyTypes } from './frontend/resolve-policy-types.js';
|
|
31
36
|
// 关键词翻译(多语言 CNL 支持)
|
|
32
37
|
export { createKeywordTranslator, buildKeywordTranslationIndex, buildFullTranslationIndex, translateTokens, translateTokensWithMarkers, translateToken, needsKeywordTranslation, } from './frontend/keyword-translator.js';
|
|
33
38
|
// 核心类型和枚举
|
|
@@ -40,6 +45,8 @@ export { controlRegistryFrom, defaultControlRegistry } from './governance/contro
|
|
|
40
45
|
export { CONTROLS_REGISTRY } from './governance/controls-registry.data.js';
|
|
41
46
|
// 输入值生成器(用于策略执行时自动生成示例输入)
|
|
42
47
|
export { generateFieldValue, generateInputValues, getFieldValueHint, } from './parser/input-generator.js';
|
|
48
|
+
// 工具链分量版本常量(ADR 0051 §7)
|
|
49
|
+
export { RESOLVER_VERSION, CASEFOLD_VERSION, CORE_IR_ABI } from './version.js';
|
|
43
50
|
// ── ADR 0037 可验证语义桥 ────────────────────────────────────────────
|
|
44
51
|
// ★接线后才导出:此前六个模块全是死代码(生产调用数 0、不在导出面内)。
|
|
45
52
|
// `runSemanticBridge` 是唯一入口,内部串起
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGtD,yDAAyD;AACzD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGjG,sBAAsB;AACtB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,OAAO,EACP,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAQhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AASxE,oBAAoB;AACpB,OAAO,EACL,uBAAuB,EACvB,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types.js';
|
|
|
32
32
|
* @param ast - AST Module 节点(通过 parser.parse 生成)
|
|
33
33
|
* @returns Core IR Module 节点,包含所有声明的规范化表示
|
|
34
34
|
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
37
|
-
* import { canonicalize, lex, parse, lowerModule } from '@aster-cloud/aster-lang-ts';
|
|
38
|
-
*
|
|
39
|
-
* const src = `Module app.
|
|
40
|
-
* Rule greet, produce Text:
|
|
41
|
-
* Return "Hello".
|
|
42
|
-
* `;
|
|
43
|
-
*
|
|
44
|
-
* const ast = parse(lex(canonicalize(src)));
|
|
45
|
-
* const core = lowerModule(ast);
|
|
46
|
-
*
|
|
47
|
-
* console.log(core.kind); // "Module"
|
|
48
|
-
* console.log(core.name); // "app"
|
|
49
|
-
* // Core IR 是更简洁的表示,适合类型检查和代码生成
|
|
50
|
-
* ```
|
|
35
|
+
* @internal 不从包入口导出:未经 R1 的 AST 降级后名字保持原写法(可能是本地化名)。
|
|
36
|
+
* 外部调用方使用 resolveAndLowerChecked(compile-pipeline)或 browser `compile`。
|
|
51
37
|
*/
|
|
52
38
|
export declare function lowerModule(ast: Module): import('./types.js').Core.Module;
|
|
53
39
|
//# sourceMappingURL=lower_to_core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lower_to_core.d.ts","sourceRoot":"","sources":["../../src/lower_to_core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"lower_to_core.d.ts","sourceRoot":"","sources":["../../src/lower_to_core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH,OAAO,KAAK,EACV,MAAM,EAYP,MAAM,YAAY,CAAC;AAsNpB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,YAAY,EAAE,IAAI,CAAC,MAAM,CAIzE"}
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
* - 简化的效果标注
|
|
18
18
|
*/
|
|
19
19
|
import { Core } from './core/core_ir.js';
|
|
20
|
-
import { markFieldTypeInferred } from './core/inferred_fields.js';
|
|
20
|
+
import { markFieldTypeInferred, markLambdaParamTypeInferred } from './core/inferred_fields.js';
|
|
21
|
+
import { markForResolution, withResolvedOrigin } from './core/resolution-mark.js';
|
|
22
|
+
import { KEYWORD_CTORS } from './frontend/resolution-choice.js';
|
|
21
23
|
import { parseEffect, getAllEffects, inferCapabilityFromName } from './config/semantic.js';
|
|
22
24
|
import { Diagnostics } from './diagnostics/diagnostics.js';
|
|
23
25
|
import { DefaultAstVisitor } from './ast/ast_visitor.js';
|
|
@@ -49,6 +51,25 @@ function withOrigin(coreNode, astNode) {
|
|
|
49
51
|
}
|
|
50
52
|
return coreNode;
|
|
51
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* 名称解析(ADR 0051):有 R1 结果时取规范名,否则保留原写法。
|
|
56
|
+
*/
|
|
57
|
+
function canonicalOf(name, resolved) {
|
|
58
|
+
return resolved?.canonical ?? name;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 在已附加的 origin 上记录 R1 的原写法与角色(仅 written !== canonical 时)。
|
|
62
|
+
* 无 R1 结果或节点无 origin 时原样返回,保证未解析的 AST 降级结果不变。
|
|
63
|
+
*/
|
|
64
|
+
function withResolution(coreNode, resolved) {
|
|
65
|
+
if (!resolved)
|
|
66
|
+
return coreNode;
|
|
67
|
+
const origin = withResolvedOrigin(coreNode.origin, resolved.written, resolved.canonical, resolved.role);
|
|
68
|
+
if (origin && origin !== coreNode.origin) {
|
|
69
|
+
coreNode.origin = origin;
|
|
70
|
+
}
|
|
71
|
+
return coreNode;
|
|
72
|
+
}
|
|
52
73
|
/**
|
|
53
74
|
* 将效果能力(effectCaps)从 AST Func 节点传递到 Core IR Func 节点。
|
|
54
75
|
*
|
|
@@ -181,22 +202,8 @@ function lowerConstraints(constraints) {
|
|
|
181
202
|
* @param ast - AST Module 节点(通过 parser.parse 生成)
|
|
182
203
|
* @returns Core IR Module 节点,包含所有声明的规范化表示
|
|
183
204
|
*
|
|
184
|
-
* @
|
|
185
|
-
*
|
|
186
|
-
* import { canonicalize, lex, parse, lowerModule } from '@aster-cloud/aster-lang-ts';
|
|
187
|
-
*
|
|
188
|
-
* const src = `Module app.
|
|
189
|
-
* Rule greet, produce Text:
|
|
190
|
-
* Return "Hello".
|
|
191
|
-
* `;
|
|
192
|
-
*
|
|
193
|
-
* const ast = parse(lex(canonicalize(src)));
|
|
194
|
-
* const core = lowerModule(ast);
|
|
195
|
-
*
|
|
196
|
-
* console.log(core.kind); // "Module"
|
|
197
|
-
* console.log(core.name); // "app"
|
|
198
|
-
* // Core IR 是更简洁的表示,适合类型检查和代码生成
|
|
199
|
-
* ```
|
|
205
|
+
* @internal 不从包入口导出:未经 R1 的 AST 降级后名字保持原写法(可能是本地化名)。
|
|
206
|
+
* 外部调用方使用 resolveAndLowerChecked(compile-pipeline)或 browser `compile`。
|
|
200
207
|
*/
|
|
201
208
|
export function lowerModule(ast) {
|
|
202
209
|
const decls = ast.decls.map(lowerDecl);
|
|
@@ -208,9 +215,9 @@ function lowerDecl(d) {
|
|
|
208
215
|
case 'Import':
|
|
209
216
|
return withOrigin(Core.Import(d.name, d.asName || null, d.version), d);
|
|
210
217
|
case 'Data':
|
|
211
|
-
return withOrigin(Core.Data(d.name, d.fields.map(f => {
|
|
218
|
+
return withResolution(withOrigin(Core.Data(canonicalOf(d.name, d.resolved), d.fields.map(f => {
|
|
212
219
|
const field = {
|
|
213
|
-
name: f.name,
|
|
220
|
+
name: canonicalOf(f.name, f.resolved),
|
|
214
221
|
type: lowerType(f.type),
|
|
215
222
|
constraints: lowerConstraints(f.constraints),
|
|
216
223
|
};
|
|
@@ -218,9 +225,9 @@ function lowerDecl(d) {
|
|
|
218
225
|
if (f.typeInferred)
|
|
219
226
|
markFieldTypeInferred(field);
|
|
220
227
|
return field;
|
|
221
|
-
})), d);
|
|
228
|
+
})), d), d.resolved);
|
|
222
229
|
case 'Enum':
|
|
223
|
-
return withOrigin(Core.Enum(d.name,
|
|
230
|
+
return withResolution(withOrigin(Core.Enum(canonicalOf(d.name, d.resolved), d.variants.map((v, i) => canonicalOf(v, d.resolvedVariants?.[i]))), d), d.resolved);
|
|
224
231
|
case 'Func':
|
|
225
232
|
return lowerFunc(d);
|
|
226
233
|
default: {
|
|
@@ -261,13 +268,13 @@ function lowerFunc(f) {
|
|
|
261
268
|
throw new Error('unreachable'); // For TypeScript's control flow analysis
|
|
262
269
|
}
|
|
263
270
|
const body = f.body ? lowerBlock(f.body) : Core.Block([]);
|
|
264
|
-
const out = Core.Func(f.name, f.typeParams ?? [], params, ret, effects, body, f.effectCaps, f.effectCapsExplicit, f.effectParams, declaredEffects, f.annotations ?? []);
|
|
271
|
+
const out = Core.Func(canonicalOf(f.name, f.resolved), f.typeParams ?? [], params, ret, effects, body, f.effectCaps, f.effectCapsExplicit, f.effectParams, declaredEffects, f.annotations ?? []);
|
|
265
272
|
if (f.retTypeInferred) {
|
|
266
273
|
out.retTypeInferred = true;
|
|
267
274
|
}
|
|
268
275
|
// 传递能力与 PII 元数据,并附带源位置信息
|
|
269
276
|
const enriched = withFuncPiiMetadata(withEffectCaps(out, f));
|
|
270
|
-
return withOrigin(enriched, f);
|
|
277
|
+
return withResolution(withOrigin(enriched, f), f.resolved);
|
|
271
278
|
}
|
|
272
279
|
function lowerBlock(b) {
|
|
273
280
|
return withOrigin(Core.Block(b.statements.map(lowerStmt)), b);
|
|
@@ -276,8 +283,12 @@ function lowerStmt(s) {
|
|
|
276
283
|
switch (s.kind) {
|
|
277
284
|
case 'Let':
|
|
278
285
|
return withOrigin(Core.Let(s.name, lowerExpr(s.expr)), s);
|
|
279
|
-
case 'Set':
|
|
280
|
-
|
|
286
|
+
case 'Set': {
|
|
287
|
+
// Set 目标属于 FIELD_REF,R1 不解析:保留原写法交给 R2
|
|
288
|
+
const set = withOrigin(Core.Set(s.name, lowerExpr(s.expr)), s);
|
|
289
|
+
markForResolution(set, { written: s.name });
|
|
290
|
+
return set;
|
|
291
|
+
}
|
|
281
292
|
case 'Return':
|
|
282
293
|
return withOrigin(Core.Return(lowerExpr(s.expr)), s);
|
|
283
294
|
case 'If':
|
|
@@ -441,7 +452,7 @@ function patternBindings(p) {
|
|
|
441
452
|
* (`AstBuilderTest.testMethodCallTransformsReceiver`);此处职责是对齐,
|
|
442
453
|
* 不是重新设计。若要改语义,应走 ADR。
|
|
443
454
|
*/
|
|
444
|
-
function splitUfcsReceiver(target) {
|
|
455
|
+
function splitUfcsReceiver(target, unresolvedTarget) {
|
|
445
456
|
if (!target || target.kind !== 'Name')
|
|
446
457
|
return null;
|
|
447
458
|
const full = target.name;
|
|
@@ -473,12 +484,17 @@ function splitUfcsReceiver(target) {
|
|
|
473
484
|
receiver.origin = span;
|
|
474
485
|
method.origin = span;
|
|
475
486
|
}
|
|
487
|
+
// 拆分前的点分名由 R1 留给 R2 时,拆出的接收者与方法名同样交给 R2(均为裸名)
|
|
488
|
+
if (unresolvedTarget) {
|
|
489
|
+
markForResolution(receiver, { written: head, ufcs: true });
|
|
490
|
+
markForResolution(method, { written: full.slice(dot + 1), ufcs: true });
|
|
491
|
+
}
|
|
476
492
|
return { receiver, method };
|
|
477
493
|
}
|
|
478
494
|
function lowerExpr(e) {
|
|
479
495
|
switch (e.kind) {
|
|
480
496
|
case 'Name':
|
|
481
|
-
return
|
|
497
|
+
return lowerName(e);
|
|
482
498
|
case 'Bool':
|
|
483
499
|
return withOrigin(Core.Bool(e.value), e);
|
|
484
500
|
case 'Int':
|
|
@@ -541,14 +557,14 @@ function lowerExpr(e) {
|
|
|
541
557
|
// 而不是单方面改变语义。若要重新设计,应走 ADR。
|
|
542
558
|
const target = lowerExpr(e.target);
|
|
543
559
|
const loweredArgs = e.args.map(lowerExpr);
|
|
544
|
-
const ufcs = splitUfcsReceiver(target);
|
|
560
|
+
const ufcs = splitUfcsReceiver(target, e.target.kind === 'Name' && !e.target.resolved);
|
|
545
561
|
if (ufcs) {
|
|
546
562
|
return withOrigin(Core.Call(ufcs.method, [ufcs.receiver, ...loweredArgs]), e);
|
|
547
563
|
}
|
|
548
564
|
return withOrigin(Core.Call(target, loweredArgs), e);
|
|
549
565
|
}
|
|
550
566
|
case 'Construct':
|
|
551
|
-
return withOrigin(Core.Construct(e.typeName, e.fields.map(f => ({ name: f.name, expr: lowerExpr(f.expr) }))), e);
|
|
567
|
+
return withResolution(withOrigin(Core.Construct(canonicalOf(e.typeName, e.resolved), e.fields.map(f => ({ name: canonicalOf(f.name, f.resolved), expr: lowerExpr(f.expr) }))), e), e.resolved);
|
|
552
568
|
case 'Ok':
|
|
553
569
|
return withOrigin(Core.Ok(lowerExpr(e.expr)), e);
|
|
554
570
|
case 'Err':
|
|
@@ -638,15 +654,23 @@ function lowerExpr(e) {
|
|
|
638
654
|
}
|
|
639
655
|
return;
|
|
640
656
|
}
|
|
641
|
-
|
|
642
|
-
|
|
657
|
+
// 以 R1 规范名记录捕获(未解析时即原写法;R2 再按其解析结果改写)
|
|
658
|
+
const captured = ex.kind === 'Name' ? canonicalOf(ex.name, ex.resolved) : '';
|
|
659
|
+
if (ex.kind === 'Name' && !isBound(captured) && !captured.includes('.')) {
|
|
660
|
+
names.add(captured);
|
|
643
661
|
}
|
|
644
662
|
super.visitExpression(ex, ctx);
|
|
645
663
|
}
|
|
646
664
|
}
|
|
647
665
|
new CaptureVisitor().visitBlock(e.body, undefined);
|
|
648
666
|
const captures = Array.from(names);
|
|
649
|
-
const coreParams = e.params.map(p =>
|
|
667
|
+
const coreParams = e.params.map(p => {
|
|
668
|
+
const param = { name: p.name, type: lowerType(p.type) };
|
|
669
|
+
// 解析器对未标注类型的 lambda 参数同样写入 typeInferred(Parameter),BaseParameter 未声明该字段
|
|
670
|
+
if (p.typeInferred)
|
|
671
|
+
markLambdaParamTypeInferred(param);
|
|
672
|
+
return param;
|
|
673
|
+
});
|
|
650
674
|
const ret = lowerType(e.retType);
|
|
651
675
|
const lambda = {
|
|
652
676
|
kind: 'Lambda',
|
|
@@ -672,13 +696,14 @@ function lowerPattern(p) {
|
|
|
672
696
|
return withOrigin(Core.PatNull(), p);
|
|
673
697
|
case 'PatternInt':
|
|
674
698
|
return withOrigin(Core.PatInt(p.value), p);
|
|
675
|
-
case 'PatternCtor':
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
699
|
+
case 'PatternCtor':
|
|
700
|
+
return lowerPatternCtor(p);
|
|
701
|
+
case 'PatternName': {
|
|
702
|
+
// 模式名可能是期望枚举下的成员(ADR 0051 裁决 R12),由 R2 判定
|
|
703
|
+
const pat = withOrigin(Core.PatName(p.name), p);
|
|
704
|
+
markForResolution(pat, { written: p.name });
|
|
705
|
+
return pat;
|
|
679
706
|
}
|
|
680
|
-
case 'PatternName':
|
|
681
|
-
return withOrigin(Core.PatName(p.name), p);
|
|
682
707
|
default: {
|
|
683
708
|
const { span } = extractMetadata(p);
|
|
684
709
|
const kind = p.kind;
|
|
@@ -687,6 +712,28 @@ function lowerPattern(p) {
|
|
|
687
712
|
}
|
|
688
713
|
}
|
|
689
714
|
}
|
|
715
|
+
function lowerPatternCtor(p) {
|
|
716
|
+
const args = p.args ? p.args.map(pp => lowerPattern(pp)) : undefined;
|
|
717
|
+
const pat = withResolution(withOrigin(Core.PatCtor(canonicalOf(p.typeName, p.resolved), [...(p.names ?? [])], args), p), p.resolved);
|
|
718
|
+
// 主语类型在 R1 未知的用户构造器留给 R2;关键词构造器不查词汇
|
|
719
|
+
if (!p.resolved && !KEYWORD_CTORS.has(p.typeName))
|
|
720
|
+
markForResolution(pat, { written: p.typeName });
|
|
721
|
+
return pat;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* 值位置名字:R1 已解析的取规范名。裸单段名一律交给 R2(期望类型为枚举时结果可能改变),
|
|
725
|
+
* 并记下 R1 的角色;R1 未决定的点分名(字段路径、限定调用)同样交给 R2。
|
|
726
|
+
*/
|
|
727
|
+
function lowerName(e) {
|
|
728
|
+
const node = withResolution(withOrigin(Core.Name(canonicalOf(e.name, e.resolved)), e), e.resolved);
|
|
729
|
+
if (!e.name.includes('.')) {
|
|
730
|
+
markForResolution(node, e.resolved ? { written: e.name, r1Role: e.resolved.role } : { written: e.name });
|
|
731
|
+
}
|
|
732
|
+
else if (!e.resolved) {
|
|
733
|
+
markForResolution(node, { written: e.name });
|
|
734
|
+
}
|
|
735
|
+
return node;
|
|
736
|
+
}
|
|
690
737
|
function spanToOrigin(span, file) {
|
|
691
738
|
if (!span)
|
|
692
739
|
return null;
|
|
@@ -702,11 +749,11 @@ function spanToOrigin(span, file) {
|
|
|
702
749
|
function lowerType(t) {
|
|
703
750
|
switch (t.kind) {
|
|
704
751
|
case 'TypeName':
|
|
705
|
-
return withOrigin(Core.TypeName(t.name), t);
|
|
752
|
+
return withResolution(withOrigin(Core.TypeName(canonicalOf(t.name, t.resolved)), t), t.resolved);
|
|
706
753
|
case 'TypeVar':
|
|
707
754
|
return withOrigin(Core.TypeVar(t.name), t);
|
|
708
755
|
case 'TypeApp':
|
|
709
|
-
return withOrigin(Core.TypeApp(t.base, t.args.map(lowerType)), t);
|
|
756
|
+
return withResolution(withOrigin(Core.TypeApp(canonicalOf(t.base, t.resolved), t.args.map(lowerType)), t), t.resolved);
|
|
710
757
|
case 'Maybe':
|
|
711
758
|
return withOrigin(Core.Maybe(lowerType(t.type)), t);
|
|
712
759
|
case 'Option':
|
|
@@ -719,6 +766,8 @@ function lowerType(t) {
|
|
|
719
766
|
return withOrigin(Core.Map(lowerType(t.key), lowerType(t.val)), t);
|
|
720
767
|
case 'TypePii':
|
|
721
768
|
return withOrigin(Core.Pii(lowerType(t.baseType), t.sensitivity, t.category), t);
|
|
769
|
+
case 'FuncType':
|
|
770
|
+
return withOrigin(Core.FuncType(t.params.map(lowerType), lowerType(t.ret)), t);
|
|
722
771
|
default: {
|
|
723
772
|
const { span } = extractMetadata(t);
|
|
724
773
|
const kind = t.kind;
|
|
@@ -727,12 +776,22 @@ function lowerType(t) {
|
|
|
727
776
|
}
|
|
728
777
|
}
|
|
729
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* 函数签名类型名的解析记录(ADR 0051 §4,与 Java 对齐):签名类型平时不带 origin,
|
|
781
|
+
* 仅当写法被改写(written !== canonical)时才附加带 written/role 的 origin,
|
|
782
|
+
* 因此无词汇或规范名直写的签名 IR 保持逐字节不变。
|
|
783
|
+
*/
|
|
784
|
+
function withSignatureResolution(coreNode, astNode, resolved) {
|
|
785
|
+
if (!resolved || resolved.written === resolved.canonical)
|
|
786
|
+
return coreNode;
|
|
787
|
+
return withResolution(withOrigin(coreNode, astNode), resolved);
|
|
788
|
+
}
|
|
730
789
|
function lowerTypeWithVars(t, vars) {
|
|
731
790
|
switch (t.kind) {
|
|
732
791
|
case 'TypeName':
|
|
733
792
|
return vars.has(t.name)
|
|
734
793
|
? { kind: 'TypeVar', name: t.name }
|
|
735
|
-
: Core.TypeName(t.name);
|
|
794
|
+
: withSignatureResolution(Core.TypeName(canonicalOf(t.name, t.resolved)), t, t.resolved);
|
|
736
795
|
case 'EffectVar':
|
|
737
796
|
return { kind: 'EffectVar', name: t.name };
|
|
738
797
|
case 'Maybe':
|
|
@@ -746,15 +805,17 @@ function lowerTypeWithVars(t, vars) {
|
|
|
746
805
|
case 'Map':
|
|
747
806
|
return Core.Map(lowerTypeWithVars(t.key, vars), lowerTypeWithVars(t.val, vars));
|
|
748
807
|
case 'TypeApp':
|
|
749
|
-
return {
|
|
808
|
+
return withSignatureResolution({
|
|
750
809
|
kind: 'TypeApp',
|
|
751
|
-
base: t.base,
|
|
810
|
+
base: canonicalOf(t.base, t.resolved),
|
|
752
811
|
args: t.args.map(tt => lowerTypeWithVars(tt, vars)),
|
|
753
|
-
};
|
|
812
|
+
}, t, t.resolved);
|
|
754
813
|
case 'TypeVar':
|
|
755
814
|
return { kind: 'TypeVar', name: t.name };
|
|
756
815
|
case 'TypePii':
|
|
757
816
|
return Core.Pii(lowerTypeWithVars(t.baseType, vars), t.sensitivity, t.category);
|
|
817
|
+
case 'FuncType':
|
|
818
|
+
return Core.FuncType(t.params.map(p => lowerTypeWithVars(p, vars)), lowerTypeWithVars(t.ret, vars));
|
|
758
819
|
default:
|
|
759
820
|
return lowerType(t);
|
|
760
821
|
}
|